Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame] | 2 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 3 | /* |
| 4 | * drivers/video/tegra/dc/sor.c |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 7 | #include <boot/tables.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 8 | #include <console/console.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 9 | #include <delay.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 10 | #include <device/device.h> |
| 11 | #include <soc/addressmap.h> |
| 12 | #include <soc/clk_rst.h> |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 13 | #include <soc/clock.h> |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 14 | #include <soc/display.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 15 | #include <soc/nvidia/tegra/dc.h> |
| 16 | #include <soc/nvidia/tegra/displayport.h> |
| 17 | #include <soc/sor.h> |
| 18 | #include <stdint.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 19 | |
| 20 | #include "chip.h" |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 21 | |
Jimmy Zhang | 47e3cf8 | 2014-04-14 12:31:06 -0700 | [diff] [blame] | 22 | #define DEBUG_SOR 0 |
| 23 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 24 | #define APBDEV_PMC_DPD_SAMPLE (0x20) |
| 25 | #define APBDEV_PMC_DPD_SAMPLE_ON_DISABLE (0) |
| 26 | #define APBDEV_PMC_DPD_SAMPLE_ON_ENABLE (1) |
| 27 | #define APBDEV_PMC_SEL_DPD_TIM (0x1c8) |
| 28 | #define APBDEV_PMC_SEL_DPD_TIM_SEL_DPD_TIM_DEFAULT (0x7f) |
| 29 | #define APBDEV_PMC_IO_DPD2_REQ (0x1c0) |
| 30 | #define APBDEV_PMC_IO_DPD2_REQ_LVDS_SHIFT (25) |
| 31 | #define APBDEV_PMC_IO_DPD2_REQ_LVDS_OFF (0 << 25) |
| 32 | #define APBDEV_PMC_IO_DPD2_REQ_LVDS_ON (1 << 25) |
| 33 | #define APBDEV_PMC_IO_DPD2_REQ_CODE_SHIFT (30) |
| 34 | #define APBDEV_PMC_IO_DPD2_REQ_CODE_DEFAULT_MASK (0x3 << 30) |
| 35 | #define APBDEV_PMC_IO_DPD2_REQ_CODE_IDLE (0 << 30) |
| 36 | #define APBDEV_PMC_IO_DPD2_REQ_CODE_DPD_OFF (1 << 30) |
| 37 | #define APBDEV_PMC_IO_DPD2_REQ_CODE_DPD_ON (2 << 30) |
| 38 | #define APBDEV_PMC_IO_DPD2_STATUS (0x1c4) |
| 39 | #define APBDEV_PMC_IO_DPD2_STATUS_LVDS_SHIFT (25) |
| 40 | #define APBDEV_PMC_IO_DPD2_STATUS_LVDS_OFF (0 << 25) |
| 41 | #define APBDEV_PMC_IO_DPD2_STATUS_LVDS_ON (1 << 25) |
| 42 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 43 | static inline u32 tegra_sor_readl(struct tegra_dc_sor_data *sor, u32 reg) |
| 44 | { |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 45 | void *addr = sor->base + (u32) (reg << 2); |
| 46 | u32 reg_val = READL(addr); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 47 | return reg_val; |
| 48 | } |
| 49 | |
| 50 | static inline void tegra_sor_writel(struct tegra_dc_sor_data *sor, |
| 51 | u32 reg, u32 val) |
| 52 | { |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 53 | void *addr = sor->base + (u32) (reg << 2); |
| 54 | WRITEL(val, addr); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static inline void tegra_sor_write_field(struct tegra_dc_sor_data *sor, |
| 58 | u32 reg, u32 mask, u32 val) |
| 59 | { |
| 60 | u32 reg_val = tegra_sor_readl(sor, reg); |
| 61 | reg_val &= ~mask; |
| 62 | reg_val |= val; |
| 63 | tegra_sor_writel(sor, reg, reg_val); |
| 64 | } |
| 65 | |
Neil Chen | 8c440a6 | 2014-09-23 17:41:59 +0800 | [diff] [blame] | 66 | void tegra_dp_disable_tx_pu(struct tegra_dc_sor_data *sor) |
| 67 | { |
| 68 | tegra_sor_write_field(sor, |
| 69 | NV_SOR_DP_PADCTL(sor->portnum), |
| 70 | NV_SOR_DP_PADCTL_TX_PU_MASK, |
| 71 | NV_SOR_DP_PADCTL_TX_PU_DISABLE); |
| 72 | } |
| 73 | |
| 74 | void tegra_dp_set_pe_vs_pc(struct tegra_dc_sor_data *sor, u32 mask, |
| 75 | u32 pe_reg, u32 vs_reg, u32 pc_reg, u8 pc_supported) |
| 76 | { |
| 77 | tegra_sor_write_field(sor, NV_SOR_PR(sor->portnum), |
| 78 | mask, pe_reg); |
| 79 | tegra_sor_write_field(sor, NV_SOR_DC(sor->portnum), |
| 80 | mask, vs_reg); |
| 81 | if (pc_supported) { |
| 82 | tegra_sor_write_field( |
| 83 | sor, NV_SOR_POSTCURSOR(sor->portnum), |
| 84 | mask, pc_reg); |
| 85 | } |
| 86 | } |
| 87 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 88 | static u32 tegra_dc_sor_poll_register(struct tegra_dc_sor_data *sor, |
| 89 | u32 reg, u32 mask, u32 exp_val, u32 poll_interval_us, u32 timeout_us) |
| 90 | { |
| 91 | u32 temp = timeout_us; |
| 92 | u32 reg_val = 0; |
| 93 | |
| 94 | do { |
| 95 | udelay(poll_interval_us); |
| 96 | reg_val = tegra_sor_readl(sor, reg); |
| 97 | if (timeout_us > poll_interval_us) |
| 98 | timeout_us -= poll_interval_us; |
| 99 | else |
| 100 | break; |
| 101 | } while ((reg_val & mask) != exp_val); |
| 102 | |
| 103 | if ((reg_val & mask) == exp_val) |
| 104 | return 0; /* success */ |
| 105 | printk(BIOS_ERR, |
| 106 | "sor_poll_register 0x%x: timeout, " |
| 107 | "(reg_val)0x%08x & (mask)0x%08x != (exp_val)0x%08x\n", |
| 108 | reg, reg_val, mask, exp_val); |
| 109 | |
| 110 | return temp; |
| 111 | } |
| 112 | |
| 113 | int tegra_dc_sor_set_power_state(struct tegra_dc_sor_data *sor, int pu_pd) |
| 114 | { |
| 115 | u32 reg_val; |
| 116 | u32 orig_val; |
| 117 | |
| 118 | orig_val = tegra_sor_readl(sor, NV_SOR_PWR); |
| 119 | |
| 120 | reg_val = pu_pd ? NV_SOR_PWR_NORMAL_STATE_PU : |
| 121 | NV_SOR_PWR_NORMAL_STATE_PD; /* normal state only */ |
| 122 | |
| 123 | if (reg_val == orig_val) |
| 124 | return 0; /* No update needed */ |
| 125 | |
| 126 | reg_val |= NV_SOR_PWR_SETTING_NEW_TRIGGER; |
| 127 | tegra_sor_writel(sor, NV_SOR_PWR, reg_val); |
| 128 | |
| 129 | /* Poll to confirm it is done */ |
| 130 | if (tegra_dc_sor_poll_register(sor, NV_SOR_PWR, |
| 131 | NV_SOR_PWR_SETTING_NEW_DEFAULT_MASK, |
| 132 | NV_SOR_PWR_SETTING_NEW_DONE, |
| 133 | 100, TEGRA_SOR_TIMEOUT_MS * 1000)) { |
| 134 | printk(BIOS_ERR, |
| 135 | "dc timeout waiting for SOR_PWR = NEW_DONE\n"); |
| 136 | return -EFAULT; |
| 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 141 | void tegra_dc_sor_set_dp_linkctl(struct tegra_dc_sor_data *sor, int ena, |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 142 | u8 training_pattern, const struct tegra_dc_dp_link_config *link_cfg) |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 143 | { |
| 144 | u32 reg_val; |
| 145 | |
| 146 | reg_val = tegra_sor_readl(sor, NV_SOR_DP_LINKCTL(sor->portnum)); |
| 147 | |
| 148 | if (ena) |
| 149 | reg_val |= NV_SOR_DP_LINKCTL_ENABLE_YES; |
| 150 | else |
| 151 | reg_val &= NV_SOR_DP_LINKCTL_ENABLE_NO; |
| 152 | |
| 153 | reg_val &= ~NV_SOR_DP_LINKCTL_TUSIZE_MASK; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 154 | reg_val |= (link_cfg->tu_size << NV_SOR_DP_LINKCTL_TUSIZE_SHIFT); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 155 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 156 | if (link_cfg->enhanced_framing) |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 157 | reg_val |= NV_SOR_DP_LINKCTL_ENHANCEDFRAME_ENABLE; |
| 158 | |
| 159 | tegra_sor_writel(sor, NV_SOR_DP_LINKCTL(sor->portnum), reg_val); |
| 160 | |
| 161 | switch (training_pattern) { |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 162 | case training_pattern_1: |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 163 | tegra_sor_writel(sor, NV_SOR_DP_TPG, 0x41414141); |
| 164 | break; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 165 | case training_pattern_2: |
| 166 | case training_pattern_3: |
| 167 | reg_val = (link_cfg->link_bw == SOR_LINK_SPEED_G5_4) ? |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 168 | 0x43434343 : 0x42424242; |
| 169 | tegra_sor_writel(sor, NV_SOR_DP_TPG, reg_val); |
| 170 | break; |
| 171 | default: |
| 172 | tegra_sor_writel(sor, NV_SOR_DP_TPG, 0x50505050); |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 177 | static int tegra_dc_sor_enable_lane_sequencer(struct tegra_dc_sor_data *sor, |
| 178 | int pu, int is_lvds) |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 179 | { |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 180 | u32 reg_val; |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 181 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 182 | /* SOR lane sequencer */ |
| 183 | if (pu) |
| 184 | reg_val = NV_SOR_LANE_SEQ_CTL_SETTING_NEW_TRIGGER | |
| 185 | NV_SOR_LANE_SEQ_CTL_SEQUENCE_DOWN | |
| 186 | NV_SOR_LANE_SEQ_CTL_NEW_POWER_STATE_PU; |
| 187 | else |
| 188 | reg_val = NV_SOR_LANE_SEQ_CTL_SETTING_NEW_TRIGGER | |
| 189 | NV_SOR_LANE_SEQ_CTL_SEQUENCE_UP | |
| 190 | NV_SOR_LANE_SEQ_CTL_NEW_POWER_STATE_PD; |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 191 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 192 | if (is_lvds) |
| 193 | reg_val |= 15 << NV_SOR_LANE_SEQ_CTL_DELAY_SHIFT; |
| 194 | else |
| 195 | reg_val |= 1 << NV_SOR_LANE_SEQ_CTL_DELAY_SHIFT; |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 196 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 197 | tegra_sor_writel(sor, NV_SOR_LANE_SEQ_CTL, reg_val); |
| 198 | |
| 199 | if (tegra_dc_sor_poll_register(sor, NV_SOR_LANE_SEQ_CTL, |
| 200 | NV_SOR_LANE_SEQ_CTL_SETTING_MASK, |
| 201 | NV_SOR_LANE_SEQ_CTL_SETTING_NEW_DONE, |
| 202 | 100, TEGRA_SOR_TIMEOUT_MS*1000)) { |
| 203 | printk(BIOS_ERR, |
| 204 | "dp: timeout while waiting for SOR lane sequencer " |
| 205 | "to power down langes\n"); |
| 206 | return -1; |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 207 | } |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 208 | return 0; |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 209 | } |
| 210 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 211 | static int tegra_dc_sor_power_dplanes(struct tegra_dc_sor_data *sor, |
| 212 | u32 lane_count, int pu) |
| 213 | { |
| 214 | u32 reg_val; |
| 215 | |
| 216 | reg_val = tegra_sor_readl(sor, NV_SOR_DP_PADCTL(sor->portnum)); |
| 217 | |
| 218 | if (pu) { |
| 219 | switch (lane_count) { |
| 220 | case 4: |
| 221 | reg_val |= (NV_SOR_DP_PADCTL_PD_TXD_3_NO | |
| 222 | NV_SOR_DP_PADCTL_PD_TXD_2_NO); |
| 223 | /* fall through */ |
| 224 | case 2: |
| 225 | reg_val |= NV_SOR_DP_PADCTL_PD_TXD_1_NO; |
Jacob Garber | 4c33a3a | 2019-07-12 10:34:06 -0600 | [diff] [blame] | 226 | /* fall through */ |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 227 | case 1: |
| 228 | reg_val |= NV_SOR_DP_PADCTL_PD_TXD_0_NO; |
| 229 | break; |
| 230 | default: |
| 231 | printk(BIOS_ERR, |
| 232 | "dp: invalid lane number %d\n", lane_count); |
| 233 | return -1; |
| 234 | } |
| 235 | |
| 236 | tegra_sor_writel(sor, NV_SOR_DP_PADCTL(sor->portnum), reg_val); |
| 237 | tegra_dc_sor_set_lane_count(sor, lane_count); |
| 238 | } |
| 239 | return tegra_dc_sor_enable_lane_sequencer(sor, pu, 0); |
| 240 | } |
| 241 | |
| 242 | void tegra_dc_sor_set_panel_power(struct tegra_dc_sor_data *sor, |
| 243 | int power_up) |
| 244 | { |
| 245 | u32 reg_val; |
| 246 | |
| 247 | /* !!TODO: need to enable panel power through GPIO operations */ |
| 248 | /* Check bug 790854 for HW progress */ |
| 249 | |
| 250 | reg_val = tegra_sor_readl(sor, NV_SOR_DP_PADCTL(sor->portnum)); |
| 251 | |
| 252 | if (power_up) |
| 253 | reg_val |= NV_SOR_DP_PADCTL_PAD_CAL_PD_POWERUP; |
| 254 | else |
| 255 | reg_val &= ~NV_SOR_DP_PADCTL_PAD_CAL_PD_POWERUP; |
| 256 | |
| 257 | tegra_sor_writel(sor, NV_SOR_DP_PADCTL(sor->portnum), reg_val); |
| 258 | } |
| 259 | |
Jimmy Zhang | 84b8be6 | 2014-04-14 12:15:38 -0700 | [diff] [blame] | 260 | static void tegra_dc_sor_config_pwm(struct tegra_dc_sor_data *sor, u32 pwm_div, |
| 261 | u32 pwm_dutycycle) |
| 262 | { |
| 263 | tegra_sor_writel(sor, NV_SOR_PWM_DIV, pwm_div); |
| 264 | tegra_sor_writel(sor, NV_SOR_PWM_CTL, |
| 265 | (pwm_dutycycle & NV_SOR_PWM_CTL_DUTY_CYCLE_MASK) | |
| 266 | NV_SOR_PWM_CTL_SETTING_NEW_TRIGGER); |
| 267 | |
| 268 | if (tegra_dc_sor_poll_register(sor, NV_SOR_PWM_CTL, |
| 269 | NV_SOR_PWM_CTL_SETTING_NEW_SHIFT, |
| 270 | NV_SOR_PWM_CTL_SETTING_NEW_DONE, |
| 271 | 100, TEGRA_SOR_TIMEOUT_MS * 1000)) { |
| 272 | printk(BIOS_ERR, |
| 273 | "dp: timeout while waiting for SOR PWM setting\n"); |
| 274 | } |
| 275 | } |
| 276 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 277 | static void tegra_dc_sor_set_dp_mode(struct tegra_dc_sor_data *sor, |
| 278 | const struct tegra_dc_dp_link_config *link_cfg) |
| 279 | { |
| 280 | u32 reg_val; |
| 281 | |
| 282 | tegra_dc_sor_set_link_bandwidth(sor, link_cfg->link_bw); |
| 283 | |
| 284 | tegra_dc_sor_set_dp_linkctl(sor, 1, training_pattern_none, link_cfg); |
| 285 | reg_val = tegra_sor_readl(sor, NV_SOR_DP_CONFIG(sor->portnum)); |
| 286 | reg_val &= ~NV_SOR_DP_CONFIG_WATERMARK_MASK; |
| 287 | reg_val |= link_cfg->watermark; |
| 288 | reg_val &= ~NV_SOR_DP_CONFIG_ACTIVESYM_COUNT_MASK; |
| 289 | reg_val |= (link_cfg->active_count << |
| 290 | NV_SOR_DP_CONFIG_ACTIVESYM_COUNT_SHIFT); |
| 291 | reg_val &= ~NV_SOR_DP_CONFIG_ACTIVESYM_FRAC_MASK; |
| 292 | reg_val |= (link_cfg->active_frac << |
| 293 | NV_SOR_DP_CONFIG_ACTIVESYM_FRAC_SHIFT); |
| 294 | if (link_cfg->activepolarity) |
| 295 | reg_val |= NV_SOR_DP_CONFIG_ACTIVESYM_POLARITY_POSITIVE; |
| 296 | else |
| 297 | reg_val &= ~NV_SOR_DP_CONFIG_ACTIVESYM_POLARITY_POSITIVE; |
| 298 | reg_val |= (NV_SOR_DP_CONFIG_ACTIVESYM_CNTL_ENABLE | |
| 299 | NV_SOR_DP_CONFIG_RD_RESET_VAL_NEGATIVE); |
| 300 | |
| 301 | tegra_sor_writel(sor, NV_SOR_DP_CONFIG(sor->portnum), reg_val); |
| 302 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 303 | /* program h/vblank sym */ |
| 304 | tegra_sor_write_field(sor, NV_SOR_DP_AUDIO_HBLANK_SYMBOLS, |
| 305 | NV_SOR_DP_AUDIO_HBLANK_SYMBOLS_MASK, link_cfg->hblank_sym); |
| 306 | |
| 307 | tegra_sor_write_field(sor, NV_SOR_DP_AUDIO_VBLANK_SYMBOLS, |
| 308 | NV_SOR_DP_AUDIO_VBLANK_SYMBOLS_MASK, link_cfg->vblank_sym); |
| 309 | } |
| 310 | |
| 311 | static inline void tegra_dc_sor_super_update(struct tegra_dc_sor_data *sor) |
| 312 | { |
| 313 | tegra_sor_writel(sor, NV_SOR_SUPER_STATE0, 0); |
| 314 | tegra_sor_writel(sor, NV_SOR_SUPER_STATE0, 1); |
| 315 | tegra_sor_writel(sor, NV_SOR_SUPER_STATE0, 0); |
| 316 | } |
| 317 | |
| 318 | static inline void tegra_dc_sor_update(struct tegra_dc_sor_data *sor) |
| 319 | { |
| 320 | tegra_sor_writel(sor, NV_SOR_STATE0, 0); |
| 321 | tegra_sor_writel(sor, NV_SOR_STATE0, 1); |
| 322 | tegra_sor_writel(sor, NV_SOR_STATE0, 0); |
| 323 | } |
| 324 | |
| 325 | static void tegra_dc_sor_io_set_dpd(struct tegra_dc_sor_data *sor, int up) |
| 326 | { |
| 327 | u32 reg_val; |
| 328 | void *pmc_base = sor->pmc_base; |
| 329 | |
| 330 | if (up) { |
| 331 | WRITEL(APBDEV_PMC_DPD_SAMPLE_ON_ENABLE, |
| 332 | pmc_base + APBDEV_PMC_DPD_SAMPLE); |
| 333 | WRITEL(10, pmc_base + APBDEV_PMC_SEL_DPD_TIM); |
| 334 | } |
| 335 | |
| 336 | reg_val = READL(pmc_base + APBDEV_PMC_IO_DPD2_REQ); |
Jacob Garber | 83369fa | 2019-07-24 15:15:20 -0600 | [diff] [blame] | 337 | reg_val &= ~(APBDEV_PMC_IO_DPD2_REQ_LVDS_ON | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 338 | APBDEV_PMC_IO_DPD2_REQ_CODE_DEFAULT_MASK); |
| 339 | |
Jacob Garber | 83369fa | 2019-07-24 15:15:20 -0600 | [diff] [blame] | 340 | reg_val |= up ? APBDEV_PMC_IO_DPD2_REQ_LVDS_ON | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 341 | APBDEV_PMC_IO_DPD2_REQ_CODE_DPD_OFF : |
| 342 | APBDEV_PMC_IO_DPD2_REQ_LVDS_OFF | |
| 343 | APBDEV_PMC_IO_DPD2_REQ_CODE_DPD_ON; |
| 344 | |
| 345 | WRITEL(reg_val, pmc_base + APBDEV_PMC_IO_DPD2_REQ); |
| 346 | |
| 347 | /* Polling */ |
| 348 | u32 temp = 10*1000; |
| 349 | do { |
| 350 | udelay(20); |
| 351 | reg_val = READL(pmc_base + APBDEV_PMC_IO_DPD2_STATUS); |
| 352 | if (temp > 20) |
| 353 | temp -= 20; |
| 354 | else |
| 355 | break; |
| 356 | } while ((reg_val & APBDEV_PMC_IO_DPD2_STATUS_LVDS_ON) != 0); |
| 357 | |
| 358 | if ((reg_val & APBDEV_PMC_IO_DPD2_STATUS_LVDS_ON) != 0) |
| 359 | printk(BIOS_ERR, |
| 360 | "PMC_IO_DPD2 polling failed (0x%x)\n", reg_val); |
| 361 | |
| 362 | if (up) |
| 363 | WRITEL(APBDEV_PMC_DPD_SAMPLE_ON_DISABLE, |
| 364 | pmc_base + APBDEV_PMC_DPD_SAMPLE); |
| 365 | } |
| 366 | |
| 367 | void tegra_dc_sor_set_internal_panel(struct tegra_dc_sor_data *sor, int is_int) |
| 368 | { |
| 369 | u32 reg_val; |
| 370 | |
| 371 | reg_val = tegra_sor_readl(sor, NV_SOR_DP_SPARE(sor->portnum)); |
| 372 | if (is_int) |
| 373 | reg_val |= NV_SOR_DP_SPARE_PANEL_INTERNAL; |
| 374 | else |
| 375 | reg_val &= ~NV_SOR_DP_SPARE_PANEL_INTERNAL; |
| 376 | |
| 377 | reg_val |= NV_SOR_DP_SPARE_SOR_CLK_SEL_MACRO_SORCLK | |
| 378 | NV_SOR_DP_SPARE_SEQ_ENABLE_YES; |
| 379 | tegra_sor_writel(sor, NV_SOR_DP_SPARE(sor->portnum), reg_val); |
| 380 | } |
| 381 | |
| 382 | void tegra_dc_sor_read_link_config(struct tegra_dc_sor_data *sor, u8 *link_bw, |
| 383 | u8 *lane_count) |
| 384 | { |
| 385 | u32 reg_val; |
| 386 | |
| 387 | reg_val = tegra_sor_readl(sor, NV_SOR_CLK_CNTRL); |
| 388 | *link_bw = (reg_val & NV_SOR_CLK_CNTRL_DP_LINK_SPEED_MASK) |
| 389 | >> NV_SOR_CLK_CNTRL_DP_LINK_SPEED_SHIFT; |
| 390 | reg_val = tegra_sor_readl(sor, |
| 391 | NV_SOR_DP_LINKCTL(sor->portnum)); |
| 392 | |
| 393 | switch (reg_val & NV_SOR_DP_LINKCTL_LANECOUNT_MASK) { |
| 394 | case NV_SOR_DP_LINKCTL_LANECOUNT_ZERO: |
| 395 | *lane_count = 0; |
| 396 | break; |
| 397 | case NV_SOR_DP_LINKCTL_LANECOUNT_ONE: |
| 398 | *lane_count = 1; |
| 399 | break; |
| 400 | case NV_SOR_DP_LINKCTL_LANECOUNT_TWO: |
| 401 | *lane_count = 2; |
| 402 | break; |
| 403 | case NV_SOR_DP_LINKCTL_LANECOUNT_FOUR: |
| 404 | *lane_count = 4; |
| 405 | break; |
| 406 | default: |
| 407 | printk(BIOS_ERR, "Unknown lane count\n"); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | void tegra_dc_sor_set_link_bandwidth(struct tegra_dc_sor_data *sor, u8 link_bw) |
| 412 | { |
| 413 | tegra_sor_write_field(sor, NV_SOR_CLK_CNTRL, |
| 414 | NV_SOR_CLK_CNTRL_DP_LINK_SPEED_MASK, |
| 415 | link_bw << NV_SOR_CLK_CNTRL_DP_LINK_SPEED_SHIFT); |
| 416 | } |
| 417 | |
| 418 | void tegra_dc_sor_set_lane_count(struct tegra_dc_sor_data *sor, u8 lane_count) |
| 419 | { |
| 420 | u32 reg_val; |
| 421 | |
| 422 | reg_val = tegra_sor_readl(sor, NV_SOR_DP_LINKCTL(sor->portnum)); |
| 423 | reg_val &= ~NV_SOR_DP_LINKCTL_LANECOUNT_MASK; |
| 424 | switch (lane_count) { |
| 425 | case 0: |
| 426 | break; |
| 427 | case 1: |
| 428 | reg_val |= NV_SOR_DP_LINKCTL_LANECOUNT_ONE; |
| 429 | break; |
| 430 | case 2: |
| 431 | reg_val |= NV_SOR_DP_LINKCTL_LANECOUNT_TWO; |
| 432 | break; |
| 433 | case 4: |
| 434 | reg_val |= NV_SOR_DP_LINKCTL_LANECOUNT_FOUR; |
| 435 | break; |
| 436 | default: |
| 437 | /* 0 should be handled earlier. */ |
| 438 | printk(BIOS_ERR, "dp: Invalid lane count %d\n", |
| 439 | lane_count); |
| 440 | return; |
| 441 | } |
| 442 | tegra_sor_writel(sor, NV_SOR_DP_LINKCTL(sor->portnum), reg_val); |
| 443 | } |
| 444 | |
| 445 | static void tegra_sor_enable_edp_clock(struct tegra_dc_sor_data *sor) |
| 446 | { |
| 447 | sor_clock_start(); |
| 448 | } |
| 449 | |
| 450 | /* The SOR power sequencer does not work for t124 so SW has to |
| 451 | go through the power sequence manually */ |
| 452 | /* Power up steps from spec: */ |
| 453 | /* STEP PDPORT PDPLL PDBG PLLVCOD PLLCAPD E_DPD PDCAL */ |
| 454 | /* 1 1 1 1 1 1 1 1 */ |
| 455 | /* 2 1 1 1 1 1 0 1 */ |
| 456 | /* 3 1 1 0 1 1 0 1 */ |
| 457 | /* 4 1 0 0 0 0 0 1 */ |
| 458 | /* 5 0 0 0 0 0 0 1 */ |
| 459 | static void tegra_dc_sor_power_up(struct tegra_dc_sor_data *sor, |
| 460 | int is_lvds) |
| 461 | { |
| 462 | if (sor->power_is_up) |
| 463 | return; |
| 464 | |
| 465 | /* Set link bw */ |
| 466 | tegra_dc_sor_set_link_bandwidth(sor, |
| 467 | is_lvds ? NV_SOR_CLK_CNTRL_DP_LINK_SPEED_LVDS : |
| 468 | NV_SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62); |
| 469 | |
| 470 | /* step 1 */ |
| 471 | tegra_sor_write_field(sor, NV_SOR_PLL2, |
| 472 | NV_SOR_PLL2_AUX7_PORT_POWERDOWN_MASK | /* PDPORT */ |
| 473 | NV_SOR_PLL2_AUX6_BANDGAP_POWERDOWN_MASK | /* PDBG */ |
| 474 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_MASK, /* PLLCAPD */ |
| 475 | NV_SOR_PLL2_AUX7_PORT_POWERDOWN_ENABLE | |
| 476 | NV_SOR_PLL2_AUX6_BANDGAP_POWERDOWN_ENABLE | |
| 477 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_ENABLE); |
| 478 | tegra_sor_write_field(sor, NV_SOR_PLL0, |
| 479 | NV_SOR_PLL0_PWR_MASK | /* PDPLL */ |
| 480 | NV_SOR_PLL0_VCOPD_MASK, /* PLLVCOPD */ |
| 481 | NV_SOR_PLL0_PWR_OFF | |
| 482 | NV_SOR_PLL0_VCOPD_ASSERT); |
| 483 | tegra_sor_write_field(sor, NV_SOR_DP_PADCTL(sor->portnum), |
| 484 | NV_SOR_DP_PADCTL_PAD_CAL_PD_POWERDOWN, /* PDCAL */ |
| 485 | NV_SOR_DP_PADCTL_PAD_CAL_PD_POWERDOWN); |
| 486 | |
| 487 | /* step 2 */ |
| 488 | tegra_dc_sor_io_set_dpd(sor, 1); |
| 489 | udelay(15); |
| 490 | |
| 491 | /* step 3 */ |
| 492 | tegra_sor_write_field(sor, NV_SOR_PLL2, |
| 493 | NV_SOR_PLL2_AUX6_BANDGAP_POWERDOWN_MASK, |
| 494 | NV_SOR_PLL2_AUX6_BANDGAP_POWERDOWN_DISABLE); |
| 495 | udelay(25); |
| 496 | |
| 497 | /* step 4 */ |
| 498 | tegra_sor_write_field(sor, NV_SOR_PLL0, |
| 499 | NV_SOR_PLL0_PWR_MASK | /* PDPLL */ |
| 500 | NV_SOR_PLL0_VCOPD_MASK, /* PLLVCOPD */ |
| 501 | NV_SOR_PLL0_PWR_ON | NV_SOR_PLL0_VCOPD_RESCIND); |
| 502 | tegra_sor_write_field(sor, NV_SOR_PLL2, |
| 503 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_MASK, /* PLLCAPD */ |
| 504 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_DISABLE); |
| 505 | udelay(225); |
| 506 | |
| 507 | /* step 5 */ |
| 508 | tegra_sor_write_field(sor, NV_SOR_PLL2, |
| 509 | NV_SOR_PLL2_AUX7_PORT_POWERDOWN_MASK, /* PDPORT */ |
| 510 | NV_SOR_PLL2_AUX7_PORT_POWERDOWN_DISABLE); |
| 511 | |
| 512 | sor->power_is_up = 1; |
| 513 | } |
| 514 | |
Jimmy Zhang | 47e3cf8 | 2014-04-14 12:31:06 -0700 | [diff] [blame] | 515 | #if DEBUG_SOR |
| 516 | static void dump_sor_reg(struct tegra_dc_sor_data *sor) |
| 517 | { |
| 518 | #define DUMP_REG(a) printk(BIOS_INFO, "%-32s %03x %08x\n", \ |
| 519 | #a, a, tegra_sor_readl(sor, a)); |
| 520 | |
| 521 | DUMP_REG(NV_SOR_SUPER_STATE0); |
| 522 | DUMP_REG(NV_SOR_SUPER_STATE1); |
| 523 | DUMP_REG(NV_SOR_STATE0); |
| 524 | DUMP_REG(NV_SOR_STATE1); |
| 525 | DUMP_REG(NV_HEAD_STATE0(0)); |
| 526 | DUMP_REG(NV_HEAD_STATE0(1)); |
| 527 | DUMP_REG(NV_HEAD_STATE1(0)); |
| 528 | DUMP_REG(NV_HEAD_STATE1(1)); |
| 529 | DUMP_REG(NV_HEAD_STATE2(0)); |
| 530 | DUMP_REG(NV_HEAD_STATE2(1)); |
| 531 | DUMP_REG(NV_HEAD_STATE3(0)); |
| 532 | DUMP_REG(NV_HEAD_STATE3(1)); |
| 533 | DUMP_REG(NV_HEAD_STATE4(0)); |
| 534 | DUMP_REG(NV_HEAD_STATE4(1)); |
| 535 | DUMP_REG(NV_HEAD_STATE5(0)); |
| 536 | DUMP_REG(NV_HEAD_STATE5(1)); |
| 537 | DUMP_REG(NV_SOR_CRC_CNTRL); |
| 538 | DUMP_REG(NV_SOR_CLK_CNTRL); |
| 539 | DUMP_REG(NV_SOR_CAP); |
| 540 | DUMP_REG(NV_SOR_PWR); |
| 541 | DUMP_REG(NV_SOR_TEST); |
| 542 | DUMP_REG(NV_SOR_PLL0); |
| 543 | DUMP_REG(NV_SOR_PLL1); |
| 544 | DUMP_REG(NV_SOR_PLL2); |
| 545 | DUMP_REG(NV_SOR_PLL3); |
| 546 | DUMP_REG(NV_SOR_CSTM); |
| 547 | DUMP_REG(NV_SOR_LVDS); |
| 548 | DUMP_REG(NV_SOR_CRCA); |
| 549 | DUMP_REG(NV_SOR_CRCB); |
| 550 | DUMP_REG(NV_SOR_SEQ_CTL); |
| 551 | DUMP_REG(NV_SOR_LANE_SEQ_CTL); |
| 552 | DUMP_REG(NV_SOR_SEQ_INST(0)); |
| 553 | DUMP_REG(NV_SOR_SEQ_INST(1)); |
| 554 | DUMP_REG(NV_SOR_SEQ_INST(2)); |
| 555 | DUMP_REG(NV_SOR_SEQ_INST(3)); |
| 556 | DUMP_REG(NV_SOR_SEQ_INST(4)); |
| 557 | DUMP_REG(NV_SOR_SEQ_INST(5)); |
| 558 | DUMP_REG(NV_SOR_SEQ_INST(6)); |
| 559 | DUMP_REG(NV_SOR_SEQ_INST(7)); |
| 560 | DUMP_REG(NV_SOR_SEQ_INST(8)); |
| 561 | DUMP_REG(NV_SOR_PWM_DIV); |
| 562 | DUMP_REG(NV_SOR_PWM_CTL); |
| 563 | DUMP_REG(NV_SOR_MSCHECK); |
| 564 | DUMP_REG(NV_SOR_XBAR_CTRL); |
| 565 | DUMP_REG(NV_SOR_DP_LINKCTL(0)); |
| 566 | DUMP_REG(NV_SOR_DP_LINKCTL(1)); |
| 567 | DUMP_REG(NV_SOR_DC(0)); |
| 568 | DUMP_REG(NV_SOR_DC(1)); |
| 569 | DUMP_REG(NV_SOR_LANE_DRIVE_CURRENT(0)); |
| 570 | DUMP_REG(NV_SOR_PR(0)); |
| 571 | DUMP_REG(NV_SOR_LANE4_PREEMPHASIS(0)); |
| 572 | DUMP_REG(NV_SOR_POSTCURSOR(0)); |
| 573 | DUMP_REG(NV_SOR_DP_CONFIG(0)); |
| 574 | DUMP_REG(NV_SOR_DP_CONFIG(1)); |
| 575 | DUMP_REG(NV_SOR_DP_MN(0)); |
| 576 | DUMP_REG(NV_SOR_DP_MN(1)); |
| 577 | DUMP_REG(NV_SOR_DP_PADCTL(0)); |
| 578 | DUMP_REG(NV_SOR_DP_PADCTL(1)); |
| 579 | DUMP_REG(NV_SOR_DP_DEBUG(0)); |
| 580 | DUMP_REG(NV_SOR_DP_DEBUG(1)); |
| 581 | DUMP_REG(NV_SOR_DP_SPARE(0)); |
| 582 | DUMP_REG(NV_SOR_DP_SPARE(1)); |
| 583 | DUMP_REG(NV_SOR_DP_TPG); |
| 584 | |
| 585 | return; |
| 586 | } |
| 587 | #endif |
| 588 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 589 | static void tegra_dc_sor_config_panel(struct tegra_dc_sor_data *sor, |
| 590 | int is_lvds) |
| 591 | { |
Elyes HAOUAS | 05498a2 | 2018-05-28 16:26:43 +0200 | [diff] [blame] | 592 | const struct tegra_dc *dc = sor->dc; |
| 593 | const struct tegra_dc_dp_data *dp = dc->out; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 594 | const struct tegra_dc_dp_link_config *link_cfg = &dp->link_cfg; |
| 595 | const struct soc_nvidia_tegra124_config *config = dc->config; |
| 596 | |
| 597 | const int head_num = 0; // based on kernel dc driver |
| 598 | u32 reg_val = NV_SOR_STATE1_ASY_OWNER_HEAD0 << head_num; |
| 599 | u32 vtotal, htotal; |
| 600 | u32 vsync_end, hsync_end; |
| 601 | u32 vblank_end, hblank_end; |
| 602 | u32 vblank_start, hblank_start; |
| 603 | |
| 604 | reg_val |= is_lvds ? NV_SOR_STATE1_ASY_PROTOCOL_LVDS_CUSTOM : |
| 605 | NV_SOR_STATE1_ASY_PROTOCOL_DP_A; |
| 606 | reg_val |= NV_SOR_STATE1_ASY_SUBOWNER_NONE | |
| 607 | NV_SOR_STATE1_ASY_CRCMODE_COMPLETE_RASTER; |
| 608 | |
| 609 | reg_val |= NV_SOR_STATE1_ASY_HSYNCPOL_NEGATIVE_TRUE; |
| 610 | reg_val |= NV_SOR_STATE1_ASY_VSYNCPOL_NEGATIVE_TRUE; |
| 611 | reg_val |= (link_cfg->bits_per_pixel > 18) ? |
| 612 | NV_SOR_STATE1_ASY_PIXELDEPTH_BPP_24_444 : |
| 613 | NV_SOR_STATE1_ASY_PIXELDEPTH_BPP_18_444; |
| 614 | |
| 615 | tegra_sor_writel(sor, NV_SOR_STATE1, reg_val); |
| 616 | |
| 617 | /* Skipping programming NV_HEAD_STATE0, assuming: |
| 618 | interlacing: PROGRESSIVE, dynamic range: VESA, colorspace: RGB */ |
| 619 | |
| 620 | vtotal = config->vsync_width + config->vback_porch + |
| 621 | config->yres + config->vfront_porch; |
| 622 | htotal = config->hsync_width + config->hback_porch + |
| 623 | config->xres + config->hfront_porch; |
| 624 | |
| 625 | tegra_sor_writel(sor, NV_HEAD_STATE1(head_num), |
| 626 | vtotal << NV_HEAD_STATE1_VTOTAL_SHIFT | |
| 627 | htotal << NV_HEAD_STATE1_HTOTAL_SHIFT); |
| 628 | |
| 629 | vsync_end = config->vsync_width - 1; |
| 630 | hsync_end = config->hsync_width - 1; |
| 631 | tegra_sor_writel(sor, NV_HEAD_STATE2(head_num), |
| 632 | vsync_end << NV_HEAD_STATE2_VSYNC_END_SHIFT | |
| 633 | hsync_end << NV_HEAD_STATE2_HSYNC_END_SHIFT); |
| 634 | |
| 635 | vblank_end = vsync_end + config->vback_porch; |
| 636 | hblank_end = hsync_end + config->hback_porch; |
| 637 | tegra_sor_writel(sor, NV_HEAD_STATE3(head_num), |
| 638 | vblank_end << NV_HEAD_STATE3_VBLANK_END_SHIFT | |
| 639 | hblank_end << NV_HEAD_STATE3_HBLANK_END_SHIFT); |
| 640 | |
| 641 | vblank_start = vblank_end + config->yres; |
| 642 | hblank_start = hblank_end + config->xres; |
| 643 | tegra_sor_writel(sor, NV_HEAD_STATE4(head_num), |
| 644 | vblank_start << NV_HEAD_STATE4_VBLANK_START_SHIFT | |
| 645 | hblank_start << NV_HEAD_STATE4_HBLANK_START_SHIFT); |
| 646 | |
| 647 | /* TODO: adding interlace mode support */ |
| 648 | tegra_sor_writel(sor, NV_HEAD_STATE5(head_num), 0x1); |
| 649 | |
| 650 | tegra_sor_write_field(sor, NV_SOR_CSTM, |
| 651 | NV_SOR_CSTM_ROTCLK_DEFAULT_MASK | |
| 652 | NV_SOR_CSTM_LVDS_EN_ENABLE, |
| 653 | 2 << NV_SOR_CSTM_ROTCLK_SHIFT | |
Patrick Georgi | 68e4cbd | 2014-11-17 09:27:08 +0100 | [diff] [blame] | 654 | (is_lvds ? NV_SOR_CSTM_LVDS_EN_ENABLE : |
| 655 | NV_SOR_CSTM_LVDS_EN_DISABLE)); |
Jimmy Zhang | 84b8be6 | 2014-04-14 12:15:38 -0700 | [diff] [blame] | 656 | tegra_dc_sor_config_pwm(sor, 1024, 1024); |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static void tegra_dc_sor_enable_dc(struct tegra_dc_sor_data *sor) |
| 660 | { |
| 661 | struct tegra_dc *dc = sor->dc; |
| 662 | struct display_controller *disp_ctrl = (void *)dc->base; |
| 663 | |
| 664 | u32 reg_val = READL(&disp_ctrl->cmd.state_access); |
| 665 | |
| 666 | WRITEL(reg_val | WRITE_MUX_ACTIVE, &disp_ctrl->cmd.state_access); |
| 667 | WRITEL(VSYNC_H_POSITION(1), &disp_ctrl->disp.disp_timing_opt); |
| 668 | |
Hung-Te Lin | 066b164 | 2014-04-18 00:32:41 +0800 | [diff] [blame] | 669 | /* Enable DC now - otherwise pure text console may not show. */ |
| 670 | WRITEL(DISP_CTRL_MODE_C_DISPLAY, &disp_ctrl->cmd.disp_cmd); |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 671 | WRITEL(reg_val, &disp_ctrl->cmd.state_access); |
| 672 | } |
| 673 | |
| 674 | void tegra_dc_sor_enable_dp(struct tegra_dc_sor_data *sor) |
| 675 | { |
| 676 | const struct tegra_dc_dp_link_config *link_cfg = sor->link_cfg; |
| 677 | |
| 678 | tegra_sor_write_field(sor, NV_SOR_CLK_CNTRL, |
| 679 | NV_SOR_CLK_CNTRL_DP_CLK_SEL_MASK, |
| 680 | NV_SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK); |
| 681 | |
| 682 | tegra_sor_write_field(sor, NV_SOR_PLL2, |
| 683 | NV_SOR_PLL2_AUX6_BANDGAP_POWERDOWN_MASK, |
| 684 | NV_SOR_PLL2_AUX6_BANDGAP_POWERDOWN_DISABLE); |
| 685 | udelay(25); |
| 686 | |
| 687 | tegra_sor_write_field(sor, NV_SOR_PLL3, |
| 688 | NV_SOR_PLL3_PLLVDD_MODE_MASK, |
| 689 | NV_SOR_PLL3_PLLVDD_MODE_V3_3); |
| 690 | tegra_sor_writel(sor, NV_SOR_PLL0, |
| 691 | 0xf << NV_SOR_PLL0_ICHPMP_SHFIT | |
| 692 | 0x3 << NV_SOR_PLL0_VCOCAP_SHIFT | |
| 693 | NV_SOR_PLL0_PLLREG_LEVEL_V45 | |
| 694 | NV_SOR_PLL0_RESISTORSEL_EXT | |
| 695 | NV_SOR_PLL0_PWR_ON | NV_SOR_PLL0_VCOPD_RESCIND); |
| 696 | tegra_sor_write_field(sor, NV_SOR_PLL2, |
| 697 | NV_SOR_PLL2_AUX1_SEQ_MASK | NV_SOR_PLL2_AUX9_LVDSEN_OVERRIDE | |
| 698 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_MASK, |
| 699 | NV_SOR_PLL2_AUX1_SEQ_PLLCAPPD_OVERRIDE | |
| 700 | NV_SOR_PLL2_AUX9_LVDSEN_OVERRIDE | |
| 701 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_DISABLE); |
| 702 | tegra_sor_writel(sor, NV_SOR_PLL1, |
| 703 | NV_SOR_PLL1_TERM_COMPOUT_HIGH | NV_SOR_PLL1_TMDS_TERM_ENABLE); |
| 704 | |
| 705 | if (tegra_dc_sor_poll_register(sor, NV_SOR_PLL2, |
| 706 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_MASK, |
| 707 | NV_SOR_PLL2_AUX8_SEQ_PLLCAPPD_ENFORCE_DISABLE, |
| 708 | 100, TEGRA_SOR_TIMEOUT_MS * 1000)) { |
| 709 | printk(BIOS_ERR, "DP failed to lock PLL\n"); |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | tegra_sor_write_field(sor, NV_SOR_PLL2, |
| 714 | NV_SOR_PLL2_AUX2_MASK | NV_SOR_PLL2_AUX7_PORT_POWERDOWN_MASK, |
| 715 | NV_SOR_PLL2_AUX2_OVERRIDE_POWERDOWN | |
| 716 | NV_SOR_PLL2_AUX7_PORT_POWERDOWN_DISABLE); |
| 717 | |
| 718 | tegra_dc_sor_power_up(sor, 0); |
| 719 | |
| 720 | /* re-enable SOR clock */ |
| 721 | tegra_sor_enable_edp_clock(sor); // select pll_dp as clock source |
| 722 | |
| 723 | /* Power up lanes */ |
| 724 | tegra_dc_sor_power_dplanes(sor, link_cfg->lane_count, 1); |
| 725 | |
| 726 | tegra_dc_sor_set_dp_mode(sor, link_cfg); |
| 727 | |
| 728 | } |
| 729 | |
| 730 | void tegra_dc_sor_attach(struct tegra_dc_sor_data *sor) |
| 731 | { |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 732 | u32 reg_val; |
| 733 | struct display_controller *disp_ctrl = (void *)sor->dc->base; |
| 734 | |
| 735 | tegra_dc_sor_enable_dc(sor); |
| 736 | tegra_dc_sor_config_panel(sor, 0); |
| 737 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 738 | WRITEL(0x9f00, &disp_ctrl->cmd.state_ctrl); |
| 739 | WRITEL(0x9f, &disp_ctrl->cmd.state_ctrl); |
Jimmy Zhang | f682ad0 | 2014-04-11 15:39:02 -0700 | [diff] [blame] | 740 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 741 | WRITEL(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | |
| 742 | PW3_ENABLE | PW4_ENABLE | PM0_ENABLE | PM1_ENABLE, |
| 743 | &disp_ctrl->cmd.disp_pow_ctrl); |
| 744 | |
Jimmy Zhang | f682ad0 | 2014-04-11 15:39:02 -0700 | [diff] [blame] | 745 | reg_val = tegra_sor_readl(sor, NV_SOR_TEST); |
| 746 | if (reg_val & NV_SOR_TEST_ATTACHED_TRUE) |
| 747 | return; |
| 748 | |
| 749 | tegra_sor_writel(sor, NV_SOR_SUPER_STATE1, |
| 750 | NV_SOR_SUPER_STATE1_ATTACHED_NO); |
| 751 | |
| 752 | /* |
| 753 | * Enable display2sor clock at least 2 cycles before DC start, |
| 754 | * to clear sor internal valid signal. |
| 755 | */ |
| 756 | WRITEL(SOR_ENABLE, &disp_ctrl->disp.disp_win_opt); |
| 757 | WRITEL(GENERAL_ACT_REQ, &disp_ctrl->cmd.state_ctrl); |
| 758 | WRITEL(0, &disp_ctrl->disp.disp_win_opt); |
| 759 | WRITEL(GENERAL_ACT_REQ, &disp_ctrl->cmd.state_ctrl); |
| 760 | |
| 761 | /* Attach head */ |
| 762 | tegra_dc_sor_update(sor); |
| 763 | tegra_sor_writel(sor, NV_SOR_SUPER_STATE1, |
| 764 | NV_SOR_SUPER_STATE1_ATTACHED_YES); |
| 765 | tegra_sor_writel(sor, NV_SOR_SUPER_STATE1, |
| 766 | NV_SOR_SUPER_STATE1_ATTACHED_YES | |
| 767 | NV_SOR_SUPER_STATE1_ASY_HEAD_OP_AWAKE | |
| 768 | NV_SOR_SUPER_STATE1_ASY_ORMODE_NORMAL); |
| 769 | tegra_dc_sor_super_update(sor); |
| 770 | |
| 771 | /* Enable dc */ |
Vince Hsu | b4bd53a | 2014-05-16 18:07:53 +0800 | [diff] [blame] | 772 | reg_val = READL(&disp_ctrl->cmd.state_access); |
| 773 | WRITEL(reg_val | WRITE_MUX_ACTIVE, &disp_ctrl->cmd.state_access); |
Jimmy Zhang | f682ad0 | 2014-04-11 15:39:02 -0700 | [diff] [blame] | 774 | WRITEL(DISP_CTRL_MODE_C_DISPLAY, &disp_ctrl->cmd.disp_cmd); |
| 775 | WRITEL(SOR_ENABLE, &disp_ctrl->disp.disp_win_opt); |
Vince Hsu | b4bd53a | 2014-05-16 18:07:53 +0800 | [diff] [blame] | 776 | WRITEL(reg_val, &disp_ctrl->cmd.state_access); |
Jimmy Zhang | f682ad0 | 2014-04-11 15:39:02 -0700 | [diff] [blame] | 777 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 778 | if (tegra_dc_sor_poll_register(sor, NV_SOR_TEST, |
| 779 | NV_SOR_TEST_ACT_HEAD_OPMODE_DEFAULT_MASK, |
| 780 | NV_SOR_TEST_ACT_HEAD_OPMODE_AWAKE, |
Jimmy Zhang | f682ad0 | 2014-04-11 15:39:02 -0700 | [diff] [blame] | 781 | 100, TEGRA_SOR_ATTACH_TIMEOUT_MS * 1000)) |
| 782 | printk(BIOS_ERR, "dc timeout waiting for OPMOD = AWAKE\n"); |
| 783 | else |
| 784 | printk(BIOS_INFO, "%s: sor is attached\n", __func__); |
Jimmy Zhang | 47e3cf8 | 2014-04-14 12:31:06 -0700 | [diff] [blame] | 785 | |
| 786 | #if DEBUG_SOR |
| 787 | dump_sor_reg(sor); |
| 788 | #endif |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | void tegra_dc_sor_set_lane_parm(struct tegra_dc_sor_data *sor, |
| 792 | const struct tegra_dc_dp_link_config *link_cfg) |
| 793 | { |
| 794 | tegra_sor_writel(sor, NV_SOR_LANE_DRIVE_CURRENT(sor->portnum), |
| 795 | link_cfg->drive_current); |
| 796 | tegra_sor_writel(sor, NV_SOR_PR(sor->portnum), |
| 797 | link_cfg->preemphasis); |
| 798 | tegra_sor_writel(sor, NV_SOR_POSTCURSOR(sor->portnum), |
| 799 | link_cfg->postcursor); |
| 800 | tegra_sor_writel(sor, NV_SOR_LVDS, 0); |
| 801 | |
| 802 | tegra_dc_sor_set_link_bandwidth(sor, link_cfg->link_bw); |
| 803 | tegra_dc_sor_set_lane_count(sor, link_cfg->lane_count); |
| 804 | |
| 805 | tegra_sor_write_field(sor, NV_SOR_DP_PADCTL(sor->portnum), |
| 806 | NV_SOR_DP_PADCTL_TX_PU_ENABLE | |
| 807 | NV_SOR_DP_PADCTL_TX_PU_VALUE_DEFAULT_MASK, |
| 808 | NV_SOR_DP_PADCTL_TX_PU_ENABLE | |
| 809 | 2 << NV_SOR_DP_PADCTL_TX_PU_VALUE_SHIFT); |
| 810 | |
| 811 | /* Precharge */ |
| 812 | tegra_sor_write_field(sor, NV_SOR_DP_PADCTL(sor->portnum), |
| 813 | 0xf0, 0xf0); |
| 814 | udelay(20); |
| 815 | |
| 816 | tegra_sor_write_field(sor, NV_SOR_DP_PADCTL(sor->portnum), |
| 817 | 0xf0, 0x0); |
| 818 | } |
| 819 | |
Neil Chen | ac4fef8 | 2014-09-24 10:41:08 +0800 | [diff] [blame] | 820 | void tegra_dc_sor_set_voltage_swing(struct tegra_dc_sor_data *sor) |
| 821 | { |
| 822 | u32 drive_current = 0; |
| 823 | u32 pre_emphasis = 0; |
| 824 | |
| 825 | /* Set to a known-good pre-calibrated setting */ |
| 826 | switch (sor->link_cfg->link_bw) { |
| 827 | case SOR_LINK_SPEED_G1_62: |
| 828 | case SOR_LINK_SPEED_G2_7: |
| 829 | drive_current = 0x13131313; |
| 830 | pre_emphasis = 0; |
| 831 | break; |
| 832 | case SOR_LINK_SPEED_G5_4: |
| 833 | printk(BIOS_WARNING, "T124 does not support 5.4G link clock.\n"); |
Jacob Garber | d9642c3 | 2019-07-12 11:28:00 -0600 | [diff] [blame] | 834 | return; |
Neil Chen | ac4fef8 | 2014-09-24 10:41:08 +0800 | [diff] [blame] | 835 | default: |
| 836 | printk(BIOS_WARNING, "Invalid sor link bandwidth: %d\n", |
| 837 | sor->link_cfg->link_bw); |
| 838 | return; |
| 839 | } |
| 840 | |
| 841 | tegra_sor_writel(sor, NV_SOR_LANE_DRIVE_CURRENT(sor->portnum), |
| 842 | drive_current); |
| 843 | tegra_sor_writel(sor, NV_SOR_PR(sor->portnum), pre_emphasis); |
| 844 | } |
| 845 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 846 | void tegra_dc_sor_power_down_unused_lanes(struct tegra_dc_sor_data *sor) |
| 847 | { |
| 848 | u32 pad_ctrl = 0; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 849 | int err = 0; |
| 850 | |
| 851 | switch (sor->link_cfg->lane_count) { |
| 852 | case 4: |
| 853 | pad_ctrl = (NV_SOR_DP_PADCTL_PD_TXD_0_NO | |
| 854 | NV_SOR_DP_PADCTL_PD_TXD_1_NO | |
| 855 | NV_SOR_DP_PADCTL_PD_TXD_2_NO | |
| 856 | NV_SOR_DP_PADCTL_PD_TXD_3_NO); |
| 857 | break; |
| 858 | case 2: |
| 859 | pad_ctrl = (NV_SOR_DP_PADCTL_PD_TXD_0_NO | |
| 860 | NV_SOR_DP_PADCTL_PD_TXD_1_NO | |
| 861 | NV_SOR_DP_PADCTL_PD_TXD_2_YES | |
| 862 | NV_SOR_DP_PADCTL_PD_TXD_3_YES); |
| 863 | break; |
| 864 | case 1: |
| 865 | pad_ctrl = (NV_SOR_DP_PADCTL_PD_TXD_0_NO | |
| 866 | NV_SOR_DP_PADCTL_PD_TXD_1_YES | |
| 867 | NV_SOR_DP_PADCTL_PD_TXD_2_YES | |
| 868 | NV_SOR_DP_PADCTL_PD_TXD_3_YES); |
| 869 | break; |
| 870 | default: |
| 871 | printk(BIOS_ERR, "Invalid sor lane count: %u\n", |
| 872 | sor->link_cfg->lane_count); |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | pad_ctrl |= NV_SOR_DP_PADCTL_PAD_CAL_PD_POWERDOWN; |
| 877 | tegra_sor_writel(sor, NV_SOR_DP_PADCTL(sor->portnum), pad_ctrl); |
| 878 | |
| 879 | err = tegra_dc_sor_enable_lane_sequencer(sor, 0, 0); |
| 880 | if (err) { |
| 881 | printk(BIOS_ERR, |
| 882 | "Wait for lane power down failed: %d\n", err); |
| 883 | return; |
| 884 | } |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 885 | } |
Neil Chen | 8c440a6 | 2014-09-23 17:41:59 +0800 | [diff] [blame] | 886 | |
| 887 | void tegra_sor_precharge_lanes(struct tegra_dc_sor_data *sor) |
| 888 | { |
| 889 | const struct tegra_dc_dp_link_config *cfg = sor->link_cfg; |
| 890 | u32 val = 0; |
| 891 | |
| 892 | switch (cfg->lane_count) { |
| 893 | case 4: |
| 894 | val |= (NV_SOR_DP_PADCTL_PD_TXD_3_NO | |
| 895 | NV_SOR_DP_PADCTL_PD_TXD_2_NO); |
| 896 | /* fall through */ |
| 897 | case 2: |
| 898 | val |= NV_SOR_DP_PADCTL_PD_TXD_1_NO; |
| 899 | /* fall through */ |
| 900 | case 1: |
| 901 | val |= NV_SOR_DP_PADCTL_PD_TXD_0_NO; |
| 902 | break; |
| 903 | default: |
| 904 | printk(BIOS_ERR, |
| 905 | "dp: invalid lane number %d\n", cfg->lane_count); |
| 906 | return; |
| 907 | } |
| 908 | |
| 909 | tegra_sor_write_field(sor, NV_SOR_DP_PADCTL(sor->portnum), |
| 910 | (0xf << NV_SOR_DP_PADCTL_COMODE_TXD_0_DP_TXD_2_SHIFT), |
| 911 | (val << NV_SOR_DP_PADCTL_COMODE_TXD_0_DP_TXD_2_SHIFT)); |
| 912 | udelay(100); |
| 913 | tegra_sor_write_field(sor, NV_SOR_DP_PADCTL(sor->portnum), |
| 914 | (0xf << NV_SOR_DP_PADCTL_COMODE_TXD_0_DP_TXD_2_SHIFT), 0); |
| 915 | } |