blob: b652201eadad234930a305264ce2988fc907695c [file] [log] [blame]
Thierry Reding6b6b6042013-11-15 16:06:05 +01001/*
2 * Copyright (C) 2013 NVIDIA Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/clk.h>
Thierry Redingb2992212015-10-01 14:25:03 +020010#include <linux/clk-provider.h>
Thierry Redinga82752e2014-01-31 10:02:15 +010011#include <linux/debugfs.h>
Thierry Reding6fad8f62014-11-28 15:41:34 +010012#include <linux/gpio.h>
Thierry Reding6b6b6042013-11-15 16:06:05 +010013#include <linux/io.h>
Thierry Reding459cc2c2015-07-30 10:34:24 +020014#include <linux/of_device.h>
Thierry Reding6b6b6042013-11-15 16:06:05 +010015#include <linux/platform_device.h>
Thierry Redingaaff8bd2015-08-07 16:04:54 +020016#include <linux/pm_runtime.h>
Thierry Reding459cc2c2015-07-30 10:34:24 +020017#include <linux/regulator/consumer.h>
Thierry Reding6b6b6042013-11-15 16:06:05 +010018#include <linux/reset.h>
Thierry Reding306a7f92014-07-17 13:17:24 +020019
Thierry Reding72323982014-07-11 13:19:06 +020020#include <soc/tegra/pmc.h>
Thierry Reding6b6b6042013-11-15 16:06:05 +010021
Thierry Reding4aa3df72014-11-24 16:27:13 +010022#include <drm/drm_atomic_helper.h>
Thierry Reding6b6b6042013-11-15 16:06:05 +010023#include <drm/drm_dp_helper.h>
Thierry Reding6fad8f62014-11-28 15:41:34 +010024#include <drm/drm_panel.h>
Thierry Reding6b6b6042013-11-15 16:06:05 +010025
26#include "dc.h"
27#include "drm.h"
28#include "sor.h"
29
Thierry Reding459cc2c2015-07-30 10:34:24 +020030#define SOR_REKEY 0x38
31
32struct tegra_sor_hdmi_settings {
33 unsigned long frequency;
34
35 u8 vcocap;
36 u8 ichpmp;
37 u8 loadadj;
38 u8 termadj;
39 u8 tx_pu;
40 u8 bg_vref;
41
42 u8 drive_current[4];
43 u8 preemphasis[4];
44};
45
46#if 1
47static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = {
48 {
49 .frequency = 54000000,
50 .vcocap = 0x0,
51 .ichpmp = 0x1,
52 .loadadj = 0x3,
53 .termadj = 0x9,
54 .tx_pu = 0x10,
55 .bg_vref = 0x8,
56 .drive_current = { 0x33, 0x3a, 0x3a, 0x3a },
57 .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
58 }, {
59 .frequency = 75000000,
60 .vcocap = 0x3,
61 .ichpmp = 0x1,
62 .loadadj = 0x3,
63 .termadj = 0x9,
64 .tx_pu = 0x40,
65 .bg_vref = 0x8,
66 .drive_current = { 0x33, 0x3a, 0x3a, 0x3a },
67 .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
68 }, {
69 .frequency = 150000000,
70 .vcocap = 0x3,
71 .ichpmp = 0x1,
72 .loadadj = 0x3,
73 .termadj = 0x9,
74 .tx_pu = 0x66,
75 .bg_vref = 0x8,
76 .drive_current = { 0x33, 0x3a, 0x3a, 0x3a },
77 .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
78 }, {
79 .frequency = 300000000,
80 .vcocap = 0x3,
81 .ichpmp = 0x1,
82 .loadadj = 0x3,
83 .termadj = 0x9,
84 .tx_pu = 0x66,
85 .bg_vref = 0xa,
86 .drive_current = { 0x33, 0x3f, 0x3f, 0x3f },
87 .preemphasis = { 0x00, 0x17, 0x17, 0x17 },
88 }, {
89 .frequency = 600000000,
90 .vcocap = 0x3,
91 .ichpmp = 0x1,
92 .loadadj = 0x3,
93 .termadj = 0x9,
94 .tx_pu = 0x66,
95 .bg_vref = 0x8,
96 .drive_current = { 0x33, 0x3f, 0x3f, 0x3f },
97 .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
98 },
99};
100#else
101static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = {
102 {
103 .frequency = 75000000,
104 .vcocap = 0x3,
105 .ichpmp = 0x1,
106 .loadadj = 0x3,
107 .termadj = 0x9,
108 .tx_pu = 0x40,
109 .bg_vref = 0x8,
110 .drive_current = { 0x29, 0x29, 0x29, 0x29 },
111 .preemphasis = { 0x00, 0x00, 0x00, 0x00 },
112 }, {
113 .frequency = 150000000,
114 .vcocap = 0x3,
115 .ichpmp = 0x1,
116 .loadadj = 0x3,
117 .termadj = 0x9,
118 .tx_pu = 0x66,
119 .bg_vref = 0x8,
120 .drive_current = { 0x30, 0x37, 0x37, 0x37 },
121 .preemphasis = { 0x01, 0x02, 0x02, 0x02 },
122 }, {
123 .frequency = 300000000,
124 .vcocap = 0x3,
125 .ichpmp = 0x6,
126 .loadadj = 0x3,
127 .termadj = 0x9,
128 .tx_pu = 0x66,
129 .bg_vref = 0xf,
130 .drive_current = { 0x30, 0x37, 0x37, 0x37 },
131 .preemphasis = { 0x10, 0x3e, 0x3e, 0x3e },
132 }, {
133 .frequency = 600000000,
134 .vcocap = 0x3,
135 .ichpmp = 0xa,
136 .loadadj = 0x3,
137 .termadj = 0xb,
138 .tx_pu = 0x66,
139 .bg_vref = 0xe,
140 .drive_current = { 0x35, 0x3e, 0x3e, 0x3e },
141 .preemphasis = { 0x02, 0x3f, 0x3f, 0x3f },
142 },
143};
144#endif
145
146struct tegra_sor_soc {
147 bool supports_edp;
148 bool supports_lvds;
149 bool supports_hdmi;
150 bool supports_dp;
151
152 const struct tegra_sor_hdmi_settings *settings;
153 unsigned int num_settings;
Thierry Reding30b49432015-08-03 15:50:32 +0200154
155 const u8 *xbar_cfg;
Thierry Reding459cc2c2015-07-30 10:34:24 +0200156};
157
158struct tegra_sor;
159
160struct tegra_sor_ops {
161 const char *name;
162 int (*probe)(struct tegra_sor *sor);
163 int (*remove)(struct tegra_sor *sor);
164};
165
Thierry Reding6b6b6042013-11-15 16:06:05 +0100166struct tegra_sor {
167 struct host1x_client client;
168 struct tegra_output output;
169 struct device *dev;
170
Thierry Reding459cc2c2015-07-30 10:34:24 +0200171 const struct tegra_sor_soc *soc;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100172 void __iomem *regs;
173
174 struct reset_control *rst;
175 struct clk *clk_parent;
Thierry Redingb2992212015-10-01 14:25:03 +0200176 struct clk *clk_brick;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100177 struct clk *clk_safe;
Thierry Reding618dee32016-06-09 17:53:57 +0200178 struct clk *clk_src;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100179 struct clk *clk_dp;
180 struct clk *clk;
181
Thierry Reding9542c232015-07-08 13:39:09 +0200182 struct drm_dp_aux *aux;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100183
Thierry Redingdab16332015-01-26 16:04:08 +0100184 struct drm_info_list *debugfs_files;
185 struct drm_minor *minor;
Thierry Redinga82752e2014-01-31 10:02:15 +0100186 struct dentry *debugfs;
Thierry Reding459cc2c2015-07-30 10:34:24 +0200187
188 const struct tegra_sor_ops *ops;
189
190 /* for HDMI 2.0 */
191 struct tegra_sor_hdmi_settings *settings;
192 unsigned int num_settings;
193
194 struct regulator *avdd_io_supply;
195 struct regulator *vdd_pll_supply;
196 struct regulator *hdmi_supply;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100197};
198
Thierry Redingc31efa72015-09-08 16:09:22 +0200199struct tegra_sor_state {
200 struct drm_connector_state base;
201
202 unsigned int bpc;
203};
204
205static inline struct tegra_sor_state *
206to_sor_state(struct drm_connector_state *state)
207{
208 return container_of(state, struct tegra_sor_state, base);
209}
210
Thierry Reding34fa1832014-06-05 16:31:10 +0200211struct tegra_sor_config {
212 u32 bits_per_pixel;
213
214 u32 active_polarity;
215 u32 active_count;
216 u32 tu_size;
217 u32 active_frac;
218 u32 watermark;
Thierry Reding7890b572014-06-05 16:12:46 +0200219
220 u32 hblank_symbols;
221 u32 vblank_symbols;
Thierry Reding34fa1832014-06-05 16:31:10 +0200222};
223
Thierry Reding6b6b6042013-11-15 16:06:05 +0100224static inline struct tegra_sor *
225host1x_client_to_sor(struct host1x_client *client)
226{
227 return container_of(client, struct tegra_sor, client);
228}
229
230static inline struct tegra_sor *to_sor(struct tegra_output *output)
231{
232 return container_of(output, struct tegra_sor, output);
233}
234
Thierry Reding28fe2072015-01-26 16:02:48 +0100235static inline u32 tegra_sor_readl(struct tegra_sor *sor, unsigned long offset)
Thierry Reding6b6b6042013-11-15 16:06:05 +0100236{
237 return readl(sor->regs + (offset << 2));
238}
239
Thierry Reding28fe2072015-01-26 16:02:48 +0100240static inline void tegra_sor_writel(struct tegra_sor *sor, u32 value,
Thierry Reding6b6b6042013-11-15 16:06:05 +0100241 unsigned long offset)
242{
243 writel(value, sor->regs + (offset << 2));
244}
245
Thierry Reding25bb2ce2015-08-03 14:23:29 +0200246static int tegra_sor_set_parent_clock(struct tegra_sor *sor, struct clk *parent)
247{
248 int err;
249
250 clk_disable_unprepare(sor->clk);
251
252 err = clk_set_parent(sor->clk, parent);
253 if (err < 0)
254 return err;
255
256 err = clk_prepare_enable(sor->clk);
257 if (err < 0)
258 return err;
259
260 return 0;
261}
262
Thierry Redingb2992212015-10-01 14:25:03 +0200263struct tegra_clk_sor_brick {
264 struct clk_hw hw;
265 struct tegra_sor *sor;
266};
267
268static inline struct tegra_clk_sor_brick *to_brick(struct clk_hw *hw)
269{
270 return container_of(hw, struct tegra_clk_sor_brick, hw);
271}
272
273static const char * const tegra_clk_sor_brick_parents[] = {
274 "pll_d2_out0", "pll_dp"
275};
276
277static int tegra_clk_sor_brick_set_parent(struct clk_hw *hw, u8 index)
278{
279 struct tegra_clk_sor_brick *brick = to_brick(hw);
280 struct tegra_sor *sor = brick->sor;
281 u32 value;
282
283 value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
284 value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
285
286 switch (index) {
287 case 0:
288 value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK;
289 break;
290
291 case 1:
292 value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK;
293 break;
294 }
295
296 tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
297
298 return 0;
299}
300
301static u8 tegra_clk_sor_brick_get_parent(struct clk_hw *hw)
302{
303 struct tegra_clk_sor_brick *brick = to_brick(hw);
304 struct tegra_sor *sor = brick->sor;
305 u8 parent = U8_MAX;
306 u32 value;
307
308 value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
309
310 switch (value & SOR_CLK_CNTRL_DP_CLK_SEL_MASK) {
311 case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK:
312 case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_PCLK:
313 parent = 0;
314 break;
315
316 case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK:
317 case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_DPCLK:
318 parent = 1;
319 break;
320 }
321
322 return parent;
323}
324
325static const struct clk_ops tegra_clk_sor_brick_ops = {
326 .set_parent = tegra_clk_sor_brick_set_parent,
327 .get_parent = tegra_clk_sor_brick_get_parent,
328};
329
330static struct clk *tegra_clk_sor_brick_register(struct tegra_sor *sor,
331 const char *name)
332{
333 struct tegra_clk_sor_brick *brick;
334 struct clk_init_data init;
335 struct clk *clk;
336
337 brick = devm_kzalloc(sor->dev, sizeof(*brick), GFP_KERNEL);
338 if (!brick)
339 return ERR_PTR(-ENOMEM);
340
341 brick->sor = sor;
342
343 init.name = name;
344 init.flags = 0;
345 init.parent_names = tegra_clk_sor_brick_parents;
346 init.num_parents = ARRAY_SIZE(tegra_clk_sor_brick_parents);
347 init.ops = &tegra_clk_sor_brick_ops;
348
349 brick->hw.init = &init;
350
351 clk = devm_clk_register(sor->dev, &brick->hw);
352 if (IS_ERR(clk))
353 kfree(brick);
354
355 return clk;
356}
357
Thierry Reding6b6b6042013-11-15 16:06:05 +0100358static int tegra_sor_dp_train_fast(struct tegra_sor *sor,
359 struct drm_dp_link *link)
360{
Thierry Reding6b6b6042013-11-15 16:06:05 +0100361 unsigned int i;
362 u8 pattern;
Thierry Reding28fe2072015-01-26 16:02:48 +0100363 u32 value;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100364 int err;
365
366 /* setup lane parameters */
367 value = SOR_LANE_DRIVE_CURRENT_LANE3(0x40) |
368 SOR_LANE_DRIVE_CURRENT_LANE2(0x40) |
369 SOR_LANE_DRIVE_CURRENT_LANE1(0x40) |
370 SOR_LANE_DRIVE_CURRENT_LANE0(0x40);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200371 tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100372
373 value = SOR_LANE_PREEMPHASIS_LANE3(0x0f) |
374 SOR_LANE_PREEMPHASIS_LANE2(0x0f) |
375 SOR_LANE_PREEMPHASIS_LANE1(0x0f) |
376 SOR_LANE_PREEMPHASIS_LANE0(0x0f);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200377 tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100378
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200379 value = SOR_LANE_POSTCURSOR_LANE3(0x00) |
380 SOR_LANE_POSTCURSOR_LANE2(0x00) |
381 SOR_LANE_POSTCURSOR_LANE1(0x00) |
382 SOR_LANE_POSTCURSOR_LANE0(0x00);
383 tegra_sor_writel(sor, value, SOR_LANE_POSTCURSOR0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100384
385 /* disable LVDS mode */
386 tegra_sor_writel(sor, 0, SOR_LVDS);
387
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200388 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100389 value |= SOR_DP_PADCTL_TX_PU_ENABLE;
390 value &= ~SOR_DP_PADCTL_TX_PU_MASK;
391 value |= SOR_DP_PADCTL_TX_PU(2); /* XXX: don't hardcode? */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200392 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100393
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200394 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100395 value |= SOR_DP_PADCTL_CM_TXD_3 | SOR_DP_PADCTL_CM_TXD_2 |
396 SOR_DP_PADCTL_CM_TXD_1 | SOR_DP_PADCTL_CM_TXD_0;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200397 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100398
399 usleep_range(10, 100);
400
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200401 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100402 value &= ~(SOR_DP_PADCTL_CM_TXD_3 | SOR_DP_PADCTL_CM_TXD_2 |
403 SOR_DP_PADCTL_CM_TXD_1 | SOR_DP_PADCTL_CM_TXD_0);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200404 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100405
Thierry Reding9542c232015-07-08 13:39:09 +0200406 err = drm_dp_aux_prepare(sor->aux, DP_SET_ANSI_8B10B);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100407 if (err < 0)
408 return err;
409
410 for (i = 0, value = 0; i < link->num_lanes; i++) {
411 unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
412 SOR_DP_TPG_SCRAMBLER_NONE |
413 SOR_DP_TPG_PATTERN_TRAIN1;
414 value = (value << 8) | lane;
415 }
416
417 tegra_sor_writel(sor, value, SOR_DP_TPG);
418
419 pattern = DP_TRAINING_PATTERN_1;
420
Thierry Reding9542c232015-07-08 13:39:09 +0200421 err = drm_dp_aux_train(sor->aux, link, pattern);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100422 if (err < 0)
423 return err;
424
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200425 value = tegra_sor_readl(sor, SOR_DP_SPARE0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100426 value |= SOR_DP_SPARE_SEQ_ENABLE;
427 value &= ~SOR_DP_SPARE_PANEL_INTERNAL;
428 value |= SOR_DP_SPARE_MACRO_SOR_CLK;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200429 tegra_sor_writel(sor, value, SOR_DP_SPARE0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100430
431 for (i = 0, value = 0; i < link->num_lanes; i++) {
432 unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
433 SOR_DP_TPG_SCRAMBLER_NONE |
434 SOR_DP_TPG_PATTERN_TRAIN2;
435 value = (value << 8) | lane;
436 }
437
438 tegra_sor_writel(sor, value, SOR_DP_TPG);
439
440 pattern = DP_LINK_SCRAMBLING_DISABLE | DP_TRAINING_PATTERN_2;
441
Thierry Reding9542c232015-07-08 13:39:09 +0200442 err = drm_dp_aux_train(sor->aux, link, pattern);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100443 if (err < 0)
444 return err;
445
446 for (i = 0, value = 0; i < link->num_lanes; i++) {
447 unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
448 SOR_DP_TPG_SCRAMBLER_GALIOS |
449 SOR_DP_TPG_PATTERN_NONE;
450 value = (value << 8) | lane;
451 }
452
453 tegra_sor_writel(sor, value, SOR_DP_TPG);
454
455 pattern = DP_TRAINING_PATTERN_DISABLE;
456
Thierry Reding9542c232015-07-08 13:39:09 +0200457 err = drm_dp_aux_train(sor->aux, link, pattern);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100458 if (err < 0)
459 return err;
460
461 return 0;
462}
463
Thierry Reding459cc2c2015-07-30 10:34:24 +0200464static void tegra_sor_dp_term_calibrate(struct tegra_sor *sor)
465{
466 u32 mask = 0x08, adj = 0, value;
467
468 /* enable pad calibration logic */
469 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
470 value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
471 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
472
473 value = tegra_sor_readl(sor, SOR_PLL1);
474 value |= SOR_PLL1_TMDS_TERM;
475 tegra_sor_writel(sor, value, SOR_PLL1);
476
477 while (mask) {
478 adj |= mask;
479
480 value = tegra_sor_readl(sor, SOR_PLL1);
481 value &= ~SOR_PLL1_TMDS_TERMADJ_MASK;
482 value |= SOR_PLL1_TMDS_TERMADJ(adj);
483 tegra_sor_writel(sor, value, SOR_PLL1);
484
485 usleep_range(100, 200);
486
487 value = tegra_sor_readl(sor, SOR_PLL1);
488 if (value & SOR_PLL1_TERM_COMPOUT)
489 adj &= ~mask;
490
491 mask >>= 1;
492 }
493
494 value = tegra_sor_readl(sor, SOR_PLL1);
495 value &= ~SOR_PLL1_TMDS_TERMADJ_MASK;
496 value |= SOR_PLL1_TMDS_TERMADJ(adj);
497 tegra_sor_writel(sor, value, SOR_PLL1);
498
499 /* disable pad calibration logic */
500 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
501 value |= SOR_DP_PADCTL_PAD_CAL_PD;
502 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
503}
504
Thierry Reding6b6b6042013-11-15 16:06:05 +0100505static void tegra_sor_super_update(struct tegra_sor *sor)
506{
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200507 tegra_sor_writel(sor, 0, SOR_SUPER_STATE0);
508 tegra_sor_writel(sor, 1, SOR_SUPER_STATE0);
509 tegra_sor_writel(sor, 0, SOR_SUPER_STATE0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100510}
511
512static void tegra_sor_update(struct tegra_sor *sor)
513{
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200514 tegra_sor_writel(sor, 0, SOR_STATE0);
515 tegra_sor_writel(sor, 1, SOR_STATE0);
516 tegra_sor_writel(sor, 0, SOR_STATE0);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100517}
518
519static int tegra_sor_setup_pwm(struct tegra_sor *sor, unsigned long timeout)
520{
Thierry Reding28fe2072015-01-26 16:02:48 +0100521 u32 value;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100522
523 value = tegra_sor_readl(sor, SOR_PWM_DIV);
524 value &= ~SOR_PWM_DIV_MASK;
525 value |= 0x400; /* period */
526 tegra_sor_writel(sor, value, SOR_PWM_DIV);
527
528 value = tegra_sor_readl(sor, SOR_PWM_CTL);
529 value &= ~SOR_PWM_CTL_DUTY_CYCLE_MASK;
530 value |= 0x400; /* duty cycle */
531 value &= ~SOR_PWM_CTL_CLK_SEL; /* clock source: PCLK */
532 value |= SOR_PWM_CTL_TRIGGER;
533 tegra_sor_writel(sor, value, SOR_PWM_CTL);
534
535 timeout = jiffies + msecs_to_jiffies(timeout);
536
537 while (time_before(jiffies, timeout)) {
538 value = tegra_sor_readl(sor, SOR_PWM_CTL);
539 if ((value & SOR_PWM_CTL_TRIGGER) == 0)
540 return 0;
541
542 usleep_range(25, 100);
543 }
544
545 return -ETIMEDOUT;
546}
547
548static int tegra_sor_attach(struct tegra_sor *sor)
549{
550 unsigned long value, timeout;
551
552 /* wake up in normal mode */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200553 value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100554 value |= SOR_SUPER_STATE_HEAD_MODE_AWAKE;
555 value |= SOR_SUPER_STATE_MODE_NORMAL;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200556 tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100557 tegra_sor_super_update(sor);
558
559 /* attach */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200560 value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100561 value |= SOR_SUPER_STATE_ATTACHED;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200562 tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
Thierry Reding6b6b6042013-11-15 16:06:05 +0100563 tegra_sor_super_update(sor);
564
565 timeout = jiffies + msecs_to_jiffies(250);
566
567 while (time_before(jiffies, timeout)) {
568 value = tegra_sor_readl(sor, SOR_TEST);
569 if ((value & SOR_TEST_ATTACHED) != 0)
570 return 0;
571
572 usleep_range(25, 100);
573 }
574
575 return -ETIMEDOUT;
576}
577
578static int tegra_sor_wakeup(struct tegra_sor *sor)
579{
Thierry Reding6b6b6042013-11-15 16:06:05 +0100580 unsigned long value, timeout;
581
Thierry Reding6b6b6042013-11-15 16:06:05 +0100582 timeout = jiffies + msecs_to_jiffies(250);
583
584 /* wait for head to wake up */
585 while (time_before(jiffies, timeout)) {
586 value = tegra_sor_readl(sor, SOR_TEST);
587 value &= SOR_TEST_HEAD_MODE_MASK;
588
589 if (value == SOR_TEST_HEAD_MODE_AWAKE)
590 return 0;
591
592 usleep_range(25, 100);
593 }
594
595 return -ETIMEDOUT;
596}
597
598static int tegra_sor_power_up(struct tegra_sor *sor, unsigned long timeout)
599{
Thierry Reding28fe2072015-01-26 16:02:48 +0100600 u32 value;
Thierry Reding6b6b6042013-11-15 16:06:05 +0100601
602 value = tegra_sor_readl(sor, SOR_PWR);
603 value |= SOR_PWR_TRIGGER | SOR_PWR_NORMAL_STATE_PU;
604 tegra_sor_writel(sor, value, SOR_PWR);
605
606 timeout = jiffies + msecs_to_jiffies(timeout);
607
608 while (time_before(jiffies, timeout)) {
609 value = tegra_sor_readl(sor, SOR_PWR);
610 if ((value & SOR_PWR_TRIGGER) == 0)
611 return 0;
612
613 usleep_range(25, 100);
614 }
615
616 return -ETIMEDOUT;
617}
618
Thierry Reding34fa1832014-06-05 16:31:10 +0200619struct tegra_sor_params {
620 /* number of link clocks per line */
621 unsigned int num_clocks;
622 /* ratio between input and output */
623 u64 ratio;
624 /* precision factor */
625 u64 precision;
626
627 unsigned int active_polarity;
628 unsigned int active_count;
629 unsigned int active_frac;
630 unsigned int tu_size;
631 unsigned int error;
632};
633
634static int tegra_sor_compute_params(struct tegra_sor *sor,
635 struct tegra_sor_params *params,
636 unsigned int tu_size)
637{
638 u64 active_sym, active_count, frac, approx;
639 u32 active_polarity, active_frac = 0;
640 const u64 f = params->precision;
641 s64 error;
642
643 active_sym = params->ratio * tu_size;
644 active_count = div_u64(active_sym, f) * f;
645 frac = active_sym - active_count;
646
647 /* fraction < 0.5 */
648 if (frac >= (f / 2)) {
649 active_polarity = 1;
650 frac = f - frac;
651 } else {
652 active_polarity = 0;
653 }
654
655 if (frac != 0) {
656 frac = div_u64(f * f, frac); /* 1/fraction */
657 if (frac <= (15 * f)) {
658 active_frac = div_u64(frac, f);
659
660 /* round up */
661 if (active_polarity)
662 active_frac++;
663 } else {
664 active_frac = active_polarity ? 1 : 15;
665 }
666 }
667
668 if (active_frac == 1)
669 active_polarity = 0;
670
671 if (active_polarity == 1) {
672 if (active_frac) {
673 approx = active_count + (active_frac * (f - 1)) * f;
674 approx = div_u64(approx, active_frac * f);
675 } else {
676 approx = active_count + f;
677 }
678 } else {
679 if (active_frac)
680 approx = active_count + div_u64(f, active_frac);
681 else
682 approx = active_count;
683 }
684
685 error = div_s64(active_sym - approx, tu_size);
686 error *= params->num_clocks;
687
Andrew Morton79211c82015-11-09 14:58:13 -0800688 if (error <= 0 && abs(error) < params->error) {
Thierry Reding34fa1832014-06-05 16:31:10 +0200689 params->active_count = div_u64(active_count, f);
690 params->active_polarity = active_polarity;
691 params->active_frac = active_frac;
Andrew Morton79211c82015-11-09 14:58:13 -0800692 params->error = abs(error);
Thierry Reding34fa1832014-06-05 16:31:10 +0200693 params->tu_size = tu_size;
694
695 if (error == 0)
696 return true;
697 }
698
699 return false;
700}
701
Thierry Redinga1983592015-07-21 16:46:52 +0200702static int tegra_sor_compute_config(struct tegra_sor *sor,
703 const struct drm_display_mode *mode,
704 struct tegra_sor_config *config,
705 struct drm_dp_link *link)
Thierry Reding34fa1832014-06-05 16:31:10 +0200706{
707 const u64 f = 100000, link_rate = link->rate * 1000;
708 const u64 pclk = mode->clock * 1000;
Thierry Reding7890b572014-06-05 16:12:46 +0200709 u64 input, output, watermark, num;
Thierry Reding34fa1832014-06-05 16:31:10 +0200710 struct tegra_sor_params params;
Thierry Reding34fa1832014-06-05 16:31:10 +0200711 u32 num_syms_per_line;
712 unsigned int i;
713
714 if (!link_rate || !link->num_lanes || !pclk || !config->bits_per_pixel)
715 return -EINVAL;
716
717 output = link_rate * 8 * link->num_lanes;
718 input = pclk * config->bits_per_pixel;
719
720 if (input >= output)
721 return -ERANGE;
722
723 memset(&params, 0, sizeof(params));
724 params.ratio = div64_u64(input * f, output);
725 params.num_clocks = div_u64(link_rate * mode->hdisplay, pclk);
726 params.precision = f;
727 params.error = 64 * f;
728 params.tu_size = 64;
729
730 for (i = params.tu_size; i >= 32; i--)
731 if (tegra_sor_compute_params(sor, &params, i))
732 break;
733
734 if (params.active_frac == 0) {
735 config->active_polarity = 0;
736 config->active_count = params.active_count;
737
738 if (!params.active_polarity)
739 config->active_count--;
740
741 config->tu_size = params.tu_size;
742 config->active_frac = 1;
743 } else {
744 config->active_polarity = params.active_polarity;
745 config->active_count = params.active_count;
746 config->active_frac = params.active_frac;
747 config->tu_size = params.tu_size;
748 }
749
750 dev_dbg(sor->dev,
751 "polarity: %d active count: %d tu size: %d active frac: %d\n",
752 config->active_polarity, config->active_count,
753 config->tu_size, config->active_frac);
754
755 watermark = params.ratio * config->tu_size * (f - params.ratio);
756 watermark = div_u64(watermark, f);
757
758 watermark = div_u64(watermark + params.error, f);
759 config->watermark = watermark + (config->bits_per_pixel / 8) + 2;
760 num_syms_per_line = (mode->hdisplay * config->bits_per_pixel) *
761 (link->num_lanes * 8);
762
763 if (config->watermark > 30) {
764 config->watermark = 30;
765 dev_err(sor->dev,
766 "unable to compute TU size, forcing watermark to %u\n",
767 config->watermark);
768 } else if (config->watermark > num_syms_per_line) {
769 config->watermark = num_syms_per_line;
770 dev_err(sor->dev, "watermark too high, forcing to %u\n",
771 config->watermark);
772 }
773
Thierry Reding7890b572014-06-05 16:12:46 +0200774 /* compute the number of symbols per horizontal blanking interval */
775 num = ((mode->htotal - mode->hdisplay) - 7) * link_rate;
776 config->hblank_symbols = div_u64(num, pclk);
777
778 if (link->capabilities & DP_LINK_CAP_ENHANCED_FRAMING)
779 config->hblank_symbols -= 3;
780
781 config->hblank_symbols -= 12 / link->num_lanes;
782
783 /* compute the number of symbols per vertical blanking interval */
784 num = (mode->hdisplay - 25) * link_rate;
785 config->vblank_symbols = div_u64(num, pclk);
786 config->vblank_symbols -= 36 / link->num_lanes + 4;
787
788 dev_dbg(sor->dev, "blank symbols: H:%u V:%u\n", config->hblank_symbols,
789 config->vblank_symbols);
790
Thierry Reding34fa1832014-06-05 16:31:10 +0200791 return 0;
792}
793
Thierry Reding402f6bc2015-07-21 16:48:19 +0200794static void tegra_sor_apply_config(struct tegra_sor *sor,
795 const struct tegra_sor_config *config)
796{
797 u32 value;
798
799 value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
800 value &= ~SOR_DP_LINKCTL_TU_SIZE_MASK;
801 value |= SOR_DP_LINKCTL_TU_SIZE(config->tu_size);
802 tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
803
804 value = tegra_sor_readl(sor, SOR_DP_CONFIG0);
805 value &= ~SOR_DP_CONFIG_WATERMARK_MASK;
806 value |= SOR_DP_CONFIG_WATERMARK(config->watermark);
807
808 value &= ~SOR_DP_CONFIG_ACTIVE_SYM_COUNT_MASK;
809 value |= SOR_DP_CONFIG_ACTIVE_SYM_COUNT(config->active_count);
810
811 value &= ~SOR_DP_CONFIG_ACTIVE_SYM_FRAC_MASK;
812 value |= SOR_DP_CONFIG_ACTIVE_SYM_FRAC(config->active_frac);
813
814 if (config->active_polarity)
815 value |= SOR_DP_CONFIG_ACTIVE_SYM_POLARITY;
816 else
817 value &= ~SOR_DP_CONFIG_ACTIVE_SYM_POLARITY;
818
819 value |= SOR_DP_CONFIG_ACTIVE_SYM_ENABLE;
820 value |= SOR_DP_CONFIG_DISPARITY_NEGATIVE;
821 tegra_sor_writel(sor, value, SOR_DP_CONFIG0);
822
823 value = tegra_sor_readl(sor, SOR_DP_AUDIO_HBLANK_SYMBOLS);
824 value &= ~SOR_DP_AUDIO_HBLANK_SYMBOLS_MASK;
825 value |= config->hblank_symbols & 0xffff;
826 tegra_sor_writel(sor, value, SOR_DP_AUDIO_HBLANK_SYMBOLS);
827
828 value = tegra_sor_readl(sor, SOR_DP_AUDIO_VBLANK_SYMBOLS);
829 value &= ~SOR_DP_AUDIO_VBLANK_SYMBOLS_MASK;
830 value |= config->vblank_symbols & 0xffff;
831 tegra_sor_writel(sor, value, SOR_DP_AUDIO_VBLANK_SYMBOLS);
832}
833
Thierry Reding2bd1dd32015-08-03 15:46:15 +0200834static void tegra_sor_mode_set(struct tegra_sor *sor,
835 const struct drm_display_mode *mode,
Thierry Redingc31efa72015-09-08 16:09:22 +0200836 struct tegra_sor_state *state)
Thierry Reding2bd1dd32015-08-03 15:46:15 +0200837{
838 struct tegra_dc *dc = to_tegra_dc(sor->output.encoder.crtc);
839 unsigned int vbe, vse, hbe, hse, vbs, hbs;
840 u32 value;
841
842 value = tegra_sor_readl(sor, SOR_STATE1);
843 value &= ~SOR_STATE_ASY_PIXELDEPTH_MASK;
844 value &= ~SOR_STATE_ASY_CRC_MODE_MASK;
845 value &= ~SOR_STATE_ASY_OWNER_MASK;
846
847 value |= SOR_STATE_ASY_CRC_MODE_COMPLETE |
848 SOR_STATE_ASY_OWNER(dc->pipe + 1);
849
850 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
851 value &= ~SOR_STATE_ASY_HSYNCPOL;
852
853 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
854 value |= SOR_STATE_ASY_HSYNCPOL;
855
856 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
857 value &= ~SOR_STATE_ASY_VSYNCPOL;
858
859 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
860 value |= SOR_STATE_ASY_VSYNCPOL;
861
Thierry Redingc31efa72015-09-08 16:09:22 +0200862 switch (state->bpc) {
863 case 16:
864 value |= SOR_STATE_ASY_PIXELDEPTH_BPP_48_444;
865 break;
866
867 case 12:
868 value |= SOR_STATE_ASY_PIXELDEPTH_BPP_36_444;
869 break;
870
871 case 10:
872 value |= SOR_STATE_ASY_PIXELDEPTH_BPP_30_444;
873 break;
874
Thierry Reding2bd1dd32015-08-03 15:46:15 +0200875 case 8:
876 value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444;
877 break;
878
879 case 6:
880 value |= SOR_STATE_ASY_PIXELDEPTH_BPP_18_444;
881 break;
882
883 default:
Thierry Redingc31efa72015-09-08 16:09:22 +0200884 value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444;
Thierry Reding2bd1dd32015-08-03 15:46:15 +0200885 break;
886 }
887
888 tegra_sor_writel(sor, value, SOR_STATE1);
889
890 /*
891 * TODO: The video timing programming below doesn't seem to match the
892 * register definitions.
893 */
894
895 value = ((mode->vtotal & 0x7fff) << 16) | (mode->htotal & 0x7fff);
896 tegra_sor_writel(sor, value, SOR_HEAD_STATE1(dc->pipe));
897
898 /* sync end = sync width - 1 */
899 vse = mode->vsync_end - mode->vsync_start - 1;
900 hse = mode->hsync_end - mode->hsync_start - 1;
901
902 value = ((vse & 0x7fff) << 16) | (hse & 0x7fff);
903 tegra_sor_writel(sor, value, SOR_HEAD_STATE2(dc->pipe));
904
905 /* blank end = sync end + back porch */
906 vbe = vse + (mode->vtotal - mode->vsync_end);
907 hbe = hse + (mode->htotal - mode->hsync_end);
908
909 value = ((vbe & 0x7fff) << 16) | (hbe & 0x7fff);
910 tegra_sor_writel(sor, value, SOR_HEAD_STATE3(dc->pipe));
911
912 /* blank start = blank end + active */
913 vbs = vbe + mode->vdisplay;
914 hbs = hbe + mode->hdisplay;
915
916 value = ((vbs & 0x7fff) << 16) | (hbs & 0x7fff);
917 tegra_sor_writel(sor, value, SOR_HEAD_STATE4(dc->pipe));
918
919 /* XXX interlacing support */
920 tegra_sor_writel(sor, 0x001, SOR_HEAD_STATE5(dc->pipe));
921}
922
Thierry Reding6fad8f62014-11-28 15:41:34 +0100923static int tegra_sor_detach(struct tegra_sor *sor)
Thierry Reding6b6b6042013-11-15 16:06:05 +0100924{
Thierry Reding6fad8f62014-11-28 15:41:34 +0100925 unsigned long value, timeout;
926
927 /* switch to safe mode */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200928 value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +0100929 value &= ~SOR_SUPER_STATE_MODE_NORMAL;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200930 tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +0100931 tegra_sor_super_update(sor);
932
933 timeout = jiffies + msecs_to_jiffies(250);
934
935 while (time_before(jiffies, timeout)) {
936 value = tegra_sor_readl(sor, SOR_PWR);
937 if (value & SOR_PWR_MODE_SAFE)
938 break;
939 }
940
941 if ((value & SOR_PWR_MODE_SAFE) == 0)
942 return -ETIMEDOUT;
943
944 /* go to sleep */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200945 value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +0100946 value &= ~SOR_SUPER_STATE_HEAD_MODE_MASK;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200947 tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +0100948 tegra_sor_super_update(sor);
949
950 /* detach */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200951 value = tegra_sor_readl(sor, SOR_SUPER_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +0100952 value &= ~SOR_SUPER_STATE_ATTACHED;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +0200953 tegra_sor_writel(sor, value, SOR_SUPER_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +0100954 tegra_sor_super_update(sor);
955
956 timeout = jiffies + msecs_to_jiffies(250);
957
958 while (time_before(jiffies, timeout)) {
959 value = tegra_sor_readl(sor, SOR_TEST);
960 if ((value & SOR_TEST_ATTACHED) == 0)
961 break;
962
963 usleep_range(25, 100);
964 }
965
966 if ((value & SOR_TEST_ATTACHED) != 0)
967 return -ETIMEDOUT;
968
969 return 0;
970}
971
972static int tegra_sor_power_down(struct tegra_sor *sor)
973{
974 unsigned long value, timeout;
975 int err;
976
977 value = tegra_sor_readl(sor, SOR_PWR);
978 value &= ~SOR_PWR_NORMAL_STATE_PU;
979 value |= SOR_PWR_TRIGGER;
980 tegra_sor_writel(sor, value, SOR_PWR);
981
982 timeout = jiffies + msecs_to_jiffies(250);
983
984 while (time_before(jiffies, timeout)) {
985 value = tegra_sor_readl(sor, SOR_PWR);
986 if ((value & SOR_PWR_TRIGGER) == 0)
987 return 0;
988
989 usleep_range(25, 100);
990 }
991
992 if ((value & SOR_PWR_TRIGGER) != 0)
993 return -ETIMEDOUT;
994
Thierry Reding25bb2ce2015-08-03 14:23:29 +0200995 /* switch to safe parent clock */
996 err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
Thierry Reding6fad8f62014-11-28 15:41:34 +0100997 if (err < 0)
998 dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
999
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001000 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001001 value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 |
1002 SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001003 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001004
1005 /* stop lane sequencer */
1006 value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_UP |
1007 SOR_LANE_SEQ_CTL_POWER_STATE_DOWN;
1008 tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
1009
1010 timeout = jiffies + msecs_to_jiffies(250);
1011
1012 while (time_before(jiffies, timeout)) {
1013 value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
1014 if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
1015 break;
1016
1017 usleep_range(25, 100);
1018 }
1019
1020 if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0)
1021 return -ETIMEDOUT;
1022
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001023 value = tegra_sor_readl(sor, SOR_PLL2);
1024 value |= SOR_PLL2_PORT_POWERDOWN;
1025 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001026
1027 usleep_range(20, 100);
1028
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001029 value = tegra_sor_readl(sor, SOR_PLL0);
1030 value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR;
1031 tegra_sor_writel(sor, value, SOR_PLL0);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001032
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001033 value = tegra_sor_readl(sor, SOR_PLL2);
1034 value |= SOR_PLL2_SEQ_PLLCAPPD;
1035 value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
1036 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001037
1038 usleep_range(20, 100);
1039
1040 return 0;
1041}
1042
Thierry Reding6fad8f62014-11-28 15:41:34 +01001043static int tegra_sor_crc_wait(struct tegra_sor *sor, unsigned long timeout)
1044{
1045 u32 value;
1046
1047 timeout = jiffies + msecs_to_jiffies(timeout);
1048
1049 while (time_before(jiffies, timeout)) {
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001050 value = tegra_sor_readl(sor, SOR_CRCA);
1051 if (value & SOR_CRCA_VALID)
Thierry Reding6fad8f62014-11-28 15:41:34 +01001052 return 0;
1053
1054 usleep_range(100, 200);
1055 }
1056
1057 return -ETIMEDOUT;
1058}
1059
Thierry Reding530239a2015-08-06 11:04:54 +02001060static int tegra_sor_show_crc(struct seq_file *s, void *data)
Thierry Reding6fad8f62014-11-28 15:41:34 +01001061{
Thierry Reding530239a2015-08-06 11:04:54 +02001062 struct drm_info_node *node = s->private;
1063 struct tegra_sor *sor = node->info_ent->data;
Thierry Reding850bab42015-07-29 17:58:41 +02001064 struct drm_crtc *crtc = sor->output.encoder.crtc;
1065 struct drm_device *drm = node->minor->dev;
Thierry Reding530239a2015-08-06 11:04:54 +02001066 int err = 0;
Thierry Reding6fad8f62014-11-28 15:41:34 +01001067 u32 value;
1068
Thierry Reding850bab42015-07-29 17:58:41 +02001069 drm_modeset_lock_all(drm);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001070
Thierry Reding850bab42015-07-29 17:58:41 +02001071 if (!crtc || !crtc->state->active) {
1072 err = -EBUSY;
Thierry Reding6fad8f62014-11-28 15:41:34 +01001073 goto unlock;
1074 }
1075
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001076 value = tegra_sor_readl(sor, SOR_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001077 value &= ~SOR_STATE_ASY_CRC_MODE_MASK;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001078 tegra_sor_writel(sor, value, SOR_STATE1);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001079
1080 value = tegra_sor_readl(sor, SOR_CRC_CNTRL);
1081 value |= SOR_CRC_CNTRL_ENABLE;
1082 tegra_sor_writel(sor, value, SOR_CRC_CNTRL);
1083
1084 value = tegra_sor_readl(sor, SOR_TEST);
1085 value &= ~SOR_TEST_CRC_POST_SERIALIZE;
1086 tegra_sor_writel(sor, value, SOR_TEST);
1087
1088 err = tegra_sor_crc_wait(sor, 100);
1089 if (err < 0)
1090 goto unlock;
1091
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001092 tegra_sor_writel(sor, SOR_CRCA_RESET, SOR_CRCA);
1093 value = tegra_sor_readl(sor, SOR_CRCB);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001094
Thierry Reding530239a2015-08-06 11:04:54 +02001095 seq_printf(s, "%08x\n", value);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001096
1097unlock:
Thierry Reding850bab42015-07-29 17:58:41 +02001098 drm_modeset_unlock_all(drm);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001099 return err;
1100}
1101
Thierry Redingdab16332015-01-26 16:04:08 +01001102static int tegra_sor_show_regs(struct seq_file *s, void *data)
1103{
1104 struct drm_info_node *node = s->private;
1105 struct tegra_sor *sor = node->info_ent->data;
Thierry Reding850bab42015-07-29 17:58:41 +02001106 struct drm_crtc *crtc = sor->output.encoder.crtc;
1107 struct drm_device *drm = node->minor->dev;
1108 int err = 0;
1109
1110 drm_modeset_lock_all(drm);
1111
1112 if (!crtc || !crtc->state->active) {
1113 err = -EBUSY;
1114 goto unlock;
1115 }
Thierry Redingdab16332015-01-26 16:04:08 +01001116
1117#define DUMP_REG(name) \
1118 seq_printf(s, "%-38s %#05x %08x\n", #name, name, \
1119 tegra_sor_readl(sor, name))
1120
1121 DUMP_REG(SOR_CTXSW);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001122 DUMP_REG(SOR_SUPER_STATE0);
1123 DUMP_REG(SOR_SUPER_STATE1);
1124 DUMP_REG(SOR_STATE0);
1125 DUMP_REG(SOR_STATE1);
1126 DUMP_REG(SOR_HEAD_STATE0(0));
1127 DUMP_REG(SOR_HEAD_STATE0(1));
1128 DUMP_REG(SOR_HEAD_STATE1(0));
1129 DUMP_REG(SOR_HEAD_STATE1(1));
1130 DUMP_REG(SOR_HEAD_STATE2(0));
1131 DUMP_REG(SOR_HEAD_STATE2(1));
1132 DUMP_REG(SOR_HEAD_STATE3(0));
1133 DUMP_REG(SOR_HEAD_STATE3(1));
1134 DUMP_REG(SOR_HEAD_STATE4(0));
1135 DUMP_REG(SOR_HEAD_STATE4(1));
1136 DUMP_REG(SOR_HEAD_STATE5(0));
1137 DUMP_REG(SOR_HEAD_STATE5(1));
Thierry Redingdab16332015-01-26 16:04:08 +01001138 DUMP_REG(SOR_CRC_CNTRL);
1139 DUMP_REG(SOR_DP_DEBUG_MVID);
1140 DUMP_REG(SOR_CLK_CNTRL);
1141 DUMP_REG(SOR_CAP);
1142 DUMP_REG(SOR_PWR);
1143 DUMP_REG(SOR_TEST);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001144 DUMP_REG(SOR_PLL0);
1145 DUMP_REG(SOR_PLL1);
1146 DUMP_REG(SOR_PLL2);
1147 DUMP_REG(SOR_PLL3);
Thierry Redingdab16332015-01-26 16:04:08 +01001148 DUMP_REG(SOR_CSTM);
1149 DUMP_REG(SOR_LVDS);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001150 DUMP_REG(SOR_CRCA);
1151 DUMP_REG(SOR_CRCB);
Thierry Redingdab16332015-01-26 16:04:08 +01001152 DUMP_REG(SOR_BLANK);
1153 DUMP_REG(SOR_SEQ_CTL);
1154 DUMP_REG(SOR_LANE_SEQ_CTL);
1155 DUMP_REG(SOR_SEQ_INST(0));
1156 DUMP_REG(SOR_SEQ_INST(1));
1157 DUMP_REG(SOR_SEQ_INST(2));
1158 DUMP_REG(SOR_SEQ_INST(3));
1159 DUMP_REG(SOR_SEQ_INST(4));
1160 DUMP_REG(SOR_SEQ_INST(5));
1161 DUMP_REG(SOR_SEQ_INST(6));
1162 DUMP_REG(SOR_SEQ_INST(7));
1163 DUMP_REG(SOR_SEQ_INST(8));
1164 DUMP_REG(SOR_SEQ_INST(9));
1165 DUMP_REG(SOR_SEQ_INST(10));
1166 DUMP_REG(SOR_SEQ_INST(11));
1167 DUMP_REG(SOR_SEQ_INST(12));
1168 DUMP_REG(SOR_SEQ_INST(13));
1169 DUMP_REG(SOR_SEQ_INST(14));
1170 DUMP_REG(SOR_SEQ_INST(15));
1171 DUMP_REG(SOR_PWM_DIV);
1172 DUMP_REG(SOR_PWM_CTL);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001173 DUMP_REG(SOR_VCRC_A0);
1174 DUMP_REG(SOR_VCRC_A1);
1175 DUMP_REG(SOR_VCRC_B0);
1176 DUMP_REG(SOR_VCRC_B1);
1177 DUMP_REG(SOR_CCRC_A0);
1178 DUMP_REG(SOR_CCRC_A1);
1179 DUMP_REG(SOR_CCRC_B0);
1180 DUMP_REG(SOR_CCRC_B1);
1181 DUMP_REG(SOR_EDATA_A0);
1182 DUMP_REG(SOR_EDATA_A1);
1183 DUMP_REG(SOR_EDATA_B0);
1184 DUMP_REG(SOR_EDATA_B1);
1185 DUMP_REG(SOR_COUNT_A0);
1186 DUMP_REG(SOR_COUNT_A1);
1187 DUMP_REG(SOR_COUNT_B0);
1188 DUMP_REG(SOR_COUNT_B1);
1189 DUMP_REG(SOR_DEBUG_A0);
1190 DUMP_REG(SOR_DEBUG_A1);
1191 DUMP_REG(SOR_DEBUG_B0);
1192 DUMP_REG(SOR_DEBUG_B1);
Thierry Redingdab16332015-01-26 16:04:08 +01001193 DUMP_REG(SOR_TRIG);
1194 DUMP_REG(SOR_MSCHECK);
1195 DUMP_REG(SOR_XBAR_CTRL);
1196 DUMP_REG(SOR_XBAR_POL);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001197 DUMP_REG(SOR_DP_LINKCTL0);
1198 DUMP_REG(SOR_DP_LINKCTL1);
1199 DUMP_REG(SOR_LANE_DRIVE_CURRENT0);
1200 DUMP_REG(SOR_LANE_DRIVE_CURRENT1);
1201 DUMP_REG(SOR_LANE4_DRIVE_CURRENT0);
1202 DUMP_REG(SOR_LANE4_DRIVE_CURRENT1);
1203 DUMP_REG(SOR_LANE_PREEMPHASIS0);
1204 DUMP_REG(SOR_LANE_PREEMPHASIS1);
1205 DUMP_REG(SOR_LANE4_PREEMPHASIS0);
1206 DUMP_REG(SOR_LANE4_PREEMPHASIS1);
1207 DUMP_REG(SOR_LANE_POSTCURSOR0);
1208 DUMP_REG(SOR_LANE_POSTCURSOR1);
1209 DUMP_REG(SOR_DP_CONFIG0);
1210 DUMP_REG(SOR_DP_CONFIG1);
1211 DUMP_REG(SOR_DP_MN0);
1212 DUMP_REG(SOR_DP_MN1);
1213 DUMP_REG(SOR_DP_PADCTL0);
1214 DUMP_REG(SOR_DP_PADCTL1);
1215 DUMP_REG(SOR_DP_DEBUG0);
1216 DUMP_REG(SOR_DP_DEBUG1);
1217 DUMP_REG(SOR_DP_SPARE0);
1218 DUMP_REG(SOR_DP_SPARE1);
Thierry Redingdab16332015-01-26 16:04:08 +01001219 DUMP_REG(SOR_DP_AUDIO_CTRL);
1220 DUMP_REG(SOR_DP_AUDIO_HBLANK_SYMBOLS);
1221 DUMP_REG(SOR_DP_AUDIO_VBLANK_SYMBOLS);
1222 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_HEADER);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001223 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK0);
1224 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK1);
1225 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK2);
1226 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK3);
1227 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK4);
1228 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK5);
1229 DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK6);
Thierry Redingdab16332015-01-26 16:04:08 +01001230 DUMP_REG(SOR_DP_TPG);
1231 DUMP_REG(SOR_DP_TPG_CONFIG);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001232 DUMP_REG(SOR_DP_LQ_CSTM0);
1233 DUMP_REG(SOR_DP_LQ_CSTM1);
1234 DUMP_REG(SOR_DP_LQ_CSTM2);
Thierry Redingdab16332015-01-26 16:04:08 +01001235
1236#undef DUMP_REG
1237
Thierry Reding850bab42015-07-29 17:58:41 +02001238unlock:
1239 drm_modeset_unlock_all(drm);
1240 return err;
Thierry Redingdab16332015-01-26 16:04:08 +01001241}
1242
1243static const struct drm_info_list debugfs_files[] = {
Thierry Reding530239a2015-08-06 11:04:54 +02001244 { "crc", tegra_sor_show_crc, 0, NULL },
Thierry Redingdab16332015-01-26 16:04:08 +01001245 { "regs", tegra_sor_show_regs, 0, NULL },
1246};
1247
Thierry Reding6fad8f62014-11-28 15:41:34 +01001248static int tegra_sor_debugfs_init(struct tegra_sor *sor,
1249 struct drm_minor *minor)
1250{
Thierry Reding459cc2c2015-07-30 10:34:24 +02001251 const char *name = sor->soc->supports_dp ? "sor1" : "sor";
Thierry Redingdab16332015-01-26 16:04:08 +01001252 unsigned int i;
Thierry Reding530239a2015-08-06 11:04:54 +02001253 int err;
Thierry Reding6fad8f62014-11-28 15:41:34 +01001254
Thierry Reding459cc2c2015-07-30 10:34:24 +02001255 sor->debugfs = debugfs_create_dir(name, minor->debugfs_root);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001256 if (!sor->debugfs)
1257 return -ENOMEM;
1258
Thierry Redingdab16332015-01-26 16:04:08 +01001259 sor->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1260 GFP_KERNEL);
1261 if (!sor->debugfs_files) {
Thierry Reding6fad8f62014-11-28 15:41:34 +01001262 err = -ENOMEM;
1263 goto remove;
1264 }
1265
Thierry Redingdab16332015-01-26 16:04:08 +01001266 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1267 sor->debugfs_files[i].data = sor;
1268
1269 err = drm_debugfs_create_files(sor->debugfs_files,
1270 ARRAY_SIZE(debugfs_files),
1271 sor->debugfs, minor);
1272 if (err < 0)
1273 goto free;
1274
Thierry Reding3ff1f222015-07-03 14:14:29 +02001275 sor->minor = minor;
1276
Thierry Reding530239a2015-08-06 11:04:54 +02001277 return 0;
Thierry Reding6fad8f62014-11-28 15:41:34 +01001278
Thierry Redingdab16332015-01-26 16:04:08 +01001279free:
1280 kfree(sor->debugfs_files);
1281 sor->debugfs_files = NULL;
Thierry Reding6fad8f62014-11-28 15:41:34 +01001282remove:
Thierry Redingdab16332015-01-26 16:04:08 +01001283 debugfs_remove_recursive(sor->debugfs);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001284 sor->debugfs = NULL;
1285 return err;
1286}
1287
Thierry Reding4009c222014-12-19 15:47:30 +01001288static void tegra_sor_debugfs_exit(struct tegra_sor *sor)
Thierry Reding6fad8f62014-11-28 15:41:34 +01001289{
Thierry Redingdab16332015-01-26 16:04:08 +01001290 drm_debugfs_remove_files(sor->debugfs_files, ARRAY_SIZE(debugfs_files),
1291 sor->minor);
1292 sor->minor = NULL;
1293
1294 kfree(sor->debugfs_files);
Thierry Reding066d30f2015-07-03 14:16:30 +02001295 sor->debugfs_files = NULL;
Thierry Redingdab16332015-01-26 16:04:08 +01001296
1297 debugfs_remove_recursive(sor->debugfs);
Thierry Reding066d30f2015-07-03 14:16:30 +02001298 sor->debugfs = NULL;
Thierry Reding6fad8f62014-11-28 15:41:34 +01001299}
1300
Thierry Redingc31efa72015-09-08 16:09:22 +02001301static void tegra_sor_connector_reset(struct drm_connector *connector)
1302{
1303 struct tegra_sor_state *state;
1304
1305 state = kzalloc(sizeof(*state), GFP_KERNEL);
1306 if (!state)
1307 return;
1308
1309 if (connector->state) {
1310 __drm_atomic_helper_connector_destroy_state(connector->state);
1311 kfree(connector->state);
1312 }
1313
1314 __drm_atomic_helper_connector_reset(connector, &state->base);
1315}
1316
Thierry Reding6fad8f62014-11-28 15:41:34 +01001317static enum drm_connector_status
1318tegra_sor_connector_detect(struct drm_connector *connector, bool force)
1319{
1320 struct tegra_output *output = connector_to_output(connector);
1321 struct tegra_sor *sor = to_sor(output);
1322
Thierry Reding9542c232015-07-08 13:39:09 +02001323 if (sor->aux)
1324 return drm_dp_aux_detect(sor->aux);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001325
Thierry Reding459cc2c2015-07-30 10:34:24 +02001326 return tegra_output_connector_detect(connector, force);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001327}
1328
Thierry Redingc31efa72015-09-08 16:09:22 +02001329static struct drm_connector_state *
1330tegra_sor_connector_duplicate_state(struct drm_connector *connector)
1331{
1332 struct tegra_sor_state *state = to_sor_state(connector->state);
1333 struct tegra_sor_state *copy;
1334
1335 copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
1336 if (!copy)
1337 return NULL;
1338
1339 __drm_atomic_helper_connector_duplicate_state(connector, &copy->base);
1340
1341 return &copy->base;
1342}
1343
Thierry Reding6fad8f62014-11-28 15:41:34 +01001344static const struct drm_connector_funcs tegra_sor_connector_funcs = {
Thierry Reding850bab42015-07-29 17:58:41 +02001345 .dpms = drm_atomic_helper_connector_dpms,
Thierry Redingc31efa72015-09-08 16:09:22 +02001346 .reset = tegra_sor_connector_reset,
Thierry Reding6fad8f62014-11-28 15:41:34 +01001347 .detect = tegra_sor_connector_detect,
1348 .fill_modes = drm_helper_probe_single_connector_modes,
1349 .destroy = tegra_output_connector_destroy,
Thierry Redingc31efa72015-09-08 16:09:22 +02001350 .atomic_duplicate_state = tegra_sor_connector_duplicate_state,
Thierry Reding4aa3df72014-11-24 16:27:13 +01001351 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Thierry Reding6fad8f62014-11-28 15:41:34 +01001352};
1353
1354static int tegra_sor_connector_get_modes(struct drm_connector *connector)
1355{
1356 struct tegra_output *output = connector_to_output(connector);
1357 struct tegra_sor *sor = to_sor(output);
1358 int err;
1359
Thierry Reding9542c232015-07-08 13:39:09 +02001360 if (sor->aux)
1361 drm_dp_aux_enable(sor->aux);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001362
1363 err = tegra_output_connector_get_modes(connector);
1364
Thierry Reding9542c232015-07-08 13:39:09 +02001365 if (sor->aux)
1366 drm_dp_aux_disable(sor->aux);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001367
1368 return err;
1369}
1370
1371static enum drm_mode_status
1372tegra_sor_connector_mode_valid(struct drm_connector *connector,
1373 struct drm_display_mode *mode)
1374{
1375 return MODE_OK;
1376}
1377
1378static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs = {
1379 .get_modes = tegra_sor_connector_get_modes,
1380 .mode_valid = tegra_sor_connector_mode_valid,
1381 .best_encoder = tegra_output_connector_best_encoder,
1382};
1383
1384static const struct drm_encoder_funcs tegra_sor_encoder_funcs = {
1385 .destroy = tegra_output_encoder_destroy,
1386};
1387
Thierry Reding850bab42015-07-29 17:58:41 +02001388static void tegra_sor_edp_disable(struct drm_encoder *encoder)
Thierry Reding6fad8f62014-11-28 15:41:34 +01001389{
Thierry Reding850bab42015-07-29 17:58:41 +02001390 struct tegra_output *output = encoder_to_output(encoder);
1391 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
1392 struct tegra_sor *sor = to_sor(output);
1393 u32 value;
1394 int err;
1395
1396 if (output->panel)
1397 drm_panel_disable(output->panel);
1398
1399 err = tegra_sor_detach(sor);
1400 if (err < 0)
1401 dev_err(sor->dev, "failed to detach SOR: %d\n", err);
1402
1403 tegra_sor_writel(sor, 0, SOR_STATE1);
1404 tegra_sor_update(sor);
1405
1406 /*
1407 * The following accesses registers of the display controller, so make
1408 * sure it's only executed when the output is attached to one.
1409 */
1410 if (dc) {
1411 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
1412 value &= ~SOR_ENABLE;
1413 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
1414
1415 tegra_dc_commit(dc);
1416 }
1417
1418 err = tegra_sor_power_down(sor);
1419 if (err < 0)
1420 dev_err(sor->dev, "failed to power down SOR: %d\n", err);
1421
Thierry Reding9542c232015-07-08 13:39:09 +02001422 if (sor->aux) {
1423 err = drm_dp_aux_disable(sor->aux);
Thierry Reding850bab42015-07-29 17:58:41 +02001424 if (err < 0)
1425 dev_err(sor->dev, "failed to disable DP: %d\n", err);
1426 }
1427
1428 err = tegra_io_rail_power_off(TEGRA_IO_RAIL_LVDS);
1429 if (err < 0)
1430 dev_err(sor->dev, "failed to power off I/O rail: %d\n", err);
1431
1432 if (output->panel)
1433 drm_panel_unprepare(output->panel);
1434
Thierry Redingaaff8bd2015-08-07 16:04:54 +02001435 pm_runtime_put(sor->dev);
Thierry Reding6fad8f62014-11-28 15:41:34 +01001436}
1437
Thierry Reding459cc2c2015-07-30 10:34:24 +02001438#if 0
1439static int calc_h_ref_to_sync(const struct drm_display_mode *mode,
1440 unsigned int *value)
1441{
1442 unsigned int hfp, hsw, hbp, a = 0, b;
1443
1444 hfp = mode->hsync_start - mode->hdisplay;
1445 hsw = mode->hsync_end - mode->hsync_start;
1446 hbp = mode->htotal - mode->hsync_end;
1447
1448 pr_info("hfp: %u, hsw: %u, hbp: %u\n", hfp, hsw, hbp);
1449
1450 b = hfp - 1;
1451
1452 pr_info("a: %u, b: %u\n", a, b);
1453 pr_info("a + hsw + hbp = %u\n", a + hsw + hbp);
1454
1455 if (a + hsw + hbp <= 11) {
1456 a = 1 + 11 - hsw - hbp;
1457 pr_info("a: %u\n", a);
1458 }
1459
1460 if (a > b)
1461 return -EINVAL;
1462
1463 if (hsw < 1)
1464 return -EINVAL;
1465
1466 if (mode->hdisplay < 16)
1467 return -EINVAL;
1468
1469 if (value) {
1470 if (b > a && a % 2)
1471 *value = a + 1;
1472 else
1473 *value = a;
1474 }
1475
1476 return 0;
1477}
1478#endif
1479
Thierry Reding850bab42015-07-29 17:58:41 +02001480static void tegra_sor_edp_enable(struct drm_encoder *encoder)
Thierry Reding6fad8f62014-11-28 15:41:34 +01001481{
Thierry Reding850bab42015-07-29 17:58:41 +02001482 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
Thierry Reding6fad8f62014-11-28 15:41:34 +01001483 struct tegra_output *output = encoder_to_output(encoder);
1484 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001485 struct tegra_sor *sor = to_sor(output);
Thierry Reding34fa1832014-06-05 16:31:10 +02001486 struct tegra_sor_config config;
Thierry Redingc31efa72015-09-08 16:09:22 +02001487 struct tegra_sor_state *state;
Thierry Reding34fa1832014-06-05 16:31:10 +02001488 struct drm_dp_link link;
Thierry Reding01b9bea2015-11-11 17:15:29 +01001489 u8 rate, lanes;
Thierry Reding2bd1dd32015-08-03 15:46:15 +02001490 unsigned int i;
Thierry Reding86f5c522014-03-26 11:13:16 +01001491 int err = 0;
Thierry Reding28fe2072015-01-26 16:02:48 +01001492 u32 value;
Thierry Reding86f5c522014-03-26 11:13:16 +01001493
Thierry Redingc31efa72015-09-08 16:09:22 +02001494 state = to_sor_state(output->connector.state);
Thierry Reding2bd1dd32015-08-03 15:46:15 +02001495
Thierry Redingaaff8bd2015-08-07 16:04:54 +02001496 pm_runtime_get_sync(sor->dev);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001497
Thierry Reding6fad8f62014-11-28 15:41:34 +01001498 if (output->panel)
1499 drm_panel_prepare(output->panel);
1500
Thierry Reding01b9bea2015-11-11 17:15:29 +01001501 err = drm_dp_aux_enable(sor->aux);
1502 if (err < 0)
1503 dev_err(sor->dev, "failed to enable DP: %d\n", err);
Thierry Reding34fa1832014-06-05 16:31:10 +02001504
Thierry Reding01b9bea2015-11-11 17:15:29 +01001505 err = drm_dp_link_probe(sor->aux, &link);
1506 if (err < 0) {
1507 dev_err(sor->dev, "failed to probe eDP link: %d\n", err);
1508 return;
Thierry Reding6b6b6042013-11-15 16:06:05 +01001509 }
1510
Thierry Reding25bb2ce2015-08-03 14:23:29 +02001511 /* switch to safe parent clock */
1512 err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001513 if (err < 0)
1514 dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
1515
Thierry Reding34fa1832014-06-05 16:31:10 +02001516 memset(&config, 0, sizeof(config));
Thierry Redingc31efa72015-09-08 16:09:22 +02001517 config.bits_per_pixel = state->bpc * 3;
Thierry Reding34fa1832014-06-05 16:31:10 +02001518
Thierry Redinga1983592015-07-21 16:46:52 +02001519 err = tegra_sor_compute_config(sor, mode, &config, &link);
Thierry Reding34fa1832014-06-05 16:31:10 +02001520 if (err < 0)
Thierry Redinga1983592015-07-21 16:46:52 +02001521 dev_err(sor->dev, "failed to compute configuration: %d\n", err);
Thierry Reding34fa1832014-06-05 16:31:10 +02001522
Thierry Reding6b6b6042013-11-15 16:06:05 +01001523 value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
1524 value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
1525 value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK;
1526 tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
1527
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001528 value = tegra_sor_readl(sor, SOR_PLL2);
1529 value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
1530 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001531 usleep_range(20, 100);
1532
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001533 value = tegra_sor_readl(sor, SOR_PLL3);
1534 value |= SOR_PLL3_PLL_VDD_MODE_3V3;
1535 tegra_sor_writel(sor, value, SOR_PLL3);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001536
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001537 value = SOR_PLL0_ICHPMP(0xf) | SOR_PLL0_VCOCAP_RST |
1538 SOR_PLL0_PLLREG_LEVEL_V45 | SOR_PLL0_RESISTOR_EXT;
1539 tegra_sor_writel(sor, value, SOR_PLL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001540
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001541 value = tegra_sor_readl(sor, SOR_PLL2);
1542 value |= SOR_PLL2_SEQ_PLLCAPPD;
1543 value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
1544 value |= SOR_PLL2_LVDS_ENABLE;
1545 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001546
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001547 value = SOR_PLL1_TERM_COMPOUT | SOR_PLL1_TMDS_TERM;
1548 tegra_sor_writel(sor, value, SOR_PLL1);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001549
1550 while (true) {
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001551 value = tegra_sor_readl(sor, SOR_PLL2);
1552 if ((value & SOR_PLL2_SEQ_PLLCAPPD_ENFORCE) == 0)
Thierry Reding6b6b6042013-11-15 16:06:05 +01001553 break;
1554
1555 usleep_range(250, 1000);
1556 }
1557
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001558 value = tegra_sor_readl(sor, SOR_PLL2);
1559 value &= ~SOR_PLL2_POWERDOWN_OVERRIDE;
1560 value &= ~SOR_PLL2_PORT_POWERDOWN;
1561 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001562
1563 /*
1564 * power up
1565 */
1566
1567 /* set safe link bandwidth (1.62 Gbps) */
1568 value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
1569 value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
1570 value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62;
1571 tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
1572
1573 /* step 1 */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001574 value = tegra_sor_readl(sor, SOR_PLL2);
1575 value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE | SOR_PLL2_PORT_POWERDOWN |
1576 SOR_PLL2_BANDGAP_POWERDOWN;
1577 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001578
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001579 value = tegra_sor_readl(sor, SOR_PLL0);
1580 value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR;
1581 tegra_sor_writel(sor, value, SOR_PLL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001582
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001583 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001584 value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001585 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001586
1587 /* step 2 */
1588 err = tegra_io_rail_power_on(TEGRA_IO_RAIL_LVDS);
Thierry Reding850bab42015-07-29 17:58:41 +02001589 if (err < 0)
Thierry Reding6b6b6042013-11-15 16:06:05 +01001590 dev_err(sor->dev, "failed to power on I/O rail: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001591
1592 usleep_range(5, 100);
1593
1594 /* step 3 */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001595 value = tegra_sor_readl(sor, SOR_PLL2);
1596 value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
1597 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001598
1599 usleep_range(20, 100);
1600
1601 /* step 4 */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001602 value = tegra_sor_readl(sor, SOR_PLL0);
1603 value &= ~SOR_PLL0_VCOPD;
1604 value &= ~SOR_PLL0_PWR;
1605 tegra_sor_writel(sor, value, SOR_PLL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001606
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001607 value = tegra_sor_readl(sor, SOR_PLL2);
1608 value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
1609 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001610
1611 usleep_range(200, 1000);
1612
1613 /* step 5 */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001614 value = tegra_sor_readl(sor, SOR_PLL2);
1615 value &= ~SOR_PLL2_PORT_POWERDOWN;
1616 tegra_sor_writel(sor, value, SOR_PLL2);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001617
Thierry Reding30b49432015-08-03 15:50:32 +02001618 /* XXX not in TRM */
1619 for (value = 0, i = 0; i < 5; i++)
1620 value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) |
1621 SOR_XBAR_CTRL_LINK1_XSEL(i, i);
1622
1623 tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL);
1624 tegra_sor_writel(sor, value, SOR_XBAR_CTRL);
1625
Thierry Reding25bb2ce2015-08-03 14:23:29 +02001626 /* switch to DP parent clock */
1627 err = tegra_sor_set_parent_clock(sor, sor->clk_dp);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001628 if (err < 0)
Thierry Reding25bb2ce2015-08-03 14:23:29 +02001629 dev_err(sor->dev, "failed to set parent clock: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001630
Thierry Reding899451b2014-06-05 16:19:48 +02001631 /* power DP lanes */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001632 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
Thierry Reding899451b2014-06-05 16:19:48 +02001633
1634 if (link.num_lanes <= 2)
1635 value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2);
1636 else
1637 value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2;
1638
1639 if (link.num_lanes <= 1)
1640 value &= ~SOR_DP_PADCTL_PD_TXD_1;
1641 else
1642 value |= SOR_DP_PADCTL_PD_TXD_1;
1643
1644 if (link.num_lanes == 0)
1645 value &= ~SOR_DP_PADCTL_PD_TXD_0;
1646 else
1647 value |= SOR_DP_PADCTL_PD_TXD_0;
1648
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001649 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001650
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001651 value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001652 value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
Thierry Reding0c90a182014-06-05 16:29:46 +02001653 value |= SOR_DP_LINKCTL_LANE_COUNT(link.num_lanes);
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001654 tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001655
1656 /* start lane sequencer */
1657 value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
1658 SOR_LANE_SEQ_CTL_POWER_STATE_UP;
1659 tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
1660
1661 while (true) {
1662 value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
1663 if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
1664 break;
1665
1666 usleep_range(250, 1000);
1667 }
1668
Thierry Redinga4263fe2014-06-05 16:16:23 +02001669 /* set link bandwidth */
Thierry Reding6b6b6042013-11-15 16:06:05 +01001670 value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
1671 value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
Thierry Redinga4263fe2014-06-05 16:16:23 +02001672 value |= drm_dp_link_rate_to_bw_code(link.rate) << 2;
Thierry Reding6b6b6042013-11-15 16:06:05 +01001673 tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
1674
Thierry Reding402f6bc2015-07-21 16:48:19 +02001675 tegra_sor_apply_config(sor, &config);
1676
1677 /* enable link */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001678 value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001679 value |= SOR_DP_LINKCTL_ENABLE;
Thierry Reding6b6b6042013-11-15 16:06:05 +01001680 value |= SOR_DP_LINKCTL_ENHANCED_FRAME;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001681 tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001682
1683 for (i = 0, value = 0; i < 4; i++) {
1684 unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
1685 SOR_DP_TPG_SCRAMBLER_GALIOS |
1686 SOR_DP_TPG_PATTERN_NONE;
1687 value = (value << 8) | lane;
1688 }
1689
1690 tegra_sor_writel(sor, value, SOR_DP_TPG);
1691
Thierry Reding6b6b6042013-11-15 16:06:05 +01001692 /* enable pad calibration logic */
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001693 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001694 value |= SOR_DP_PADCTL_PAD_CAL_PD;
Thierry Redinga9a9e4f2015-04-27 15:01:14 +02001695 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001696
Thierry Reding01b9bea2015-11-11 17:15:29 +01001697 err = drm_dp_link_probe(sor->aux, &link);
1698 if (err < 0)
1699 dev_err(sor->dev, "failed to probe eDP link: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001700
Thierry Reding01b9bea2015-11-11 17:15:29 +01001701 err = drm_dp_link_power_up(sor->aux, &link);
1702 if (err < 0)
1703 dev_err(sor->dev, "failed to power up eDP link: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001704
Thierry Reding01b9bea2015-11-11 17:15:29 +01001705 err = drm_dp_link_configure(sor->aux, &link);
1706 if (err < 0)
1707 dev_err(sor->dev, "failed to configure eDP link: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001708
Thierry Reding01b9bea2015-11-11 17:15:29 +01001709 rate = drm_dp_link_rate_to_bw_code(link.rate);
1710 lanes = link.num_lanes;
Thierry Reding6b6b6042013-11-15 16:06:05 +01001711
Thierry Reding01b9bea2015-11-11 17:15:29 +01001712 value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
1713 value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
1714 value |= SOR_CLK_CNTRL_DP_LINK_SPEED(rate);
1715 tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001716
Thierry Reding01b9bea2015-11-11 17:15:29 +01001717 value = tegra_sor_readl(sor, SOR_DP_LINKCTL0);
1718 value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK;
1719 value |= SOR_DP_LINKCTL_LANE_COUNT(lanes);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001720
Thierry Reding01b9bea2015-11-11 17:15:29 +01001721 if (link.capabilities & DP_LINK_CAP_ENHANCED_FRAMING)
1722 value |= SOR_DP_LINKCTL_ENHANCED_FRAME;
Thierry Reding6b6b6042013-11-15 16:06:05 +01001723
Thierry Reding01b9bea2015-11-11 17:15:29 +01001724 tegra_sor_writel(sor, value, SOR_DP_LINKCTL0);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001725
Thierry Reding01b9bea2015-11-11 17:15:29 +01001726 /* disable training pattern generator */
Thierry Reding6b6b6042013-11-15 16:06:05 +01001727
Thierry Reding01b9bea2015-11-11 17:15:29 +01001728 for (i = 0; i < link.num_lanes; i++) {
1729 unsigned long lane = SOR_DP_TPG_CHANNEL_CODING |
1730 SOR_DP_TPG_SCRAMBLER_GALIOS |
1731 SOR_DP_TPG_PATTERN_NONE;
1732 value = (value << 8) | lane;
Thierry Reding6b6b6042013-11-15 16:06:05 +01001733 }
1734
Thierry Reding01b9bea2015-11-11 17:15:29 +01001735 tegra_sor_writel(sor, value, SOR_DP_TPG);
1736
1737 err = tegra_sor_dp_train_fast(sor, &link);
1738 if (err < 0)
1739 dev_err(sor->dev, "DP fast link training failed: %d\n", err);
1740
1741 dev_dbg(sor->dev, "fast link training succeeded\n");
1742
Thierry Reding6b6b6042013-11-15 16:06:05 +01001743 err = tegra_sor_power_up(sor, 250);
Thierry Reding850bab42015-07-29 17:58:41 +02001744 if (err < 0)
Thierry Reding6b6b6042013-11-15 16:06:05 +01001745 dev_err(sor->dev, "failed to power up SOR: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001746
Thierry Reding6b6b6042013-11-15 16:06:05 +01001747 /* CSTM (LVDS, link A/B, upper) */
Stéphane Marchesin143b1df2014-05-22 20:32:47 -07001748 value = SOR_CSTM_LVDS | SOR_CSTM_LINK_ACT_A | SOR_CSTM_LINK_ACT_B |
Thierry Reding6b6b6042013-11-15 16:06:05 +01001749 SOR_CSTM_UPPER;
1750 tegra_sor_writel(sor, value, SOR_CSTM);
1751
Thierry Reding2bd1dd32015-08-03 15:46:15 +02001752 /* use DP-A protocol */
1753 value = tegra_sor_readl(sor, SOR_STATE1);
1754 value &= ~SOR_STATE_ASY_PROTOCOL_MASK;
1755 value |= SOR_STATE_ASY_PROTOCOL_DP_A;
1756 tegra_sor_writel(sor, value, SOR_STATE1);
1757
Thierry Redingc31efa72015-09-08 16:09:22 +02001758 tegra_sor_mode_set(sor, mode, state);
Thierry Reding2bd1dd32015-08-03 15:46:15 +02001759
Thierry Reding6b6b6042013-11-15 16:06:05 +01001760 /* PWM setup */
1761 err = tegra_sor_setup_pwm(sor, 250);
Thierry Reding850bab42015-07-29 17:58:41 +02001762 if (err < 0)
Thierry Reding6b6b6042013-11-15 16:06:05 +01001763 dev_err(sor->dev, "failed to setup PWM: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001764
Thierry Reding666cb872014-12-08 16:32:47 +01001765 tegra_sor_update(sor);
1766
Thierry Reding6b6b6042013-11-15 16:06:05 +01001767 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
1768 value |= SOR_ENABLE;
1769 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
1770
Thierry Reding666cb872014-12-08 16:32:47 +01001771 tegra_dc_commit(dc);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001772
1773 err = tegra_sor_attach(sor);
Thierry Reding850bab42015-07-29 17:58:41 +02001774 if (err < 0)
Thierry Reding6b6b6042013-11-15 16:06:05 +01001775 dev_err(sor->dev, "failed to attach SOR: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001776
1777 err = tegra_sor_wakeup(sor);
Thierry Reding850bab42015-07-29 17:58:41 +02001778 if (err < 0)
Thierry Reding6b6b6042013-11-15 16:06:05 +01001779 dev_err(sor->dev, "failed to enable DC: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001780
Thierry Reding6fad8f62014-11-28 15:41:34 +01001781 if (output->panel)
1782 drm_panel_enable(output->panel);
Thierry Reding6b6b6042013-11-15 16:06:05 +01001783}
1784
Thierry Reding82f15112014-12-08 17:26:46 +01001785static int
1786tegra_sor_encoder_atomic_check(struct drm_encoder *encoder,
1787 struct drm_crtc_state *crtc_state,
1788 struct drm_connector_state *conn_state)
1789{
1790 struct tegra_output *output = encoder_to_output(encoder);
Thierry Redingc31efa72015-09-08 16:09:22 +02001791 struct tegra_sor_state *state = to_sor_state(conn_state);
Thierry Reding82f15112014-12-08 17:26:46 +01001792 struct tegra_dc *dc = to_tegra_dc(conn_state->crtc);
1793 unsigned long pclk = crtc_state->mode.clock * 1000;
1794 struct tegra_sor *sor = to_sor(output);
Thierry Redingc31efa72015-09-08 16:09:22 +02001795 struct drm_display_info *info;
Thierry Reding82f15112014-12-08 17:26:46 +01001796 int err;
1797
Thierry Redingc31efa72015-09-08 16:09:22 +02001798 info = &output->connector.display_info;
1799
Thierry Reding82f15112014-12-08 17:26:46 +01001800 err = tegra_dc_state_setup_clock(dc, crtc_state, sor->clk_parent,
1801 pclk, 0);
1802 if (err < 0) {
1803 dev_err(output->dev, "failed to setup CRTC state: %d\n", err);
1804 return err;
1805 }
1806
Thierry Redingc31efa72015-09-08 16:09:22 +02001807 switch (info->bpc) {
1808 case 8:
1809 case 6:
1810 state->bpc = info->bpc;
1811 break;
1812
1813 default:
1814 DRM_DEBUG_KMS("%u bits-per-color not supported\n", info->bpc);
1815 state->bpc = 8;
1816 break;
1817 }
1818
Thierry Reding82f15112014-12-08 17:26:46 +01001819 return 0;
1820}
1821
Thierry Reding459cc2c2015-07-30 10:34:24 +02001822static const struct drm_encoder_helper_funcs tegra_sor_edp_helpers = {
Thierry Reding850bab42015-07-29 17:58:41 +02001823 .disable = tegra_sor_edp_disable,
1824 .enable = tegra_sor_edp_enable,
Thierry Reding82f15112014-12-08 17:26:46 +01001825 .atomic_check = tegra_sor_encoder_atomic_check,
Thierry Reding6b6b6042013-11-15 16:06:05 +01001826};
1827
Thierry Reding459cc2c2015-07-30 10:34:24 +02001828static inline u32 tegra_sor_hdmi_subpack(const u8 *ptr, size_t size)
1829{
1830 u32 value = 0;
1831 size_t i;
1832
1833 for (i = size; i > 0; i--)
1834 value = (value << 8) | ptr[i - 1];
1835
1836 return value;
1837}
1838
1839static void tegra_sor_hdmi_write_infopack(struct tegra_sor *sor,
1840 const void *data, size_t size)
1841{
1842 const u8 *ptr = data;
1843 unsigned long offset;
1844 size_t i, j;
1845 u32 value;
1846
1847 switch (ptr[0]) {
1848 case HDMI_INFOFRAME_TYPE_AVI:
1849 offset = SOR_HDMI_AVI_INFOFRAME_HEADER;
1850 break;
1851
1852 case HDMI_INFOFRAME_TYPE_AUDIO:
1853 offset = SOR_HDMI_AUDIO_INFOFRAME_HEADER;
1854 break;
1855
1856 case HDMI_INFOFRAME_TYPE_VENDOR:
1857 offset = SOR_HDMI_VSI_INFOFRAME_HEADER;
1858 break;
1859
1860 default:
1861 dev_err(sor->dev, "unsupported infoframe type: %02x\n",
1862 ptr[0]);
1863 return;
1864 }
1865
1866 value = INFOFRAME_HEADER_TYPE(ptr[0]) |
1867 INFOFRAME_HEADER_VERSION(ptr[1]) |
1868 INFOFRAME_HEADER_LEN(ptr[2]);
1869 tegra_sor_writel(sor, value, offset);
1870 offset++;
1871
1872 /*
1873 * Each subpack contains 7 bytes, divided into:
1874 * - subpack_low: bytes 0 - 3
1875 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
1876 */
1877 for (i = 3, j = 0; i < size; i += 7, j += 8) {
1878 size_t rem = size - i, num = min_t(size_t, rem, 4);
1879
1880 value = tegra_sor_hdmi_subpack(&ptr[i], num);
1881 tegra_sor_writel(sor, value, offset++);
1882
1883 num = min_t(size_t, rem - num, 3);
1884
1885 value = tegra_sor_hdmi_subpack(&ptr[i + 4], num);
1886 tegra_sor_writel(sor, value, offset++);
1887 }
1888}
1889
1890static int
1891tegra_sor_hdmi_setup_avi_infoframe(struct tegra_sor *sor,
1892 const struct drm_display_mode *mode)
1893{
1894 u8 buffer[HDMI_INFOFRAME_SIZE(AVI)];
1895 struct hdmi_avi_infoframe frame;
1896 u32 value;
1897 int err;
1898
1899 /* disable AVI infoframe */
1900 value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL);
1901 value &= ~INFOFRAME_CTRL_SINGLE;
1902 value &= ~INFOFRAME_CTRL_OTHER;
1903 value &= ~INFOFRAME_CTRL_ENABLE;
1904 tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL);
1905
1906 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
1907 if (err < 0) {
1908 dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err);
1909 return err;
1910 }
1911
1912 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
1913 if (err < 0) {
1914 dev_err(sor->dev, "failed to pack AVI infoframe: %d\n", err);
1915 return err;
1916 }
1917
1918 tegra_sor_hdmi_write_infopack(sor, buffer, err);
1919
1920 /* enable AVI infoframe */
1921 value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL);
1922 value |= INFOFRAME_CTRL_CHECKSUM_ENABLE;
1923 value |= INFOFRAME_CTRL_ENABLE;
1924 tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL);
1925
1926 return 0;
1927}
1928
1929static void tegra_sor_hdmi_disable_audio_infoframe(struct tegra_sor *sor)
1930{
1931 u32 value;
1932
1933 value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_INFOFRAME_CTRL);
1934 value &= ~INFOFRAME_CTRL_ENABLE;
1935 tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_INFOFRAME_CTRL);
1936}
1937
1938static struct tegra_sor_hdmi_settings *
1939tegra_sor_hdmi_find_settings(struct tegra_sor *sor, unsigned long frequency)
1940{
1941 unsigned int i;
1942
1943 for (i = 0; i < sor->num_settings; i++)
1944 if (frequency <= sor->settings[i].frequency)
1945 return &sor->settings[i];
1946
1947 return NULL;
1948}
1949
1950static void tegra_sor_hdmi_disable(struct drm_encoder *encoder)
1951{
1952 struct tegra_output *output = encoder_to_output(encoder);
1953 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
1954 struct tegra_sor *sor = to_sor(output);
1955 u32 value;
1956 int err;
1957
1958 err = tegra_sor_detach(sor);
1959 if (err < 0)
1960 dev_err(sor->dev, "failed to detach SOR: %d\n", err);
1961
1962 tegra_sor_writel(sor, 0, SOR_STATE1);
1963 tegra_sor_update(sor);
1964
1965 /* disable display to SOR clock */
1966 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
1967 value &= ~SOR1_TIMING_CYA;
1968 value &= ~SOR1_ENABLE;
1969 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
1970
1971 tegra_dc_commit(dc);
1972
1973 err = tegra_sor_power_down(sor);
1974 if (err < 0)
1975 dev_err(sor->dev, "failed to power down SOR: %d\n", err);
1976
1977 err = tegra_io_rail_power_off(TEGRA_IO_RAIL_HDMI);
1978 if (err < 0)
1979 dev_err(sor->dev, "failed to power off HDMI rail: %d\n", err);
1980
Thierry Redingaaff8bd2015-08-07 16:04:54 +02001981 pm_runtime_put(sor->dev);
Thierry Reding459cc2c2015-07-30 10:34:24 +02001982}
1983
1984static void tegra_sor_hdmi_enable(struct drm_encoder *encoder)
1985{
1986 struct tegra_output *output = encoder_to_output(encoder);
1987 unsigned int h_ref_to_sync = 1, pulse_start, max_ac;
1988 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
Thierry Reding459cc2c2015-07-30 10:34:24 +02001989 struct tegra_sor_hdmi_settings *settings;
1990 struct tegra_sor *sor = to_sor(output);
Thierry Redingc31efa72015-09-08 16:09:22 +02001991 struct tegra_sor_state *state;
Thierry Reding459cc2c2015-07-30 10:34:24 +02001992 struct drm_display_mode *mode;
Thierry Reding30b49432015-08-03 15:50:32 +02001993 unsigned int div, i;
Thierry Reding459cc2c2015-07-30 10:34:24 +02001994 u32 value;
1995 int err;
1996
Thierry Redingc31efa72015-09-08 16:09:22 +02001997 state = to_sor_state(output->connector.state);
Thierry Reding459cc2c2015-07-30 10:34:24 +02001998 mode = &encoder->crtc->state->adjusted_mode;
Thierry Reding459cc2c2015-07-30 10:34:24 +02001999
Thierry Redingaaff8bd2015-08-07 16:04:54 +02002000 pm_runtime_get_sync(sor->dev);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002001
Thierry Reding25bb2ce2015-08-03 14:23:29 +02002002 /* switch to safe parent clock */
2003 err = tegra_sor_set_parent_clock(sor, sor->clk_safe);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002004 if (err < 0)
2005 dev_err(sor->dev, "failed to set safe parent clock: %d\n", err);
2006
2007 div = clk_get_rate(sor->clk) / 1000000 * 4;
2008
2009 err = tegra_io_rail_power_on(TEGRA_IO_RAIL_HDMI);
2010 if (err < 0)
2011 dev_err(sor->dev, "failed to power on HDMI rail: %d\n", err);
2012
2013 usleep_range(20, 100);
2014
2015 value = tegra_sor_readl(sor, SOR_PLL2);
2016 value &= ~SOR_PLL2_BANDGAP_POWERDOWN;
2017 tegra_sor_writel(sor, value, SOR_PLL2);
2018
2019 usleep_range(20, 100);
2020
2021 value = tegra_sor_readl(sor, SOR_PLL3);
2022 value &= ~SOR_PLL3_PLL_VDD_MODE_3V3;
2023 tegra_sor_writel(sor, value, SOR_PLL3);
2024
2025 value = tegra_sor_readl(sor, SOR_PLL0);
2026 value &= ~SOR_PLL0_VCOPD;
2027 value &= ~SOR_PLL0_PWR;
2028 tegra_sor_writel(sor, value, SOR_PLL0);
2029
2030 value = tegra_sor_readl(sor, SOR_PLL2);
2031 value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE;
2032 tegra_sor_writel(sor, value, SOR_PLL2);
2033
2034 usleep_range(200, 400);
2035
2036 value = tegra_sor_readl(sor, SOR_PLL2);
2037 value &= ~SOR_PLL2_POWERDOWN_OVERRIDE;
2038 value &= ~SOR_PLL2_PORT_POWERDOWN;
2039 tegra_sor_writel(sor, value, SOR_PLL2);
2040
2041 usleep_range(20, 100);
2042
2043 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
2044 value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 |
2045 SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2;
2046 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
2047
2048 while (true) {
2049 value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
2050 if ((value & SOR_LANE_SEQ_CTL_STATE_BUSY) == 0)
2051 break;
2052
2053 usleep_range(250, 1000);
2054 }
2055
2056 value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN |
2057 SOR_LANE_SEQ_CTL_POWER_STATE_UP | SOR_LANE_SEQ_CTL_DELAY(5);
2058 tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL);
2059
2060 while (true) {
2061 value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL);
2062 if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0)
2063 break;
2064
2065 usleep_range(250, 1000);
2066 }
2067
2068 value = tegra_sor_readl(sor, SOR_CLK_CNTRL);
2069 value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK;
2070 value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK;
2071
2072 if (mode->clock < 340000)
2073 value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G2_70;
2074 else
2075 value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G5_40;
2076
2077 value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK;
2078 tegra_sor_writel(sor, value, SOR_CLK_CNTRL);
2079
2080 value = tegra_sor_readl(sor, SOR_DP_SPARE0);
2081 value |= SOR_DP_SPARE_DISP_VIDEO_PREAMBLE;
2082 value &= ~SOR_DP_SPARE_PANEL_INTERNAL;
2083 value |= SOR_DP_SPARE_SEQ_ENABLE;
2084 tegra_sor_writel(sor, value, SOR_DP_SPARE0);
2085
2086 value = SOR_SEQ_CTL_PU_PC(0) | SOR_SEQ_CTL_PU_PC_ALT(0) |
2087 SOR_SEQ_CTL_PD_PC(8) | SOR_SEQ_CTL_PD_PC_ALT(8);
2088 tegra_sor_writel(sor, value, SOR_SEQ_CTL);
2089
2090 value = SOR_SEQ_INST_DRIVE_PWM_OUT_LO | SOR_SEQ_INST_HALT |
2091 SOR_SEQ_INST_WAIT_VSYNC | SOR_SEQ_INST_WAIT(1);
2092 tegra_sor_writel(sor, value, SOR_SEQ_INST(0));
2093 tegra_sor_writel(sor, value, SOR_SEQ_INST(8));
2094
2095 /* program the reference clock */
2096 value = SOR_REFCLK_DIV_INT(div) | SOR_REFCLK_DIV_FRAC(div);
2097 tegra_sor_writel(sor, value, SOR_REFCLK);
2098
Thierry Reding30b49432015-08-03 15:50:32 +02002099 /* XXX not in TRM */
2100 for (value = 0, i = 0; i < 5; i++)
2101 value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) |
2102 SOR_XBAR_CTRL_LINK1_XSEL(i, i);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002103
2104 tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL);
Thierry Reding30b49432015-08-03 15:50:32 +02002105 tegra_sor_writel(sor, value, SOR_XBAR_CTRL);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002106
Thierry Reding25bb2ce2015-08-03 14:23:29 +02002107 /* switch to parent clock */
Thierry Reding618dee32016-06-09 17:53:57 +02002108 err = clk_set_parent(sor->clk_src, sor->clk_parent);
2109 if (err < 0)
2110 dev_err(sor->dev, "failed to set source clock: %d\n", err);
2111
2112 err = tegra_sor_set_parent_clock(sor, sor->clk_src);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002113 if (err < 0)
2114 dev_err(sor->dev, "failed to set parent clock: %d\n", err);
2115
2116 value = SOR_INPUT_CONTROL_HDMI_SRC_SELECT(dc->pipe);
2117
2118 /* XXX is this the proper check? */
2119 if (mode->clock < 75000)
2120 value |= SOR_INPUT_CONTROL_ARM_VIDEO_RANGE_LIMITED;
2121
2122 tegra_sor_writel(sor, value, SOR_INPUT_CONTROL);
2123
2124 max_ac = ((mode->htotal - mode->hdisplay) - SOR_REKEY - 18) / 32;
2125
2126 value = SOR_HDMI_CTRL_ENABLE | SOR_HDMI_CTRL_MAX_AC_PACKET(max_ac) |
2127 SOR_HDMI_CTRL_AUDIO_LAYOUT | SOR_HDMI_CTRL_REKEY(SOR_REKEY);
2128 tegra_sor_writel(sor, value, SOR_HDMI_CTRL);
2129
2130 /* H_PULSE2 setup */
2131 pulse_start = h_ref_to_sync + (mode->hsync_end - mode->hsync_start) +
2132 (mode->htotal - mode->hsync_end) - 10;
2133
2134 value = PULSE_LAST_END_A | PULSE_QUAL_VACTIVE |
2135 PULSE_POLARITY_HIGH | PULSE_MODE_NORMAL;
2136 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
2137
2138 value = PULSE_END(pulse_start + 8) | PULSE_START(pulse_start);
2139 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
2140
2141 value = tegra_dc_readl(dc, DC_DISP_DISP_SIGNAL_OPTIONS0);
2142 value |= H_PULSE2_ENABLE;
2143 tegra_dc_writel(dc, value, DC_DISP_DISP_SIGNAL_OPTIONS0);
2144
2145 /* infoframe setup */
2146 err = tegra_sor_hdmi_setup_avi_infoframe(sor, mode);
2147 if (err < 0)
2148 dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err);
2149
2150 /* XXX HDMI audio support not implemented yet */
2151 tegra_sor_hdmi_disable_audio_infoframe(sor);
2152
2153 /* use single TMDS protocol */
2154 value = tegra_sor_readl(sor, SOR_STATE1);
2155 value &= ~SOR_STATE_ASY_PROTOCOL_MASK;
2156 value |= SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A;
2157 tegra_sor_writel(sor, value, SOR_STATE1);
2158
2159 /* power up pad calibration */
2160 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
2161 value &= ~SOR_DP_PADCTL_PAD_CAL_PD;
2162 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
2163
2164 /* production settings */
2165 settings = tegra_sor_hdmi_find_settings(sor, mode->clock * 1000);
Dan Carpenterdb8b42f2015-08-17 17:37:03 +03002166 if (!settings) {
2167 dev_err(sor->dev, "no settings for pixel clock %d Hz\n",
2168 mode->clock * 1000);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002169 return;
2170 }
2171
2172 value = tegra_sor_readl(sor, SOR_PLL0);
2173 value &= ~SOR_PLL0_ICHPMP_MASK;
2174 value &= ~SOR_PLL0_VCOCAP_MASK;
2175 value |= SOR_PLL0_ICHPMP(settings->ichpmp);
2176 value |= SOR_PLL0_VCOCAP(settings->vcocap);
2177 tegra_sor_writel(sor, value, SOR_PLL0);
2178
2179 tegra_sor_dp_term_calibrate(sor);
2180
2181 value = tegra_sor_readl(sor, SOR_PLL1);
2182 value &= ~SOR_PLL1_LOADADJ_MASK;
2183 value |= SOR_PLL1_LOADADJ(settings->loadadj);
2184 tegra_sor_writel(sor, value, SOR_PLL1);
2185
2186 value = tegra_sor_readl(sor, SOR_PLL3);
2187 value &= ~SOR_PLL3_BG_VREF_LEVEL_MASK;
2188 value |= SOR_PLL3_BG_VREF_LEVEL(settings->bg_vref);
2189 tegra_sor_writel(sor, value, SOR_PLL3);
2190
2191 value = settings->drive_current[0] << 24 |
2192 settings->drive_current[1] << 16 |
2193 settings->drive_current[2] << 8 |
2194 settings->drive_current[3] << 0;
2195 tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0);
2196
2197 value = settings->preemphasis[0] << 24 |
2198 settings->preemphasis[1] << 16 |
2199 settings->preemphasis[2] << 8 |
2200 settings->preemphasis[3] << 0;
2201 tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0);
2202
2203 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
2204 value &= ~SOR_DP_PADCTL_TX_PU_MASK;
2205 value |= SOR_DP_PADCTL_TX_PU_ENABLE;
2206 value |= SOR_DP_PADCTL_TX_PU(settings->tx_pu);
2207 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
2208
2209 /* power down pad calibration */
2210 value = tegra_sor_readl(sor, SOR_DP_PADCTL0);
2211 value |= SOR_DP_PADCTL_PAD_CAL_PD;
2212 tegra_sor_writel(sor, value, SOR_DP_PADCTL0);
2213
2214 /* miscellaneous display controller settings */
2215 value = VSYNC_H_POSITION(1);
2216 tegra_dc_writel(dc, value, DC_DISP_DISP_TIMING_OPTIONS);
2217
2218 value = tegra_dc_readl(dc, DC_DISP_DISP_COLOR_CONTROL);
2219 value &= ~DITHER_CONTROL_MASK;
2220 value &= ~BASE_COLOR_SIZE_MASK;
2221
Thierry Redingc31efa72015-09-08 16:09:22 +02002222 switch (state->bpc) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002223 case 6:
2224 value |= BASE_COLOR_SIZE_666;
2225 break;
2226
2227 case 8:
2228 value |= BASE_COLOR_SIZE_888;
2229 break;
2230
2231 default:
Thierry Redingc31efa72015-09-08 16:09:22 +02002232 WARN(1, "%u bits-per-color not supported\n", state->bpc);
2233 value |= BASE_COLOR_SIZE_888;
Thierry Reding459cc2c2015-07-30 10:34:24 +02002234 break;
2235 }
2236
2237 tegra_dc_writel(dc, value, DC_DISP_DISP_COLOR_CONTROL);
2238
2239 err = tegra_sor_power_up(sor, 250);
2240 if (err < 0)
2241 dev_err(sor->dev, "failed to power up SOR: %d\n", err);
2242
Thierry Reding2bd1dd32015-08-03 15:46:15 +02002243 /* configure dynamic range of output */
Thierry Reding459cc2c2015-07-30 10:34:24 +02002244 value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe));
2245 value &= ~SOR_HEAD_STATE_RANGECOMPRESS_MASK;
2246 value &= ~SOR_HEAD_STATE_DYNRANGE_MASK;
2247 tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe));
2248
Thierry Reding2bd1dd32015-08-03 15:46:15 +02002249 /* configure colorspace */
Thierry Reding459cc2c2015-07-30 10:34:24 +02002250 value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe));
2251 value &= ~SOR_HEAD_STATE_COLORSPACE_MASK;
2252 value |= SOR_HEAD_STATE_COLORSPACE_RGB;
2253 tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe));
2254
Thierry Redingc31efa72015-09-08 16:09:22 +02002255 tegra_sor_mode_set(sor, mode, state);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002256
2257 tegra_sor_update(sor);
2258
2259 err = tegra_sor_attach(sor);
2260 if (err < 0)
2261 dev_err(sor->dev, "failed to attach SOR: %d\n", err);
2262
2263 /* enable display to SOR clock and generate HDMI preamble */
2264 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
2265 value |= SOR1_ENABLE | SOR1_TIMING_CYA;
2266 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
2267
2268 tegra_dc_commit(dc);
2269
2270 err = tegra_sor_wakeup(sor);
2271 if (err < 0)
2272 dev_err(sor->dev, "failed to wakeup SOR: %d\n", err);
2273}
2274
2275static const struct drm_encoder_helper_funcs tegra_sor_hdmi_helpers = {
2276 .disable = tegra_sor_hdmi_disable,
2277 .enable = tegra_sor_hdmi_enable,
2278 .atomic_check = tegra_sor_encoder_atomic_check,
2279};
2280
Thierry Reding6b6b6042013-11-15 16:06:05 +01002281static int tegra_sor_init(struct host1x_client *client)
2282{
Thierry Reding9910f5c2014-05-22 09:57:15 +02002283 struct drm_device *drm = dev_get_drvdata(client->parent);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002284 const struct drm_encoder_helper_funcs *helpers = NULL;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002285 struct tegra_sor *sor = host1x_client_to_sor(client);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002286 int connector = DRM_MODE_CONNECTOR_Unknown;
2287 int encoder = DRM_MODE_ENCODER_NONE;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002288 int err;
2289
Thierry Reding9542c232015-07-08 13:39:09 +02002290 if (!sor->aux) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002291 if (sor->soc->supports_hdmi) {
2292 connector = DRM_MODE_CONNECTOR_HDMIA;
2293 encoder = DRM_MODE_ENCODER_TMDS;
2294 helpers = &tegra_sor_hdmi_helpers;
2295 } else if (sor->soc->supports_lvds) {
2296 connector = DRM_MODE_CONNECTOR_LVDS;
2297 encoder = DRM_MODE_ENCODER_LVDS;
2298 }
2299 } else {
2300 if (sor->soc->supports_edp) {
2301 connector = DRM_MODE_CONNECTOR_eDP;
2302 encoder = DRM_MODE_ENCODER_TMDS;
2303 helpers = &tegra_sor_edp_helpers;
2304 } else if (sor->soc->supports_dp) {
2305 connector = DRM_MODE_CONNECTOR_DisplayPort;
2306 encoder = DRM_MODE_ENCODER_TMDS;
2307 }
2308 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002309
Thierry Reding6b6b6042013-11-15 16:06:05 +01002310 sor->output.dev = sor->dev;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002311
Thierry Reding6fad8f62014-11-28 15:41:34 +01002312 drm_connector_init(drm, &sor->output.connector,
2313 &tegra_sor_connector_funcs,
Thierry Reding459cc2c2015-07-30 10:34:24 +02002314 connector);
Thierry Reding6fad8f62014-11-28 15:41:34 +01002315 drm_connector_helper_add(&sor->output.connector,
2316 &tegra_sor_connector_helper_funcs);
2317 sor->output.connector.dpms = DRM_MODE_DPMS_OFF;
2318
Thierry Reding6fad8f62014-11-28 15:41:34 +01002319 drm_encoder_init(drm, &sor->output.encoder, &tegra_sor_encoder_funcs,
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002320 encoder, NULL);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002321 drm_encoder_helper_add(&sor->output.encoder, helpers);
Thierry Reding6fad8f62014-11-28 15:41:34 +01002322
2323 drm_mode_connector_attach_encoder(&sor->output.connector,
2324 &sor->output.encoder);
2325 drm_connector_register(&sor->output.connector);
2326
Thierry Redingea130b22014-12-19 15:51:35 +01002327 err = tegra_output_init(drm, &sor->output);
2328 if (err < 0) {
2329 dev_err(client->dev, "failed to initialize output: %d\n", err);
2330 return err;
2331 }
Thierry Reding6fad8f62014-11-28 15:41:34 +01002332
Thierry Redingea130b22014-12-19 15:51:35 +01002333 sor->output.encoder.possible_crtcs = 0x3;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002334
Thierry Redinga82752e2014-01-31 10:02:15 +01002335 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding1b0c7b42014-05-28 13:46:12 +02002336 err = tegra_sor_debugfs_init(sor, drm->primary);
Thierry Redinga82752e2014-01-31 10:02:15 +01002337 if (err < 0)
2338 dev_err(sor->dev, "debugfs setup failed: %d\n", err);
2339 }
2340
Thierry Reding9542c232015-07-08 13:39:09 +02002341 if (sor->aux) {
2342 err = drm_dp_aux_attach(sor->aux, &sor->output);
Thierry Reding6b6b6042013-11-15 16:06:05 +01002343 if (err < 0) {
2344 dev_err(sor->dev, "failed to attach DP: %d\n", err);
2345 return err;
2346 }
2347 }
2348
Tomeu Vizoso535a65d2015-03-30 10:33:03 +02002349 /*
2350 * XXX: Remove this reset once proper hand-over from firmware to
2351 * kernel is possible.
2352 */
2353 err = reset_control_assert(sor->rst);
2354 if (err < 0) {
2355 dev_err(sor->dev, "failed to assert SOR reset: %d\n", err);
2356 return err;
2357 }
2358
Thierry Reding6fad8f62014-11-28 15:41:34 +01002359 err = clk_prepare_enable(sor->clk);
2360 if (err < 0) {
2361 dev_err(sor->dev, "failed to enable clock: %d\n", err);
2362 return err;
2363 }
2364
Tomeu Vizoso535a65d2015-03-30 10:33:03 +02002365 usleep_range(1000, 3000);
2366
2367 err = reset_control_deassert(sor->rst);
2368 if (err < 0) {
2369 dev_err(sor->dev, "failed to deassert SOR reset: %d\n", err);
2370 return err;
2371 }
2372
Thierry Reding6fad8f62014-11-28 15:41:34 +01002373 err = clk_prepare_enable(sor->clk_safe);
2374 if (err < 0)
2375 return err;
2376
2377 err = clk_prepare_enable(sor->clk_dp);
2378 if (err < 0)
2379 return err;
2380
Thierry Reding6b6b6042013-11-15 16:06:05 +01002381 return 0;
2382}
2383
2384static int tegra_sor_exit(struct host1x_client *client)
2385{
2386 struct tegra_sor *sor = host1x_client_to_sor(client);
2387 int err;
2388
Thierry Reding328ec692014-12-19 15:55:08 +01002389 tegra_output_exit(&sor->output);
2390
Thierry Reding9542c232015-07-08 13:39:09 +02002391 if (sor->aux) {
2392 err = drm_dp_aux_detach(sor->aux);
Thierry Reding6b6b6042013-11-15 16:06:05 +01002393 if (err < 0) {
2394 dev_err(sor->dev, "failed to detach DP: %d\n", err);
2395 return err;
2396 }
2397 }
2398
Thierry Reding6fad8f62014-11-28 15:41:34 +01002399 clk_disable_unprepare(sor->clk_safe);
2400 clk_disable_unprepare(sor->clk_dp);
2401 clk_disable_unprepare(sor->clk);
2402
Thierry Reding4009c222014-12-19 15:47:30 +01002403 if (IS_ENABLED(CONFIG_DEBUG_FS))
2404 tegra_sor_debugfs_exit(sor);
Thierry Redinga82752e2014-01-31 10:02:15 +01002405
Thierry Reding6b6b6042013-11-15 16:06:05 +01002406 return 0;
2407}
2408
2409static const struct host1x_client_ops sor_client_ops = {
2410 .init = tegra_sor_init,
2411 .exit = tegra_sor_exit,
2412};
2413
Thierry Reding459cc2c2015-07-30 10:34:24 +02002414static const struct tegra_sor_ops tegra_sor_edp_ops = {
2415 .name = "eDP",
2416};
2417
2418static int tegra_sor_hdmi_probe(struct tegra_sor *sor)
2419{
2420 int err;
2421
2422 sor->avdd_io_supply = devm_regulator_get(sor->dev, "avdd-io");
2423 if (IS_ERR(sor->avdd_io_supply)) {
2424 dev_err(sor->dev, "cannot get AVDD I/O supply: %ld\n",
2425 PTR_ERR(sor->avdd_io_supply));
2426 return PTR_ERR(sor->avdd_io_supply);
2427 }
2428
2429 err = regulator_enable(sor->avdd_io_supply);
2430 if (err < 0) {
2431 dev_err(sor->dev, "failed to enable AVDD I/O supply: %d\n",
2432 err);
2433 return err;
2434 }
2435
2436 sor->vdd_pll_supply = devm_regulator_get(sor->dev, "vdd-pll");
2437 if (IS_ERR(sor->vdd_pll_supply)) {
2438 dev_err(sor->dev, "cannot get VDD PLL supply: %ld\n",
2439 PTR_ERR(sor->vdd_pll_supply));
2440 return PTR_ERR(sor->vdd_pll_supply);
2441 }
2442
2443 err = regulator_enable(sor->vdd_pll_supply);
2444 if (err < 0) {
2445 dev_err(sor->dev, "failed to enable VDD PLL supply: %d\n",
2446 err);
2447 return err;
2448 }
2449
2450 sor->hdmi_supply = devm_regulator_get(sor->dev, "hdmi");
2451 if (IS_ERR(sor->hdmi_supply)) {
2452 dev_err(sor->dev, "cannot get HDMI supply: %ld\n",
2453 PTR_ERR(sor->hdmi_supply));
2454 return PTR_ERR(sor->hdmi_supply);
2455 }
2456
2457 err = regulator_enable(sor->hdmi_supply);
2458 if (err < 0) {
2459 dev_err(sor->dev, "failed to enable HDMI supply: %d\n", err);
2460 return err;
2461 }
2462
2463 return 0;
2464}
2465
2466static int tegra_sor_hdmi_remove(struct tegra_sor *sor)
2467{
2468 regulator_disable(sor->hdmi_supply);
2469 regulator_disable(sor->vdd_pll_supply);
2470 regulator_disable(sor->avdd_io_supply);
2471
2472 return 0;
2473}
2474
2475static const struct tegra_sor_ops tegra_sor_hdmi_ops = {
2476 .name = "HDMI",
2477 .probe = tegra_sor_hdmi_probe,
2478 .remove = tegra_sor_hdmi_remove,
2479};
2480
Thierry Reding30b49432015-08-03 15:50:32 +02002481static const u8 tegra124_sor_xbar_cfg[5] = {
2482 0, 1, 2, 3, 4
2483};
2484
Thierry Reding459cc2c2015-07-30 10:34:24 +02002485static const struct tegra_sor_soc tegra124_sor = {
2486 .supports_edp = true,
2487 .supports_lvds = true,
2488 .supports_hdmi = false,
2489 .supports_dp = false,
Thierry Reding30b49432015-08-03 15:50:32 +02002490 .xbar_cfg = tegra124_sor_xbar_cfg,
Thierry Reding459cc2c2015-07-30 10:34:24 +02002491};
2492
2493static const struct tegra_sor_soc tegra210_sor = {
2494 .supports_edp = true,
2495 .supports_lvds = false,
2496 .supports_hdmi = false,
2497 .supports_dp = false,
Thierry Reding30b49432015-08-03 15:50:32 +02002498 .xbar_cfg = tegra124_sor_xbar_cfg,
2499};
2500
2501static const u8 tegra210_sor_xbar_cfg[5] = {
2502 2, 1, 0, 3, 4
Thierry Reding459cc2c2015-07-30 10:34:24 +02002503};
2504
2505static const struct tegra_sor_soc tegra210_sor1 = {
2506 .supports_edp = false,
2507 .supports_lvds = false,
2508 .supports_hdmi = true,
2509 .supports_dp = true,
2510
2511 .num_settings = ARRAY_SIZE(tegra210_sor_hdmi_defaults),
2512 .settings = tegra210_sor_hdmi_defaults,
Thierry Reding30b49432015-08-03 15:50:32 +02002513
2514 .xbar_cfg = tegra210_sor_xbar_cfg,
Thierry Reding459cc2c2015-07-30 10:34:24 +02002515};
2516
2517static const struct of_device_id tegra_sor_of_match[] = {
2518 { .compatible = "nvidia,tegra210-sor1", .data = &tegra210_sor1 },
2519 { .compatible = "nvidia,tegra210-sor", .data = &tegra210_sor },
2520 { .compatible = "nvidia,tegra124-sor", .data = &tegra124_sor },
2521 { },
2522};
2523MODULE_DEVICE_TABLE(of, tegra_sor_of_match);
2524
Thierry Reding6b6b6042013-11-15 16:06:05 +01002525static int tegra_sor_probe(struct platform_device *pdev)
2526{
Thierry Reding459cc2c2015-07-30 10:34:24 +02002527 const struct of_device_id *match;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002528 struct device_node *np;
2529 struct tegra_sor *sor;
2530 struct resource *regs;
2531 int err;
2532
Thierry Reding459cc2c2015-07-30 10:34:24 +02002533 match = of_match_device(tegra_sor_of_match, &pdev->dev);
2534
Thierry Reding6b6b6042013-11-15 16:06:05 +01002535 sor = devm_kzalloc(&pdev->dev, sizeof(*sor), GFP_KERNEL);
2536 if (!sor)
2537 return -ENOMEM;
2538
2539 sor->output.dev = sor->dev = &pdev->dev;
Thierry Reding459cc2c2015-07-30 10:34:24 +02002540 sor->soc = match->data;
2541
2542 sor->settings = devm_kmemdup(&pdev->dev, sor->soc->settings,
2543 sor->soc->num_settings *
2544 sizeof(*sor->settings),
2545 GFP_KERNEL);
2546 if (!sor->settings)
2547 return -ENOMEM;
2548
2549 sor->num_settings = sor->soc->num_settings;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002550
2551 np = of_parse_phandle(pdev->dev.of_node, "nvidia,dpaux", 0);
2552 if (np) {
Thierry Reding9542c232015-07-08 13:39:09 +02002553 sor->aux = drm_dp_aux_find_by_of_node(np);
Thierry Reding6b6b6042013-11-15 16:06:05 +01002554 of_node_put(np);
2555
Thierry Reding9542c232015-07-08 13:39:09 +02002556 if (!sor->aux)
Thierry Reding6b6b6042013-11-15 16:06:05 +01002557 return -EPROBE_DEFER;
2558 }
2559
Thierry Reding9542c232015-07-08 13:39:09 +02002560 if (!sor->aux) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002561 if (sor->soc->supports_hdmi) {
2562 sor->ops = &tegra_sor_hdmi_ops;
2563 } else if (sor->soc->supports_lvds) {
2564 dev_err(&pdev->dev, "LVDS not supported yet\n");
2565 return -ENODEV;
2566 } else {
2567 dev_err(&pdev->dev, "unknown (non-DP) support\n");
2568 return -ENODEV;
2569 }
2570 } else {
2571 if (sor->soc->supports_edp) {
2572 sor->ops = &tegra_sor_edp_ops;
2573 } else if (sor->soc->supports_dp) {
2574 dev_err(&pdev->dev, "DisplayPort not supported yet\n");
2575 return -ENODEV;
2576 } else {
2577 dev_err(&pdev->dev, "unknown (DP) support\n");
2578 return -ENODEV;
2579 }
2580 }
2581
Thierry Reding6b6b6042013-11-15 16:06:05 +01002582 err = tegra_output_probe(&sor->output);
Thierry Reding4dbdc742015-04-27 15:04:26 +02002583 if (err < 0) {
2584 dev_err(&pdev->dev, "failed to probe output: %d\n", err);
Thierry Reding6b6b6042013-11-15 16:06:05 +01002585 return err;
Thierry Reding4dbdc742015-04-27 15:04:26 +02002586 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002587
Thierry Reding459cc2c2015-07-30 10:34:24 +02002588 if (sor->ops && sor->ops->probe) {
2589 err = sor->ops->probe(sor);
2590 if (err < 0) {
2591 dev_err(&pdev->dev, "failed to probe %s: %d\n",
2592 sor->ops->name, err);
2593 goto output;
2594 }
2595 }
2596
Thierry Reding6b6b6042013-11-15 16:06:05 +01002597 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2598 sor->regs = devm_ioremap_resource(&pdev->dev, regs);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002599 if (IS_ERR(sor->regs)) {
2600 err = PTR_ERR(sor->regs);
2601 goto remove;
2602 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002603
2604 sor->rst = devm_reset_control_get(&pdev->dev, "sor");
Thierry Reding4dbdc742015-04-27 15:04:26 +02002605 if (IS_ERR(sor->rst)) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002606 err = PTR_ERR(sor->rst);
2607 dev_err(&pdev->dev, "failed to get reset control: %d\n", err);
2608 goto remove;
Thierry Reding4dbdc742015-04-27 15:04:26 +02002609 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002610
2611 sor->clk = devm_clk_get(&pdev->dev, NULL);
Thierry Reding4dbdc742015-04-27 15:04:26 +02002612 if (IS_ERR(sor->clk)) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002613 err = PTR_ERR(sor->clk);
2614 dev_err(&pdev->dev, "failed to get module clock: %d\n", err);
2615 goto remove;
Thierry Reding4dbdc742015-04-27 15:04:26 +02002616 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002617
Thierry Reding618dee32016-06-09 17:53:57 +02002618 if (sor->soc->supports_hdmi || sor->soc->supports_dp) {
2619 sor->clk_src = devm_clk_get(&pdev->dev, "source");
2620 if (IS_ERR(sor->clk_src)) {
2621 err = PTR_ERR(sor->clk_src);
2622 dev_err(sor->dev, "failed to get source clock: %d\n",
2623 err);
2624 goto remove;
2625 }
2626 }
2627
Thierry Reding6b6b6042013-11-15 16:06:05 +01002628 sor->clk_parent = devm_clk_get(&pdev->dev, "parent");
Thierry Reding4dbdc742015-04-27 15:04:26 +02002629 if (IS_ERR(sor->clk_parent)) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002630 err = PTR_ERR(sor->clk_parent);
2631 dev_err(&pdev->dev, "failed to get parent clock: %d\n", err);
2632 goto remove;
Thierry Reding4dbdc742015-04-27 15:04:26 +02002633 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002634
Thierry Reding6b6b6042013-11-15 16:06:05 +01002635 sor->clk_safe = devm_clk_get(&pdev->dev, "safe");
Thierry Reding4dbdc742015-04-27 15:04:26 +02002636 if (IS_ERR(sor->clk_safe)) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002637 err = PTR_ERR(sor->clk_safe);
2638 dev_err(&pdev->dev, "failed to get safe clock: %d\n", err);
2639 goto remove;
Thierry Reding4dbdc742015-04-27 15:04:26 +02002640 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002641
Thierry Reding6b6b6042013-11-15 16:06:05 +01002642 sor->clk_dp = devm_clk_get(&pdev->dev, "dp");
Thierry Reding4dbdc742015-04-27 15:04:26 +02002643 if (IS_ERR(sor->clk_dp)) {
Thierry Reding459cc2c2015-07-30 10:34:24 +02002644 err = PTR_ERR(sor->clk_dp);
2645 dev_err(&pdev->dev, "failed to get DP clock: %d\n", err);
2646 goto remove;
Thierry Reding4dbdc742015-04-27 15:04:26 +02002647 }
Thierry Reding6b6b6042013-11-15 16:06:05 +01002648
Thierry Redingaaff8bd2015-08-07 16:04:54 +02002649 platform_set_drvdata(pdev, sor);
2650 pm_runtime_enable(&pdev->dev);
2651
Thierry Redingb2992212015-10-01 14:25:03 +02002652 pm_runtime_get_sync(&pdev->dev);
2653 sor->clk_brick = tegra_clk_sor_brick_register(sor, "sor1_brick");
2654 pm_runtime_put(&pdev->dev);
2655
2656 if (IS_ERR(sor->clk_brick)) {
2657 err = PTR_ERR(sor->clk_brick);
2658 dev_err(&pdev->dev, "failed to register SOR clock: %d\n", err);
2659 goto remove;
2660 }
2661
Thierry Reding6b6b6042013-11-15 16:06:05 +01002662 INIT_LIST_HEAD(&sor->client.list);
2663 sor->client.ops = &sor_client_ops;
2664 sor->client.dev = &pdev->dev;
2665
Thierry Reding6b6b6042013-11-15 16:06:05 +01002666 err = host1x_client_register(&sor->client);
2667 if (err < 0) {
2668 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
2669 err);
Thierry Reding459cc2c2015-07-30 10:34:24 +02002670 goto remove;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002671 }
2672
Thierry Reding6b6b6042013-11-15 16:06:05 +01002673 return 0;
Thierry Reding459cc2c2015-07-30 10:34:24 +02002674
2675remove:
2676 if (sor->ops && sor->ops->remove)
2677 sor->ops->remove(sor);
2678output:
2679 tegra_output_remove(&sor->output);
2680 return err;
Thierry Reding6b6b6042013-11-15 16:06:05 +01002681}
2682
2683static int tegra_sor_remove(struct platform_device *pdev)
2684{
2685 struct tegra_sor *sor = platform_get_drvdata(pdev);
2686 int err;
2687
Thierry Redingaaff8bd2015-08-07 16:04:54 +02002688 pm_runtime_disable(&pdev->dev);
2689
Thierry Reding6b6b6042013-11-15 16:06:05 +01002690 err = host1x_client_unregister(&sor->client);
2691 if (err < 0) {
2692 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
2693 err);
2694 return err;
2695 }
2696
Thierry Reding459cc2c2015-07-30 10:34:24 +02002697 if (sor->ops && sor->ops->remove) {
2698 err = sor->ops->remove(sor);
2699 if (err < 0)
2700 dev_err(&pdev->dev, "failed to remove SOR: %d\n", err);
2701 }
2702
Thierry Reding328ec692014-12-19 15:55:08 +01002703 tegra_output_remove(&sor->output);
Thierry Reding6b6b6042013-11-15 16:06:05 +01002704
2705 return 0;
2706}
2707
Thierry Redingaaff8bd2015-08-07 16:04:54 +02002708#ifdef CONFIG_PM
2709static int tegra_sor_suspend(struct device *dev)
2710{
2711 struct tegra_sor *sor = dev_get_drvdata(dev);
2712 int err;
2713
2714 err = reset_control_assert(sor->rst);
2715 if (err < 0) {
2716 dev_err(dev, "failed to assert reset: %d\n", err);
2717 return err;
2718 }
2719
2720 usleep_range(1000, 2000);
2721
2722 clk_disable_unprepare(sor->clk);
2723
2724 return 0;
2725}
2726
2727static int tegra_sor_resume(struct device *dev)
2728{
2729 struct tegra_sor *sor = dev_get_drvdata(dev);
2730 int err;
2731
2732 err = clk_prepare_enable(sor->clk);
2733 if (err < 0) {
2734 dev_err(dev, "failed to enable clock: %d\n", err);
2735 return err;
2736 }
2737
2738 usleep_range(1000, 2000);
2739
2740 err = reset_control_deassert(sor->rst);
2741 if (err < 0) {
2742 dev_err(dev, "failed to deassert reset: %d\n", err);
2743 clk_disable_unprepare(sor->clk);
2744 return err;
2745 }
2746
2747 return 0;
2748}
2749#endif
2750
2751static const struct dev_pm_ops tegra_sor_pm_ops = {
2752 SET_RUNTIME_PM_OPS(tegra_sor_suspend, tegra_sor_resume, NULL)
2753};
2754
Thierry Reding6b6b6042013-11-15 16:06:05 +01002755struct platform_driver tegra_sor_driver = {
2756 .driver = {
2757 .name = "tegra-sor",
2758 .of_match_table = tegra_sor_of_match,
Thierry Redingaaff8bd2015-08-07 16:04:54 +02002759 .pm = &tegra_sor_pm_ops,
Thierry Reding6b6b6042013-11-15 16:06:05 +01002760 },
2761 .probe = tegra_sor_probe,
2762 .remove = tegra_sor_remove,
2763};