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