1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013 NVIDIA Corporation
7 #include <linux/clk-provider.h>
8 #include <linux/debugfs.h>
10 #include <linux/module.h>
11 #include <linux/of_device.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_runtime.h>
14 #include <linux/regulator/consumer.h>
15 #include <linux/reset.h>
17 #include <soc/tegra/pmc.h>
19 #include <drm/drm_atomic_helper.h>
20 #include <drm/drm_debugfs.h>
21 #include <drm/drm_dp_helper.h>
22 #include <drm/drm_file.h>
23 #include <drm/drm_panel.h>
24 #include <drm/drm_scdc_helper.h>
25 #include <drm/drm_simple_kms_helper.h>
34 #define SOR_REKEY 0x38
36 struct tegra_sor_hdmi_settings
{
37 unsigned long frequency
;
56 static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults
[] = {
58 .frequency
= 54000000,
70 .drive_current
= { 0x33, 0x3a, 0x3a, 0x3a },
71 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
73 .frequency
= 75000000,
85 .drive_current
= { 0x33, 0x3a, 0x3a, 0x3a },
86 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
88 .frequency
= 150000000,
100 .drive_current
= { 0x33, 0x3a, 0x3a, 0x3a },
101 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
103 .frequency
= 300000000,
111 .bg_vref_level
= 0xa,
115 .drive_current
= { 0x33, 0x3f, 0x3f, 0x3f },
116 .preemphasis
= { 0x00, 0x17, 0x17, 0x17 },
118 .frequency
= 600000000,
126 .bg_vref_level
= 0x8,
130 .drive_current
= { 0x33, 0x3f, 0x3f, 0x3f },
131 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
135 static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults
[] = {
137 .frequency
= 75000000,
145 .bg_vref_level
= 0x8,
149 .drive_current
= { 0x29, 0x29, 0x29, 0x29 },
150 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
152 .frequency
= 150000000,
160 .bg_vref_level
= 0x8,
164 .drive_current
= { 0x30, 0x37, 0x37, 0x37 },
165 .preemphasis
= { 0x01, 0x02, 0x02, 0x02 },
167 .frequency
= 300000000,
175 .bg_vref_level
= 0xf,
179 .drive_current
= { 0x30, 0x37, 0x37, 0x37 },
180 .preemphasis
= { 0x10, 0x3e, 0x3e, 0x3e },
182 .frequency
= 600000000,
190 .bg_vref_level
= 0xe,
194 .drive_current
= { 0x35, 0x3e, 0x3e, 0x3e },
195 .preemphasis
= { 0x02, 0x3f, 0x3f, 0x3f },
200 static const struct tegra_sor_hdmi_settings tegra186_sor_hdmi_defaults
[] = {
202 .frequency
= 54000000,
214 .drive_current
= { 0x3a, 0x3a, 0x3a, 0x33 },
215 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
217 .frequency
= 75000000,
229 .drive_current
= { 0x3a, 0x3a, 0x3a, 0x33 },
230 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
232 .frequency
= 150000000,
238 .tx_pu_value
= 0x66 /* 0 */,
243 .sparepll
= 0x00, /* 0x34 */
244 .drive_current
= { 0x3a, 0x3a, 0x3a, 0x37 },
245 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
247 .frequency
= 300000000,
259 .drive_current
= { 0x3d, 0x3d, 0x3d, 0x33 },
260 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
262 .frequency
= 600000000,
274 .drive_current
= { 0x3d, 0x3d, 0x3d, 0x33 },
275 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
279 static const struct tegra_sor_hdmi_settings tegra194_sor_hdmi_defaults
[] = {
281 .frequency
= 54000000,
293 .drive_current
= { 0x3a, 0x3a, 0x3a, 0x33 },
294 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
296 .frequency
= 75000000,
308 .drive_current
= { 0x3a, 0x3a, 0x3a, 0x33 },
309 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
311 .frequency
= 150000000,
317 .tx_pu_value
= 0x66 /* 0 */,
322 .sparepll
= 0x00, /* 0x34 */
323 .drive_current
= { 0x3a, 0x3a, 0x3a, 0x37 },
324 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
326 .frequency
= 300000000,
338 .drive_current
= { 0x3d, 0x3d, 0x3d, 0x33 },
339 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
341 .frequency
= 600000000,
353 .drive_current
= { 0x3d, 0x3d, 0x3d, 0x33 },
354 .preemphasis
= { 0x00, 0x00, 0x00, 0x00 },
358 struct tegra_sor_regs
{
359 unsigned int head_state0
;
360 unsigned int head_state1
;
361 unsigned int head_state2
;
362 unsigned int head_state3
;
363 unsigned int head_state4
;
364 unsigned int head_state5
;
369 unsigned int dp_padctl0
;
370 unsigned int dp_padctl2
;
373 struct tegra_sor_soc
{
380 const struct tegra_sor_regs
*regs
;
383 const struct tegra_sor_hdmi_settings
*settings
;
384 unsigned int num_settings
;
389 const u8 (*voltage_swing
)[4][4];
390 const u8 (*pre_emphasis
)[4][4];
391 const u8 (*post_cursor
)[4][4];
392 const u8 (*tx_pu
)[4][4];
397 struct tegra_sor_ops
{
399 int (*probe
)(struct tegra_sor
*sor
);
400 void (*audio_enable
)(struct tegra_sor
*sor
);
401 void (*audio_disable
)(struct tegra_sor
*sor
);
405 struct host1x_client client
;
406 struct tegra_output output
;
409 const struct tegra_sor_soc
*soc
;
414 struct reset_control
*rst
;
415 struct clk
*clk_parent
;
416 struct clk
*clk_safe
;
424 struct drm_dp_link link
;
425 struct drm_dp_aux
*aux
;
427 struct drm_info_list
*debugfs_files
;
429 const struct tegra_sor_ops
*ops
;
430 enum tegra_io_pad pad
;
433 struct tegra_sor_hdmi_settings
*settings
;
434 unsigned int num_settings
;
436 struct regulator
*avdd_io_supply
;
437 struct regulator
*vdd_pll_supply
;
438 struct regulator
*hdmi_supply
;
440 struct delayed_work scdc
;
443 struct tegra_hda_format format
;
446 struct tegra_sor_state
{
447 struct drm_connector_state base
;
449 unsigned int link_speed
;
454 static inline struct tegra_sor_state
*
455 to_sor_state(struct drm_connector_state
*state
)
457 return container_of(state
, struct tegra_sor_state
, base
);
460 struct tegra_sor_config
{
473 static inline struct tegra_sor
*
474 host1x_client_to_sor(struct host1x_client
*client
)
476 return container_of(client
, struct tegra_sor
, client
);
479 static inline struct tegra_sor
*to_sor(struct tegra_output
*output
)
481 return container_of(output
, struct tegra_sor
, output
);
484 static inline u32
tegra_sor_readl(struct tegra_sor
*sor
, unsigned int offset
)
486 u32 value
= readl(sor
->regs
+ (offset
<< 2));
488 trace_sor_readl(sor
->dev
, offset
, value
);
493 static inline void tegra_sor_writel(struct tegra_sor
*sor
, u32 value
,
496 trace_sor_writel(sor
->dev
, offset
, value
);
497 writel(value
, sor
->regs
+ (offset
<< 2));
500 static int tegra_sor_set_parent_clock(struct tegra_sor
*sor
, struct clk
*parent
)
504 clk_disable_unprepare(sor
->clk
);
506 err
= clk_set_parent(sor
->clk_out
, parent
);
510 err
= clk_prepare_enable(sor
->clk
);
517 struct tegra_clk_sor_pad
{
519 struct tegra_sor
*sor
;
522 static inline struct tegra_clk_sor_pad
*to_pad(struct clk_hw
*hw
)
524 return container_of(hw
, struct tegra_clk_sor_pad
, hw
);
527 static const char * const tegra_clk_sor_pad_parents
[2][2] = {
528 { "pll_d_out0", "pll_dp" },
529 { "pll_d2_out0", "pll_dp" },
533 * Implementing ->set_parent() here isn't really required because the parent
534 * will be explicitly selected in the driver code via the DP_CLK_SEL mux in
535 * the SOR_CLK_CNTRL register. This is primarily for compatibility with the
536 * Tegra186 and later SoC generations where the BPMP implements this clock
537 * and doesn't expose the mux via the common clock framework.
540 static int tegra_clk_sor_pad_set_parent(struct clk_hw
*hw
, u8 index
)
542 struct tegra_clk_sor_pad
*pad
= to_pad(hw
);
543 struct tegra_sor
*sor
= pad
->sor
;
546 value
= tegra_sor_readl(sor
, SOR_CLK_CNTRL
);
547 value
&= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK
;
551 value
|= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK
;
555 value
|= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK
;
559 tegra_sor_writel(sor
, value
, SOR_CLK_CNTRL
);
564 static u8
tegra_clk_sor_pad_get_parent(struct clk_hw
*hw
)
566 struct tegra_clk_sor_pad
*pad
= to_pad(hw
);
567 struct tegra_sor
*sor
= pad
->sor
;
571 value
= tegra_sor_readl(sor
, SOR_CLK_CNTRL
);
573 switch (value
& SOR_CLK_CNTRL_DP_CLK_SEL_MASK
) {
574 case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK
:
575 case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_PCLK
:
579 case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK
:
580 case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_DPCLK
:
588 static const struct clk_ops tegra_clk_sor_pad_ops
= {
589 .set_parent
= tegra_clk_sor_pad_set_parent
,
590 .get_parent
= tegra_clk_sor_pad_get_parent
,
593 static struct clk
*tegra_clk_sor_pad_register(struct tegra_sor
*sor
,
596 struct tegra_clk_sor_pad
*pad
;
597 struct clk_init_data init
;
600 pad
= devm_kzalloc(sor
->dev
, sizeof(*pad
), GFP_KERNEL
);
602 return ERR_PTR(-ENOMEM
);
608 init
.parent_names
= tegra_clk_sor_pad_parents
[sor
->index
];
609 init
.num_parents
= ARRAY_SIZE(tegra_clk_sor_pad_parents
[sor
->index
]);
610 init
.ops
= &tegra_clk_sor_pad_ops
;
612 pad
->hw
.init
= &init
;
614 clk
= devm_clk_register(sor
->dev
, &pad
->hw
);
619 static void tegra_sor_filter_rates(struct tegra_sor
*sor
)
621 struct drm_dp_link
*link
= &sor
->link
;
624 /* Tegra only supports RBR, HBR and HBR2 */
625 for (i
= 0; i
< link
->num_rates
; i
++) {
626 switch (link
->rates
[i
]) {
633 DRM_DEBUG_KMS("link rate %lu kHz not supported\n",
640 drm_dp_link_update_rates(link
);
643 static int tegra_sor_power_up_lanes(struct tegra_sor
*sor
, unsigned int lanes
)
645 unsigned long timeout
;
649 * Clear or set the PD_TXD bit corresponding to each lane, depending
650 * on whether it is used or not.
652 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
655 value
&= ~(SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[3]) |
656 SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[2]));
658 value
|= SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[3]) |
659 SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[2]);
662 value
&= ~SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[1]);
664 value
|= SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[1]);
667 value
&= ~SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[0]);
669 value
|= SOR_DP_PADCTL_PD_TXD(sor
->soc
->lane_map
[0]);
671 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
673 /* start lane sequencer */
674 value
= SOR_LANE_SEQ_CTL_TRIGGER
| SOR_LANE_SEQ_CTL_SEQUENCE_DOWN
|
675 SOR_LANE_SEQ_CTL_POWER_STATE_UP
;
676 tegra_sor_writel(sor
, value
, SOR_LANE_SEQ_CTL
);
678 timeout
= jiffies
+ msecs_to_jiffies(250);
680 while (time_before(jiffies
, timeout
)) {
681 value
= tegra_sor_readl(sor
, SOR_LANE_SEQ_CTL
);
682 if ((value
& SOR_LANE_SEQ_CTL_TRIGGER
) == 0)
685 usleep_range(250, 1000);
688 if ((value
& SOR_LANE_SEQ_CTL_TRIGGER
) != 0)
694 static int tegra_sor_power_down_lanes(struct tegra_sor
*sor
)
696 unsigned long timeout
;
699 /* power down all lanes */
700 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
701 value
&= ~(SOR_DP_PADCTL_PD_TXD_3
| SOR_DP_PADCTL_PD_TXD_0
|
702 SOR_DP_PADCTL_PD_TXD_1
| SOR_DP_PADCTL_PD_TXD_2
);
703 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
705 /* start lane sequencer */
706 value
= SOR_LANE_SEQ_CTL_TRIGGER
| SOR_LANE_SEQ_CTL_SEQUENCE_UP
|
707 SOR_LANE_SEQ_CTL_POWER_STATE_DOWN
;
708 tegra_sor_writel(sor
, value
, SOR_LANE_SEQ_CTL
);
710 timeout
= jiffies
+ msecs_to_jiffies(250);
712 while (time_before(jiffies
, timeout
)) {
713 value
= tegra_sor_readl(sor
, SOR_LANE_SEQ_CTL
);
714 if ((value
& SOR_LANE_SEQ_CTL_TRIGGER
) == 0)
717 usleep_range(25, 100);
720 if ((value
& SOR_LANE_SEQ_CTL_TRIGGER
) != 0)
726 static void tegra_sor_dp_precharge(struct tegra_sor
*sor
, unsigned int lanes
)
730 /* pre-charge all used lanes */
731 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
734 value
&= ~(SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[3]) |
735 SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[2]));
737 value
|= SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[3]) |
738 SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[2]);
741 value
&= ~SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[1]);
743 value
|= SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[1]);
746 value
&= ~SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[0]);
748 value
|= SOR_DP_PADCTL_CM_TXD(sor
->soc
->lane_map
[0]);
750 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
752 usleep_range(15, 100);
754 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
755 value
&= ~(SOR_DP_PADCTL_CM_TXD_3
| SOR_DP_PADCTL_CM_TXD_2
|
756 SOR_DP_PADCTL_CM_TXD_1
| SOR_DP_PADCTL_CM_TXD_0
);
757 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
760 static void tegra_sor_dp_term_calibrate(struct tegra_sor
*sor
)
762 u32 mask
= 0x08, adj
= 0, value
;
764 /* enable pad calibration logic */
765 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
766 value
&= ~SOR_DP_PADCTL_PAD_CAL_PD
;
767 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
769 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll1
);
770 value
|= SOR_PLL1_TMDS_TERM
;
771 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll1
);
776 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll1
);
777 value
&= ~SOR_PLL1_TMDS_TERMADJ_MASK
;
778 value
|= SOR_PLL1_TMDS_TERMADJ(adj
);
779 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll1
);
781 usleep_range(100, 200);
783 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll1
);
784 if (value
& SOR_PLL1_TERM_COMPOUT
)
790 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll1
);
791 value
&= ~SOR_PLL1_TMDS_TERMADJ_MASK
;
792 value
|= SOR_PLL1_TMDS_TERMADJ(adj
);
793 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll1
);
795 /* disable pad calibration logic */
796 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
797 value
|= SOR_DP_PADCTL_PAD_CAL_PD
;
798 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
801 static int tegra_sor_dp_link_apply_training(struct drm_dp_link
*link
)
803 struct tegra_sor
*sor
= container_of(link
, struct tegra_sor
, link
);
804 u32 voltage_swing
= 0, pre_emphasis
= 0, post_cursor
= 0;
805 const struct tegra_sor_soc
*soc
= sor
->soc
;
806 u32 pattern
= 0, tx_pu
= 0, value
;
809 for (value
= 0, i
= 0; i
< link
->lanes
; i
++) {
810 u8 vs
= link
->train
.request
.voltage_swing
[i
];
811 u8 pe
= link
->train
.request
.pre_emphasis
[i
];
812 u8 pc
= link
->train
.request
.post_cursor
[i
];
813 u8 shift
= sor
->soc
->lane_map
[i
] << 3;
815 voltage_swing
|= soc
->voltage_swing
[pc
][vs
][pe
] << shift
;
816 pre_emphasis
|= soc
->pre_emphasis
[pc
][vs
][pe
] << shift
;
817 post_cursor
|= soc
->post_cursor
[pc
][vs
][pe
] << shift
;
819 if (sor
->soc
->tx_pu
[pc
][vs
][pe
] > tx_pu
)
820 tx_pu
= sor
->soc
->tx_pu
[pc
][vs
][pe
];
822 switch (link
->train
.pattern
) {
823 case DP_TRAINING_PATTERN_DISABLE
:
824 value
= SOR_DP_TPG_SCRAMBLER_GALIOS
|
825 SOR_DP_TPG_PATTERN_NONE
;
828 case DP_TRAINING_PATTERN_1
:
829 value
= SOR_DP_TPG_SCRAMBLER_NONE
|
830 SOR_DP_TPG_PATTERN_TRAIN1
;
833 case DP_TRAINING_PATTERN_2
:
834 value
= SOR_DP_TPG_SCRAMBLER_NONE
|
835 SOR_DP_TPG_PATTERN_TRAIN2
;
838 case DP_TRAINING_PATTERN_3
:
839 value
= SOR_DP_TPG_SCRAMBLER_NONE
|
840 SOR_DP_TPG_PATTERN_TRAIN3
;
847 if (link
->caps
.channel_coding
)
848 value
|= SOR_DP_TPG_CHANNEL_CODING
;
850 pattern
= pattern
<< 8 | value
;
853 tegra_sor_writel(sor
, voltage_swing
, SOR_LANE_DRIVE_CURRENT0
);
854 tegra_sor_writel(sor
, pre_emphasis
, SOR_LANE_PREEMPHASIS0
);
856 if (link
->caps
.tps3_supported
)
857 tegra_sor_writel(sor
, post_cursor
, SOR_LANE_POSTCURSOR0
);
859 tegra_sor_writel(sor
, pattern
, SOR_DP_TPG
);
861 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
862 value
&= ~SOR_DP_PADCTL_TX_PU_MASK
;
863 value
|= SOR_DP_PADCTL_TX_PU_ENABLE
;
864 value
|= SOR_DP_PADCTL_TX_PU(tx_pu
);
865 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
867 usleep_range(20, 100);
872 static int tegra_sor_dp_link_configure(struct drm_dp_link
*link
)
874 struct tegra_sor
*sor
= container_of(link
, struct tegra_sor
, link
);
875 unsigned int rate
, lanes
;
879 rate
= drm_dp_link_rate_to_bw_code(link
->rate
);
882 /* configure link speed and lane count */
883 value
= tegra_sor_readl(sor
, SOR_CLK_CNTRL
);
884 value
&= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK
;
885 value
|= SOR_CLK_CNTRL_DP_LINK_SPEED(rate
);
886 tegra_sor_writel(sor
, value
, SOR_CLK_CNTRL
);
888 value
= tegra_sor_readl(sor
, SOR_DP_LINKCTL0
);
889 value
&= ~SOR_DP_LINKCTL_LANE_COUNT_MASK
;
890 value
|= SOR_DP_LINKCTL_LANE_COUNT(lanes
);
892 if (link
->caps
.enhanced_framing
)
893 value
|= SOR_DP_LINKCTL_ENHANCED_FRAME
;
895 tegra_sor_writel(sor
, value
, SOR_DP_LINKCTL0
);
897 usleep_range(400, 1000);
899 /* configure load pulse position adjustment */
900 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll1
);
901 value
&= ~SOR_PLL1_LOADADJ_MASK
;
904 case DP_LINK_BW_1_62
:
905 value
|= SOR_PLL1_LOADADJ(0x3);
909 value
|= SOR_PLL1_LOADADJ(0x4);
913 value
|= SOR_PLL1_LOADADJ(0x6);
917 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll1
);
919 /* use alternate scrambler reset for eDP */
920 value
= tegra_sor_readl(sor
, SOR_DP_SPARE0
);
923 value
&= ~SOR_DP_SPARE_PANEL_INTERNAL
;
925 value
|= SOR_DP_SPARE_PANEL_INTERNAL
;
927 tegra_sor_writel(sor
, value
, SOR_DP_SPARE0
);
929 err
= tegra_sor_power_down_lanes(sor
);
931 dev_err(sor
->dev
, "failed to power down lanes: %d\n", err
);
935 /* power up and pre-charge lanes */
936 err
= tegra_sor_power_up_lanes(sor
, lanes
);
938 dev_err(sor
->dev
, "failed to power up %u lane%s: %d\n",
939 lanes
, (lanes
!= 1) ? "s" : "", err
);
943 tegra_sor_dp_precharge(sor
, lanes
);
948 static const struct drm_dp_link_ops tegra_sor_dp_link_ops
= {
949 .apply_training
= tegra_sor_dp_link_apply_training
,
950 .configure
= tegra_sor_dp_link_configure
,
953 static void tegra_sor_super_update(struct tegra_sor
*sor
)
955 tegra_sor_writel(sor
, 0, SOR_SUPER_STATE0
);
956 tegra_sor_writel(sor
, 1, SOR_SUPER_STATE0
);
957 tegra_sor_writel(sor
, 0, SOR_SUPER_STATE0
);
960 static void tegra_sor_update(struct tegra_sor
*sor
)
962 tegra_sor_writel(sor
, 0, SOR_STATE0
);
963 tegra_sor_writel(sor
, 1, SOR_STATE0
);
964 tegra_sor_writel(sor
, 0, SOR_STATE0
);
967 static int tegra_sor_setup_pwm(struct tegra_sor
*sor
, unsigned long timeout
)
971 value
= tegra_sor_readl(sor
, SOR_PWM_DIV
);
972 value
&= ~SOR_PWM_DIV_MASK
;
973 value
|= 0x400; /* period */
974 tegra_sor_writel(sor
, value
, SOR_PWM_DIV
);
976 value
= tegra_sor_readl(sor
, SOR_PWM_CTL
);
977 value
&= ~SOR_PWM_CTL_DUTY_CYCLE_MASK
;
978 value
|= 0x400; /* duty cycle */
979 value
&= ~SOR_PWM_CTL_CLK_SEL
; /* clock source: PCLK */
980 value
|= SOR_PWM_CTL_TRIGGER
;
981 tegra_sor_writel(sor
, value
, SOR_PWM_CTL
);
983 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
985 while (time_before(jiffies
, timeout
)) {
986 value
= tegra_sor_readl(sor
, SOR_PWM_CTL
);
987 if ((value
& SOR_PWM_CTL_TRIGGER
) == 0)
990 usleep_range(25, 100);
996 static int tegra_sor_attach(struct tegra_sor
*sor
)
998 unsigned long value
, timeout
;
1000 /* wake up in normal mode */
1001 value
= tegra_sor_readl(sor
, SOR_SUPER_STATE1
);
1002 value
|= SOR_SUPER_STATE_HEAD_MODE_AWAKE
;
1003 value
|= SOR_SUPER_STATE_MODE_NORMAL
;
1004 tegra_sor_writel(sor
, value
, SOR_SUPER_STATE1
);
1005 tegra_sor_super_update(sor
);
1008 value
= tegra_sor_readl(sor
, SOR_SUPER_STATE1
);
1009 value
|= SOR_SUPER_STATE_ATTACHED
;
1010 tegra_sor_writel(sor
, value
, SOR_SUPER_STATE1
);
1011 tegra_sor_super_update(sor
);
1013 timeout
= jiffies
+ msecs_to_jiffies(250);
1015 while (time_before(jiffies
, timeout
)) {
1016 value
= tegra_sor_readl(sor
, SOR_TEST
);
1017 if ((value
& SOR_TEST_ATTACHED
) != 0)
1020 usleep_range(25, 100);
1026 static int tegra_sor_wakeup(struct tegra_sor
*sor
)
1028 unsigned long value
, timeout
;
1030 timeout
= jiffies
+ msecs_to_jiffies(250);
1032 /* wait for head to wake up */
1033 while (time_before(jiffies
, timeout
)) {
1034 value
= tegra_sor_readl(sor
, SOR_TEST
);
1035 value
&= SOR_TEST_HEAD_MODE_MASK
;
1037 if (value
== SOR_TEST_HEAD_MODE_AWAKE
)
1040 usleep_range(25, 100);
1046 static int tegra_sor_power_up(struct tegra_sor
*sor
, unsigned long timeout
)
1050 value
= tegra_sor_readl(sor
, SOR_PWR
);
1051 value
|= SOR_PWR_TRIGGER
| SOR_PWR_NORMAL_STATE_PU
;
1052 tegra_sor_writel(sor
, value
, SOR_PWR
);
1054 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
1056 while (time_before(jiffies
, timeout
)) {
1057 value
= tegra_sor_readl(sor
, SOR_PWR
);
1058 if ((value
& SOR_PWR_TRIGGER
) == 0)
1061 usleep_range(25, 100);
1067 struct tegra_sor_params
{
1068 /* number of link clocks per line */
1069 unsigned int num_clocks
;
1070 /* ratio between input and output */
1072 /* precision factor */
1075 unsigned int active_polarity
;
1076 unsigned int active_count
;
1077 unsigned int active_frac
;
1078 unsigned int tu_size
;
1082 static int tegra_sor_compute_params(struct tegra_sor
*sor
,
1083 struct tegra_sor_params
*params
,
1084 unsigned int tu_size
)
1086 u64 active_sym
, active_count
, frac
, approx
;
1087 u32 active_polarity
, active_frac
= 0;
1088 const u64 f
= params
->precision
;
1091 active_sym
= params
->ratio
* tu_size
;
1092 active_count
= div_u64(active_sym
, f
) * f
;
1093 frac
= active_sym
- active_count
;
1095 /* fraction < 0.5 */
1096 if (frac
>= (f
/ 2)) {
1097 active_polarity
= 1;
1100 active_polarity
= 0;
1104 frac
= div_u64(f
* f
, frac
); /* 1/fraction */
1105 if (frac
<= (15 * f
)) {
1106 active_frac
= div_u64(frac
, f
);
1109 if (active_polarity
)
1112 active_frac
= active_polarity
? 1 : 15;
1116 if (active_frac
== 1)
1117 active_polarity
= 0;
1119 if (active_polarity
== 1) {
1121 approx
= active_count
+ (active_frac
* (f
- 1)) * f
;
1122 approx
= div_u64(approx
, active_frac
* f
);
1124 approx
= active_count
+ f
;
1128 approx
= active_count
+ div_u64(f
, active_frac
);
1130 approx
= active_count
;
1133 error
= div_s64(active_sym
- approx
, tu_size
);
1134 error
*= params
->num_clocks
;
1136 if (error
<= 0 && abs(error
) < params
->error
) {
1137 params
->active_count
= div_u64(active_count
, f
);
1138 params
->active_polarity
= active_polarity
;
1139 params
->active_frac
= active_frac
;
1140 params
->error
= abs(error
);
1141 params
->tu_size
= tu_size
;
1150 static int tegra_sor_compute_config(struct tegra_sor
*sor
,
1151 const struct drm_display_mode
*mode
,
1152 struct tegra_sor_config
*config
,
1153 struct drm_dp_link
*link
)
1155 const u64 f
= 100000, link_rate
= link
->rate
* 1000;
1156 const u64 pclk
= mode
->clock
* 1000;
1157 u64 input
, output
, watermark
, num
;
1158 struct tegra_sor_params params
;
1159 u32 num_syms_per_line
;
1162 if (!link_rate
|| !link
->lanes
|| !pclk
|| !config
->bits_per_pixel
)
1165 input
= pclk
* config
->bits_per_pixel
;
1166 output
= link_rate
* 8 * link
->lanes
;
1168 if (input
>= output
)
1171 memset(¶ms
, 0, sizeof(params
));
1172 params
.ratio
= div64_u64(input
* f
, output
);
1173 params
.num_clocks
= div_u64(link_rate
* mode
->hdisplay
, pclk
);
1174 params
.precision
= f
;
1175 params
.error
= 64 * f
;
1176 params
.tu_size
= 64;
1178 for (i
= params
.tu_size
; i
>= 32; i
--)
1179 if (tegra_sor_compute_params(sor
, ¶ms
, i
))
1182 if (params
.active_frac
== 0) {
1183 config
->active_polarity
= 0;
1184 config
->active_count
= params
.active_count
;
1186 if (!params
.active_polarity
)
1187 config
->active_count
--;
1189 config
->tu_size
= params
.tu_size
;
1190 config
->active_frac
= 1;
1192 config
->active_polarity
= params
.active_polarity
;
1193 config
->active_count
= params
.active_count
;
1194 config
->active_frac
= params
.active_frac
;
1195 config
->tu_size
= params
.tu_size
;
1199 "polarity: %d active count: %d tu size: %d active frac: %d\n",
1200 config
->active_polarity
, config
->active_count
,
1201 config
->tu_size
, config
->active_frac
);
1203 watermark
= params
.ratio
* config
->tu_size
* (f
- params
.ratio
);
1204 watermark
= div_u64(watermark
, f
);
1206 watermark
= div_u64(watermark
+ params
.error
, f
);
1207 config
->watermark
= watermark
+ (config
->bits_per_pixel
/ 8) + 2;
1208 num_syms_per_line
= (mode
->hdisplay
* config
->bits_per_pixel
) *
1211 if (config
->watermark
> 30) {
1212 config
->watermark
= 30;
1214 "unable to compute TU size, forcing watermark to %u\n",
1216 } else if (config
->watermark
> num_syms_per_line
) {
1217 config
->watermark
= num_syms_per_line
;
1218 dev_err(sor
->dev
, "watermark too high, forcing to %u\n",
1222 /* compute the number of symbols per horizontal blanking interval */
1223 num
= ((mode
->htotal
- mode
->hdisplay
) - 7) * link_rate
;
1224 config
->hblank_symbols
= div_u64(num
, pclk
);
1226 if (link
->caps
.enhanced_framing
)
1227 config
->hblank_symbols
-= 3;
1229 config
->hblank_symbols
-= 12 / link
->lanes
;
1231 /* compute the number of symbols per vertical blanking interval */
1232 num
= (mode
->hdisplay
- 25) * link_rate
;
1233 config
->vblank_symbols
= div_u64(num
, pclk
);
1234 config
->vblank_symbols
-= 36 / link
->lanes
+ 4;
1236 dev_dbg(sor
->dev
, "blank symbols: H:%u V:%u\n", config
->hblank_symbols
,
1237 config
->vblank_symbols
);
1242 static void tegra_sor_apply_config(struct tegra_sor
*sor
,
1243 const struct tegra_sor_config
*config
)
1247 value
= tegra_sor_readl(sor
, SOR_DP_LINKCTL0
);
1248 value
&= ~SOR_DP_LINKCTL_TU_SIZE_MASK
;
1249 value
|= SOR_DP_LINKCTL_TU_SIZE(config
->tu_size
);
1250 tegra_sor_writel(sor
, value
, SOR_DP_LINKCTL0
);
1252 value
= tegra_sor_readl(sor
, SOR_DP_CONFIG0
);
1253 value
&= ~SOR_DP_CONFIG_WATERMARK_MASK
;
1254 value
|= SOR_DP_CONFIG_WATERMARK(config
->watermark
);
1256 value
&= ~SOR_DP_CONFIG_ACTIVE_SYM_COUNT_MASK
;
1257 value
|= SOR_DP_CONFIG_ACTIVE_SYM_COUNT(config
->active_count
);
1259 value
&= ~SOR_DP_CONFIG_ACTIVE_SYM_FRAC_MASK
;
1260 value
|= SOR_DP_CONFIG_ACTIVE_SYM_FRAC(config
->active_frac
);
1262 if (config
->active_polarity
)
1263 value
|= SOR_DP_CONFIG_ACTIVE_SYM_POLARITY
;
1265 value
&= ~SOR_DP_CONFIG_ACTIVE_SYM_POLARITY
;
1267 value
|= SOR_DP_CONFIG_ACTIVE_SYM_ENABLE
;
1268 value
|= SOR_DP_CONFIG_DISPARITY_NEGATIVE
;
1269 tegra_sor_writel(sor
, value
, SOR_DP_CONFIG0
);
1271 value
= tegra_sor_readl(sor
, SOR_DP_AUDIO_HBLANK_SYMBOLS
);
1272 value
&= ~SOR_DP_AUDIO_HBLANK_SYMBOLS_MASK
;
1273 value
|= config
->hblank_symbols
& 0xffff;
1274 tegra_sor_writel(sor
, value
, SOR_DP_AUDIO_HBLANK_SYMBOLS
);
1276 value
= tegra_sor_readl(sor
, SOR_DP_AUDIO_VBLANK_SYMBOLS
);
1277 value
&= ~SOR_DP_AUDIO_VBLANK_SYMBOLS_MASK
;
1278 value
|= config
->vblank_symbols
& 0xffff;
1279 tegra_sor_writel(sor
, value
, SOR_DP_AUDIO_VBLANK_SYMBOLS
);
1282 static void tegra_sor_mode_set(struct tegra_sor
*sor
,
1283 const struct drm_display_mode
*mode
,
1284 struct tegra_sor_state
*state
)
1286 struct tegra_dc
*dc
= to_tegra_dc(sor
->output
.encoder
.crtc
);
1287 unsigned int vbe
, vse
, hbe
, hse
, vbs
, hbs
;
1290 value
= tegra_sor_readl(sor
, SOR_STATE1
);
1291 value
&= ~SOR_STATE_ASY_PIXELDEPTH_MASK
;
1292 value
&= ~SOR_STATE_ASY_CRC_MODE_MASK
;
1293 value
&= ~SOR_STATE_ASY_OWNER_MASK
;
1295 value
|= SOR_STATE_ASY_CRC_MODE_COMPLETE
|
1296 SOR_STATE_ASY_OWNER(dc
->pipe
+ 1);
1298 if (mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
1299 value
&= ~SOR_STATE_ASY_HSYNCPOL
;
1301 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
1302 value
|= SOR_STATE_ASY_HSYNCPOL
;
1304 if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
1305 value
&= ~SOR_STATE_ASY_VSYNCPOL
;
1307 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
1308 value
|= SOR_STATE_ASY_VSYNCPOL
;
1310 switch (state
->bpc
) {
1312 value
|= SOR_STATE_ASY_PIXELDEPTH_BPP_48_444
;
1316 value
|= SOR_STATE_ASY_PIXELDEPTH_BPP_36_444
;
1320 value
|= SOR_STATE_ASY_PIXELDEPTH_BPP_30_444
;
1324 value
|= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444
;
1328 value
|= SOR_STATE_ASY_PIXELDEPTH_BPP_18_444
;
1332 value
|= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444
;
1336 tegra_sor_writel(sor
, value
, SOR_STATE1
);
1339 * TODO: The video timing programming below doesn't seem to match the
1340 * register definitions.
1343 value
= ((mode
->vtotal
& 0x7fff) << 16) | (mode
->htotal
& 0x7fff);
1344 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->head_state1
+ dc
->pipe
);
1346 /* sync end = sync width - 1 */
1347 vse
= mode
->vsync_end
- mode
->vsync_start
- 1;
1348 hse
= mode
->hsync_end
- mode
->hsync_start
- 1;
1350 value
= ((vse
& 0x7fff) << 16) | (hse
& 0x7fff);
1351 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->head_state2
+ dc
->pipe
);
1353 /* blank end = sync end + back porch */
1354 vbe
= vse
+ (mode
->vtotal
- mode
->vsync_end
);
1355 hbe
= hse
+ (mode
->htotal
- mode
->hsync_end
);
1357 value
= ((vbe
& 0x7fff) << 16) | (hbe
& 0x7fff);
1358 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->head_state3
+ dc
->pipe
);
1360 /* blank start = blank end + active */
1361 vbs
= vbe
+ mode
->vdisplay
;
1362 hbs
= hbe
+ mode
->hdisplay
;
1364 value
= ((vbs
& 0x7fff) << 16) | (hbs
& 0x7fff);
1365 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->head_state4
+ dc
->pipe
);
1367 /* XXX interlacing support */
1368 tegra_sor_writel(sor
, 0x001, sor
->soc
->regs
->head_state5
+ dc
->pipe
);
1371 static int tegra_sor_detach(struct tegra_sor
*sor
)
1373 unsigned long value
, timeout
;
1375 /* switch to safe mode */
1376 value
= tegra_sor_readl(sor
, SOR_SUPER_STATE1
);
1377 value
&= ~SOR_SUPER_STATE_MODE_NORMAL
;
1378 tegra_sor_writel(sor
, value
, SOR_SUPER_STATE1
);
1379 tegra_sor_super_update(sor
);
1381 timeout
= jiffies
+ msecs_to_jiffies(250);
1383 while (time_before(jiffies
, timeout
)) {
1384 value
= tegra_sor_readl(sor
, SOR_PWR
);
1385 if (value
& SOR_PWR_MODE_SAFE
)
1389 if ((value
& SOR_PWR_MODE_SAFE
) == 0)
1393 value
= tegra_sor_readl(sor
, SOR_SUPER_STATE1
);
1394 value
&= ~SOR_SUPER_STATE_HEAD_MODE_MASK
;
1395 tegra_sor_writel(sor
, value
, SOR_SUPER_STATE1
);
1396 tegra_sor_super_update(sor
);
1399 value
= tegra_sor_readl(sor
, SOR_SUPER_STATE1
);
1400 value
&= ~SOR_SUPER_STATE_ATTACHED
;
1401 tegra_sor_writel(sor
, value
, SOR_SUPER_STATE1
);
1402 tegra_sor_super_update(sor
);
1404 timeout
= jiffies
+ msecs_to_jiffies(250);
1406 while (time_before(jiffies
, timeout
)) {
1407 value
= tegra_sor_readl(sor
, SOR_TEST
);
1408 if ((value
& SOR_TEST_ATTACHED
) == 0)
1411 usleep_range(25, 100);
1414 if ((value
& SOR_TEST_ATTACHED
) != 0)
1420 static int tegra_sor_power_down(struct tegra_sor
*sor
)
1422 unsigned long value
, timeout
;
1425 value
= tegra_sor_readl(sor
, SOR_PWR
);
1426 value
&= ~SOR_PWR_NORMAL_STATE_PU
;
1427 value
|= SOR_PWR_TRIGGER
;
1428 tegra_sor_writel(sor
, value
, SOR_PWR
);
1430 timeout
= jiffies
+ msecs_to_jiffies(250);
1432 while (time_before(jiffies
, timeout
)) {
1433 value
= tegra_sor_readl(sor
, SOR_PWR
);
1434 if ((value
& SOR_PWR_TRIGGER
) == 0)
1437 usleep_range(25, 100);
1440 if ((value
& SOR_PWR_TRIGGER
) != 0)
1443 /* switch to safe parent clock */
1444 err
= tegra_sor_set_parent_clock(sor
, sor
->clk_safe
);
1446 dev_err(sor
->dev
, "failed to set safe parent clock: %d\n", err
);
1450 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
1451 value
|= SOR_PLL2_PORT_POWERDOWN
;
1452 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
1454 usleep_range(20, 100);
1456 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll0
);
1457 value
|= SOR_PLL0_VCOPD
| SOR_PLL0_PWR
;
1458 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll0
);
1460 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
1461 value
|= SOR_PLL2_SEQ_PLLCAPPD
;
1462 value
|= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE
;
1463 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
1465 usleep_range(20, 100);
1470 static int tegra_sor_crc_wait(struct tegra_sor
*sor
, unsigned long timeout
)
1474 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
1476 while (time_before(jiffies
, timeout
)) {
1477 value
= tegra_sor_readl(sor
, SOR_CRCA
);
1478 if (value
& SOR_CRCA_VALID
)
1481 usleep_range(100, 200);
1487 static int tegra_sor_show_crc(struct seq_file
*s
, void *data
)
1489 struct drm_info_node
*node
= s
->private;
1490 struct tegra_sor
*sor
= node
->info_ent
->data
;
1491 struct drm_crtc
*crtc
= sor
->output
.encoder
.crtc
;
1492 struct drm_device
*drm
= node
->minor
->dev
;
1496 drm_modeset_lock_all(drm
);
1498 if (!crtc
|| !crtc
->state
->active
) {
1503 value
= tegra_sor_readl(sor
, SOR_STATE1
);
1504 value
&= ~SOR_STATE_ASY_CRC_MODE_MASK
;
1505 tegra_sor_writel(sor
, value
, SOR_STATE1
);
1507 value
= tegra_sor_readl(sor
, SOR_CRC_CNTRL
);
1508 value
|= SOR_CRC_CNTRL_ENABLE
;
1509 tegra_sor_writel(sor
, value
, SOR_CRC_CNTRL
);
1511 value
= tegra_sor_readl(sor
, SOR_TEST
);
1512 value
&= ~SOR_TEST_CRC_POST_SERIALIZE
;
1513 tegra_sor_writel(sor
, value
, SOR_TEST
);
1515 err
= tegra_sor_crc_wait(sor
, 100);
1519 tegra_sor_writel(sor
, SOR_CRCA_RESET
, SOR_CRCA
);
1520 value
= tegra_sor_readl(sor
, SOR_CRCB
);
1522 seq_printf(s
, "%08x\n", value
);
1525 drm_modeset_unlock_all(drm
);
1529 #define DEBUGFS_REG32(_name) { .name = #_name, .offset = _name }
1531 static const struct debugfs_reg32 tegra_sor_regs
[] = {
1532 DEBUGFS_REG32(SOR_CTXSW
),
1533 DEBUGFS_REG32(SOR_SUPER_STATE0
),
1534 DEBUGFS_REG32(SOR_SUPER_STATE1
),
1535 DEBUGFS_REG32(SOR_STATE0
),
1536 DEBUGFS_REG32(SOR_STATE1
),
1537 DEBUGFS_REG32(SOR_HEAD_STATE0(0)),
1538 DEBUGFS_REG32(SOR_HEAD_STATE0(1)),
1539 DEBUGFS_REG32(SOR_HEAD_STATE1(0)),
1540 DEBUGFS_REG32(SOR_HEAD_STATE1(1)),
1541 DEBUGFS_REG32(SOR_HEAD_STATE2(0)),
1542 DEBUGFS_REG32(SOR_HEAD_STATE2(1)),
1543 DEBUGFS_REG32(SOR_HEAD_STATE3(0)),
1544 DEBUGFS_REG32(SOR_HEAD_STATE3(1)),
1545 DEBUGFS_REG32(SOR_HEAD_STATE4(0)),
1546 DEBUGFS_REG32(SOR_HEAD_STATE4(1)),
1547 DEBUGFS_REG32(SOR_HEAD_STATE5(0)),
1548 DEBUGFS_REG32(SOR_HEAD_STATE5(1)),
1549 DEBUGFS_REG32(SOR_CRC_CNTRL
),
1550 DEBUGFS_REG32(SOR_DP_DEBUG_MVID
),
1551 DEBUGFS_REG32(SOR_CLK_CNTRL
),
1552 DEBUGFS_REG32(SOR_CAP
),
1553 DEBUGFS_REG32(SOR_PWR
),
1554 DEBUGFS_REG32(SOR_TEST
),
1555 DEBUGFS_REG32(SOR_PLL0
),
1556 DEBUGFS_REG32(SOR_PLL1
),
1557 DEBUGFS_REG32(SOR_PLL2
),
1558 DEBUGFS_REG32(SOR_PLL3
),
1559 DEBUGFS_REG32(SOR_CSTM
),
1560 DEBUGFS_REG32(SOR_LVDS
),
1561 DEBUGFS_REG32(SOR_CRCA
),
1562 DEBUGFS_REG32(SOR_CRCB
),
1563 DEBUGFS_REG32(SOR_BLANK
),
1564 DEBUGFS_REG32(SOR_SEQ_CTL
),
1565 DEBUGFS_REG32(SOR_LANE_SEQ_CTL
),
1566 DEBUGFS_REG32(SOR_SEQ_INST(0)),
1567 DEBUGFS_REG32(SOR_SEQ_INST(1)),
1568 DEBUGFS_REG32(SOR_SEQ_INST(2)),
1569 DEBUGFS_REG32(SOR_SEQ_INST(3)),
1570 DEBUGFS_REG32(SOR_SEQ_INST(4)),
1571 DEBUGFS_REG32(SOR_SEQ_INST(5)),
1572 DEBUGFS_REG32(SOR_SEQ_INST(6)),
1573 DEBUGFS_REG32(SOR_SEQ_INST(7)),
1574 DEBUGFS_REG32(SOR_SEQ_INST(8)),
1575 DEBUGFS_REG32(SOR_SEQ_INST(9)),
1576 DEBUGFS_REG32(SOR_SEQ_INST(10)),
1577 DEBUGFS_REG32(SOR_SEQ_INST(11)),
1578 DEBUGFS_REG32(SOR_SEQ_INST(12)),
1579 DEBUGFS_REG32(SOR_SEQ_INST(13)),
1580 DEBUGFS_REG32(SOR_SEQ_INST(14)),
1581 DEBUGFS_REG32(SOR_SEQ_INST(15)),
1582 DEBUGFS_REG32(SOR_PWM_DIV
),
1583 DEBUGFS_REG32(SOR_PWM_CTL
),
1584 DEBUGFS_REG32(SOR_VCRC_A0
),
1585 DEBUGFS_REG32(SOR_VCRC_A1
),
1586 DEBUGFS_REG32(SOR_VCRC_B0
),
1587 DEBUGFS_REG32(SOR_VCRC_B1
),
1588 DEBUGFS_REG32(SOR_CCRC_A0
),
1589 DEBUGFS_REG32(SOR_CCRC_A1
),
1590 DEBUGFS_REG32(SOR_CCRC_B0
),
1591 DEBUGFS_REG32(SOR_CCRC_B1
),
1592 DEBUGFS_REG32(SOR_EDATA_A0
),
1593 DEBUGFS_REG32(SOR_EDATA_A1
),
1594 DEBUGFS_REG32(SOR_EDATA_B0
),
1595 DEBUGFS_REG32(SOR_EDATA_B1
),
1596 DEBUGFS_REG32(SOR_COUNT_A0
),
1597 DEBUGFS_REG32(SOR_COUNT_A1
),
1598 DEBUGFS_REG32(SOR_COUNT_B0
),
1599 DEBUGFS_REG32(SOR_COUNT_B1
),
1600 DEBUGFS_REG32(SOR_DEBUG_A0
),
1601 DEBUGFS_REG32(SOR_DEBUG_A1
),
1602 DEBUGFS_REG32(SOR_DEBUG_B0
),
1603 DEBUGFS_REG32(SOR_DEBUG_B1
),
1604 DEBUGFS_REG32(SOR_TRIG
),
1605 DEBUGFS_REG32(SOR_MSCHECK
),
1606 DEBUGFS_REG32(SOR_XBAR_CTRL
),
1607 DEBUGFS_REG32(SOR_XBAR_POL
),
1608 DEBUGFS_REG32(SOR_DP_LINKCTL0
),
1609 DEBUGFS_REG32(SOR_DP_LINKCTL1
),
1610 DEBUGFS_REG32(SOR_LANE_DRIVE_CURRENT0
),
1611 DEBUGFS_REG32(SOR_LANE_DRIVE_CURRENT1
),
1612 DEBUGFS_REG32(SOR_LANE4_DRIVE_CURRENT0
),
1613 DEBUGFS_REG32(SOR_LANE4_DRIVE_CURRENT1
),
1614 DEBUGFS_REG32(SOR_LANE_PREEMPHASIS0
),
1615 DEBUGFS_REG32(SOR_LANE_PREEMPHASIS1
),
1616 DEBUGFS_REG32(SOR_LANE4_PREEMPHASIS0
),
1617 DEBUGFS_REG32(SOR_LANE4_PREEMPHASIS1
),
1618 DEBUGFS_REG32(SOR_LANE_POSTCURSOR0
),
1619 DEBUGFS_REG32(SOR_LANE_POSTCURSOR1
),
1620 DEBUGFS_REG32(SOR_DP_CONFIG0
),
1621 DEBUGFS_REG32(SOR_DP_CONFIG1
),
1622 DEBUGFS_REG32(SOR_DP_MN0
),
1623 DEBUGFS_REG32(SOR_DP_MN1
),
1624 DEBUGFS_REG32(SOR_DP_PADCTL0
),
1625 DEBUGFS_REG32(SOR_DP_PADCTL1
),
1626 DEBUGFS_REG32(SOR_DP_PADCTL2
),
1627 DEBUGFS_REG32(SOR_DP_DEBUG0
),
1628 DEBUGFS_REG32(SOR_DP_DEBUG1
),
1629 DEBUGFS_REG32(SOR_DP_SPARE0
),
1630 DEBUGFS_REG32(SOR_DP_SPARE1
),
1631 DEBUGFS_REG32(SOR_DP_AUDIO_CTRL
),
1632 DEBUGFS_REG32(SOR_DP_AUDIO_HBLANK_SYMBOLS
),
1633 DEBUGFS_REG32(SOR_DP_AUDIO_VBLANK_SYMBOLS
),
1634 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_HEADER
),
1635 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK0
),
1636 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK1
),
1637 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK2
),
1638 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK3
),
1639 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK4
),
1640 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK5
),
1641 DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK6
),
1642 DEBUGFS_REG32(SOR_DP_TPG
),
1643 DEBUGFS_REG32(SOR_DP_TPG_CONFIG
),
1644 DEBUGFS_REG32(SOR_DP_LQ_CSTM0
),
1645 DEBUGFS_REG32(SOR_DP_LQ_CSTM1
),
1646 DEBUGFS_REG32(SOR_DP_LQ_CSTM2
),
1649 static int tegra_sor_show_regs(struct seq_file
*s
, void *data
)
1651 struct drm_info_node
*node
= s
->private;
1652 struct tegra_sor
*sor
= node
->info_ent
->data
;
1653 struct drm_crtc
*crtc
= sor
->output
.encoder
.crtc
;
1654 struct drm_device
*drm
= node
->minor
->dev
;
1658 drm_modeset_lock_all(drm
);
1660 if (!crtc
|| !crtc
->state
->active
) {
1665 for (i
= 0; i
< ARRAY_SIZE(tegra_sor_regs
); i
++) {
1666 unsigned int offset
= tegra_sor_regs
[i
].offset
;
1668 seq_printf(s
, "%-38s %#05x %08x\n", tegra_sor_regs
[i
].name
,
1669 offset
, tegra_sor_readl(sor
, offset
));
1673 drm_modeset_unlock_all(drm
);
1677 static const struct drm_info_list debugfs_files
[] = {
1678 { "crc", tegra_sor_show_crc
, 0, NULL
},
1679 { "regs", tegra_sor_show_regs
, 0, NULL
},
1682 static int tegra_sor_late_register(struct drm_connector
*connector
)
1684 struct tegra_output
*output
= connector_to_output(connector
);
1685 unsigned int i
, count
= ARRAY_SIZE(debugfs_files
);
1686 struct drm_minor
*minor
= connector
->dev
->primary
;
1687 struct dentry
*root
= connector
->debugfs_entry
;
1688 struct tegra_sor
*sor
= to_sor(output
);
1690 sor
->debugfs_files
= kmemdup(debugfs_files
, sizeof(debugfs_files
),
1692 if (!sor
->debugfs_files
)
1695 for (i
= 0; i
< count
; i
++)
1696 sor
->debugfs_files
[i
].data
= sor
;
1698 drm_debugfs_create_files(sor
->debugfs_files
, count
, root
, minor
);
1703 static void tegra_sor_early_unregister(struct drm_connector
*connector
)
1705 struct tegra_output
*output
= connector_to_output(connector
);
1706 unsigned int count
= ARRAY_SIZE(debugfs_files
);
1707 struct tegra_sor
*sor
= to_sor(output
);
1709 drm_debugfs_remove_files(sor
->debugfs_files
, count
,
1710 connector
->dev
->primary
);
1711 kfree(sor
->debugfs_files
);
1712 sor
->debugfs_files
= NULL
;
1715 static void tegra_sor_connector_reset(struct drm_connector
*connector
)
1717 struct tegra_sor_state
*state
;
1719 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1723 if (connector
->state
) {
1724 __drm_atomic_helper_connector_destroy_state(connector
->state
);
1725 kfree(connector
->state
);
1728 __drm_atomic_helper_connector_reset(connector
, &state
->base
);
1731 static enum drm_connector_status
1732 tegra_sor_connector_detect(struct drm_connector
*connector
, bool force
)
1734 struct tegra_output
*output
= connector_to_output(connector
);
1735 struct tegra_sor
*sor
= to_sor(output
);
1738 return drm_dp_aux_detect(sor
->aux
);
1740 return tegra_output_connector_detect(connector
, force
);
1743 static struct drm_connector_state
*
1744 tegra_sor_connector_duplicate_state(struct drm_connector
*connector
)
1746 struct tegra_sor_state
*state
= to_sor_state(connector
->state
);
1747 struct tegra_sor_state
*copy
;
1749 copy
= kmemdup(state
, sizeof(*state
), GFP_KERNEL
);
1753 __drm_atomic_helper_connector_duplicate_state(connector
, ©
->base
);
1758 static const struct drm_connector_funcs tegra_sor_connector_funcs
= {
1759 .reset
= tegra_sor_connector_reset
,
1760 .detect
= tegra_sor_connector_detect
,
1761 .fill_modes
= drm_helper_probe_single_connector_modes
,
1762 .destroy
= tegra_output_connector_destroy
,
1763 .atomic_duplicate_state
= tegra_sor_connector_duplicate_state
,
1764 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
1765 .late_register
= tegra_sor_late_register
,
1766 .early_unregister
= tegra_sor_early_unregister
,
1769 static int tegra_sor_connector_get_modes(struct drm_connector
*connector
)
1771 struct tegra_output
*output
= connector_to_output(connector
);
1772 struct tegra_sor
*sor
= to_sor(output
);
1776 drm_dp_aux_enable(sor
->aux
);
1778 err
= tegra_output_connector_get_modes(connector
);
1781 drm_dp_aux_disable(sor
->aux
);
1786 static enum drm_mode_status
1787 tegra_sor_connector_mode_valid(struct drm_connector
*connector
,
1788 struct drm_display_mode
*mode
)
1793 static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs
= {
1794 .get_modes
= tegra_sor_connector_get_modes
,
1795 .mode_valid
= tegra_sor_connector_mode_valid
,
1799 tegra_sor_encoder_atomic_check(struct drm_encoder
*encoder
,
1800 struct drm_crtc_state
*crtc_state
,
1801 struct drm_connector_state
*conn_state
)
1803 struct tegra_output
*output
= encoder_to_output(encoder
);
1804 struct tegra_sor_state
*state
= to_sor_state(conn_state
);
1805 struct tegra_dc
*dc
= to_tegra_dc(conn_state
->crtc
);
1806 unsigned long pclk
= crtc_state
->mode
.clock
* 1000;
1807 struct tegra_sor
*sor
= to_sor(output
);
1808 struct drm_display_info
*info
;
1811 info
= &output
->connector
.display_info
;
1814 * For HBR2 modes, the SOR brick needs to use the x20 multiplier, so
1815 * the pixel clock must be corrected accordingly.
1817 if (pclk
>= 340000000) {
1818 state
->link_speed
= 20;
1819 state
->pclk
= pclk
/ 2;
1821 state
->link_speed
= 10;
1825 err
= tegra_dc_state_setup_clock(dc
, crtc_state
, sor
->clk_parent
,
1828 dev_err(output
->dev
, "failed to setup CRTC state: %d\n", err
);
1832 switch (info
->bpc
) {
1835 state
->bpc
= info
->bpc
;
1839 DRM_DEBUG_KMS("%u bits-per-color not supported\n", info
->bpc
);
1847 static inline u32
tegra_sor_hdmi_subpack(const u8
*ptr
, size_t size
)
1852 for (i
= size
; i
> 0; i
--)
1853 value
= (value
<< 8) | ptr
[i
- 1];
1858 static void tegra_sor_hdmi_write_infopack(struct tegra_sor
*sor
,
1859 const void *data
, size_t size
)
1861 const u8
*ptr
= data
;
1862 unsigned long offset
;
1867 case HDMI_INFOFRAME_TYPE_AVI
:
1868 offset
= SOR_HDMI_AVI_INFOFRAME_HEADER
;
1871 case HDMI_INFOFRAME_TYPE_AUDIO
:
1872 offset
= SOR_HDMI_AUDIO_INFOFRAME_HEADER
;
1875 case HDMI_INFOFRAME_TYPE_VENDOR
:
1876 offset
= SOR_HDMI_VSI_INFOFRAME_HEADER
;
1880 dev_err(sor
->dev
, "unsupported infoframe type: %02x\n",
1885 value
= INFOFRAME_HEADER_TYPE(ptr
[0]) |
1886 INFOFRAME_HEADER_VERSION(ptr
[1]) |
1887 INFOFRAME_HEADER_LEN(ptr
[2]);
1888 tegra_sor_writel(sor
, value
, offset
);
1892 * Each subpack contains 7 bytes, divided into:
1893 * - subpack_low: bytes 0 - 3
1894 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
1896 for (i
= 3, j
= 0; i
< size
; i
+= 7, j
+= 8) {
1897 size_t rem
= size
- i
, num
= min_t(size_t, rem
, 4);
1899 value
= tegra_sor_hdmi_subpack(&ptr
[i
], num
);
1900 tegra_sor_writel(sor
, value
, offset
++);
1902 num
= min_t(size_t, rem
- num
, 3);
1904 value
= tegra_sor_hdmi_subpack(&ptr
[i
+ 4], num
);
1905 tegra_sor_writel(sor
, value
, offset
++);
1910 tegra_sor_hdmi_setup_avi_infoframe(struct tegra_sor
*sor
,
1911 const struct drm_display_mode
*mode
)
1913 u8 buffer
[HDMI_INFOFRAME_SIZE(AVI
)];
1914 struct hdmi_avi_infoframe frame
;
1918 /* disable AVI infoframe */
1919 value
= tegra_sor_readl(sor
, SOR_HDMI_AVI_INFOFRAME_CTRL
);
1920 value
&= ~INFOFRAME_CTRL_SINGLE
;
1921 value
&= ~INFOFRAME_CTRL_OTHER
;
1922 value
&= ~INFOFRAME_CTRL_ENABLE
;
1923 tegra_sor_writel(sor
, value
, SOR_HDMI_AVI_INFOFRAME_CTRL
);
1925 err
= drm_hdmi_avi_infoframe_from_display_mode(&frame
,
1926 &sor
->output
.connector
, mode
);
1928 dev_err(sor
->dev
, "failed to setup AVI infoframe: %d\n", err
);
1932 err
= hdmi_avi_infoframe_pack(&frame
, buffer
, sizeof(buffer
));
1934 dev_err(sor
->dev
, "failed to pack AVI infoframe: %d\n", err
);
1938 tegra_sor_hdmi_write_infopack(sor
, buffer
, err
);
1940 /* enable AVI infoframe */
1941 value
= tegra_sor_readl(sor
, SOR_HDMI_AVI_INFOFRAME_CTRL
);
1942 value
|= INFOFRAME_CTRL_CHECKSUM_ENABLE
;
1943 value
|= INFOFRAME_CTRL_ENABLE
;
1944 tegra_sor_writel(sor
, value
, SOR_HDMI_AVI_INFOFRAME_CTRL
);
1949 static void tegra_sor_write_eld(struct tegra_sor
*sor
)
1951 size_t length
= drm_eld_size(sor
->output
.connector
.eld
), i
;
1953 for (i
= 0; i
< length
; i
++)
1954 tegra_sor_writel(sor
, i
<< 8 | sor
->output
.connector
.eld
[i
],
1955 SOR_AUDIO_HDA_ELD_BUFWR
);
1958 * The HDA codec will always report an ELD buffer size of 96 bytes and
1959 * the HDA codec driver will check that each byte read from the buffer
1960 * is valid. Therefore every byte must be written, even if no 96 bytes
1961 * were parsed from EDID.
1963 for (i
= length
; i
< 96; i
++)
1964 tegra_sor_writel(sor
, i
<< 8 | 0, SOR_AUDIO_HDA_ELD_BUFWR
);
1967 static void tegra_sor_audio_prepare(struct tegra_sor
*sor
)
1972 * Enable and unmask the HDA codec SCRATCH0 register interrupt. This
1973 * is used for interoperability between the HDA codec driver and the
1976 value
= SOR_INT_CODEC_SCRATCH1
| SOR_INT_CODEC_SCRATCH0
;
1977 tegra_sor_writel(sor
, value
, SOR_INT_ENABLE
);
1978 tegra_sor_writel(sor
, value
, SOR_INT_MASK
);
1980 tegra_sor_write_eld(sor
);
1982 value
= SOR_AUDIO_HDA_PRESENSE_ELDV
| SOR_AUDIO_HDA_PRESENSE_PD
;
1983 tegra_sor_writel(sor
, value
, SOR_AUDIO_HDA_PRESENSE
);
1986 static void tegra_sor_audio_unprepare(struct tegra_sor
*sor
)
1988 tegra_sor_writel(sor
, 0, SOR_AUDIO_HDA_PRESENSE
);
1989 tegra_sor_writel(sor
, 0, SOR_INT_MASK
);
1990 tegra_sor_writel(sor
, 0, SOR_INT_ENABLE
);
1993 static void tegra_sor_audio_enable(struct tegra_sor
*sor
)
1997 value
= tegra_sor_readl(sor
, SOR_AUDIO_CNTRL
);
1999 /* select HDA audio input */
2000 value
&= ~SOR_AUDIO_CNTRL_SOURCE_SELECT(SOURCE_SELECT_MASK
);
2001 value
|= SOR_AUDIO_CNTRL_SOURCE_SELECT(SOURCE_SELECT_HDA
);
2003 /* inject null samples */
2004 if (sor
->format
.channels
!= 2)
2005 value
&= ~SOR_AUDIO_CNTRL_INJECT_NULLSMPL
;
2007 value
|= SOR_AUDIO_CNTRL_INJECT_NULLSMPL
;
2009 value
|= SOR_AUDIO_CNTRL_AFIFO_FLUSH
;
2011 tegra_sor_writel(sor
, value
, SOR_AUDIO_CNTRL
);
2013 /* enable advertising HBR capability */
2014 tegra_sor_writel(sor
, SOR_AUDIO_SPARE_HBR_ENABLE
, SOR_AUDIO_SPARE
);
2017 static int tegra_sor_hdmi_enable_audio_infoframe(struct tegra_sor
*sor
)
2019 u8 buffer
[HDMI_INFOFRAME_SIZE(AUDIO
)];
2020 struct hdmi_audio_infoframe frame
;
2024 err
= hdmi_audio_infoframe_init(&frame
);
2026 dev_err(sor
->dev
, "failed to setup audio infoframe: %d\n", err
);
2030 frame
.channels
= sor
->format
.channels
;
2032 err
= hdmi_audio_infoframe_pack(&frame
, buffer
, sizeof(buffer
));
2034 dev_err(sor
->dev
, "failed to pack audio infoframe: %d\n", err
);
2038 tegra_sor_hdmi_write_infopack(sor
, buffer
, err
);
2040 value
= tegra_sor_readl(sor
, SOR_HDMI_AUDIO_INFOFRAME_CTRL
);
2041 value
|= INFOFRAME_CTRL_CHECKSUM_ENABLE
;
2042 value
|= INFOFRAME_CTRL_ENABLE
;
2043 tegra_sor_writel(sor
, value
, SOR_HDMI_AUDIO_INFOFRAME_CTRL
);
2048 static void tegra_sor_hdmi_audio_enable(struct tegra_sor
*sor
)
2052 tegra_sor_audio_enable(sor
);
2054 tegra_sor_writel(sor
, 0, SOR_HDMI_ACR_CTRL
);
2056 value
= SOR_HDMI_SPARE_ACR_PRIORITY_HIGH
|
2057 SOR_HDMI_SPARE_CTS_RESET(1) |
2058 SOR_HDMI_SPARE_HW_CTS_ENABLE
;
2059 tegra_sor_writel(sor
, value
, SOR_HDMI_SPARE
);
2062 value
= SOR_HDMI_ACR_SUBPACK_LOW_SB1(0);
2063 tegra_sor_writel(sor
, value
, SOR_HDMI_ACR_0441_SUBPACK_LOW
);
2065 /* allow packet to be sent */
2066 value
= SOR_HDMI_ACR_SUBPACK_HIGH_ENABLE
;
2067 tegra_sor_writel(sor
, value
, SOR_HDMI_ACR_0441_SUBPACK_HIGH
);
2069 /* reset N counter and enable lookup */
2070 value
= SOR_HDMI_AUDIO_N_RESET
| SOR_HDMI_AUDIO_N_LOOKUP
;
2071 tegra_sor_writel(sor
, value
, SOR_HDMI_AUDIO_N
);
2073 value
= (24000 * 4096) / (128 * sor
->format
.sample_rate
/ 1000);
2074 tegra_sor_writel(sor
, value
, SOR_AUDIO_AVAL_0320
);
2075 tegra_sor_writel(sor
, 4096, SOR_AUDIO_NVAL_0320
);
2077 tegra_sor_writel(sor
, 20000, SOR_AUDIO_AVAL_0441
);
2078 tegra_sor_writel(sor
, 4704, SOR_AUDIO_NVAL_0441
);
2080 tegra_sor_writel(sor
, 20000, SOR_AUDIO_AVAL_0882
);
2081 tegra_sor_writel(sor
, 9408, SOR_AUDIO_NVAL_0882
);
2083 tegra_sor_writel(sor
, 20000, SOR_AUDIO_AVAL_1764
);
2084 tegra_sor_writel(sor
, 18816, SOR_AUDIO_NVAL_1764
);
2086 value
= (24000 * 6144) / (128 * sor
->format
.sample_rate
/ 1000);
2087 tegra_sor_writel(sor
, value
, SOR_AUDIO_AVAL_0480
);
2088 tegra_sor_writel(sor
, 6144, SOR_AUDIO_NVAL_0480
);
2090 value
= (24000 * 12288) / (128 * sor
->format
.sample_rate
/ 1000);
2091 tegra_sor_writel(sor
, value
, SOR_AUDIO_AVAL_0960
);
2092 tegra_sor_writel(sor
, 12288, SOR_AUDIO_NVAL_0960
);
2094 value
= (24000 * 24576) / (128 * sor
->format
.sample_rate
/ 1000);
2095 tegra_sor_writel(sor
, value
, SOR_AUDIO_AVAL_1920
);
2096 tegra_sor_writel(sor
, 24576, SOR_AUDIO_NVAL_1920
);
2098 value
= tegra_sor_readl(sor
, SOR_HDMI_AUDIO_N
);
2099 value
&= ~SOR_HDMI_AUDIO_N_RESET
;
2100 tegra_sor_writel(sor
, value
, SOR_HDMI_AUDIO_N
);
2102 tegra_sor_hdmi_enable_audio_infoframe(sor
);
2105 static void tegra_sor_hdmi_disable_audio_infoframe(struct tegra_sor
*sor
)
2109 value
= tegra_sor_readl(sor
, SOR_HDMI_AUDIO_INFOFRAME_CTRL
);
2110 value
&= ~INFOFRAME_CTRL_ENABLE
;
2111 tegra_sor_writel(sor
, value
, SOR_HDMI_AUDIO_INFOFRAME_CTRL
);
2114 static void tegra_sor_hdmi_audio_disable(struct tegra_sor
*sor
)
2116 tegra_sor_hdmi_disable_audio_infoframe(sor
);
2119 static struct tegra_sor_hdmi_settings
*
2120 tegra_sor_hdmi_find_settings(struct tegra_sor
*sor
, unsigned long frequency
)
2124 for (i
= 0; i
< sor
->num_settings
; i
++)
2125 if (frequency
<= sor
->settings
[i
].frequency
)
2126 return &sor
->settings
[i
];
2131 static void tegra_sor_hdmi_disable_scrambling(struct tegra_sor
*sor
)
2135 value
= tegra_sor_readl(sor
, SOR_HDMI2_CTRL
);
2136 value
&= ~SOR_HDMI2_CTRL_CLOCK_MODE_DIV_BY_4
;
2137 value
&= ~SOR_HDMI2_CTRL_SCRAMBLE
;
2138 tegra_sor_writel(sor
, value
, SOR_HDMI2_CTRL
);
2141 static void tegra_sor_hdmi_scdc_disable(struct tegra_sor
*sor
)
2143 struct i2c_adapter
*ddc
= sor
->output
.ddc
;
2145 drm_scdc_set_high_tmds_clock_ratio(ddc
, false);
2146 drm_scdc_set_scrambling(ddc
, false);
2148 tegra_sor_hdmi_disable_scrambling(sor
);
2151 static void tegra_sor_hdmi_scdc_stop(struct tegra_sor
*sor
)
2153 if (sor
->scdc_enabled
) {
2154 cancel_delayed_work_sync(&sor
->scdc
);
2155 tegra_sor_hdmi_scdc_disable(sor
);
2159 static void tegra_sor_hdmi_enable_scrambling(struct tegra_sor
*sor
)
2163 value
= tegra_sor_readl(sor
, SOR_HDMI2_CTRL
);
2164 value
|= SOR_HDMI2_CTRL_CLOCK_MODE_DIV_BY_4
;
2165 value
|= SOR_HDMI2_CTRL_SCRAMBLE
;
2166 tegra_sor_writel(sor
, value
, SOR_HDMI2_CTRL
);
2169 static void tegra_sor_hdmi_scdc_enable(struct tegra_sor
*sor
)
2171 struct i2c_adapter
*ddc
= sor
->output
.ddc
;
2173 drm_scdc_set_high_tmds_clock_ratio(ddc
, true);
2174 drm_scdc_set_scrambling(ddc
, true);
2176 tegra_sor_hdmi_enable_scrambling(sor
);
2179 static void tegra_sor_hdmi_scdc_work(struct work_struct
*work
)
2181 struct tegra_sor
*sor
= container_of(work
, struct tegra_sor
, scdc
.work
);
2182 struct i2c_adapter
*ddc
= sor
->output
.ddc
;
2184 if (!drm_scdc_get_scrambling_status(ddc
)) {
2185 DRM_DEBUG_KMS("SCDC not scrambled\n");
2186 tegra_sor_hdmi_scdc_enable(sor
);
2189 schedule_delayed_work(&sor
->scdc
, msecs_to_jiffies(5000));
2192 static void tegra_sor_hdmi_scdc_start(struct tegra_sor
*sor
)
2194 struct drm_scdc
*scdc
= &sor
->output
.connector
.display_info
.hdmi
.scdc
;
2195 struct drm_display_mode
*mode
;
2197 mode
= &sor
->output
.encoder
.crtc
->state
->adjusted_mode
;
2199 if (mode
->clock
>= 340000 && scdc
->supported
) {
2200 schedule_delayed_work(&sor
->scdc
, msecs_to_jiffies(5000));
2201 tegra_sor_hdmi_scdc_enable(sor
);
2202 sor
->scdc_enabled
= true;
2206 static void tegra_sor_hdmi_disable(struct drm_encoder
*encoder
)
2208 struct tegra_output
*output
= encoder_to_output(encoder
);
2209 struct tegra_dc
*dc
= to_tegra_dc(encoder
->crtc
);
2210 struct tegra_sor
*sor
= to_sor(output
);
2214 tegra_sor_audio_unprepare(sor
);
2215 tegra_sor_hdmi_scdc_stop(sor
);
2217 err
= tegra_sor_detach(sor
);
2219 dev_err(sor
->dev
, "failed to detach SOR: %d\n", err
);
2221 tegra_sor_writel(sor
, 0, SOR_STATE1
);
2222 tegra_sor_update(sor
);
2224 /* disable display to SOR clock */
2225 value
= tegra_dc_readl(dc
, DC_DISP_DISP_WIN_OPTIONS
);
2227 if (!sor
->soc
->has_nvdisplay
)
2228 value
&= ~SOR1_TIMING_CYA
;
2230 value
&= ~SOR_ENABLE(sor
->index
);
2232 tegra_dc_writel(dc
, value
, DC_DISP_DISP_WIN_OPTIONS
);
2234 tegra_dc_commit(dc
);
2236 err
= tegra_sor_power_down(sor
);
2238 dev_err(sor
->dev
, "failed to power down SOR: %d\n", err
);
2240 err
= tegra_io_pad_power_disable(sor
->pad
);
2242 dev_err(sor
->dev
, "failed to power off I/O pad: %d\n", err
);
2244 host1x_client_suspend(&sor
->client
);
2247 static void tegra_sor_hdmi_enable(struct drm_encoder
*encoder
)
2249 struct tegra_output
*output
= encoder_to_output(encoder
);
2250 unsigned int h_ref_to_sync
= 1, pulse_start
, max_ac
;
2251 struct tegra_dc
*dc
= to_tegra_dc(encoder
->crtc
);
2252 struct tegra_sor_hdmi_settings
*settings
;
2253 struct tegra_sor
*sor
= to_sor(output
);
2254 struct tegra_sor_state
*state
;
2255 struct drm_display_mode
*mode
;
2256 unsigned long rate
, pclk
;
2257 unsigned int div
, i
;
2261 state
= to_sor_state(output
->connector
.state
);
2262 mode
= &encoder
->crtc
->state
->adjusted_mode
;
2263 pclk
= mode
->clock
* 1000;
2265 err
= host1x_client_resume(&sor
->client
);
2267 dev_err(sor
->dev
, "failed to resume: %d\n", err
);
2271 /* switch to safe parent clock */
2272 err
= tegra_sor_set_parent_clock(sor
, sor
->clk_safe
);
2274 dev_err(sor
->dev
, "failed to set safe parent clock: %d\n", err
);
2278 div
= clk_get_rate(sor
->clk
) / 1000000 * 4;
2280 err
= tegra_io_pad_power_enable(sor
->pad
);
2282 dev_err(sor
->dev
, "failed to power on I/O pad: %d\n", err
);
2284 usleep_range(20, 100);
2286 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
2287 value
&= ~SOR_PLL2_BANDGAP_POWERDOWN
;
2288 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
2290 usleep_range(20, 100);
2292 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll3
);
2293 value
&= ~SOR_PLL3_PLL_VDD_MODE_3V3
;
2294 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll3
);
2296 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll0
);
2297 value
&= ~SOR_PLL0_VCOPD
;
2298 value
&= ~SOR_PLL0_PWR
;
2299 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll0
);
2301 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
2302 value
&= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE
;
2303 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
2305 usleep_range(200, 400);
2307 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
2308 value
&= ~SOR_PLL2_POWERDOWN_OVERRIDE
;
2309 value
&= ~SOR_PLL2_PORT_POWERDOWN
;
2310 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
2312 usleep_range(20, 100);
2314 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
2315 value
|= SOR_DP_PADCTL_PD_TXD_3
| SOR_DP_PADCTL_PD_TXD_0
|
2316 SOR_DP_PADCTL_PD_TXD_1
| SOR_DP_PADCTL_PD_TXD_2
;
2317 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
2320 value
= tegra_sor_readl(sor
, SOR_LANE_SEQ_CTL
);
2321 if ((value
& SOR_LANE_SEQ_CTL_STATE_BUSY
) == 0)
2324 usleep_range(250, 1000);
2327 value
= SOR_LANE_SEQ_CTL_TRIGGER
| SOR_LANE_SEQ_CTL_SEQUENCE_DOWN
|
2328 SOR_LANE_SEQ_CTL_POWER_STATE_UP
| SOR_LANE_SEQ_CTL_DELAY(5);
2329 tegra_sor_writel(sor
, value
, SOR_LANE_SEQ_CTL
);
2332 value
= tegra_sor_readl(sor
, SOR_LANE_SEQ_CTL
);
2333 if ((value
& SOR_LANE_SEQ_CTL_TRIGGER
) == 0)
2336 usleep_range(250, 1000);
2339 value
= tegra_sor_readl(sor
, SOR_CLK_CNTRL
);
2340 value
&= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK
;
2341 value
&= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK
;
2343 if (mode
->clock
< 340000) {
2344 DRM_DEBUG_KMS("setting 2.7 GHz link speed\n");
2345 value
|= SOR_CLK_CNTRL_DP_LINK_SPEED_G2_70
;
2347 DRM_DEBUG_KMS("setting 5.4 GHz link speed\n");
2348 value
|= SOR_CLK_CNTRL_DP_LINK_SPEED_G5_40
;
2351 value
|= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK
;
2352 tegra_sor_writel(sor
, value
, SOR_CLK_CNTRL
);
2354 /* SOR pad PLL stabilization time */
2355 usleep_range(250, 1000);
2357 value
= tegra_sor_readl(sor
, SOR_DP_LINKCTL0
);
2358 value
&= ~SOR_DP_LINKCTL_LANE_COUNT_MASK
;
2359 value
|= SOR_DP_LINKCTL_LANE_COUNT(4);
2360 tegra_sor_writel(sor
, value
, SOR_DP_LINKCTL0
);
2362 value
= tegra_sor_readl(sor
, SOR_DP_SPARE0
);
2363 value
&= ~SOR_DP_SPARE_DISP_VIDEO_PREAMBLE
;
2364 value
&= ~SOR_DP_SPARE_PANEL_INTERNAL
;
2365 value
&= ~SOR_DP_SPARE_SEQ_ENABLE
;
2366 value
&= ~SOR_DP_SPARE_MACRO_SOR_CLK
;
2367 tegra_sor_writel(sor
, value
, SOR_DP_SPARE0
);
2369 value
= SOR_SEQ_CTL_PU_PC(0) | SOR_SEQ_CTL_PU_PC_ALT(0) |
2370 SOR_SEQ_CTL_PD_PC(8) | SOR_SEQ_CTL_PD_PC_ALT(8);
2371 tegra_sor_writel(sor
, value
, SOR_SEQ_CTL
);
2373 value
= SOR_SEQ_INST_DRIVE_PWM_OUT_LO
| SOR_SEQ_INST_HALT
|
2374 SOR_SEQ_INST_WAIT_VSYNC
| SOR_SEQ_INST_WAIT(1);
2375 tegra_sor_writel(sor
, value
, SOR_SEQ_INST(0));
2376 tegra_sor_writel(sor
, value
, SOR_SEQ_INST(8));
2378 if (!sor
->soc
->has_nvdisplay
) {
2379 /* program the reference clock */
2380 value
= SOR_REFCLK_DIV_INT(div
) | SOR_REFCLK_DIV_FRAC(div
);
2381 tegra_sor_writel(sor
, value
, SOR_REFCLK
);
2384 /* XXX not in TRM */
2385 for (value
= 0, i
= 0; i
< 5; i
++)
2386 value
|= SOR_XBAR_CTRL_LINK0_XSEL(i
, sor
->xbar_cfg
[i
]) |
2387 SOR_XBAR_CTRL_LINK1_XSEL(i
, i
);
2389 tegra_sor_writel(sor
, 0x00000000, SOR_XBAR_POL
);
2390 tegra_sor_writel(sor
, value
, SOR_XBAR_CTRL
);
2393 * Switch the pad clock to the DP clock. Note that we cannot actually
2394 * do this because Tegra186 and later don't support clk_set_parent()
2395 * on the sorX_pad_clkout clocks. We already do the equivalent above
2396 * using the DP_CLK_SEL mux of the SOR_CLK_CNTRL register.
2399 err
= clk_set_parent(sor
->clk_pad
, sor
->clk_dp
);
2401 dev_err(sor
->dev
, "failed to select pad parent clock: %d\n",
2407 /* switch the SOR clock to the pad clock */
2408 err
= tegra_sor_set_parent_clock(sor
, sor
->clk_pad
);
2410 dev_err(sor
->dev
, "failed to select SOR parent clock: %d\n",
2415 /* switch the output clock to the parent pixel clock */
2416 err
= clk_set_parent(sor
->clk
, sor
->clk_parent
);
2418 dev_err(sor
->dev
, "failed to select output parent clock: %d\n",
2423 /* adjust clock rate for HDMI 2.0 modes */
2424 rate
= clk_get_rate(sor
->clk_parent
);
2426 if (mode
->clock
>= 340000)
2429 DRM_DEBUG_KMS("setting clock to %lu Hz, mode: %lu Hz\n", rate
, pclk
);
2431 clk_set_rate(sor
->clk
, rate
);
2433 if (!sor
->soc
->has_nvdisplay
) {
2434 value
= SOR_INPUT_CONTROL_HDMI_SRC_SELECT(dc
->pipe
);
2436 /* XXX is this the proper check? */
2437 if (mode
->clock
< 75000)
2438 value
|= SOR_INPUT_CONTROL_ARM_VIDEO_RANGE_LIMITED
;
2440 tegra_sor_writel(sor
, value
, SOR_INPUT_CONTROL
);
2443 max_ac
= ((mode
->htotal
- mode
->hdisplay
) - SOR_REKEY
- 18) / 32;
2445 value
= SOR_HDMI_CTRL_ENABLE
| SOR_HDMI_CTRL_MAX_AC_PACKET(max_ac
) |
2446 SOR_HDMI_CTRL_AUDIO_LAYOUT
| SOR_HDMI_CTRL_REKEY(SOR_REKEY
);
2447 tegra_sor_writel(sor
, value
, SOR_HDMI_CTRL
);
2449 if (!dc
->soc
->has_nvdisplay
) {
2450 /* H_PULSE2 setup */
2451 pulse_start
= h_ref_to_sync
+
2452 (mode
->hsync_end
- mode
->hsync_start
) +
2453 (mode
->htotal
- mode
->hsync_end
) - 10;
2455 value
= PULSE_LAST_END_A
| PULSE_QUAL_VACTIVE
|
2456 PULSE_POLARITY_HIGH
| PULSE_MODE_NORMAL
;
2457 tegra_dc_writel(dc
, value
, DC_DISP_H_PULSE2_CONTROL
);
2459 value
= PULSE_END(pulse_start
+ 8) | PULSE_START(pulse_start
);
2460 tegra_dc_writel(dc
, value
, DC_DISP_H_PULSE2_POSITION_A
);
2462 value
= tegra_dc_readl(dc
, DC_DISP_DISP_SIGNAL_OPTIONS0
);
2463 value
|= H_PULSE2_ENABLE
;
2464 tegra_dc_writel(dc
, value
, DC_DISP_DISP_SIGNAL_OPTIONS0
);
2467 /* infoframe setup */
2468 err
= tegra_sor_hdmi_setup_avi_infoframe(sor
, mode
);
2470 dev_err(sor
->dev
, "failed to setup AVI infoframe: %d\n", err
);
2472 /* XXX HDMI audio support not implemented yet */
2473 tegra_sor_hdmi_disable_audio_infoframe(sor
);
2475 /* use single TMDS protocol */
2476 value
= tegra_sor_readl(sor
, SOR_STATE1
);
2477 value
&= ~SOR_STATE_ASY_PROTOCOL_MASK
;
2478 value
|= SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A
;
2479 tegra_sor_writel(sor
, value
, SOR_STATE1
);
2481 /* power up pad calibration */
2482 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
2483 value
&= ~SOR_DP_PADCTL_PAD_CAL_PD
;
2484 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
2486 /* production settings */
2487 settings
= tegra_sor_hdmi_find_settings(sor
, mode
->clock
* 1000);
2489 dev_err(sor
->dev
, "no settings for pixel clock %d Hz\n",
2490 mode
->clock
* 1000);
2494 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll0
);
2495 value
&= ~SOR_PLL0_ICHPMP_MASK
;
2496 value
&= ~SOR_PLL0_FILTER_MASK
;
2497 value
&= ~SOR_PLL0_VCOCAP_MASK
;
2498 value
|= SOR_PLL0_ICHPMP(settings
->ichpmp
);
2499 value
|= SOR_PLL0_FILTER(settings
->filter
);
2500 value
|= SOR_PLL0_VCOCAP(settings
->vcocap
);
2501 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll0
);
2503 /* XXX not in TRM */
2504 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll1
);
2505 value
&= ~SOR_PLL1_LOADADJ_MASK
;
2506 value
&= ~SOR_PLL1_TMDS_TERMADJ_MASK
;
2507 value
|= SOR_PLL1_LOADADJ(settings
->loadadj
);
2508 value
|= SOR_PLL1_TMDS_TERMADJ(settings
->tmds_termadj
);
2509 value
|= SOR_PLL1_TMDS_TERM
;
2510 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll1
);
2512 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll3
);
2513 value
&= ~SOR_PLL3_BG_TEMP_COEF_MASK
;
2514 value
&= ~SOR_PLL3_BG_VREF_LEVEL_MASK
;
2515 value
&= ~SOR_PLL3_AVDD10_LEVEL_MASK
;
2516 value
&= ~SOR_PLL3_AVDD14_LEVEL_MASK
;
2517 value
|= SOR_PLL3_BG_TEMP_COEF(settings
->bg_temp_coef
);
2518 value
|= SOR_PLL3_BG_VREF_LEVEL(settings
->bg_vref_level
);
2519 value
|= SOR_PLL3_AVDD10_LEVEL(settings
->avdd10_level
);
2520 value
|= SOR_PLL3_AVDD14_LEVEL(settings
->avdd14_level
);
2521 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll3
);
2523 value
= settings
->drive_current
[3] << 24 |
2524 settings
->drive_current
[2] << 16 |
2525 settings
->drive_current
[1] << 8 |
2526 settings
->drive_current
[0] << 0;
2527 tegra_sor_writel(sor
, value
, SOR_LANE_DRIVE_CURRENT0
);
2529 value
= settings
->preemphasis
[3] << 24 |
2530 settings
->preemphasis
[2] << 16 |
2531 settings
->preemphasis
[1] << 8 |
2532 settings
->preemphasis
[0] << 0;
2533 tegra_sor_writel(sor
, value
, SOR_LANE_PREEMPHASIS0
);
2535 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
2536 value
&= ~SOR_DP_PADCTL_TX_PU_MASK
;
2537 value
|= SOR_DP_PADCTL_TX_PU_ENABLE
;
2538 value
|= SOR_DP_PADCTL_TX_PU(settings
->tx_pu_value
);
2539 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
2541 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl2
);
2542 value
&= ~SOR_DP_PADCTL_SPAREPLL_MASK
;
2543 value
|= SOR_DP_PADCTL_SPAREPLL(settings
->sparepll
);
2544 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl2
);
2546 /* power down pad calibration */
2547 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->dp_padctl0
);
2548 value
|= SOR_DP_PADCTL_PAD_CAL_PD
;
2549 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->dp_padctl0
);
2551 if (!dc
->soc
->has_nvdisplay
) {
2552 /* miscellaneous display controller settings */
2553 value
= VSYNC_H_POSITION(1);
2554 tegra_dc_writel(dc
, value
, DC_DISP_DISP_TIMING_OPTIONS
);
2557 value
= tegra_dc_readl(dc
, DC_DISP_DISP_COLOR_CONTROL
);
2558 value
&= ~DITHER_CONTROL_MASK
;
2559 value
&= ~BASE_COLOR_SIZE_MASK
;
2561 switch (state
->bpc
) {
2563 value
|= BASE_COLOR_SIZE_666
;
2567 value
|= BASE_COLOR_SIZE_888
;
2571 value
|= BASE_COLOR_SIZE_101010
;
2575 value
|= BASE_COLOR_SIZE_121212
;
2579 WARN(1, "%u bits-per-color not supported\n", state
->bpc
);
2580 value
|= BASE_COLOR_SIZE_888
;
2584 tegra_dc_writel(dc
, value
, DC_DISP_DISP_COLOR_CONTROL
);
2586 /* XXX set display head owner */
2587 value
= tegra_sor_readl(sor
, SOR_STATE1
);
2588 value
&= ~SOR_STATE_ASY_OWNER_MASK
;
2589 value
|= SOR_STATE_ASY_OWNER(1 + dc
->pipe
);
2590 tegra_sor_writel(sor
, value
, SOR_STATE1
);
2592 err
= tegra_sor_power_up(sor
, 250);
2594 dev_err(sor
->dev
, "failed to power up SOR: %d\n", err
);
2596 /* configure dynamic range of output */
2597 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->head_state0
+ dc
->pipe
);
2598 value
&= ~SOR_HEAD_STATE_RANGECOMPRESS_MASK
;
2599 value
&= ~SOR_HEAD_STATE_DYNRANGE_MASK
;
2600 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->head_state0
+ dc
->pipe
);
2602 /* configure colorspace */
2603 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->head_state0
+ dc
->pipe
);
2604 value
&= ~SOR_HEAD_STATE_COLORSPACE_MASK
;
2605 value
|= SOR_HEAD_STATE_COLORSPACE_RGB
;
2606 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->head_state0
+ dc
->pipe
);
2608 tegra_sor_mode_set(sor
, mode
, state
);
2610 tegra_sor_update(sor
);
2612 /* program preamble timing in SOR (XXX) */
2613 value
= tegra_sor_readl(sor
, SOR_DP_SPARE0
);
2614 value
&= ~SOR_DP_SPARE_DISP_VIDEO_PREAMBLE
;
2615 tegra_sor_writel(sor
, value
, SOR_DP_SPARE0
);
2617 err
= tegra_sor_attach(sor
);
2619 dev_err(sor
->dev
, "failed to attach SOR: %d\n", err
);
2621 /* enable display to SOR clock and generate HDMI preamble */
2622 value
= tegra_dc_readl(dc
, DC_DISP_DISP_WIN_OPTIONS
);
2624 if (!sor
->soc
->has_nvdisplay
)
2625 value
|= SOR1_TIMING_CYA
;
2627 value
|= SOR_ENABLE(sor
->index
);
2629 tegra_dc_writel(dc
, value
, DC_DISP_DISP_WIN_OPTIONS
);
2631 if (dc
->soc
->has_nvdisplay
) {
2632 value
= tegra_dc_readl(dc
, DC_DISP_CORE_SOR_SET_CONTROL(sor
->index
));
2633 value
&= ~PROTOCOL_MASK
;
2634 value
|= PROTOCOL_SINGLE_TMDS_A
;
2635 tegra_dc_writel(dc
, value
, DC_DISP_CORE_SOR_SET_CONTROL(sor
->index
));
2638 tegra_dc_commit(dc
);
2640 err
= tegra_sor_wakeup(sor
);
2642 dev_err(sor
->dev
, "failed to wakeup SOR: %d\n", err
);
2644 tegra_sor_hdmi_scdc_start(sor
);
2645 tegra_sor_audio_prepare(sor
);
2648 static const struct drm_encoder_helper_funcs tegra_sor_hdmi_helpers
= {
2649 .disable
= tegra_sor_hdmi_disable
,
2650 .enable
= tegra_sor_hdmi_enable
,
2651 .atomic_check
= tegra_sor_encoder_atomic_check
,
2654 static void tegra_sor_dp_disable(struct drm_encoder
*encoder
)
2656 struct tegra_output
*output
= encoder_to_output(encoder
);
2657 struct tegra_dc
*dc
= to_tegra_dc(encoder
->crtc
);
2658 struct tegra_sor
*sor
= to_sor(output
);
2663 drm_panel_disable(output
->panel
);
2666 * Do not attempt to power down a DP link if we're not connected since
2667 * the AUX transactions would just be timing out.
2669 if (output
->connector
.status
!= connector_status_disconnected
) {
2670 err
= drm_dp_link_power_down(sor
->aux
, &sor
->link
);
2672 dev_err(sor
->dev
, "failed to power down link: %d\n",
2676 err
= tegra_sor_detach(sor
);
2678 dev_err(sor
->dev
, "failed to detach SOR: %d\n", err
);
2680 tegra_sor_writel(sor
, 0, SOR_STATE1
);
2681 tegra_sor_update(sor
);
2683 value
= tegra_dc_readl(dc
, DC_DISP_DISP_WIN_OPTIONS
);
2684 value
&= ~SOR_ENABLE(sor
->index
);
2685 tegra_dc_writel(dc
, value
, DC_DISP_DISP_WIN_OPTIONS
);
2686 tegra_dc_commit(dc
);
2688 value
= tegra_sor_readl(sor
, SOR_STATE1
);
2689 value
&= ~SOR_STATE_ASY_PROTOCOL_MASK
;
2690 value
&= ~SOR_STATE_ASY_SUBOWNER_MASK
;
2691 value
&= ~SOR_STATE_ASY_OWNER_MASK
;
2692 tegra_sor_writel(sor
, value
, SOR_STATE1
);
2693 tegra_sor_update(sor
);
2695 /* switch to safe parent clock */
2696 err
= tegra_sor_set_parent_clock(sor
, sor
->clk_safe
);
2698 dev_err(sor
->dev
, "failed to set safe clock: %d\n", err
);
2700 err
= tegra_sor_power_down(sor
);
2702 dev_err(sor
->dev
, "failed to power down SOR: %d\n", err
);
2704 err
= tegra_io_pad_power_disable(sor
->pad
);
2706 dev_err(sor
->dev
, "failed to power off I/O pad: %d\n", err
);
2708 err
= drm_dp_aux_disable(sor
->aux
);
2710 dev_err(sor
->dev
, "failed disable DPAUX: %d\n", err
);
2713 drm_panel_unprepare(output
->panel
);
2715 host1x_client_suspend(&sor
->client
);
2718 static void tegra_sor_dp_enable(struct drm_encoder
*encoder
)
2720 struct tegra_output
*output
= encoder_to_output(encoder
);
2721 struct tegra_dc
*dc
= to_tegra_dc(encoder
->crtc
);
2722 struct tegra_sor
*sor
= to_sor(output
);
2723 struct tegra_sor_config config
;
2724 struct tegra_sor_state
*state
;
2725 struct drm_display_mode
*mode
;
2726 struct drm_display_info
*info
;
2731 state
= to_sor_state(output
->connector
.state
);
2732 mode
= &encoder
->crtc
->state
->adjusted_mode
;
2733 info
= &output
->connector
.display_info
;
2735 err
= host1x_client_resume(&sor
->client
);
2737 dev_err(sor
->dev
, "failed to resume: %d\n", err
);
2741 /* switch to safe parent clock */
2742 err
= tegra_sor_set_parent_clock(sor
, sor
->clk_safe
);
2744 dev_err(sor
->dev
, "failed to set safe parent clock: %d\n", err
);
2746 err
= tegra_io_pad_power_enable(sor
->pad
);
2748 dev_err(sor
->dev
, "failed to power on LVDS rail: %d\n", err
);
2750 usleep_range(20, 100);
2752 err
= drm_dp_aux_enable(sor
->aux
);
2754 dev_err(sor
->dev
, "failed to enable DPAUX: %d\n", err
);
2756 err
= drm_dp_link_probe(sor
->aux
, &sor
->link
);
2758 dev_err(sor
->dev
, "failed to probe DP link: %d\n", err
);
2760 tegra_sor_filter_rates(sor
);
2762 err
= drm_dp_link_choose(&sor
->link
, mode
, info
);
2764 dev_err(sor
->dev
, "failed to choose link: %d\n", err
);
2767 drm_panel_prepare(output
->panel
);
2769 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
2770 value
&= ~SOR_PLL2_BANDGAP_POWERDOWN
;
2771 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
2773 usleep_range(20, 40);
2775 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll3
);
2776 value
|= SOR_PLL3_PLL_VDD_MODE_3V3
;
2777 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll3
);
2779 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll0
);
2780 value
&= ~(SOR_PLL0_VCOPD
| SOR_PLL0_PWR
);
2781 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll0
);
2783 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
2784 value
&= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE
;
2785 value
|= SOR_PLL2_SEQ_PLLCAPPD
;
2786 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
2788 usleep_range(200, 400);
2790 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll2
);
2791 value
&= ~SOR_PLL2_POWERDOWN_OVERRIDE
;
2792 value
&= ~SOR_PLL2_PORT_POWERDOWN
;
2793 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll2
);
2795 value
= tegra_sor_readl(sor
, SOR_CLK_CNTRL
);
2796 value
&= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK
;
2799 value
|= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK
;
2801 value
|= SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_DPCLK
;
2803 tegra_sor_writel(sor
, value
, SOR_CLK_CNTRL
);
2805 usleep_range(200, 400);
2807 value
= tegra_sor_readl(sor
, SOR_DP_SPARE0
);
2808 /* XXX not in TRM */
2810 value
|= SOR_DP_SPARE_PANEL_INTERNAL
;
2812 value
&= ~SOR_DP_SPARE_PANEL_INTERNAL
;
2814 value
|= SOR_DP_SPARE_SEQ_ENABLE
;
2815 tegra_sor_writel(sor
, value
, SOR_DP_SPARE0
);
2817 /* XXX not in TRM */
2818 tegra_sor_writel(sor
, 0, SOR_LVDS
);
2820 value
= tegra_sor_readl(sor
, sor
->soc
->regs
->pll0
);
2821 value
&= ~SOR_PLL0_ICHPMP_MASK
;
2822 value
&= ~SOR_PLL0_VCOCAP_MASK
;
2823 value
|= SOR_PLL0_ICHPMP(0x1);
2824 value
|= SOR_PLL0_VCOCAP(0x3);
2825 value
|= SOR_PLL0_RESISTOR_EXT
;
2826 tegra_sor_writel(sor
, value
, sor
->soc
->regs
->pll0
);
2828 /* XXX not in TRM */
2829 for (value
= 0, i
= 0; i
< 5; i
++)
2830 value
|= SOR_XBAR_CTRL_LINK0_XSEL(i
, sor
->soc
->xbar_cfg
[i
]) |
2831 SOR_XBAR_CTRL_LINK1_XSEL(i
, i
);
2833 tegra_sor_writel(sor
, 0x00000000, SOR_XBAR_POL
);
2834 tegra_sor_writel(sor
, value
, SOR_XBAR_CTRL
);
2837 * Switch the pad clock to the DP clock. Note that we cannot actually
2838 * do this because Tegra186 and later don't support clk_set_parent()
2839 * on the sorX_pad_clkout clocks. We already do the equivalent above
2840 * using the DP_CLK_SEL mux of the SOR_CLK_CNTRL register.
2843 err
= clk_set_parent(sor
->clk_pad
, sor
->clk_parent
);
2845 dev_err(sor
->dev
, "failed to select pad parent clock: %d\n",
2851 /* switch the SOR clock to the pad clock */
2852 err
= tegra_sor_set_parent_clock(sor
, sor
->clk_pad
);
2854 dev_err(sor
->dev
, "failed to select SOR parent clock: %d\n",
2859 /* switch the output clock to the parent pixel clock */
2860 err
= clk_set_parent(sor
->clk
, sor
->clk_parent
);
2862 dev_err(sor
->dev
, "failed to select output parent clock: %d\n",
2867 /* use DP-A protocol */
2868 value
= tegra_sor_readl(sor
, SOR_STATE1
);
2869 value
&= ~SOR_STATE_ASY_PROTOCOL_MASK
;
2870 value
|= SOR_STATE_ASY_PROTOCOL_DP_A
;
2871 tegra_sor_writel(sor
, value
, SOR_STATE1
);
2874 value
= tegra_sor_readl(sor
, SOR_DP_LINKCTL0
);
2875 value
|= SOR_DP_LINKCTL_ENABLE
;
2876 tegra_sor_writel(sor
, value
, SOR_DP_LINKCTL0
);
2878 tegra_sor_dp_term_calibrate(sor
);
2880 err
= drm_dp_link_train(&sor
->link
);
2882 dev_err(sor
->dev
, "link training failed: %d\n", err
);
2884 dev_dbg(sor
->dev
, "link training succeeded\n");
2886 err
= drm_dp_link_power_up(sor
->aux
, &sor
->link
);
2888 dev_err(sor
->dev
, "failed to power up DP link: %d\n", err
);
2890 /* compute configuration */
2891 memset(&config
, 0, sizeof(config
));
2892 config
.bits_per_pixel
= state
->bpc
* 3;
2894 err
= tegra_sor_compute_config(sor
, mode
, &config
, &sor
->link
);
2896 dev_err(sor
->dev
, "failed to compute configuration: %d\n", err
);
2898 tegra_sor_apply_config(sor
, &config
);
2899 tegra_sor_mode_set(sor
, mode
, state
);
2901 if (output
->panel
) {
2902 /* CSTM (LVDS, link A/B, upper) */
2903 value
= SOR_CSTM_LVDS
| SOR_CSTM_LINK_ACT_A
| SOR_CSTM_LINK_ACT_B
|
2905 tegra_sor_writel(sor
, value
, SOR_CSTM
);
2908 err
= tegra_sor_setup_pwm(sor
, 250);
2910 dev_err(sor
->dev
, "failed to setup PWM: %d\n", err
);
2913 tegra_sor_update(sor
);
2915 err
= tegra_sor_power_up(sor
, 250);
2917 dev_err(sor
->dev
, "failed to power up SOR: %d\n", err
);
2919 /* attach and wake up */
2920 err
= tegra_sor_attach(sor
);
2922 dev_err(sor
->dev
, "failed to attach SOR: %d\n", err
);
2924 value
= tegra_dc_readl(dc
, DC_DISP_DISP_WIN_OPTIONS
);
2925 value
|= SOR_ENABLE(sor
->index
);
2926 tegra_dc_writel(dc
, value
, DC_DISP_DISP_WIN_OPTIONS
);
2928 tegra_dc_commit(dc
);
2930 err
= tegra_sor_wakeup(sor
);
2932 dev_err(sor
->dev
, "failed to wakeup SOR: %d\n", err
);
2935 drm_panel_enable(output
->panel
);
2938 static const struct drm_encoder_helper_funcs tegra_sor_dp_helpers
= {
2939 .disable
= tegra_sor_dp_disable
,
2940 .enable
= tegra_sor_dp_enable
,
2941 .atomic_check
= tegra_sor_encoder_atomic_check
,
2944 static void tegra_sor_disable_regulator(void *data
)
2946 struct regulator
*reg
= data
;
2948 regulator_disable(reg
);
2951 static int tegra_sor_enable_regulator(struct tegra_sor
*sor
, struct regulator
*reg
)
2955 err
= regulator_enable(reg
);
2959 return devm_add_action_or_reset(sor
->dev
, tegra_sor_disable_regulator
, reg
);
2962 static int tegra_sor_hdmi_probe(struct tegra_sor
*sor
)
2966 sor
->avdd_io_supply
= devm_regulator_get(sor
->dev
, "avdd-io-hdmi-dp");
2967 if (IS_ERR(sor
->avdd_io_supply
)) {
2968 dev_err(sor
->dev
, "cannot get AVDD I/O supply: %ld\n",
2969 PTR_ERR(sor
->avdd_io_supply
));
2970 return PTR_ERR(sor
->avdd_io_supply
);
2973 err
= tegra_sor_enable_regulator(sor
, sor
->avdd_io_supply
);
2975 dev_err(sor
->dev
, "failed to enable AVDD I/O supply: %d\n",
2980 sor
->vdd_pll_supply
= devm_regulator_get(sor
->dev
, "vdd-hdmi-dp-pll");
2981 if (IS_ERR(sor
->vdd_pll_supply
)) {
2982 dev_err(sor
->dev
, "cannot get VDD PLL supply: %ld\n",
2983 PTR_ERR(sor
->vdd_pll_supply
));
2984 return PTR_ERR(sor
->vdd_pll_supply
);
2987 err
= tegra_sor_enable_regulator(sor
, sor
->vdd_pll_supply
);
2989 dev_err(sor
->dev
, "failed to enable VDD PLL supply: %d\n",
2994 sor
->hdmi_supply
= devm_regulator_get(sor
->dev
, "hdmi");
2995 if (IS_ERR(sor
->hdmi_supply
)) {
2996 dev_err(sor
->dev
, "cannot get HDMI supply: %ld\n",
2997 PTR_ERR(sor
->hdmi_supply
));
2998 return PTR_ERR(sor
->hdmi_supply
);
3001 err
= tegra_sor_enable_regulator(sor
, sor
->hdmi_supply
);
3003 dev_err(sor
->dev
, "failed to enable HDMI supply: %d\n", err
);
3007 INIT_DELAYED_WORK(&sor
->scdc
, tegra_sor_hdmi_scdc_work
);
3012 static const struct tegra_sor_ops tegra_sor_hdmi_ops
= {
3014 .probe
= tegra_sor_hdmi_probe
,
3015 .audio_enable
= tegra_sor_hdmi_audio_enable
,
3016 .audio_disable
= tegra_sor_hdmi_audio_disable
,
3019 static int tegra_sor_dp_probe(struct tegra_sor
*sor
)
3023 sor
->avdd_io_supply
= devm_regulator_get(sor
->dev
, "avdd-io-hdmi-dp");
3024 if (IS_ERR(sor
->avdd_io_supply
))
3025 return PTR_ERR(sor
->avdd_io_supply
);
3027 err
= tegra_sor_enable_regulator(sor
, sor
->avdd_io_supply
);
3031 sor
->vdd_pll_supply
= devm_regulator_get(sor
->dev
, "vdd-hdmi-dp-pll");
3032 if (IS_ERR(sor
->vdd_pll_supply
))
3033 return PTR_ERR(sor
->vdd_pll_supply
);
3035 err
= tegra_sor_enable_regulator(sor
, sor
->vdd_pll_supply
);
3042 static const struct tegra_sor_ops tegra_sor_dp_ops
= {
3044 .probe
= tegra_sor_dp_probe
,
3047 static int tegra_sor_init(struct host1x_client
*client
)
3049 struct drm_device
*drm
= dev_get_drvdata(client
->host
);
3050 const struct drm_encoder_helper_funcs
*helpers
= NULL
;
3051 struct tegra_sor
*sor
= host1x_client_to_sor(client
);
3052 int connector
= DRM_MODE_CONNECTOR_Unknown
;
3053 int encoder
= DRM_MODE_ENCODER_NONE
;
3057 if (sor
->ops
== &tegra_sor_hdmi_ops
) {
3058 connector
= DRM_MODE_CONNECTOR_HDMIA
;
3059 encoder
= DRM_MODE_ENCODER_TMDS
;
3060 helpers
= &tegra_sor_hdmi_helpers
;
3061 } else if (sor
->soc
->supports_lvds
) {
3062 connector
= DRM_MODE_CONNECTOR_LVDS
;
3063 encoder
= DRM_MODE_ENCODER_LVDS
;
3066 if (sor
->output
.panel
) {
3067 connector
= DRM_MODE_CONNECTOR_eDP
;
3068 encoder
= DRM_MODE_ENCODER_TMDS
;
3069 helpers
= &tegra_sor_dp_helpers
;
3071 connector
= DRM_MODE_CONNECTOR_DisplayPort
;
3072 encoder
= DRM_MODE_ENCODER_TMDS
;
3073 helpers
= &tegra_sor_dp_helpers
;
3076 sor
->link
.ops
= &tegra_sor_dp_link_ops
;
3077 sor
->link
.aux
= sor
->aux
;
3080 sor
->output
.dev
= sor
->dev
;
3082 drm_connector_init_with_ddc(drm
, &sor
->output
.connector
,
3083 &tegra_sor_connector_funcs
,
3086 drm_connector_helper_add(&sor
->output
.connector
,
3087 &tegra_sor_connector_helper_funcs
);
3088 sor
->output
.connector
.dpms
= DRM_MODE_DPMS_OFF
;
3090 drm_simple_encoder_init(drm
, &sor
->output
.encoder
, encoder
);
3091 drm_encoder_helper_add(&sor
->output
.encoder
, helpers
);
3093 drm_connector_attach_encoder(&sor
->output
.connector
,
3094 &sor
->output
.encoder
);
3095 drm_connector_register(&sor
->output
.connector
);
3097 err
= tegra_output_init(drm
, &sor
->output
);
3099 dev_err(client
->dev
, "failed to initialize output: %d\n", err
);
3103 tegra_output_find_possible_crtcs(&sor
->output
, drm
);
3106 err
= drm_dp_aux_attach(sor
->aux
, &sor
->output
);
3108 dev_err(sor
->dev
, "failed to attach DP: %d\n", err
);
3114 * XXX: Remove this reset once proper hand-over from firmware to
3115 * kernel is possible.
3118 err
= reset_control_acquire(sor
->rst
);
3120 dev_err(sor
->dev
, "failed to acquire SOR reset: %d\n",
3125 err
= reset_control_assert(sor
->rst
);
3127 dev_err(sor
->dev
, "failed to assert SOR reset: %d\n",
3133 err
= clk_prepare_enable(sor
->clk
);
3135 dev_err(sor
->dev
, "failed to enable clock: %d\n", err
);
3139 usleep_range(1000, 3000);
3142 err
= reset_control_deassert(sor
->rst
);
3144 dev_err(sor
->dev
, "failed to deassert SOR reset: %d\n",
3146 clk_disable_unprepare(sor
->clk
);
3150 reset_control_release(sor
->rst
);
3153 err
= clk_prepare_enable(sor
->clk_safe
);
3155 clk_disable_unprepare(sor
->clk
);
3159 err
= clk_prepare_enable(sor
->clk_dp
);
3161 clk_disable_unprepare(sor
->clk_safe
);
3162 clk_disable_unprepare(sor
->clk
);
3169 static int tegra_sor_exit(struct host1x_client
*client
)
3171 struct tegra_sor
*sor
= host1x_client_to_sor(client
);
3174 tegra_output_exit(&sor
->output
);
3177 err
= drm_dp_aux_detach(sor
->aux
);
3179 dev_err(sor
->dev
, "failed to detach DP: %d\n", err
);
3184 clk_disable_unprepare(sor
->clk_safe
);
3185 clk_disable_unprepare(sor
->clk_dp
);
3186 clk_disable_unprepare(sor
->clk
);
3191 static int tegra_sor_runtime_suspend(struct host1x_client
*client
)
3193 struct tegra_sor
*sor
= host1x_client_to_sor(client
);
3194 struct device
*dev
= client
->dev
;
3198 err
= reset_control_assert(sor
->rst
);
3200 dev_err(dev
, "failed to assert reset: %d\n", err
);
3204 reset_control_release(sor
->rst
);
3207 usleep_range(1000, 2000);
3209 clk_disable_unprepare(sor
->clk
);
3210 pm_runtime_put_sync(dev
);
3215 static int tegra_sor_runtime_resume(struct host1x_client
*client
)
3217 struct tegra_sor
*sor
= host1x_client_to_sor(client
);
3218 struct device
*dev
= client
->dev
;
3221 err
= pm_runtime_get_sync(dev
);
3223 dev_err(dev
, "failed to get runtime PM: %d\n", err
);
3227 err
= clk_prepare_enable(sor
->clk
);
3229 dev_err(dev
, "failed to enable clock: %d\n", err
);
3233 usleep_range(1000, 2000);
3236 err
= reset_control_acquire(sor
->rst
);
3238 dev_err(dev
, "failed to acquire reset: %d\n", err
);
3242 err
= reset_control_deassert(sor
->rst
);
3244 dev_err(dev
, "failed to deassert reset: %d\n", err
);
3252 reset_control_release(sor
->rst
);
3254 clk_disable_unprepare(sor
->clk
);
3256 pm_runtime_put_sync(dev
);
3260 static const struct host1x_client_ops sor_client_ops
= {
3261 .init
= tegra_sor_init
,
3262 .exit
= tegra_sor_exit
,
3263 .suspend
= tegra_sor_runtime_suspend
,
3264 .resume
= tegra_sor_runtime_resume
,
3267 static const u8 tegra124_sor_xbar_cfg
[5] = {
3271 static const struct tegra_sor_regs tegra124_sor_regs
= {
3272 .head_state0
= 0x05,
3273 .head_state1
= 0x07,
3274 .head_state2
= 0x09,
3275 .head_state3
= 0x0b,
3276 .head_state4
= 0x0d,
3277 .head_state5
= 0x0f,
3286 /* Tegra124 and Tegra132 have lanes 0 and 2 swapped. */
3287 static const u8 tegra124_sor_lane_map
[4] = {
3291 static const u8 tegra124_sor_voltage_swing
[4][4][4] = {
3293 { 0x13, 0x19, 0x1e, 0x28 },
3294 { 0x1e, 0x25, 0x2d, },
3298 { 0x12, 0x17, 0x1b, 0x25 },
3299 { 0x1c, 0x23, 0x2a, },
3303 { 0x12, 0x16, 0x1a, 0x22 },
3304 { 0x1b, 0x20, 0x27, },
3308 { 0x11, 0x14, 0x17, 0x1f },
3309 { 0x19, 0x1e, 0x24, },
3315 static const u8 tegra124_sor_pre_emphasis
[4][4][4] = {
3317 { 0x00, 0x09, 0x13, 0x25 },
3318 { 0x00, 0x0f, 0x1e, },
3322 { 0x00, 0x0a, 0x14, 0x28 },
3323 { 0x00, 0x0f, 0x1e, },
3327 { 0x00, 0x0a, 0x14, 0x28 },
3328 { 0x00, 0x0f, 0x1e, },
3332 { 0x00, 0x0a, 0x14, 0x28 },
3333 { 0x00, 0x0f, 0x1e, },
3339 static const u8 tegra124_sor_post_cursor
[4][4][4] = {
3341 { 0x00, 0x00, 0x00, 0x00 },
3342 { 0x00, 0x00, 0x00, },
3346 { 0x02, 0x02, 0x04, 0x05 },
3347 { 0x02, 0x04, 0x05, },
3351 { 0x04, 0x05, 0x08, 0x0b },
3352 { 0x05, 0x09, 0x0b, },
3356 { 0x05, 0x09, 0x0b, 0x12 },
3357 { 0x09, 0x0d, 0x12, },
3363 static const u8 tegra124_sor_tx_pu
[4][4][4] = {
3365 { 0x20, 0x30, 0x40, 0x60 },
3366 { 0x30, 0x40, 0x60, },
3370 { 0x20, 0x20, 0x30, 0x50 },
3371 { 0x30, 0x40, 0x50, },
3375 { 0x20, 0x20, 0x30, 0x40, },
3376 { 0x30, 0x30, 0x40, },
3380 { 0x20, 0x20, 0x20, 0x40, },
3381 { 0x30, 0x30, 0x40, },
3387 static const struct tegra_sor_soc tegra124_sor
= {
3388 .supports_lvds
= true,
3389 .supports_hdmi
= false,
3390 .supports_dp
= true,
3391 .supports_audio
= false,
3392 .supports_hdcp
= false,
3393 .regs
= &tegra124_sor_regs
,
3394 .has_nvdisplay
= false,
3395 .xbar_cfg
= tegra124_sor_xbar_cfg
,
3396 .lane_map
= tegra124_sor_lane_map
,
3397 .voltage_swing
= tegra124_sor_voltage_swing
,
3398 .pre_emphasis
= tegra124_sor_pre_emphasis
,
3399 .post_cursor
= tegra124_sor_post_cursor
,
3400 .tx_pu
= tegra124_sor_tx_pu
,
3403 static const u8 tegra132_sor_pre_emphasis
[4][4][4] = {
3405 { 0x00, 0x08, 0x12, 0x24 },
3406 { 0x01, 0x0e, 0x1d, },
3410 { 0x00, 0x08, 0x12, 0x24 },
3411 { 0x00, 0x0e, 0x1d, },
3415 { 0x00, 0x08, 0x12, 0x24 },
3416 { 0x00, 0x0e, 0x1d, },
3420 { 0x00, 0x08, 0x12, 0x24 },
3421 { 0x00, 0x0e, 0x1d, },
3427 static const struct tegra_sor_soc tegra132_sor
= {
3428 .supports_lvds
= true,
3429 .supports_hdmi
= false,
3430 .supports_dp
= true,
3431 .supports_audio
= false,
3432 .supports_hdcp
= false,
3433 .regs
= &tegra124_sor_regs
,
3434 .has_nvdisplay
= false,
3435 .xbar_cfg
= tegra124_sor_xbar_cfg
,
3436 .lane_map
= tegra124_sor_lane_map
,
3437 .voltage_swing
= tegra124_sor_voltage_swing
,
3438 .pre_emphasis
= tegra132_sor_pre_emphasis
,
3439 .post_cursor
= tegra124_sor_post_cursor
,
3440 .tx_pu
= tegra124_sor_tx_pu
,
3443 static const struct tegra_sor_regs tegra210_sor_regs
= {
3444 .head_state0
= 0x05,
3445 .head_state1
= 0x07,
3446 .head_state2
= 0x09,
3447 .head_state3
= 0x0b,
3448 .head_state4
= 0x0d,
3449 .head_state5
= 0x0f,
3458 static const u8 tegra210_sor_xbar_cfg
[5] = {
3462 static const u8 tegra210_sor_lane_map
[4] = {
3466 static const struct tegra_sor_soc tegra210_sor
= {
3467 .supports_lvds
= false,
3468 .supports_hdmi
= false,
3469 .supports_dp
= true,
3470 .supports_audio
= false,
3471 .supports_hdcp
= false,
3473 .regs
= &tegra210_sor_regs
,
3474 .has_nvdisplay
= false,
3476 .xbar_cfg
= tegra210_sor_xbar_cfg
,
3477 .lane_map
= tegra210_sor_lane_map
,
3478 .voltage_swing
= tegra124_sor_voltage_swing
,
3479 .pre_emphasis
= tegra124_sor_pre_emphasis
,
3480 .post_cursor
= tegra124_sor_post_cursor
,
3481 .tx_pu
= tegra124_sor_tx_pu
,
3484 static const struct tegra_sor_soc tegra210_sor1
= {
3485 .supports_lvds
= false,
3486 .supports_hdmi
= true,
3487 .supports_dp
= true,
3488 .supports_audio
= true,
3489 .supports_hdcp
= true,
3491 .regs
= &tegra210_sor_regs
,
3492 .has_nvdisplay
= false,
3494 .num_settings
= ARRAY_SIZE(tegra210_sor_hdmi_defaults
),
3495 .settings
= tegra210_sor_hdmi_defaults
,
3496 .xbar_cfg
= tegra210_sor_xbar_cfg
,
3497 .lane_map
= tegra210_sor_lane_map
,
3498 .voltage_swing
= tegra124_sor_voltage_swing
,
3499 .pre_emphasis
= tegra124_sor_pre_emphasis
,
3500 .post_cursor
= tegra124_sor_post_cursor
,
3501 .tx_pu
= tegra124_sor_tx_pu
,
3504 static const struct tegra_sor_regs tegra186_sor_regs
= {
3505 .head_state0
= 0x151,
3506 .head_state1
= 0x154,
3507 .head_state2
= 0x157,
3508 .head_state3
= 0x15a,
3509 .head_state4
= 0x15d,
3510 .head_state5
= 0x160,
3515 .dp_padctl0
= 0x168,
3516 .dp_padctl2
= 0x16a,
3519 static const u8 tegra186_sor_voltage_swing
[4][4][4] = {
3521 { 0x13, 0x19, 0x1e, 0x28 },
3522 { 0x1e, 0x25, 0x2d, },
3526 { 0x12, 0x16, 0x1b, 0x25 },
3527 { 0x1c, 0x23, 0x2a, },
3531 { 0x12, 0x16, 0x1a, 0x22 },
3532 { 0x1b, 0x20, 0x27, },
3536 { 0x11, 0x14, 0x17, 0x1f },
3537 { 0x19, 0x1e, 0x24, },
3543 static const u8 tegra186_sor_pre_emphasis
[4][4][4] = {
3545 { 0x00, 0x08, 0x12, 0x24 },
3546 { 0x01, 0x0e, 0x1d, },
3550 { 0x00, 0x08, 0x12, 0x24 },
3551 { 0x00, 0x0e, 0x1d, },
3555 { 0x00, 0x08, 0x14, 0x24 },
3556 { 0x00, 0x0e, 0x1d, },
3560 { 0x00, 0x08, 0x12, 0x24 },
3561 { 0x00, 0x0e, 0x1d, },
3567 static const struct tegra_sor_soc tegra186_sor
= {
3568 .supports_lvds
= false,
3569 .supports_hdmi
= true,
3570 .supports_dp
= true,
3571 .supports_audio
= true,
3572 .supports_hdcp
= true,
3574 .regs
= &tegra186_sor_regs
,
3575 .has_nvdisplay
= true,
3577 .num_settings
= ARRAY_SIZE(tegra186_sor_hdmi_defaults
),
3578 .settings
= tegra186_sor_hdmi_defaults
,
3579 .xbar_cfg
= tegra124_sor_xbar_cfg
,
3580 .lane_map
= tegra124_sor_lane_map
,
3581 .voltage_swing
= tegra186_sor_voltage_swing
,
3582 .pre_emphasis
= tegra186_sor_pre_emphasis
,
3583 .post_cursor
= tegra124_sor_post_cursor
,
3584 .tx_pu
= tegra124_sor_tx_pu
,
3587 static const struct tegra_sor_regs tegra194_sor_regs
= {
3588 .head_state0
= 0x151,
3589 .head_state1
= 0x155,
3590 .head_state2
= 0x159,
3591 .head_state3
= 0x15d,
3592 .head_state4
= 0x161,
3593 .head_state5
= 0x165,
3598 .dp_padctl0
= 0x16e,
3599 .dp_padctl2
= 0x16f,
3602 static const struct tegra_sor_soc tegra194_sor
= {
3603 .supports_lvds
= false,
3604 .supports_hdmi
= true,
3605 .supports_dp
= true,
3606 .supports_audio
= true,
3607 .supports_hdcp
= true,
3609 .regs
= &tegra194_sor_regs
,
3610 .has_nvdisplay
= true,
3612 .num_settings
= ARRAY_SIZE(tegra194_sor_hdmi_defaults
),
3613 .settings
= tegra194_sor_hdmi_defaults
,
3615 .xbar_cfg
= tegra210_sor_xbar_cfg
,
3616 .lane_map
= tegra124_sor_lane_map
,
3617 .voltage_swing
= tegra186_sor_voltage_swing
,
3618 .pre_emphasis
= tegra186_sor_pre_emphasis
,
3619 .post_cursor
= tegra124_sor_post_cursor
,
3620 .tx_pu
= tegra124_sor_tx_pu
,
3623 static const struct of_device_id tegra_sor_of_match
[] = {
3624 { .compatible
= "nvidia,tegra194-sor", .data
= &tegra194_sor
},
3625 { .compatible
= "nvidia,tegra186-sor", .data
= &tegra186_sor
},
3626 { .compatible
= "nvidia,tegra210-sor1", .data
= &tegra210_sor1
},
3627 { .compatible
= "nvidia,tegra210-sor", .data
= &tegra210_sor
},
3628 { .compatible
= "nvidia,tegra132-sor", .data
= &tegra132_sor
},
3629 { .compatible
= "nvidia,tegra124-sor", .data
= &tegra124_sor
},
3632 MODULE_DEVICE_TABLE(of
, tegra_sor_of_match
);
3634 static int tegra_sor_parse_dt(struct tegra_sor
*sor
)
3636 struct device_node
*np
= sor
->dev
->of_node
;
3642 if (sor
->soc
->has_nvdisplay
) {
3643 err
= of_property_read_u32(np
, "nvidia,interface", &value
);
3650 * override the default that we already set for Tegra210 and
3653 sor
->pad
= TEGRA_IO_PAD_HDMI_DP0
+ sor
->index
;
3655 if (!sor
->soc
->supports_audio
)
3661 err
= of_property_read_u32_array(np
, "nvidia,xbar-cfg", xbar_cfg
, 5);
3663 /* fall back to default per-SoC XBAR configuration */
3664 for (i
= 0; i
< 5; i
++)
3665 sor
->xbar_cfg
[i
] = sor
->soc
->xbar_cfg
[i
];
3667 /* copy cells to SOR XBAR configuration */
3668 for (i
= 0; i
< 5; i
++)
3669 sor
->xbar_cfg
[i
] = xbar_cfg
[i
];
3675 static irqreturn_t
tegra_sor_irq(int irq
, void *data
)
3677 struct tegra_sor
*sor
= data
;
3680 value
= tegra_sor_readl(sor
, SOR_INT_STATUS
);
3681 tegra_sor_writel(sor
, value
, SOR_INT_STATUS
);
3683 if (value
& SOR_INT_CODEC_SCRATCH0
) {
3684 value
= tegra_sor_readl(sor
, SOR_AUDIO_HDA_CODEC_SCRATCH0
);
3686 if (value
& SOR_AUDIO_HDA_CODEC_SCRATCH0_VALID
) {
3687 unsigned int format
;
3689 format
= value
& SOR_AUDIO_HDA_CODEC_SCRATCH0_FMT_MASK
;
3691 tegra_hda_parse_format(format
, &sor
->format
);
3693 if (sor
->ops
->audio_enable
)
3694 sor
->ops
->audio_enable(sor
);
3696 if (sor
->ops
->audio_disable
)
3697 sor
->ops
->audio_disable(sor
);
3704 static int tegra_sor_probe(struct platform_device
*pdev
)
3706 struct device_node
*np
;
3707 struct tegra_sor
*sor
;
3708 struct resource
*regs
;
3711 sor
= devm_kzalloc(&pdev
->dev
, sizeof(*sor
), GFP_KERNEL
);
3715 sor
->soc
= of_device_get_match_data(&pdev
->dev
);
3716 sor
->output
.dev
= sor
->dev
= &pdev
->dev
;
3718 sor
->settings
= devm_kmemdup(&pdev
->dev
, sor
->soc
->settings
,
3719 sor
->soc
->num_settings
*
3720 sizeof(*sor
->settings
),
3725 sor
->num_settings
= sor
->soc
->num_settings
;
3727 np
= of_parse_phandle(pdev
->dev
.of_node
, "nvidia,dpaux", 0);
3729 sor
->aux
= drm_dp_aux_find_by_of_node(np
);
3733 return -EPROBE_DEFER
;
3735 if (get_device(&sor
->aux
->ddc
.dev
)) {
3736 if (try_module_get(sor
->aux
->ddc
.owner
))
3737 sor
->output
.ddc
= &sor
->aux
->ddc
;
3739 put_device(&sor
->aux
->ddc
.dev
);
3744 if (sor
->soc
->supports_hdmi
) {
3745 sor
->ops
= &tegra_sor_hdmi_ops
;
3746 sor
->pad
= TEGRA_IO_PAD_HDMI
;
3747 } else if (sor
->soc
->supports_lvds
) {
3748 dev_err(&pdev
->dev
, "LVDS not supported yet\n");
3751 dev_err(&pdev
->dev
, "unknown (non-DP) support\n");
3755 np
= of_parse_phandle(pdev
->dev
.of_node
, "nvidia,panel", 0);
3757 * No need to keep this around since we only use it as a check
3758 * to see if a panel is connected (eDP) or not (DP).
3762 sor
->ops
= &tegra_sor_dp_ops
;
3763 sor
->pad
= TEGRA_IO_PAD_LVDS
;
3766 err
= tegra_sor_parse_dt(sor
);
3770 err
= tegra_output_probe(&sor
->output
);
3772 return dev_err_probe(&pdev
->dev
, err
,
3773 "failed to probe output\n");
3775 if (sor
->ops
&& sor
->ops
->probe
) {
3776 err
= sor
->ops
->probe(sor
);
3778 dev_err(&pdev
->dev
, "failed to probe %s: %d\n",
3779 sor
->ops
->name
, err
);
3784 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
3785 sor
->regs
= devm_ioremap_resource(&pdev
->dev
, regs
);
3786 if (IS_ERR(sor
->regs
)) {
3787 err
= PTR_ERR(sor
->regs
);
3791 err
= platform_get_irq(pdev
, 0);
3793 dev_err(&pdev
->dev
, "failed to get IRQ: %d\n", err
);
3799 err
= devm_request_irq(sor
->dev
, sor
->irq
, tegra_sor_irq
, 0,
3800 dev_name(sor
->dev
), sor
);
3802 dev_err(&pdev
->dev
, "failed to request IRQ: %d\n", err
);
3806 sor
->rst
= devm_reset_control_get_exclusive_released(&pdev
->dev
, "sor");
3807 if (IS_ERR(sor
->rst
)) {
3808 err
= PTR_ERR(sor
->rst
);
3810 if (err
!= -EBUSY
|| WARN_ON(!pdev
->dev
.pm_domain
)) {
3811 dev_err(&pdev
->dev
, "failed to get reset control: %d\n",
3817 * At this point, the reset control is most likely being used
3818 * by the generic power domain implementation. With any luck
3819 * the power domain will have taken care of resetting the SOR
3820 * and we don't have to do anything.
3825 sor
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
3826 if (IS_ERR(sor
->clk
)) {
3827 err
= PTR_ERR(sor
->clk
);
3828 dev_err(&pdev
->dev
, "failed to get module clock: %d\n", err
);
3832 if (sor
->soc
->supports_hdmi
|| sor
->soc
->supports_dp
) {
3833 struct device_node
*np
= pdev
->dev
.of_node
;
3837 * For backwards compatibility with Tegra210 device trees,
3838 * fall back to the old clock name "source" if the new "out"
3839 * clock is not available.
3841 if (of_property_match_string(np
, "clock-names", "out") < 0)
3846 sor
->clk_out
= devm_clk_get(&pdev
->dev
, name
);
3847 if (IS_ERR(sor
->clk_out
)) {
3848 err
= PTR_ERR(sor
->clk_out
);
3849 dev_err(sor
->dev
, "failed to get %s clock: %d\n",
3854 /* fall back to the module clock on SOR0 (eDP/LVDS only) */
3855 sor
->clk_out
= sor
->clk
;
3858 sor
->clk_parent
= devm_clk_get(&pdev
->dev
, "parent");
3859 if (IS_ERR(sor
->clk_parent
)) {
3860 err
= PTR_ERR(sor
->clk_parent
);
3861 dev_err(&pdev
->dev
, "failed to get parent clock: %d\n", err
);
3865 sor
->clk_safe
= devm_clk_get(&pdev
->dev
, "safe");
3866 if (IS_ERR(sor
->clk_safe
)) {
3867 err
= PTR_ERR(sor
->clk_safe
);
3868 dev_err(&pdev
->dev
, "failed to get safe clock: %d\n", err
);
3872 sor
->clk_dp
= devm_clk_get(&pdev
->dev
, "dp");
3873 if (IS_ERR(sor
->clk_dp
)) {
3874 err
= PTR_ERR(sor
->clk_dp
);
3875 dev_err(&pdev
->dev
, "failed to get DP clock: %d\n", err
);
3880 * Starting with Tegra186, the BPMP provides an implementation for
3881 * the pad output clock, so we have to look it up from device tree.
3883 sor
->clk_pad
= devm_clk_get(&pdev
->dev
, "pad");
3884 if (IS_ERR(sor
->clk_pad
)) {
3885 if (sor
->clk_pad
!= ERR_PTR(-ENOENT
)) {
3886 err
= PTR_ERR(sor
->clk_pad
);
3891 * If the pad output clock is not available, then we assume
3892 * we're on Tegra210 or earlier and have to provide our own
3895 sor
->clk_pad
= NULL
;
3899 * The bootloader may have set up the SOR such that it's module clock
3900 * is sourced by one of the display PLLs. However, that doesn't work
3901 * without properly having set up other bits of the SOR.
3903 err
= clk_set_parent(sor
->clk_out
, sor
->clk_safe
);
3905 dev_err(&pdev
->dev
, "failed to use safe clock: %d\n", err
);
3909 platform_set_drvdata(pdev
, sor
);
3910 pm_runtime_enable(&pdev
->dev
);
3912 INIT_LIST_HEAD(&sor
->client
.list
);
3913 sor
->client
.ops
= &sor_client_ops
;
3914 sor
->client
.dev
= &pdev
->dev
;
3916 err
= host1x_client_register(&sor
->client
);
3918 dev_err(&pdev
->dev
, "failed to register host1x client: %d\n",
3924 * On Tegra210 and earlier, provide our own implementation for the
3927 if (!sor
->clk_pad
) {
3930 name
= devm_kasprintf(sor
->dev
, GFP_KERNEL
, "sor%u_pad_clkout",
3937 err
= host1x_client_resume(&sor
->client
);
3939 dev_err(sor
->dev
, "failed to resume: %d\n", err
);
3943 sor
->clk_pad
= tegra_clk_sor_pad_register(sor
, name
);
3944 host1x_client_suspend(&sor
->client
);
3947 if (IS_ERR(sor
->clk_pad
)) {
3948 err
= PTR_ERR(sor
->clk_pad
);
3949 dev_err(sor
->dev
, "failed to register SOR pad clock: %d\n",
3957 host1x_client_unregister(&sor
->client
);
3959 pm_runtime_disable(&pdev
->dev
);
3961 tegra_output_remove(&sor
->output
);
3965 static int tegra_sor_remove(struct platform_device
*pdev
)
3967 struct tegra_sor
*sor
= platform_get_drvdata(pdev
);
3970 err
= host1x_client_unregister(&sor
->client
);
3972 dev_err(&pdev
->dev
, "failed to unregister host1x client: %d\n",
3977 pm_runtime_disable(&pdev
->dev
);
3979 tegra_output_remove(&sor
->output
);
3984 static int __maybe_unused
tegra_sor_suspend(struct device
*dev
)
3986 struct tegra_sor
*sor
= dev_get_drvdata(dev
);
3989 err
= tegra_output_suspend(&sor
->output
);
3991 dev_err(dev
, "failed to suspend output: %d\n", err
);
3995 if (sor
->hdmi_supply
) {
3996 err
= regulator_disable(sor
->hdmi_supply
);
3998 tegra_output_resume(&sor
->output
);
4006 static int __maybe_unused
tegra_sor_resume(struct device
*dev
)
4008 struct tegra_sor
*sor
= dev_get_drvdata(dev
);
4011 if (sor
->hdmi_supply
) {
4012 err
= regulator_enable(sor
->hdmi_supply
);
4017 err
= tegra_output_resume(&sor
->output
);
4019 dev_err(dev
, "failed to resume output: %d\n", err
);
4021 if (sor
->hdmi_supply
)
4022 regulator_disable(sor
->hdmi_supply
);
4030 static const struct dev_pm_ops tegra_sor_pm_ops
= {
4031 SET_SYSTEM_SLEEP_PM_OPS(tegra_sor_suspend
, tegra_sor_resume
)
4034 struct platform_driver tegra_sor_driver
= {
4036 .name
= "tegra-sor",
4037 .of_match_table
= tegra_sor_of_match
,
4038 .pm
= &tegra_sor_pm_ops
,
4040 .probe
= tegra_sor_probe
,
4041 .remove
= tegra_sor_remove
,