| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 NVIDIA Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/clk.h> |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 10 | #include <linux/clk-provider.h> |
| Thierry Reding | a82752e | 2014-01-31 10:02:15 +0100 | [diff] [blame] | 11 | #include <linux/debugfs.h> |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 12 | #include <linux/gpio.h> |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 13 | #include <linux/io.h> |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 14 | #include <linux/of_device.h> |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 17 | #include <linux/regulator/consumer.h> |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 18 | #include <linux/reset.h> |
| Thierry Reding | 306a7f9 | 2014-07-17 13:17:24 +0200 | [diff] [blame] | 19 | |
| Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 20 | #include <soc/tegra/pmc.h> |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 21 | |
| Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame] | 22 | #include <drm/drm_atomic_helper.h> |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 23 | #include <drm/drm_dp_helper.h> |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 24 | #include <drm/drm_panel.h> |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 25 | |
| 26 | #include "dc.h" |
| 27 | #include "drm.h" |
| 28 | #include "sor.h" |
| Thierry Reding | 932f652 | 2017-08-15 15:41:14 +0200 | [diff] [blame] | 29 | #include "trace.h" |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 30 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 31 | #define SOR_REKEY 0x38 |
| 32 | |
| 33 | struct tegra_sor_hdmi_settings { |
| 34 | unsigned long frequency; |
| 35 | |
| 36 | u8 vcocap; |
| 37 | u8 ichpmp; |
| 38 | u8 loadadj; |
| 39 | u8 termadj; |
| 40 | u8 tx_pu; |
| 41 | u8 bg_vref; |
| 42 | |
| 43 | u8 drive_current[4]; |
| 44 | u8 preemphasis[4]; |
| 45 | }; |
| 46 | |
| 47 | #if 1 |
| 48 | static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = { |
| 49 | { |
| 50 | .frequency = 54000000, |
| 51 | .vcocap = 0x0, |
| 52 | .ichpmp = 0x1, |
| 53 | .loadadj = 0x3, |
| 54 | .termadj = 0x9, |
| 55 | .tx_pu = 0x10, |
| 56 | .bg_vref = 0x8, |
| 57 | .drive_current = { 0x33, 0x3a, 0x3a, 0x3a }, |
| 58 | .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, |
| 59 | }, { |
| 60 | .frequency = 75000000, |
| 61 | .vcocap = 0x3, |
| 62 | .ichpmp = 0x1, |
| 63 | .loadadj = 0x3, |
| 64 | .termadj = 0x9, |
| 65 | .tx_pu = 0x40, |
| 66 | .bg_vref = 0x8, |
| 67 | .drive_current = { 0x33, 0x3a, 0x3a, 0x3a }, |
| 68 | .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, |
| 69 | }, { |
| 70 | .frequency = 150000000, |
| 71 | .vcocap = 0x3, |
| 72 | .ichpmp = 0x1, |
| 73 | .loadadj = 0x3, |
| 74 | .termadj = 0x9, |
| 75 | .tx_pu = 0x66, |
| 76 | .bg_vref = 0x8, |
| 77 | .drive_current = { 0x33, 0x3a, 0x3a, 0x3a }, |
| 78 | .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, |
| 79 | }, { |
| 80 | .frequency = 300000000, |
| 81 | .vcocap = 0x3, |
| 82 | .ichpmp = 0x1, |
| 83 | .loadadj = 0x3, |
| 84 | .termadj = 0x9, |
| 85 | .tx_pu = 0x66, |
| 86 | .bg_vref = 0xa, |
| 87 | .drive_current = { 0x33, 0x3f, 0x3f, 0x3f }, |
| 88 | .preemphasis = { 0x00, 0x17, 0x17, 0x17 }, |
| 89 | }, { |
| 90 | .frequency = 600000000, |
| 91 | .vcocap = 0x3, |
| 92 | .ichpmp = 0x1, |
| 93 | .loadadj = 0x3, |
| 94 | .termadj = 0x9, |
| 95 | .tx_pu = 0x66, |
| 96 | .bg_vref = 0x8, |
| 97 | .drive_current = { 0x33, 0x3f, 0x3f, 0x3f }, |
| 98 | .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, |
| 99 | }, |
| 100 | }; |
| 101 | #else |
| 102 | static const struct tegra_sor_hdmi_settings tegra210_sor_hdmi_defaults[] = { |
| 103 | { |
| 104 | .frequency = 75000000, |
| 105 | .vcocap = 0x3, |
| 106 | .ichpmp = 0x1, |
| 107 | .loadadj = 0x3, |
| 108 | .termadj = 0x9, |
| 109 | .tx_pu = 0x40, |
| 110 | .bg_vref = 0x8, |
| 111 | .drive_current = { 0x29, 0x29, 0x29, 0x29 }, |
| 112 | .preemphasis = { 0x00, 0x00, 0x00, 0x00 }, |
| 113 | }, { |
| 114 | .frequency = 150000000, |
| 115 | .vcocap = 0x3, |
| 116 | .ichpmp = 0x1, |
| 117 | .loadadj = 0x3, |
| 118 | .termadj = 0x9, |
| 119 | .tx_pu = 0x66, |
| 120 | .bg_vref = 0x8, |
| 121 | .drive_current = { 0x30, 0x37, 0x37, 0x37 }, |
| 122 | .preemphasis = { 0x01, 0x02, 0x02, 0x02 }, |
| 123 | }, { |
| 124 | .frequency = 300000000, |
| 125 | .vcocap = 0x3, |
| 126 | .ichpmp = 0x6, |
| 127 | .loadadj = 0x3, |
| 128 | .termadj = 0x9, |
| 129 | .tx_pu = 0x66, |
| 130 | .bg_vref = 0xf, |
| 131 | .drive_current = { 0x30, 0x37, 0x37, 0x37 }, |
| 132 | .preemphasis = { 0x10, 0x3e, 0x3e, 0x3e }, |
| 133 | }, { |
| 134 | .frequency = 600000000, |
| 135 | .vcocap = 0x3, |
| 136 | .ichpmp = 0xa, |
| 137 | .loadadj = 0x3, |
| 138 | .termadj = 0xb, |
| 139 | .tx_pu = 0x66, |
| 140 | .bg_vref = 0xe, |
| 141 | .drive_current = { 0x35, 0x3e, 0x3e, 0x3e }, |
| 142 | .preemphasis = { 0x02, 0x3f, 0x3f, 0x3f }, |
| 143 | }, |
| 144 | }; |
| 145 | #endif |
| 146 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 147 | struct tegra_sor_regs { |
| 148 | unsigned int head_state0; |
| 149 | unsigned int head_state1; |
| 150 | unsigned int head_state2; |
| 151 | unsigned int head_state3; |
| 152 | unsigned int head_state4; |
| 153 | unsigned int head_state5; |
| 154 | unsigned int pll0; |
| 155 | unsigned int pll1; |
| 156 | unsigned int pll2; |
| 157 | unsigned int pll3; |
| 158 | unsigned int dp_padctl0; |
| 159 | unsigned int dp_padctl2; |
| 160 | }; |
| 161 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 162 | struct tegra_sor_soc { |
| 163 | bool supports_edp; |
| 164 | bool supports_lvds; |
| 165 | bool supports_hdmi; |
| 166 | bool supports_dp; |
| 167 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 168 | const struct tegra_sor_regs *regs; |
| 169 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 170 | const struct tegra_sor_hdmi_settings *settings; |
| 171 | unsigned int num_settings; |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 172 | |
| 173 | const u8 *xbar_cfg; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | struct tegra_sor; |
| 177 | |
| 178 | struct tegra_sor_ops { |
| 179 | const char *name; |
| 180 | int (*probe)(struct tegra_sor *sor); |
| 181 | int (*remove)(struct tegra_sor *sor); |
| 182 | }; |
| 183 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 184 | struct tegra_sor { |
| 185 | struct host1x_client client; |
| 186 | struct tegra_output output; |
| 187 | struct device *dev; |
| 188 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 189 | const struct tegra_sor_soc *soc; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 190 | void __iomem *regs; |
| 191 | |
| 192 | struct reset_control *rst; |
| 193 | struct clk *clk_parent; |
| 194 | struct clk *clk_safe; |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 195 | struct clk *clk_out; |
| 196 | struct clk *clk_pad; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 197 | struct clk *clk_dp; |
| 198 | struct clk *clk; |
| 199 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 200 | struct drm_dp_aux *aux; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 201 | |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 202 | struct drm_info_list *debugfs_files; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 203 | |
| 204 | const struct tegra_sor_ops *ops; |
| 205 | |
| 206 | /* for HDMI 2.0 */ |
| 207 | struct tegra_sor_hdmi_settings *settings; |
| 208 | unsigned int num_settings; |
| 209 | |
| 210 | struct regulator *avdd_io_supply; |
| 211 | struct regulator *vdd_pll_supply; |
| 212 | struct regulator *hdmi_supply; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 213 | }; |
| 214 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 215 | struct tegra_sor_state { |
| 216 | struct drm_connector_state base; |
| 217 | |
| 218 | unsigned int bpc; |
| 219 | }; |
| 220 | |
| 221 | static inline struct tegra_sor_state * |
| 222 | to_sor_state(struct drm_connector_state *state) |
| 223 | { |
| 224 | return container_of(state, struct tegra_sor_state, base); |
| 225 | } |
| 226 | |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 227 | struct tegra_sor_config { |
| 228 | u32 bits_per_pixel; |
| 229 | |
| 230 | u32 active_polarity; |
| 231 | u32 active_count; |
| 232 | u32 tu_size; |
| 233 | u32 active_frac; |
| 234 | u32 watermark; |
| Thierry Reding | 7890b57 | 2014-06-05 16:12:46 +0200 | [diff] [blame] | 235 | |
| 236 | u32 hblank_symbols; |
| 237 | u32 vblank_symbols; |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 238 | }; |
| 239 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 240 | static inline struct tegra_sor * |
| 241 | host1x_client_to_sor(struct host1x_client *client) |
| 242 | { |
| 243 | return container_of(client, struct tegra_sor, client); |
| 244 | } |
| 245 | |
| 246 | static inline struct tegra_sor *to_sor(struct tegra_output *output) |
| 247 | { |
| 248 | return container_of(output, struct tegra_sor, output); |
| 249 | } |
| 250 | |
| Thierry Reding | 5c5f130 | 2017-08-15 15:41:09 +0200 | [diff] [blame] | 251 | static inline u32 tegra_sor_readl(struct tegra_sor *sor, unsigned int offset) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 252 | { |
| Thierry Reding | 932f652 | 2017-08-15 15:41:14 +0200 | [diff] [blame] | 253 | u32 value = readl(sor->regs + (offset << 2)); |
| 254 | |
| 255 | trace_sor_readl(sor->dev, offset, value); |
| 256 | |
| 257 | return value; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 258 | } |
| 259 | |
| Thierry Reding | 28fe207 | 2015-01-26 16:02:48 +0100 | [diff] [blame] | 260 | static inline void tegra_sor_writel(struct tegra_sor *sor, u32 value, |
| Thierry Reding | 5c5f130 | 2017-08-15 15:41:09 +0200 | [diff] [blame] | 261 | unsigned int offset) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 262 | { |
| Thierry Reding | 932f652 | 2017-08-15 15:41:14 +0200 | [diff] [blame] | 263 | trace_sor_writel(sor->dev, offset, value); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 264 | writel(value, sor->regs + (offset << 2)); |
| 265 | } |
| 266 | |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 267 | static int tegra_sor_set_parent_clock(struct tegra_sor *sor, struct clk *parent) |
| 268 | { |
| 269 | int err; |
| 270 | |
| 271 | clk_disable_unprepare(sor->clk); |
| 272 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 273 | err = clk_set_parent(sor->clk_out, parent); |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 274 | if (err < 0) |
| 275 | return err; |
| 276 | |
| 277 | err = clk_prepare_enable(sor->clk); |
| 278 | if (err < 0) |
| 279 | return err; |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 284 | struct tegra_clk_sor_pad { |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 285 | struct clk_hw hw; |
| 286 | struct tegra_sor *sor; |
| 287 | }; |
| 288 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 289 | static inline struct tegra_clk_sor_pad *to_pad(struct clk_hw *hw) |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 290 | { |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 291 | return container_of(hw, struct tegra_clk_sor_pad, hw); |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 294 | static const char * const tegra_clk_sor_pad_parents[] = { |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 295 | "pll_d2_out0", "pll_dp" |
| 296 | }; |
| 297 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 298 | static int tegra_clk_sor_pad_set_parent(struct clk_hw *hw, u8 index) |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 299 | { |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 300 | struct tegra_clk_sor_pad *pad = to_pad(hw); |
| 301 | struct tegra_sor *sor = pad->sor; |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 302 | u32 value; |
| 303 | |
| 304 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 305 | value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; |
| 306 | |
| 307 | switch (index) { |
| 308 | case 0: |
| 309 | value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK; |
| 310 | break; |
| 311 | |
| 312 | case 1: |
| 313 | value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK; |
| 314 | break; |
| 315 | } |
| 316 | |
| 317 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 322 | static u8 tegra_clk_sor_pad_get_parent(struct clk_hw *hw) |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 323 | { |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 324 | struct tegra_clk_sor_pad *pad = to_pad(hw); |
| 325 | struct tegra_sor *sor = pad->sor; |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 326 | u8 parent = U8_MAX; |
| 327 | u32 value; |
| 328 | |
| 329 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 330 | |
| 331 | switch (value & SOR_CLK_CNTRL_DP_CLK_SEL_MASK) { |
| 332 | case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK: |
| 333 | case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_PCLK: |
| 334 | parent = 0; |
| 335 | break; |
| 336 | |
| 337 | case SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK: |
| 338 | case SOR_CLK_CNTRL_DP_CLK_SEL_DIFF_DPCLK: |
| 339 | parent = 1; |
| 340 | break; |
| 341 | } |
| 342 | |
| 343 | return parent; |
| 344 | } |
| 345 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 346 | static const struct clk_ops tegra_clk_sor_pad_ops = { |
| 347 | .set_parent = tegra_clk_sor_pad_set_parent, |
| 348 | .get_parent = tegra_clk_sor_pad_get_parent, |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 349 | }; |
| 350 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 351 | static struct clk *tegra_clk_sor_pad_register(struct tegra_sor *sor, |
| 352 | const char *name) |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 353 | { |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 354 | struct tegra_clk_sor_pad *pad; |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 355 | struct clk_init_data init; |
| 356 | struct clk *clk; |
| 357 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 358 | pad = devm_kzalloc(sor->dev, sizeof(*pad), GFP_KERNEL); |
| 359 | if (!pad) |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 360 | return ERR_PTR(-ENOMEM); |
| 361 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 362 | pad->sor = sor; |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 363 | |
| 364 | init.name = name; |
| 365 | init.flags = 0; |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 366 | init.parent_names = tegra_clk_sor_pad_parents; |
| 367 | init.num_parents = ARRAY_SIZE(tegra_clk_sor_pad_parents); |
| 368 | init.ops = &tegra_clk_sor_pad_ops; |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 369 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 370 | pad->hw.init = &init; |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 371 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 372 | clk = devm_clk_register(sor->dev, &pad->hw); |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 373 | |
| 374 | return clk; |
| 375 | } |
| 376 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 377 | static int tegra_sor_dp_train_fast(struct tegra_sor *sor, |
| 378 | struct drm_dp_link *link) |
| 379 | { |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 380 | unsigned int i; |
| 381 | u8 pattern; |
| Thierry Reding | 28fe207 | 2015-01-26 16:02:48 +0100 | [diff] [blame] | 382 | u32 value; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 383 | int err; |
| 384 | |
| 385 | /* setup lane parameters */ |
| 386 | value = SOR_LANE_DRIVE_CURRENT_LANE3(0x40) | |
| 387 | SOR_LANE_DRIVE_CURRENT_LANE2(0x40) | |
| 388 | SOR_LANE_DRIVE_CURRENT_LANE1(0x40) | |
| 389 | SOR_LANE_DRIVE_CURRENT_LANE0(0x40); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 390 | tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 391 | |
| 392 | value = SOR_LANE_PREEMPHASIS_LANE3(0x0f) | |
| 393 | SOR_LANE_PREEMPHASIS_LANE2(0x0f) | |
| 394 | SOR_LANE_PREEMPHASIS_LANE1(0x0f) | |
| 395 | SOR_LANE_PREEMPHASIS_LANE0(0x0f); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 396 | tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 397 | |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 398 | value = SOR_LANE_POSTCURSOR_LANE3(0x00) | |
| 399 | SOR_LANE_POSTCURSOR_LANE2(0x00) | |
| 400 | SOR_LANE_POSTCURSOR_LANE1(0x00) | |
| 401 | SOR_LANE_POSTCURSOR_LANE0(0x00); |
| 402 | tegra_sor_writel(sor, value, SOR_LANE_POSTCURSOR0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 403 | |
| 404 | /* disable LVDS mode */ |
| 405 | tegra_sor_writel(sor, 0, SOR_LVDS); |
| 406 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 407 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 408 | value |= SOR_DP_PADCTL_TX_PU_ENABLE; |
| 409 | value &= ~SOR_DP_PADCTL_TX_PU_MASK; |
| 410 | value |= SOR_DP_PADCTL_TX_PU(2); /* XXX: don't hardcode? */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 411 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 412 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 413 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 414 | value |= SOR_DP_PADCTL_CM_TXD_3 | SOR_DP_PADCTL_CM_TXD_2 | |
| 415 | SOR_DP_PADCTL_CM_TXD_1 | SOR_DP_PADCTL_CM_TXD_0; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 416 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 417 | |
| 418 | usleep_range(10, 100); |
| 419 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 420 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 421 | value &= ~(SOR_DP_PADCTL_CM_TXD_3 | SOR_DP_PADCTL_CM_TXD_2 | |
| 422 | SOR_DP_PADCTL_CM_TXD_1 | SOR_DP_PADCTL_CM_TXD_0); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 423 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 424 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 425 | err = drm_dp_aux_prepare(sor->aux, DP_SET_ANSI_8B10B); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 426 | if (err < 0) |
| 427 | return err; |
| 428 | |
| 429 | for (i = 0, value = 0; i < link->num_lanes; i++) { |
| 430 | unsigned long lane = SOR_DP_TPG_CHANNEL_CODING | |
| 431 | SOR_DP_TPG_SCRAMBLER_NONE | |
| 432 | SOR_DP_TPG_PATTERN_TRAIN1; |
| 433 | value = (value << 8) | lane; |
| 434 | } |
| 435 | |
| 436 | tegra_sor_writel(sor, value, SOR_DP_TPG); |
| 437 | |
| 438 | pattern = DP_TRAINING_PATTERN_1; |
| 439 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 440 | err = drm_dp_aux_train(sor->aux, link, pattern); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 441 | if (err < 0) |
| 442 | return err; |
| 443 | |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 444 | value = tegra_sor_readl(sor, SOR_DP_SPARE0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 445 | value |= SOR_DP_SPARE_SEQ_ENABLE; |
| 446 | value &= ~SOR_DP_SPARE_PANEL_INTERNAL; |
| 447 | value |= SOR_DP_SPARE_MACRO_SOR_CLK; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 448 | tegra_sor_writel(sor, value, SOR_DP_SPARE0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 449 | |
| 450 | for (i = 0, value = 0; i < link->num_lanes; i++) { |
| 451 | unsigned long lane = SOR_DP_TPG_CHANNEL_CODING | |
| 452 | SOR_DP_TPG_SCRAMBLER_NONE | |
| 453 | SOR_DP_TPG_PATTERN_TRAIN2; |
| 454 | value = (value << 8) | lane; |
| 455 | } |
| 456 | |
| 457 | tegra_sor_writel(sor, value, SOR_DP_TPG); |
| 458 | |
| 459 | pattern = DP_LINK_SCRAMBLING_DISABLE | DP_TRAINING_PATTERN_2; |
| 460 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 461 | err = drm_dp_aux_train(sor->aux, link, pattern); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 462 | if (err < 0) |
| 463 | return err; |
| 464 | |
| 465 | for (i = 0, value = 0; i < link->num_lanes; i++) { |
| 466 | unsigned long lane = SOR_DP_TPG_CHANNEL_CODING | |
| 467 | SOR_DP_TPG_SCRAMBLER_GALIOS | |
| 468 | SOR_DP_TPG_PATTERN_NONE; |
| 469 | value = (value << 8) | lane; |
| 470 | } |
| 471 | |
| 472 | tegra_sor_writel(sor, value, SOR_DP_TPG); |
| 473 | |
| 474 | pattern = DP_TRAINING_PATTERN_DISABLE; |
| 475 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 476 | err = drm_dp_aux_train(sor->aux, link, pattern); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 477 | if (err < 0) |
| 478 | return err; |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 483 | static void tegra_sor_dp_term_calibrate(struct tegra_sor *sor) |
| 484 | { |
| 485 | u32 mask = 0x08, adj = 0, value; |
| 486 | |
| 487 | /* enable pad calibration logic */ |
| 488 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
| 489 | value &= ~SOR_DP_PADCTL_PAD_CAL_PD; |
| 490 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
| 491 | |
| 492 | value = tegra_sor_readl(sor, SOR_PLL1); |
| 493 | value |= SOR_PLL1_TMDS_TERM; |
| 494 | tegra_sor_writel(sor, value, SOR_PLL1); |
| 495 | |
| 496 | while (mask) { |
| 497 | adj |= mask; |
| 498 | |
| 499 | value = tegra_sor_readl(sor, SOR_PLL1); |
| 500 | value &= ~SOR_PLL1_TMDS_TERMADJ_MASK; |
| 501 | value |= SOR_PLL1_TMDS_TERMADJ(adj); |
| 502 | tegra_sor_writel(sor, value, SOR_PLL1); |
| 503 | |
| 504 | usleep_range(100, 200); |
| 505 | |
| 506 | value = tegra_sor_readl(sor, SOR_PLL1); |
| 507 | if (value & SOR_PLL1_TERM_COMPOUT) |
| 508 | adj &= ~mask; |
| 509 | |
| 510 | mask >>= 1; |
| 511 | } |
| 512 | |
| 513 | value = tegra_sor_readl(sor, SOR_PLL1); |
| 514 | value &= ~SOR_PLL1_TMDS_TERMADJ_MASK; |
| 515 | value |= SOR_PLL1_TMDS_TERMADJ(adj); |
| 516 | tegra_sor_writel(sor, value, SOR_PLL1); |
| 517 | |
| 518 | /* disable pad calibration logic */ |
| 519 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
| 520 | value |= SOR_DP_PADCTL_PAD_CAL_PD; |
| 521 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
| 522 | } |
| 523 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 524 | static void tegra_sor_super_update(struct tegra_sor *sor) |
| 525 | { |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 526 | tegra_sor_writel(sor, 0, SOR_SUPER_STATE0); |
| 527 | tegra_sor_writel(sor, 1, SOR_SUPER_STATE0); |
| 528 | tegra_sor_writel(sor, 0, SOR_SUPER_STATE0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | static void tegra_sor_update(struct tegra_sor *sor) |
| 532 | { |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 533 | tegra_sor_writel(sor, 0, SOR_STATE0); |
| 534 | tegra_sor_writel(sor, 1, SOR_STATE0); |
| 535 | tegra_sor_writel(sor, 0, SOR_STATE0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static int tegra_sor_setup_pwm(struct tegra_sor *sor, unsigned long timeout) |
| 539 | { |
| Thierry Reding | 28fe207 | 2015-01-26 16:02:48 +0100 | [diff] [blame] | 540 | u32 value; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 541 | |
| 542 | value = tegra_sor_readl(sor, SOR_PWM_DIV); |
| 543 | value &= ~SOR_PWM_DIV_MASK; |
| 544 | value |= 0x400; /* period */ |
| 545 | tegra_sor_writel(sor, value, SOR_PWM_DIV); |
| 546 | |
| 547 | value = tegra_sor_readl(sor, SOR_PWM_CTL); |
| 548 | value &= ~SOR_PWM_CTL_DUTY_CYCLE_MASK; |
| 549 | value |= 0x400; /* duty cycle */ |
| 550 | value &= ~SOR_PWM_CTL_CLK_SEL; /* clock source: PCLK */ |
| 551 | value |= SOR_PWM_CTL_TRIGGER; |
| 552 | tegra_sor_writel(sor, value, SOR_PWM_CTL); |
| 553 | |
| 554 | timeout = jiffies + msecs_to_jiffies(timeout); |
| 555 | |
| 556 | while (time_before(jiffies, timeout)) { |
| 557 | value = tegra_sor_readl(sor, SOR_PWM_CTL); |
| 558 | if ((value & SOR_PWM_CTL_TRIGGER) == 0) |
| 559 | return 0; |
| 560 | |
| 561 | usleep_range(25, 100); |
| 562 | } |
| 563 | |
| 564 | return -ETIMEDOUT; |
| 565 | } |
| 566 | |
| 567 | static int tegra_sor_attach(struct tegra_sor *sor) |
| 568 | { |
| 569 | unsigned long value, timeout; |
| 570 | |
| 571 | /* wake up in normal mode */ |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 572 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 573 | value |= SOR_SUPER_STATE_HEAD_MODE_AWAKE; |
| 574 | value |= SOR_SUPER_STATE_MODE_NORMAL; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 575 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 576 | tegra_sor_super_update(sor); |
| 577 | |
| 578 | /* attach */ |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 579 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 580 | value |= SOR_SUPER_STATE_ATTACHED; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 581 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 582 | tegra_sor_super_update(sor); |
| 583 | |
| 584 | timeout = jiffies + msecs_to_jiffies(250); |
| 585 | |
| 586 | while (time_before(jiffies, timeout)) { |
| 587 | value = tegra_sor_readl(sor, SOR_TEST); |
| 588 | if ((value & SOR_TEST_ATTACHED) != 0) |
| 589 | return 0; |
| 590 | |
| 591 | usleep_range(25, 100); |
| 592 | } |
| 593 | |
| 594 | return -ETIMEDOUT; |
| 595 | } |
| 596 | |
| 597 | static int tegra_sor_wakeup(struct tegra_sor *sor) |
| 598 | { |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 599 | unsigned long value, timeout; |
| 600 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 601 | timeout = jiffies + msecs_to_jiffies(250); |
| 602 | |
| 603 | /* wait for head to wake up */ |
| 604 | while (time_before(jiffies, timeout)) { |
| 605 | value = tegra_sor_readl(sor, SOR_TEST); |
| 606 | value &= SOR_TEST_HEAD_MODE_MASK; |
| 607 | |
| 608 | if (value == SOR_TEST_HEAD_MODE_AWAKE) |
| 609 | return 0; |
| 610 | |
| 611 | usleep_range(25, 100); |
| 612 | } |
| 613 | |
| 614 | return -ETIMEDOUT; |
| 615 | } |
| 616 | |
| 617 | static int tegra_sor_power_up(struct tegra_sor *sor, unsigned long timeout) |
| 618 | { |
| Thierry Reding | 28fe207 | 2015-01-26 16:02:48 +0100 | [diff] [blame] | 619 | u32 value; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 620 | |
| 621 | value = tegra_sor_readl(sor, SOR_PWR); |
| 622 | value |= SOR_PWR_TRIGGER | SOR_PWR_NORMAL_STATE_PU; |
| 623 | tegra_sor_writel(sor, value, SOR_PWR); |
| 624 | |
| 625 | timeout = jiffies + msecs_to_jiffies(timeout); |
| 626 | |
| 627 | while (time_before(jiffies, timeout)) { |
| 628 | value = tegra_sor_readl(sor, SOR_PWR); |
| 629 | if ((value & SOR_PWR_TRIGGER) == 0) |
| 630 | return 0; |
| 631 | |
| 632 | usleep_range(25, 100); |
| 633 | } |
| 634 | |
| 635 | return -ETIMEDOUT; |
| 636 | } |
| 637 | |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 638 | struct tegra_sor_params { |
| 639 | /* number of link clocks per line */ |
| 640 | unsigned int num_clocks; |
| 641 | /* ratio between input and output */ |
| 642 | u64 ratio; |
| 643 | /* precision factor */ |
| 644 | u64 precision; |
| 645 | |
| 646 | unsigned int active_polarity; |
| 647 | unsigned int active_count; |
| 648 | unsigned int active_frac; |
| 649 | unsigned int tu_size; |
| 650 | unsigned int error; |
| 651 | }; |
| 652 | |
| 653 | static int tegra_sor_compute_params(struct tegra_sor *sor, |
| 654 | struct tegra_sor_params *params, |
| 655 | unsigned int tu_size) |
| 656 | { |
| 657 | u64 active_sym, active_count, frac, approx; |
| 658 | u32 active_polarity, active_frac = 0; |
| 659 | const u64 f = params->precision; |
| 660 | s64 error; |
| 661 | |
| 662 | active_sym = params->ratio * tu_size; |
| 663 | active_count = div_u64(active_sym, f) * f; |
| 664 | frac = active_sym - active_count; |
| 665 | |
| 666 | /* fraction < 0.5 */ |
| 667 | if (frac >= (f / 2)) { |
| 668 | active_polarity = 1; |
| 669 | frac = f - frac; |
| 670 | } else { |
| 671 | active_polarity = 0; |
| 672 | } |
| 673 | |
| 674 | if (frac != 0) { |
| 675 | frac = div_u64(f * f, frac); /* 1/fraction */ |
| 676 | if (frac <= (15 * f)) { |
| 677 | active_frac = div_u64(frac, f); |
| 678 | |
| 679 | /* round up */ |
| 680 | if (active_polarity) |
| 681 | active_frac++; |
| 682 | } else { |
| 683 | active_frac = active_polarity ? 1 : 15; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | if (active_frac == 1) |
| 688 | active_polarity = 0; |
| 689 | |
| 690 | if (active_polarity == 1) { |
| 691 | if (active_frac) { |
| 692 | approx = active_count + (active_frac * (f - 1)) * f; |
| 693 | approx = div_u64(approx, active_frac * f); |
| 694 | } else { |
| 695 | approx = active_count + f; |
| 696 | } |
| 697 | } else { |
| 698 | if (active_frac) |
| 699 | approx = active_count + div_u64(f, active_frac); |
| 700 | else |
| 701 | approx = active_count; |
| 702 | } |
| 703 | |
| 704 | error = div_s64(active_sym - approx, tu_size); |
| 705 | error *= params->num_clocks; |
| 706 | |
| Andrew Morton | 79211c8 | 2015-11-09 14:58:13 -0800 | [diff] [blame] | 707 | if (error <= 0 && abs(error) < params->error) { |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 708 | params->active_count = div_u64(active_count, f); |
| 709 | params->active_polarity = active_polarity; |
| 710 | params->active_frac = active_frac; |
| Andrew Morton | 79211c8 | 2015-11-09 14:58:13 -0800 | [diff] [blame] | 711 | params->error = abs(error); |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 712 | params->tu_size = tu_size; |
| 713 | |
| 714 | if (error == 0) |
| 715 | return true; |
| 716 | } |
| 717 | |
| 718 | return false; |
| 719 | } |
| 720 | |
| Thierry Reding | a198359 | 2015-07-21 16:46:52 +0200 | [diff] [blame] | 721 | static int tegra_sor_compute_config(struct tegra_sor *sor, |
| 722 | const struct drm_display_mode *mode, |
| 723 | struct tegra_sor_config *config, |
| 724 | struct drm_dp_link *link) |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 725 | { |
| 726 | const u64 f = 100000, link_rate = link->rate * 1000; |
| 727 | const u64 pclk = mode->clock * 1000; |
| Thierry Reding | 7890b57 | 2014-06-05 16:12:46 +0200 | [diff] [blame] | 728 | u64 input, output, watermark, num; |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 729 | struct tegra_sor_params params; |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 730 | u32 num_syms_per_line; |
| 731 | unsigned int i; |
| 732 | |
| 733 | if (!link_rate || !link->num_lanes || !pclk || !config->bits_per_pixel) |
| 734 | return -EINVAL; |
| 735 | |
| 736 | output = link_rate * 8 * link->num_lanes; |
| 737 | input = pclk * config->bits_per_pixel; |
| 738 | |
| 739 | if (input >= output) |
| 740 | return -ERANGE; |
| 741 | |
| 742 | memset(¶ms, 0, sizeof(params)); |
| 743 | params.ratio = div64_u64(input * f, output); |
| 744 | params.num_clocks = div_u64(link_rate * mode->hdisplay, pclk); |
| 745 | params.precision = f; |
| 746 | params.error = 64 * f; |
| 747 | params.tu_size = 64; |
| 748 | |
| 749 | for (i = params.tu_size; i >= 32; i--) |
| 750 | if (tegra_sor_compute_params(sor, ¶ms, i)) |
| 751 | break; |
| 752 | |
| 753 | if (params.active_frac == 0) { |
| 754 | config->active_polarity = 0; |
| 755 | config->active_count = params.active_count; |
| 756 | |
| 757 | if (!params.active_polarity) |
| 758 | config->active_count--; |
| 759 | |
| 760 | config->tu_size = params.tu_size; |
| 761 | config->active_frac = 1; |
| 762 | } else { |
| 763 | config->active_polarity = params.active_polarity; |
| 764 | config->active_count = params.active_count; |
| 765 | config->active_frac = params.active_frac; |
| 766 | config->tu_size = params.tu_size; |
| 767 | } |
| 768 | |
| 769 | dev_dbg(sor->dev, |
| 770 | "polarity: %d active count: %d tu size: %d active frac: %d\n", |
| 771 | config->active_polarity, config->active_count, |
| 772 | config->tu_size, config->active_frac); |
| 773 | |
| 774 | watermark = params.ratio * config->tu_size * (f - params.ratio); |
| 775 | watermark = div_u64(watermark, f); |
| 776 | |
| 777 | watermark = div_u64(watermark + params.error, f); |
| 778 | config->watermark = watermark + (config->bits_per_pixel / 8) + 2; |
| 779 | num_syms_per_line = (mode->hdisplay * config->bits_per_pixel) * |
| 780 | (link->num_lanes * 8); |
| 781 | |
| 782 | if (config->watermark > 30) { |
| 783 | config->watermark = 30; |
| 784 | dev_err(sor->dev, |
| 785 | "unable to compute TU size, forcing watermark to %u\n", |
| 786 | config->watermark); |
| 787 | } else if (config->watermark > num_syms_per_line) { |
| 788 | config->watermark = num_syms_per_line; |
| 789 | dev_err(sor->dev, "watermark too high, forcing to %u\n", |
| 790 | config->watermark); |
| 791 | } |
| 792 | |
| Thierry Reding | 7890b57 | 2014-06-05 16:12:46 +0200 | [diff] [blame] | 793 | /* compute the number of symbols per horizontal blanking interval */ |
| 794 | num = ((mode->htotal - mode->hdisplay) - 7) * link_rate; |
| 795 | config->hblank_symbols = div_u64(num, pclk); |
| 796 | |
| 797 | if (link->capabilities & DP_LINK_CAP_ENHANCED_FRAMING) |
| 798 | config->hblank_symbols -= 3; |
| 799 | |
| 800 | config->hblank_symbols -= 12 / link->num_lanes; |
| 801 | |
| 802 | /* compute the number of symbols per vertical blanking interval */ |
| 803 | num = (mode->hdisplay - 25) * link_rate; |
| 804 | config->vblank_symbols = div_u64(num, pclk); |
| 805 | config->vblank_symbols -= 36 / link->num_lanes + 4; |
| 806 | |
| 807 | dev_dbg(sor->dev, "blank symbols: H:%u V:%u\n", config->hblank_symbols, |
| 808 | config->vblank_symbols); |
| 809 | |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 810 | return 0; |
| 811 | } |
| 812 | |
| Thierry Reding | 402f6bc | 2015-07-21 16:48:19 +0200 | [diff] [blame] | 813 | static void tegra_sor_apply_config(struct tegra_sor *sor, |
| 814 | const struct tegra_sor_config *config) |
| 815 | { |
| 816 | u32 value; |
| 817 | |
| 818 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
| 819 | value &= ~SOR_DP_LINKCTL_TU_SIZE_MASK; |
| 820 | value |= SOR_DP_LINKCTL_TU_SIZE(config->tu_size); |
| 821 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
| 822 | |
| 823 | value = tegra_sor_readl(sor, SOR_DP_CONFIG0); |
| 824 | value &= ~SOR_DP_CONFIG_WATERMARK_MASK; |
| 825 | value |= SOR_DP_CONFIG_WATERMARK(config->watermark); |
| 826 | |
| 827 | value &= ~SOR_DP_CONFIG_ACTIVE_SYM_COUNT_MASK; |
| 828 | value |= SOR_DP_CONFIG_ACTIVE_SYM_COUNT(config->active_count); |
| 829 | |
| 830 | value &= ~SOR_DP_CONFIG_ACTIVE_SYM_FRAC_MASK; |
| 831 | value |= SOR_DP_CONFIG_ACTIVE_SYM_FRAC(config->active_frac); |
| 832 | |
| 833 | if (config->active_polarity) |
| 834 | value |= SOR_DP_CONFIG_ACTIVE_SYM_POLARITY; |
| 835 | else |
| 836 | value &= ~SOR_DP_CONFIG_ACTIVE_SYM_POLARITY; |
| 837 | |
| 838 | value |= SOR_DP_CONFIG_ACTIVE_SYM_ENABLE; |
| 839 | value |= SOR_DP_CONFIG_DISPARITY_NEGATIVE; |
| 840 | tegra_sor_writel(sor, value, SOR_DP_CONFIG0); |
| 841 | |
| 842 | value = tegra_sor_readl(sor, SOR_DP_AUDIO_HBLANK_SYMBOLS); |
| 843 | value &= ~SOR_DP_AUDIO_HBLANK_SYMBOLS_MASK; |
| 844 | value |= config->hblank_symbols & 0xffff; |
| 845 | tegra_sor_writel(sor, value, SOR_DP_AUDIO_HBLANK_SYMBOLS); |
| 846 | |
| 847 | value = tegra_sor_readl(sor, SOR_DP_AUDIO_VBLANK_SYMBOLS); |
| 848 | value &= ~SOR_DP_AUDIO_VBLANK_SYMBOLS_MASK; |
| 849 | value |= config->vblank_symbols & 0xffff; |
| 850 | tegra_sor_writel(sor, value, SOR_DP_AUDIO_VBLANK_SYMBOLS); |
| 851 | } |
| 852 | |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 853 | static void tegra_sor_mode_set(struct tegra_sor *sor, |
| 854 | const struct drm_display_mode *mode, |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 855 | struct tegra_sor_state *state) |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 856 | { |
| 857 | struct tegra_dc *dc = to_tegra_dc(sor->output.encoder.crtc); |
| 858 | unsigned int vbe, vse, hbe, hse, vbs, hbs; |
| 859 | u32 value; |
| 860 | |
| 861 | value = tegra_sor_readl(sor, SOR_STATE1); |
| 862 | value &= ~SOR_STATE_ASY_PIXELDEPTH_MASK; |
| 863 | value &= ~SOR_STATE_ASY_CRC_MODE_MASK; |
| 864 | value &= ~SOR_STATE_ASY_OWNER_MASK; |
| 865 | |
| 866 | value |= SOR_STATE_ASY_CRC_MODE_COMPLETE | |
| 867 | SOR_STATE_ASY_OWNER(dc->pipe + 1); |
| 868 | |
| 869 | if (mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 870 | value &= ~SOR_STATE_ASY_HSYNCPOL; |
| 871 | |
| 872 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 873 | value |= SOR_STATE_ASY_HSYNCPOL; |
| 874 | |
| 875 | if (mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 876 | value &= ~SOR_STATE_ASY_VSYNCPOL; |
| 877 | |
| 878 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 879 | value |= SOR_STATE_ASY_VSYNCPOL; |
| 880 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 881 | switch (state->bpc) { |
| 882 | case 16: |
| 883 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_48_444; |
| 884 | break; |
| 885 | |
| 886 | case 12: |
| 887 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_36_444; |
| 888 | break; |
| 889 | |
| 890 | case 10: |
| 891 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_30_444; |
| 892 | break; |
| 893 | |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 894 | case 8: |
| 895 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444; |
| 896 | break; |
| 897 | |
| 898 | case 6: |
| 899 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_18_444; |
| 900 | break; |
| 901 | |
| 902 | default: |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 903 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444; |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 904 | break; |
| 905 | } |
| 906 | |
| 907 | tegra_sor_writel(sor, value, SOR_STATE1); |
| 908 | |
| 909 | /* |
| 910 | * TODO: The video timing programming below doesn't seem to match the |
| 911 | * register definitions. |
| 912 | */ |
| 913 | |
| 914 | value = ((mode->vtotal & 0x7fff) << 16) | (mode->htotal & 0x7fff); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 915 | tegra_sor_writel(sor, value, sor->soc->regs->head_state1 + dc->pipe); |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 916 | |
| 917 | /* sync end = sync width - 1 */ |
| 918 | vse = mode->vsync_end - mode->vsync_start - 1; |
| 919 | hse = mode->hsync_end - mode->hsync_start - 1; |
| 920 | |
| 921 | value = ((vse & 0x7fff) << 16) | (hse & 0x7fff); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 922 | tegra_sor_writel(sor, value, sor->soc->regs->head_state2 + dc->pipe); |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 923 | |
| 924 | /* blank end = sync end + back porch */ |
| 925 | vbe = vse + (mode->vtotal - mode->vsync_end); |
| 926 | hbe = hse + (mode->htotal - mode->hsync_end); |
| 927 | |
| 928 | value = ((vbe & 0x7fff) << 16) | (hbe & 0x7fff); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 929 | tegra_sor_writel(sor, value, sor->soc->regs->head_state3 + dc->pipe); |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 930 | |
| 931 | /* blank start = blank end + active */ |
| 932 | vbs = vbe + mode->vdisplay; |
| 933 | hbs = hbe + mode->hdisplay; |
| 934 | |
| 935 | value = ((vbs & 0x7fff) << 16) | (hbs & 0x7fff); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 936 | tegra_sor_writel(sor, value, sor->soc->regs->head_state4 + dc->pipe); |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 937 | |
| 938 | /* XXX interlacing support */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 939 | tegra_sor_writel(sor, 0x001, sor->soc->regs->head_state5 + dc->pipe); |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 940 | } |
| 941 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 942 | static int tegra_sor_detach(struct tegra_sor *sor) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 943 | { |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 944 | unsigned long value, timeout; |
| 945 | |
| 946 | /* switch to safe mode */ |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 947 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 948 | value &= ~SOR_SUPER_STATE_MODE_NORMAL; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 949 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 950 | tegra_sor_super_update(sor); |
| 951 | |
| 952 | timeout = jiffies + msecs_to_jiffies(250); |
| 953 | |
| 954 | while (time_before(jiffies, timeout)) { |
| 955 | value = tegra_sor_readl(sor, SOR_PWR); |
| 956 | if (value & SOR_PWR_MODE_SAFE) |
| 957 | break; |
| 958 | } |
| 959 | |
| 960 | if ((value & SOR_PWR_MODE_SAFE) == 0) |
| 961 | return -ETIMEDOUT; |
| 962 | |
| 963 | /* go to sleep */ |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 964 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 965 | value &= ~SOR_SUPER_STATE_HEAD_MODE_MASK; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 966 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 967 | tegra_sor_super_update(sor); |
| 968 | |
| 969 | /* detach */ |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 970 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 971 | value &= ~SOR_SUPER_STATE_ATTACHED; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 972 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 973 | tegra_sor_super_update(sor); |
| 974 | |
| 975 | timeout = jiffies + msecs_to_jiffies(250); |
| 976 | |
| 977 | while (time_before(jiffies, timeout)) { |
| 978 | value = tegra_sor_readl(sor, SOR_TEST); |
| 979 | if ((value & SOR_TEST_ATTACHED) == 0) |
| 980 | break; |
| 981 | |
| 982 | usleep_range(25, 100); |
| 983 | } |
| 984 | |
| 985 | if ((value & SOR_TEST_ATTACHED) != 0) |
| 986 | return -ETIMEDOUT; |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static int tegra_sor_power_down(struct tegra_sor *sor) |
| 992 | { |
| 993 | unsigned long value, timeout; |
| 994 | int err; |
| 995 | |
| 996 | value = tegra_sor_readl(sor, SOR_PWR); |
| 997 | value &= ~SOR_PWR_NORMAL_STATE_PU; |
| 998 | value |= SOR_PWR_TRIGGER; |
| 999 | tegra_sor_writel(sor, value, SOR_PWR); |
| 1000 | |
| 1001 | timeout = jiffies + msecs_to_jiffies(250); |
| 1002 | |
| 1003 | while (time_before(jiffies, timeout)) { |
| 1004 | value = tegra_sor_readl(sor, SOR_PWR); |
| 1005 | if ((value & SOR_PWR_TRIGGER) == 0) |
| 1006 | return 0; |
| 1007 | |
| 1008 | usleep_range(25, 100); |
| 1009 | } |
| 1010 | |
| 1011 | if ((value & SOR_PWR_TRIGGER) != 0) |
| 1012 | return -ETIMEDOUT; |
| 1013 | |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1014 | /* switch to safe parent clock */ |
| 1015 | err = tegra_sor_set_parent_clock(sor, sor->clk_safe); |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 1016 | if (err < 0) { |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1017 | dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 1018 | return err; |
| 1019 | } |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1020 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1021 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1022 | value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 | |
| 1023 | SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1024 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1025 | |
| 1026 | /* stop lane sequencer */ |
| 1027 | value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_UP | |
| 1028 | SOR_LANE_SEQ_CTL_POWER_STATE_DOWN; |
| 1029 | tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); |
| 1030 | |
| 1031 | timeout = jiffies + msecs_to_jiffies(250); |
| 1032 | |
| 1033 | while (time_before(jiffies, timeout)) { |
| 1034 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 1035 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) |
| 1036 | break; |
| 1037 | |
| 1038 | usleep_range(25, 100); |
| 1039 | } |
| 1040 | |
| 1041 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0) |
| 1042 | return -ETIMEDOUT; |
| 1043 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1044 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1045 | value |= SOR_PLL2_PORT_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1046 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1047 | |
| 1048 | usleep_range(20, 100); |
| 1049 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1050 | value = tegra_sor_readl(sor, sor->soc->regs->pll0); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1051 | value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1052 | tegra_sor_writel(sor, value, sor->soc->regs->pll0); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1053 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1054 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1055 | value |= SOR_PLL2_SEQ_PLLCAPPD; |
| 1056 | value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1057 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1058 | |
| 1059 | usleep_range(20, 100); |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1064 | static int tegra_sor_crc_wait(struct tegra_sor *sor, unsigned long timeout) |
| 1065 | { |
| 1066 | u32 value; |
| 1067 | |
| 1068 | timeout = jiffies + msecs_to_jiffies(timeout); |
| 1069 | |
| 1070 | while (time_before(jiffies, timeout)) { |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1071 | value = tegra_sor_readl(sor, SOR_CRCA); |
| 1072 | if (value & SOR_CRCA_VALID) |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1073 | return 0; |
| 1074 | |
| 1075 | usleep_range(100, 200); |
| 1076 | } |
| 1077 | |
| 1078 | return -ETIMEDOUT; |
| 1079 | } |
| 1080 | |
| Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1081 | static int tegra_sor_show_crc(struct seq_file *s, void *data) |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1082 | { |
| Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1083 | struct drm_info_node *node = s->private; |
| 1084 | struct tegra_sor *sor = node->info_ent->data; |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1085 | struct drm_crtc *crtc = sor->output.encoder.crtc; |
| 1086 | struct drm_device *drm = node->minor->dev; |
| Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1087 | int err = 0; |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1088 | u32 value; |
| 1089 | |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1090 | drm_modeset_lock_all(drm); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1091 | |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1092 | if (!crtc || !crtc->state->active) { |
| 1093 | err = -EBUSY; |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1094 | goto unlock; |
| 1095 | } |
| 1096 | |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1097 | value = tegra_sor_readl(sor, SOR_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1098 | value &= ~SOR_STATE_ASY_CRC_MODE_MASK; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1099 | tegra_sor_writel(sor, value, SOR_STATE1); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1100 | |
| 1101 | value = tegra_sor_readl(sor, SOR_CRC_CNTRL); |
| 1102 | value |= SOR_CRC_CNTRL_ENABLE; |
| 1103 | tegra_sor_writel(sor, value, SOR_CRC_CNTRL); |
| 1104 | |
| 1105 | value = tegra_sor_readl(sor, SOR_TEST); |
| 1106 | value &= ~SOR_TEST_CRC_POST_SERIALIZE; |
| 1107 | tegra_sor_writel(sor, value, SOR_TEST); |
| 1108 | |
| 1109 | err = tegra_sor_crc_wait(sor, 100); |
| 1110 | if (err < 0) |
| 1111 | goto unlock; |
| 1112 | |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1113 | tegra_sor_writel(sor, SOR_CRCA_RESET, SOR_CRCA); |
| 1114 | value = tegra_sor_readl(sor, SOR_CRCB); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1115 | |
| Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1116 | seq_printf(s, "%08x\n", value); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1117 | |
| 1118 | unlock: |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1119 | drm_modeset_unlock_all(drm); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1120 | return err; |
| 1121 | } |
| 1122 | |
| Thierry Reding | 062f5b2c | 2017-11-10 12:21:51 +0100 | [diff] [blame] | 1123 | #define DEBUGFS_REG32(_name) { .name = #_name, .offset = _name } |
| 1124 | |
| 1125 | static const struct debugfs_reg32 tegra_sor_regs[] = { |
| 1126 | DEBUGFS_REG32(SOR_CTXSW), |
| 1127 | DEBUGFS_REG32(SOR_SUPER_STATE0), |
| 1128 | DEBUGFS_REG32(SOR_SUPER_STATE1), |
| 1129 | DEBUGFS_REG32(SOR_STATE0), |
| 1130 | DEBUGFS_REG32(SOR_STATE1), |
| 1131 | DEBUGFS_REG32(SOR_HEAD_STATE0(0)), |
| 1132 | DEBUGFS_REG32(SOR_HEAD_STATE0(1)), |
| 1133 | DEBUGFS_REG32(SOR_HEAD_STATE1(0)), |
| 1134 | DEBUGFS_REG32(SOR_HEAD_STATE1(1)), |
| 1135 | DEBUGFS_REG32(SOR_HEAD_STATE2(0)), |
| 1136 | DEBUGFS_REG32(SOR_HEAD_STATE2(1)), |
| 1137 | DEBUGFS_REG32(SOR_HEAD_STATE3(0)), |
| 1138 | DEBUGFS_REG32(SOR_HEAD_STATE3(1)), |
| 1139 | DEBUGFS_REG32(SOR_HEAD_STATE4(0)), |
| 1140 | DEBUGFS_REG32(SOR_HEAD_STATE4(1)), |
| 1141 | DEBUGFS_REG32(SOR_HEAD_STATE5(0)), |
| 1142 | DEBUGFS_REG32(SOR_HEAD_STATE5(1)), |
| 1143 | DEBUGFS_REG32(SOR_CRC_CNTRL), |
| 1144 | DEBUGFS_REG32(SOR_DP_DEBUG_MVID), |
| 1145 | DEBUGFS_REG32(SOR_CLK_CNTRL), |
| 1146 | DEBUGFS_REG32(SOR_CAP), |
| 1147 | DEBUGFS_REG32(SOR_PWR), |
| 1148 | DEBUGFS_REG32(SOR_TEST), |
| 1149 | DEBUGFS_REG32(SOR_PLL0), |
| 1150 | DEBUGFS_REG32(SOR_PLL1), |
| 1151 | DEBUGFS_REG32(SOR_PLL2), |
| 1152 | DEBUGFS_REG32(SOR_PLL3), |
| 1153 | DEBUGFS_REG32(SOR_CSTM), |
| 1154 | DEBUGFS_REG32(SOR_LVDS), |
| 1155 | DEBUGFS_REG32(SOR_CRCA), |
| 1156 | DEBUGFS_REG32(SOR_CRCB), |
| 1157 | DEBUGFS_REG32(SOR_BLANK), |
| 1158 | DEBUGFS_REG32(SOR_SEQ_CTL), |
| 1159 | DEBUGFS_REG32(SOR_LANE_SEQ_CTL), |
| 1160 | DEBUGFS_REG32(SOR_SEQ_INST(0)), |
| 1161 | DEBUGFS_REG32(SOR_SEQ_INST(1)), |
| 1162 | DEBUGFS_REG32(SOR_SEQ_INST(2)), |
| 1163 | DEBUGFS_REG32(SOR_SEQ_INST(3)), |
| 1164 | DEBUGFS_REG32(SOR_SEQ_INST(4)), |
| 1165 | DEBUGFS_REG32(SOR_SEQ_INST(5)), |
| 1166 | DEBUGFS_REG32(SOR_SEQ_INST(6)), |
| 1167 | DEBUGFS_REG32(SOR_SEQ_INST(7)), |
| 1168 | DEBUGFS_REG32(SOR_SEQ_INST(8)), |
| 1169 | DEBUGFS_REG32(SOR_SEQ_INST(9)), |
| 1170 | DEBUGFS_REG32(SOR_SEQ_INST(10)), |
| 1171 | DEBUGFS_REG32(SOR_SEQ_INST(11)), |
| 1172 | DEBUGFS_REG32(SOR_SEQ_INST(12)), |
| 1173 | DEBUGFS_REG32(SOR_SEQ_INST(13)), |
| 1174 | DEBUGFS_REG32(SOR_SEQ_INST(14)), |
| 1175 | DEBUGFS_REG32(SOR_SEQ_INST(15)), |
| 1176 | DEBUGFS_REG32(SOR_PWM_DIV), |
| 1177 | DEBUGFS_REG32(SOR_PWM_CTL), |
| 1178 | DEBUGFS_REG32(SOR_VCRC_A0), |
| 1179 | DEBUGFS_REG32(SOR_VCRC_A1), |
| 1180 | DEBUGFS_REG32(SOR_VCRC_B0), |
| 1181 | DEBUGFS_REG32(SOR_VCRC_B1), |
| 1182 | DEBUGFS_REG32(SOR_CCRC_A0), |
| 1183 | DEBUGFS_REG32(SOR_CCRC_A1), |
| 1184 | DEBUGFS_REG32(SOR_CCRC_B0), |
| 1185 | DEBUGFS_REG32(SOR_CCRC_B1), |
| 1186 | DEBUGFS_REG32(SOR_EDATA_A0), |
| 1187 | DEBUGFS_REG32(SOR_EDATA_A1), |
| 1188 | DEBUGFS_REG32(SOR_EDATA_B0), |
| 1189 | DEBUGFS_REG32(SOR_EDATA_B1), |
| 1190 | DEBUGFS_REG32(SOR_COUNT_A0), |
| 1191 | DEBUGFS_REG32(SOR_COUNT_A1), |
| 1192 | DEBUGFS_REG32(SOR_COUNT_B0), |
| 1193 | DEBUGFS_REG32(SOR_COUNT_B1), |
| 1194 | DEBUGFS_REG32(SOR_DEBUG_A0), |
| 1195 | DEBUGFS_REG32(SOR_DEBUG_A1), |
| 1196 | DEBUGFS_REG32(SOR_DEBUG_B0), |
| 1197 | DEBUGFS_REG32(SOR_DEBUG_B1), |
| 1198 | DEBUGFS_REG32(SOR_TRIG), |
| 1199 | DEBUGFS_REG32(SOR_MSCHECK), |
| 1200 | DEBUGFS_REG32(SOR_XBAR_CTRL), |
| 1201 | DEBUGFS_REG32(SOR_XBAR_POL), |
| 1202 | DEBUGFS_REG32(SOR_DP_LINKCTL0), |
| 1203 | DEBUGFS_REG32(SOR_DP_LINKCTL1), |
| 1204 | DEBUGFS_REG32(SOR_LANE_DRIVE_CURRENT0), |
| 1205 | DEBUGFS_REG32(SOR_LANE_DRIVE_CURRENT1), |
| 1206 | DEBUGFS_REG32(SOR_LANE4_DRIVE_CURRENT0), |
| 1207 | DEBUGFS_REG32(SOR_LANE4_DRIVE_CURRENT1), |
| 1208 | DEBUGFS_REG32(SOR_LANE_PREEMPHASIS0), |
| 1209 | DEBUGFS_REG32(SOR_LANE_PREEMPHASIS1), |
| 1210 | DEBUGFS_REG32(SOR_LANE4_PREEMPHASIS0), |
| 1211 | DEBUGFS_REG32(SOR_LANE4_PREEMPHASIS1), |
| 1212 | DEBUGFS_REG32(SOR_LANE_POSTCURSOR0), |
| 1213 | DEBUGFS_REG32(SOR_LANE_POSTCURSOR1), |
| 1214 | DEBUGFS_REG32(SOR_DP_CONFIG0), |
| 1215 | DEBUGFS_REG32(SOR_DP_CONFIG1), |
| 1216 | DEBUGFS_REG32(SOR_DP_MN0), |
| 1217 | DEBUGFS_REG32(SOR_DP_MN1), |
| 1218 | DEBUGFS_REG32(SOR_DP_PADCTL0), |
| 1219 | DEBUGFS_REG32(SOR_DP_PADCTL1), |
| 1220 | DEBUGFS_REG32(SOR_DP_DEBUG0), |
| 1221 | DEBUGFS_REG32(SOR_DP_DEBUG1), |
| 1222 | DEBUGFS_REG32(SOR_DP_SPARE0), |
| 1223 | DEBUGFS_REG32(SOR_DP_SPARE1), |
| 1224 | DEBUGFS_REG32(SOR_DP_AUDIO_CTRL), |
| 1225 | DEBUGFS_REG32(SOR_DP_AUDIO_HBLANK_SYMBOLS), |
| 1226 | DEBUGFS_REG32(SOR_DP_AUDIO_VBLANK_SYMBOLS), |
| 1227 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_HEADER), |
| 1228 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK0), |
| 1229 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK1), |
| 1230 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK2), |
| 1231 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK3), |
| 1232 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK4), |
| 1233 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK5), |
| 1234 | DEBUGFS_REG32(SOR_DP_GENERIC_INFOFRAME_SUBPACK6), |
| 1235 | DEBUGFS_REG32(SOR_DP_TPG), |
| 1236 | DEBUGFS_REG32(SOR_DP_TPG_CONFIG), |
| 1237 | DEBUGFS_REG32(SOR_DP_LQ_CSTM0), |
| 1238 | DEBUGFS_REG32(SOR_DP_LQ_CSTM1), |
| 1239 | DEBUGFS_REG32(SOR_DP_LQ_CSTM2), |
| 1240 | }; |
| 1241 | |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1242 | static int tegra_sor_show_regs(struct seq_file *s, void *data) |
| 1243 | { |
| 1244 | struct drm_info_node *node = s->private; |
| 1245 | struct tegra_sor *sor = node->info_ent->data; |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1246 | struct drm_crtc *crtc = sor->output.encoder.crtc; |
| 1247 | struct drm_device *drm = node->minor->dev; |
| Thierry Reding | 062f5b2c | 2017-11-10 12:21:51 +0100 | [diff] [blame] | 1248 | unsigned int i; |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1249 | int err = 0; |
| 1250 | |
| 1251 | drm_modeset_lock_all(drm); |
| 1252 | |
| 1253 | if (!crtc || !crtc->state->active) { |
| 1254 | err = -EBUSY; |
| 1255 | goto unlock; |
| 1256 | } |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1257 | |
| Thierry Reding | 062f5b2c | 2017-11-10 12:21:51 +0100 | [diff] [blame] | 1258 | for (i = 0; i < ARRAY_SIZE(tegra_sor_regs); i++) { |
| 1259 | unsigned int offset = tegra_sor_regs[i].offset; |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1260 | |
| Thierry Reding | 062f5b2c | 2017-11-10 12:21:51 +0100 | [diff] [blame] | 1261 | seq_printf(s, "%-38s %#05x %08x\n", tegra_sor_regs[i].name, |
| 1262 | offset, tegra_sor_readl(sor, offset)); |
| 1263 | } |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1264 | |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1265 | unlock: |
| 1266 | drm_modeset_unlock_all(drm); |
| 1267 | return err; |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | static const struct drm_info_list debugfs_files[] = { |
| Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1271 | { "crc", tegra_sor_show_crc, 0, NULL }, |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1272 | { "regs", tegra_sor_show_regs, 0, NULL }, |
| 1273 | }; |
| 1274 | |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1275 | static int tegra_sor_late_register(struct drm_connector *connector) |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1276 | { |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1277 | struct tegra_output *output = connector_to_output(connector); |
| 1278 | unsigned int i, count = ARRAY_SIZE(debugfs_files); |
| 1279 | struct drm_minor *minor = connector->dev->primary; |
| 1280 | struct dentry *root = connector->debugfs_entry; |
| 1281 | struct tegra_sor *sor = to_sor(output); |
| Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1282 | int err; |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1283 | |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1284 | sor->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), |
| 1285 | GFP_KERNEL); |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1286 | if (!sor->debugfs_files) |
| 1287 | return -ENOMEM; |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1288 | |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1289 | for (i = 0; i < count; i++) |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1290 | sor->debugfs_files[i].data = sor; |
| 1291 | |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1292 | err = drm_debugfs_create_files(sor->debugfs_files, count, root, minor); |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1293 | if (err < 0) |
| 1294 | goto free; |
| 1295 | |
| Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1296 | return 0; |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1297 | |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1298 | free: |
| 1299 | kfree(sor->debugfs_files); |
| 1300 | sor->debugfs_files = NULL; |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1301 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1302 | return err; |
| 1303 | } |
| 1304 | |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1305 | static void tegra_sor_early_unregister(struct drm_connector *connector) |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1306 | { |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1307 | struct tegra_output *output = connector_to_output(connector); |
| 1308 | unsigned int count = ARRAY_SIZE(debugfs_files); |
| 1309 | struct tegra_sor *sor = to_sor(output); |
| Thierry Reding | d92e600 | 2017-10-12 19:07:54 +0200 | [diff] [blame] | 1310 | |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1311 | drm_debugfs_remove_files(sor->debugfs_files, count, |
| 1312 | connector->dev->primary); |
| Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1313 | kfree(sor->debugfs_files); |
| Thierry Reding | 066d30f | 2015-07-03 14:16:30 +0200 | [diff] [blame] | 1314 | sor->debugfs_files = NULL; |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1317 | static void tegra_sor_connector_reset(struct drm_connector *connector) |
| 1318 | { |
| 1319 | struct tegra_sor_state *state; |
| 1320 | |
| 1321 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 1322 | if (!state) |
| 1323 | return; |
| 1324 | |
| 1325 | if (connector->state) { |
| 1326 | __drm_atomic_helper_connector_destroy_state(connector->state); |
| 1327 | kfree(connector->state); |
| 1328 | } |
| 1329 | |
| 1330 | __drm_atomic_helper_connector_reset(connector, &state->base); |
| 1331 | } |
| 1332 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1333 | static enum drm_connector_status |
| 1334 | tegra_sor_connector_detect(struct drm_connector *connector, bool force) |
| 1335 | { |
| 1336 | struct tegra_output *output = connector_to_output(connector); |
| 1337 | struct tegra_sor *sor = to_sor(output); |
| 1338 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1339 | if (sor->aux) |
| 1340 | return drm_dp_aux_detect(sor->aux); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1341 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1342 | return tegra_output_connector_detect(connector, force); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1345 | static struct drm_connector_state * |
| 1346 | tegra_sor_connector_duplicate_state(struct drm_connector *connector) |
| 1347 | { |
| 1348 | struct tegra_sor_state *state = to_sor_state(connector->state); |
| 1349 | struct tegra_sor_state *copy; |
| 1350 | |
| 1351 | copy = kmemdup(state, sizeof(*state), GFP_KERNEL); |
| 1352 | if (!copy) |
| 1353 | return NULL; |
| 1354 | |
| 1355 | __drm_atomic_helper_connector_duplicate_state(connector, ©->base); |
| 1356 | |
| 1357 | return ©->base; |
| 1358 | } |
| 1359 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1360 | static const struct drm_connector_funcs tegra_sor_connector_funcs = { |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1361 | .reset = tegra_sor_connector_reset, |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1362 | .detect = tegra_sor_connector_detect, |
| 1363 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 1364 | .destroy = tegra_output_connector_destroy, |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1365 | .atomic_duplicate_state = tegra_sor_connector_duplicate_state, |
| Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame] | 1366 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
| Thierry Reding | 5b8e043 | 2017-11-08 13:20:01 +0100 | [diff] [blame] | 1367 | .late_register = tegra_sor_late_register, |
| 1368 | .early_unregister = tegra_sor_early_unregister, |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1369 | }; |
| 1370 | |
| 1371 | static int tegra_sor_connector_get_modes(struct drm_connector *connector) |
| 1372 | { |
| 1373 | struct tegra_output *output = connector_to_output(connector); |
| 1374 | struct tegra_sor *sor = to_sor(output); |
| 1375 | int err; |
| 1376 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1377 | if (sor->aux) |
| 1378 | drm_dp_aux_enable(sor->aux); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1379 | |
| 1380 | err = tegra_output_connector_get_modes(connector); |
| 1381 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1382 | if (sor->aux) |
| 1383 | drm_dp_aux_disable(sor->aux); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1384 | |
| 1385 | return err; |
| 1386 | } |
| 1387 | |
| 1388 | static enum drm_mode_status |
| 1389 | tegra_sor_connector_mode_valid(struct drm_connector *connector, |
| 1390 | struct drm_display_mode *mode) |
| 1391 | { |
| Thierry Reding | 64ea25c | 2016-07-12 16:52:22 +0200 | [diff] [blame] | 1392 | /* HDMI 2.0 modes are not yet supported */ |
| 1393 | if (mode->clock > 340000) |
| 1394 | return MODE_NOCLOCK; |
| 1395 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1396 | return MODE_OK; |
| 1397 | } |
| 1398 | |
| 1399 | static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs = { |
| 1400 | .get_modes = tegra_sor_connector_get_modes, |
| 1401 | .mode_valid = tegra_sor_connector_mode_valid, |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1402 | }; |
| 1403 | |
| 1404 | static const struct drm_encoder_funcs tegra_sor_encoder_funcs = { |
| 1405 | .destroy = tegra_output_encoder_destroy, |
| 1406 | }; |
| 1407 | |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1408 | static void tegra_sor_edp_disable(struct drm_encoder *encoder) |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1409 | { |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1410 | struct tegra_output *output = encoder_to_output(encoder); |
| 1411 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
| 1412 | struct tegra_sor *sor = to_sor(output); |
| 1413 | u32 value; |
| 1414 | int err; |
| 1415 | |
| 1416 | if (output->panel) |
| 1417 | drm_panel_disable(output->panel); |
| 1418 | |
| 1419 | err = tegra_sor_detach(sor); |
| 1420 | if (err < 0) |
| 1421 | dev_err(sor->dev, "failed to detach SOR: %d\n", err); |
| 1422 | |
| 1423 | tegra_sor_writel(sor, 0, SOR_STATE1); |
| 1424 | tegra_sor_update(sor); |
| 1425 | |
| 1426 | /* |
| 1427 | * The following accesses registers of the display controller, so make |
| 1428 | * sure it's only executed when the output is attached to one. |
| 1429 | */ |
| 1430 | if (dc) { |
| 1431 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 1432 | value &= ~SOR_ENABLE; |
| 1433 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 1434 | |
| 1435 | tegra_dc_commit(dc); |
| 1436 | } |
| 1437 | |
| 1438 | err = tegra_sor_power_down(sor); |
| 1439 | if (err < 0) |
| 1440 | dev_err(sor->dev, "failed to power down SOR: %d\n", err); |
| 1441 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1442 | if (sor->aux) { |
| 1443 | err = drm_dp_aux_disable(sor->aux); |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1444 | if (err < 0) |
| 1445 | dev_err(sor->dev, "failed to disable DP: %d\n", err); |
| 1446 | } |
| 1447 | |
| 1448 | err = tegra_io_rail_power_off(TEGRA_IO_RAIL_LVDS); |
| 1449 | if (err < 0) |
| 1450 | dev_err(sor->dev, "failed to power off I/O rail: %d\n", err); |
| 1451 | |
| 1452 | if (output->panel) |
| 1453 | drm_panel_unprepare(output->panel); |
| 1454 | |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 1455 | pm_runtime_put(sor->dev); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1456 | } |
| 1457 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1458 | #if 0 |
| 1459 | static int calc_h_ref_to_sync(const struct drm_display_mode *mode, |
| 1460 | unsigned int *value) |
| 1461 | { |
| 1462 | unsigned int hfp, hsw, hbp, a = 0, b; |
| 1463 | |
| 1464 | hfp = mode->hsync_start - mode->hdisplay; |
| 1465 | hsw = mode->hsync_end - mode->hsync_start; |
| 1466 | hbp = mode->htotal - mode->hsync_end; |
| 1467 | |
| 1468 | pr_info("hfp: %u, hsw: %u, hbp: %u\n", hfp, hsw, hbp); |
| 1469 | |
| 1470 | b = hfp - 1; |
| 1471 | |
| 1472 | pr_info("a: %u, b: %u\n", a, b); |
| 1473 | pr_info("a + hsw + hbp = %u\n", a + hsw + hbp); |
| 1474 | |
| 1475 | if (a + hsw + hbp <= 11) { |
| 1476 | a = 1 + 11 - hsw - hbp; |
| 1477 | pr_info("a: %u\n", a); |
| 1478 | } |
| 1479 | |
| 1480 | if (a > b) |
| 1481 | return -EINVAL; |
| 1482 | |
| 1483 | if (hsw < 1) |
| 1484 | return -EINVAL; |
| 1485 | |
| 1486 | if (mode->hdisplay < 16) |
| 1487 | return -EINVAL; |
| 1488 | |
| 1489 | if (value) { |
| 1490 | if (b > a && a % 2) |
| 1491 | *value = a + 1; |
| 1492 | else |
| 1493 | *value = a; |
| 1494 | } |
| 1495 | |
| 1496 | return 0; |
| 1497 | } |
| 1498 | #endif |
| 1499 | |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1500 | static void tegra_sor_edp_enable(struct drm_encoder *encoder) |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1501 | { |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1502 | struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1503 | struct tegra_output *output = encoder_to_output(encoder); |
| 1504 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1505 | struct tegra_sor *sor = to_sor(output); |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1506 | struct tegra_sor_config config; |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1507 | struct tegra_sor_state *state; |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1508 | struct drm_dp_link link; |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1509 | u8 rate, lanes; |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 1510 | unsigned int i; |
| Thierry Reding | 86f5c52 | 2014-03-26 11:13:16 +0100 | [diff] [blame] | 1511 | int err = 0; |
| Thierry Reding | 28fe207 | 2015-01-26 16:02:48 +0100 | [diff] [blame] | 1512 | u32 value; |
| Thierry Reding | 86f5c52 | 2014-03-26 11:13:16 +0100 | [diff] [blame] | 1513 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1514 | state = to_sor_state(output->connector.state); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1515 | |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 1516 | pm_runtime_get_sync(sor->dev); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1517 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1518 | if (output->panel) |
| 1519 | drm_panel_prepare(output->panel); |
| 1520 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1521 | err = drm_dp_aux_enable(sor->aux); |
| 1522 | if (err < 0) |
| 1523 | dev_err(sor->dev, "failed to enable DP: %d\n", err); |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1524 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1525 | err = drm_dp_link_probe(sor->aux, &link); |
| 1526 | if (err < 0) { |
| 1527 | dev_err(sor->dev, "failed to probe eDP link: %d\n", err); |
| 1528 | return; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1529 | } |
| 1530 | |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1531 | /* switch to safe parent clock */ |
| 1532 | err = tegra_sor_set_parent_clock(sor, sor->clk_safe); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1533 | if (err < 0) |
| 1534 | dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); |
| 1535 | |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1536 | memset(&config, 0, sizeof(config)); |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1537 | config.bits_per_pixel = state->bpc * 3; |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1538 | |
| Thierry Reding | a198359 | 2015-07-21 16:46:52 +0200 | [diff] [blame] | 1539 | err = tegra_sor_compute_config(sor, mode, &config, &link); |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1540 | if (err < 0) |
| Thierry Reding | a198359 | 2015-07-21 16:46:52 +0200 | [diff] [blame] | 1541 | dev_err(sor->dev, "failed to compute configuration: %d\n", err); |
| Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1542 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1543 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1544 | value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; |
| 1545 | value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK; |
| 1546 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 1547 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1548 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1549 | value &= ~SOR_PLL2_BANDGAP_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1550 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1551 | usleep_range(20, 100); |
| 1552 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1553 | value = tegra_sor_readl(sor, sor->soc->regs->pll3); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1554 | value |= SOR_PLL3_PLL_VDD_MODE_3V3; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1555 | tegra_sor_writel(sor, value, sor->soc->regs->pll3); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1556 | |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1557 | value = SOR_PLL0_ICHPMP(0xf) | SOR_PLL0_VCOCAP_RST | |
| 1558 | SOR_PLL0_PLLREG_LEVEL_V45 | SOR_PLL0_RESISTOR_EXT; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1559 | tegra_sor_writel(sor, value, sor->soc->regs->pll0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1560 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1561 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1562 | value |= SOR_PLL2_SEQ_PLLCAPPD; |
| 1563 | value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| 1564 | value |= SOR_PLL2_LVDS_ENABLE; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1565 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1566 | |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1567 | value = SOR_PLL1_TERM_COMPOUT | SOR_PLL1_TMDS_TERM; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1568 | tegra_sor_writel(sor, value, sor->soc->regs->pll1); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1569 | |
| 1570 | while (true) { |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1571 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1572 | if ((value & SOR_PLL2_SEQ_PLLCAPPD_ENFORCE) == 0) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1573 | break; |
| 1574 | |
| 1575 | usleep_range(250, 1000); |
| 1576 | } |
| 1577 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1578 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1579 | value &= ~SOR_PLL2_POWERDOWN_OVERRIDE; |
| 1580 | value &= ~SOR_PLL2_PORT_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1581 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1582 | |
| 1583 | /* |
| 1584 | * power up |
| 1585 | */ |
| 1586 | |
| 1587 | /* set safe link bandwidth (1.62 Gbps) */ |
| 1588 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1589 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
| 1590 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62; |
| 1591 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 1592 | |
| 1593 | /* step 1 */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1594 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1595 | value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE | SOR_PLL2_PORT_POWERDOWN | |
| 1596 | SOR_PLL2_BANDGAP_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1597 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1598 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1599 | value = tegra_sor_readl(sor, sor->soc->regs->pll0); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1600 | value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1601 | tegra_sor_writel(sor, value, sor->soc->regs->pll0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1602 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1603 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1604 | value &= ~SOR_DP_PADCTL_PAD_CAL_PD; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1605 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1606 | |
| 1607 | /* step 2 */ |
| 1608 | err = tegra_io_rail_power_on(TEGRA_IO_RAIL_LVDS); |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1609 | if (err < 0) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1610 | dev_err(sor->dev, "failed to power on I/O rail: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1611 | |
| 1612 | usleep_range(5, 100); |
| 1613 | |
| 1614 | /* step 3 */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1615 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1616 | value &= ~SOR_PLL2_BANDGAP_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1617 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1618 | |
| 1619 | usleep_range(20, 100); |
| 1620 | |
| 1621 | /* step 4 */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1622 | value = tegra_sor_readl(sor, sor->soc->regs->pll0); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1623 | value &= ~SOR_PLL0_VCOPD; |
| 1624 | value &= ~SOR_PLL0_PWR; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1625 | tegra_sor_writel(sor, value, sor->soc->regs->pll0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1626 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1627 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1628 | value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1629 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1630 | |
| 1631 | usleep_range(200, 1000); |
| 1632 | |
| 1633 | /* step 5 */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1634 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1635 | value &= ~SOR_PLL2_PORT_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1636 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1637 | |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 1638 | /* XXX not in TRM */ |
| 1639 | for (value = 0, i = 0; i < 5; i++) |
| 1640 | value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) | |
| 1641 | SOR_XBAR_CTRL_LINK1_XSEL(i, i); |
| 1642 | |
| 1643 | tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL); |
| 1644 | tegra_sor_writel(sor, value, SOR_XBAR_CTRL); |
| 1645 | |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1646 | /* switch to DP parent clock */ |
| 1647 | err = tegra_sor_set_parent_clock(sor, sor->clk_dp); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1648 | if (err < 0) |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1649 | dev_err(sor->dev, "failed to set parent clock: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1650 | |
| Thierry Reding | 899451b | 2014-06-05 16:19:48 +0200 | [diff] [blame] | 1651 | /* power DP lanes */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1652 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 899451b | 2014-06-05 16:19:48 +0200 | [diff] [blame] | 1653 | |
| 1654 | if (link.num_lanes <= 2) |
| 1655 | value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2); |
| 1656 | else |
| 1657 | value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2; |
| 1658 | |
| 1659 | if (link.num_lanes <= 1) |
| 1660 | value &= ~SOR_DP_PADCTL_PD_TXD_1; |
| 1661 | else |
| 1662 | value |= SOR_DP_PADCTL_PD_TXD_1; |
| 1663 | |
| 1664 | if (link.num_lanes == 0) |
| 1665 | value &= ~SOR_DP_PADCTL_PD_TXD_0; |
| 1666 | else |
| 1667 | value |= SOR_DP_PADCTL_PD_TXD_0; |
| 1668 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1669 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1670 | |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1671 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1672 | value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK; |
| Thierry Reding | 0c90a18 | 2014-06-05 16:29:46 +0200 | [diff] [blame] | 1673 | value |= SOR_DP_LINKCTL_LANE_COUNT(link.num_lanes); |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1674 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1675 | |
| 1676 | /* start lane sequencer */ |
| 1677 | value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN | |
| 1678 | SOR_LANE_SEQ_CTL_POWER_STATE_UP; |
| 1679 | tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); |
| 1680 | |
| 1681 | while (true) { |
| 1682 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 1683 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) |
| 1684 | break; |
| 1685 | |
| 1686 | usleep_range(250, 1000); |
| 1687 | } |
| 1688 | |
| Thierry Reding | a4263fe | 2014-06-05 16:16:23 +0200 | [diff] [blame] | 1689 | /* set link bandwidth */ |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1690 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1691 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
| Thierry Reding | a4263fe | 2014-06-05 16:16:23 +0200 | [diff] [blame] | 1692 | value |= drm_dp_link_rate_to_bw_code(link.rate) << 2; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1693 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 1694 | |
| Thierry Reding | 402f6bc | 2015-07-21 16:48:19 +0200 | [diff] [blame] | 1695 | tegra_sor_apply_config(sor, &config); |
| 1696 | |
| 1697 | /* enable link */ |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1698 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1699 | value |= SOR_DP_LINKCTL_ENABLE; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1700 | value |= SOR_DP_LINKCTL_ENHANCED_FRAME; |
| Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1701 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1702 | |
| 1703 | for (i = 0, value = 0; i < 4; i++) { |
| 1704 | unsigned long lane = SOR_DP_TPG_CHANNEL_CODING | |
| 1705 | SOR_DP_TPG_SCRAMBLER_GALIOS | |
| 1706 | SOR_DP_TPG_PATTERN_NONE; |
| 1707 | value = (value << 8) | lane; |
| 1708 | } |
| 1709 | |
| 1710 | tegra_sor_writel(sor, value, SOR_DP_TPG); |
| 1711 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1712 | /* enable pad calibration logic */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1713 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1714 | value |= SOR_DP_PADCTL_PAD_CAL_PD; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 1715 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1716 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1717 | err = drm_dp_link_probe(sor->aux, &link); |
| 1718 | if (err < 0) |
| 1719 | dev_err(sor->dev, "failed to probe eDP link: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1720 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1721 | err = drm_dp_link_power_up(sor->aux, &link); |
| 1722 | if (err < 0) |
| 1723 | dev_err(sor->dev, "failed to power up eDP link: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1724 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1725 | err = drm_dp_link_configure(sor->aux, &link); |
| 1726 | if (err < 0) |
| 1727 | dev_err(sor->dev, "failed to configure eDP link: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1728 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1729 | rate = drm_dp_link_rate_to_bw_code(link.rate); |
| 1730 | lanes = link.num_lanes; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1731 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1732 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1733 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
| 1734 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED(rate); |
| 1735 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1736 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1737 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
| 1738 | value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK; |
| 1739 | value |= SOR_DP_LINKCTL_LANE_COUNT(lanes); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1740 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1741 | if (link.capabilities & DP_LINK_CAP_ENHANCED_FRAMING) |
| 1742 | value |= SOR_DP_LINKCTL_ENHANCED_FRAME; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1743 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1744 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1745 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1746 | /* disable training pattern generator */ |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1747 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1748 | for (i = 0; i < link.num_lanes; i++) { |
| 1749 | unsigned long lane = SOR_DP_TPG_CHANNEL_CODING | |
| 1750 | SOR_DP_TPG_SCRAMBLER_GALIOS | |
| 1751 | SOR_DP_TPG_PATTERN_NONE; |
| 1752 | value = (value << 8) | lane; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1753 | } |
| 1754 | |
| Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1755 | tegra_sor_writel(sor, value, SOR_DP_TPG); |
| 1756 | |
| 1757 | err = tegra_sor_dp_train_fast(sor, &link); |
| 1758 | if (err < 0) |
| 1759 | dev_err(sor->dev, "DP fast link training failed: %d\n", err); |
| 1760 | |
| 1761 | dev_dbg(sor->dev, "fast link training succeeded\n"); |
| 1762 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1763 | err = tegra_sor_power_up(sor, 250); |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1764 | if (err < 0) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1765 | dev_err(sor->dev, "failed to power up SOR: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1766 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1767 | /* CSTM (LVDS, link A/B, upper) */ |
| Stéphane Marchesin | 143b1df | 2014-05-22 20:32:47 -0700 | [diff] [blame] | 1768 | value = SOR_CSTM_LVDS | SOR_CSTM_LINK_ACT_A | SOR_CSTM_LINK_ACT_B | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1769 | SOR_CSTM_UPPER; |
| 1770 | tegra_sor_writel(sor, value, SOR_CSTM); |
| 1771 | |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 1772 | /* use DP-A protocol */ |
| 1773 | value = tegra_sor_readl(sor, SOR_STATE1); |
| 1774 | value &= ~SOR_STATE_ASY_PROTOCOL_MASK; |
| 1775 | value |= SOR_STATE_ASY_PROTOCOL_DP_A; |
| 1776 | tegra_sor_writel(sor, value, SOR_STATE1); |
| 1777 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1778 | tegra_sor_mode_set(sor, mode, state); |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 1779 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1780 | /* PWM setup */ |
| 1781 | err = tegra_sor_setup_pwm(sor, 250); |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1782 | if (err < 0) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1783 | dev_err(sor->dev, "failed to setup PWM: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1784 | |
| Thierry Reding | 666cb87 | 2014-12-08 16:32:47 +0100 | [diff] [blame] | 1785 | tegra_sor_update(sor); |
| 1786 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1787 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 1788 | value |= SOR_ENABLE; |
| 1789 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 1790 | |
| Thierry Reding | 666cb87 | 2014-12-08 16:32:47 +0100 | [diff] [blame] | 1791 | tegra_dc_commit(dc); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1792 | |
| 1793 | err = tegra_sor_attach(sor); |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1794 | if (err < 0) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1795 | dev_err(sor->dev, "failed to attach SOR: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1796 | |
| 1797 | err = tegra_sor_wakeup(sor); |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1798 | if (err < 0) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1799 | dev_err(sor->dev, "failed to enable DC: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1800 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1801 | if (output->panel) |
| 1802 | drm_panel_enable(output->panel); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1803 | } |
| 1804 | |
| Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1805 | static int |
| 1806 | tegra_sor_encoder_atomic_check(struct drm_encoder *encoder, |
| 1807 | struct drm_crtc_state *crtc_state, |
| 1808 | struct drm_connector_state *conn_state) |
| 1809 | { |
| 1810 | struct tegra_output *output = encoder_to_output(encoder); |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1811 | struct tegra_sor_state *state = to_sor_state(conn_state); |
| Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1812 | struct tegra_dc *dc = to_tegra_dc(conn_state->crtc); |
| 1813 | unsigned long pclk = crtc_state->mode.clock * 1000; |
| 1814 | struct tegra_sor *sor = to_sor(output); |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1815 | struct drm_display_info *info; |
| Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1816 | int err; |
| 1817 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1818 | info = &output->connector.display_info; |
| 1819 | |
| Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1820 | err = tegra_dc_state_setup_clock(dc, crtc_state, sor->clk_parent, |
| 1821 | pclk, 0); |
| 1822 | if (err < 0) { |
| 1823 | dev_err(output->dev, "failed to setup CRTC state: %d\n", err); |
| 1824 | return err; |
| 1825 | } |
| 1826 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 1827 | switch (info->bpc) { |
| 1828 | case 8: |
| 1829 | case 6: |
| 1830 | state->bpc = info->bpc; |
| 1831 | break; |
| 1832 | |
| 1833 | default: |
| 1834 | DRM_DEBUG_KMS("%u bits-per-color not supported\n", info->bpc); |
| 1835 | state->bpc = 8; |
| 1836 | break; |
| 1837 | } |
| 1838 | |
| Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1839 | return 0; |
| 1840 | } |
| 1841 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1842 | static const struct drm_encoder_helper_funcs tegra_sor_edp_helpers = { |
| Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1843 | .disable = tegra_sor_edp_disable, |
| 1844 | .enable = tegra_sor_edp_enable, |
| Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1845 | .atomic_check = tegra_sor_encoder_atomic_check, |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1846 | }; |
| 1847 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1848 | static inline u32 tegra_sor_hdmi_subpack(const u8 *ptr, size_t size) |
| 1849 | { |
| 1850 | u32 value = 0; |
| 1851 | size_t i; |
| 1852 | |
| 1853 | for (i = size; i > 0; i--) |
| 1854 | value = (value << 8) | ptr[i - 1]; |
| 1855 | |
| 1856 | return value; |
| 1857 | } |
| 1858 | |
| 1859 | static void tegra_sor_hdmi_write_infopack(struct tegra_sor *sor, |
| 1860 | const void *data, size_t size) |
| 1861 | { |
| 1862 | const u8 *ptr = data; |
| 1863 | unsigned long offset; |
| 1864 | size_t i, j; |
| 1865 | u32 value; |
| 1866 | |
| 1867 | switch (ptr[0]) { |
| 1868 | case HDMI_INFOFRAME_TYPE_AVI: |
| 1869 | offset = SOR_HDMI_AVI_INFOFRAME_HEADER; |
| 1870 | break; |
| 1871 | |
| 1872 | case HDMI_INFOFRAME_TYPE_AUDIO: |
| 1873 | offset = SOR_HDMI_AUDIO_INFOFRAME_HEADER; |
| 1874 | break; |
| 1875 | |
| 1876 | case HDMI_INFOFRAME_TYPE_VENDOR: |
| 1877 | offset = SOR_HDMI_VSI_INFOFRAME_HEADER; |
| 1878 | break; |
| 1879 | |
| 1880 | default: |
| 1881 | dev_err(sor->dev, "unsupported infoframe type: %02x\n", |
| 1882 | ptr[0]); |
| 1883 | return; |
| 1884 | } |
| 1885 | |
| 1886 | value = INFOFRAME_HEADER_TYPE(ptr[0]) | |
| 1887 | INFOFRAME_HEADER_VERSION(ptr[1]) | |
| 1888 | INFOFRAME_HEADER_LEN(ptr[2]); |
| 1889 | tegra_sor_writel(sor, value, offset); |
| 1890 | offset++; |
| 1891 | |
| 1892 | /* |
| 1893 | * Each subpack contains 7 bytes, divided into: |
| 1894 | * - subpack_low: bytes 0 - 3 |
| 1895 | * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00) |
| 1896 | */ |
| 1897 | for (i = 3, j = 0; i < size; i += 7, j += 8) { |
| 1898 | size_t rem = size - i, num = min_t(size_t, rem, 4); |
| 1899 | |
| 1900 | value = tegra_sor_hdmi_subpack(&ptr[i], num); |
| 1901 | tegra_sor_writel(sor, value, offset++); |
| 1902 | |
| 1903 | num = min_t(size_t, rem - num, 3); |
| 1904 | |
| 1905 | value = tegra_sor_hdmi_subpack(&ptr[i + 4], num); |
| 1906 | tegra_sor_writel(sor, value, offset++); |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | static int |
| 1911 | tegra_sor_hdmi_setup_avi_infoframe(struct tegra_sor *sor, |
| 1912 | const struct drm_display_mode *mode) |
| 1913 | { |
| 1914 | u8 buffer[HDMI_INFOFRAME_SIZE(AVI)]; |
| 1915 | struct hdmi_avi_infoframe frame; |
| 1916 | u32 value; |
| 1917 | int err; |
| 1918 | |
| 1919 | /* disable AVI infoframe */ |
| 1920 | value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL); |
| 1921 | value &= ~INFOFRAME_CTRL_SINGLE; |
| 1922 | value &= ~INFOFRAME_CTRL_OTHER; |
| 1923 | value &= ~INFOFRAME_CTRL_ENABLE; |
| 1924 | tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL); |
| 1925 | |
| Shashank Sharma | 0c1f528 | 2017-07-13 21:03:07 +0530 | [diff] [blame] | 1926 | err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode, false); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1927 | if (err < 0) { |
| 1928 | dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err); |
| 1929 | return err; |
| 1930 | } |
| 1931 | |
| 1932 | err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 1933 | if (err < 0) { |
| 1934 | dev_err(sor->dev, "failed to pack AVI infoframe: %d\n", err); |
| 1935 | return err; |
| 1936 | } |
| 1937 | |
| 1938 | tegra_sor_hdmi_write_infopack(sor, buffer, err); |
| 1939 | |
| 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); |
| 1945 | |
| 1946 | return 0; |
| 1947 | } |
| 1948 | |
| 1949 | static void tegra_sor_hdmi_disable_audio_infoframe(struct tegra_sor *sor) |
| 1950 | { |
| 1951 | u32 value; |
| 1952 | |
| 1953 | value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_INFOFRAME_CTRL); |
| 1954 | value &= ~INFOFRAME_CTRL_ENABLE; |
| 1955 | tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_INFOFRAME_CTRL); |
| 1956 | } |
| 1957 | |
| 1958 | static struct tegra_sor_hdmi_settings * |
| 1959 | tegra_sor_hdmi_find_settings(struct tegra_sor *sor, unsigned long frequency) |
| 1960 | { |
| 1961 | unsigned int i; |
| 1962 | |
| 1963 | for (i = 0; i < sor->num_settings; i++) |
| 1964 | if (frequency <= sor->settings[i].frequency) |
| 1965 | return &sor->settings[i]; |
| 1966 | |
| 1967 | return NULL; |
| 1968 | } |
| 1969 | |
| 1970 | static void tegra_sor_hdmi_disable(struct drm_encoder *encoder) |
| 1971 | { |
| 1972 | struct tegra_output *output = encoder_to_output(encoder); |
| 1973 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
| 1974 | struct tegra_sor *sor = to_sor(output); |
| 1975 | u32 value; |
| 1976 | int err; |
| 1977 | |
| 1978 | err = tegra_sor_detach(sor); |
| 1979 | if (err < 0) |
| 1980 | dev_err(sor->dev, "failed to detach SOR: %d\n", err); |
| 1981 | |
| 1982 | tegra_sor_writel(sor, 0, SOR_STATE1); |
| 1983 | tegra_sor_update(sor); |
| 1984 | |
| 1985 | /* disable display to SOR clock */ |
| 1986 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 1987 | value &= ~SOR1_TIMING_CYA; |
| 1988 | value &= ~SOR1_ENABLE; |
| 1989 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 1990 | |
| 1991 | tegra_dc_commit(dc); |
| 1992 | |
| 1993 | err = tegra_sor_power_down(sor); |
| 1994 | if (err < 0) |
| 1995 | dev_err(sor->dev, "failed to power down SOR: %d\n", err); |
| 1996 | |
| 1997 | err = tegra_io_rail_power_off(TEGRA_IO_RAIL_HDMI); |
| 1998 | if (err < 0) |
| 1999 | dev_err(sor->dev, "failed to power off HDMI rail: %d\n", err); |
| 2000 | |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2001 | pm_runtime_put(sor->dev); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | static void tegra_sor_hdmi_enable(struct drm_encoder *encoder) |
| 2005 | { |
| 2006 | struct tegra_output *output = encoder_to_output(encoder); |
| 2007 | unsigned int h_ref_to_sync = 1, pulse_start, max_ac; |
| 2008 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2009 | struct tegra_sor_hdmi_settings *settings; |
| 2010 | struct tegra_sor *sor = to_sor(output); |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 2011 | struct tegra_sor_state *state; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2012 | struct drm_display_mode *mode; |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 2013 | unsigned int div, i; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2014 | u32 value; |
| 2015 | int err; |
| 2016 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 2017 | state = to_sor_state(output->connector.state); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2018 | mode = &encoder->crtc->state->adjusted_mode; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2019 | |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2020 | pm_runtime_get_sync(sor->dev); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2021 | |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 2022 | /* switch to safe parent clock */ |
| 2023 | err = tegra_sor_set_parent_clock(sor, sor->clk_safe); |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2024 | if (err < 0) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2025 | dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2026 | return; |
| 2027 | } |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2028 | |
| 2029 | div = clk_get_rate(sor->clk) / 1000000 * 4; |
| 2030 | |
| 2031 | err = tegra_io_rail_power_on(TEGRA_IO_RAIL_HDMI); |
| 2032 | if (err < 0) |
| 2033 | dev_err(sor->dev, "failed to power on HDMI rail: %d\n", err); |
| 2034 | |
| 2035 | usleep_range(20, 100); |
| 2036 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2037 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2038 | value &= ~SOR_PLL2_BANDGAP_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2039 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2040 | |
| 2041 | usleep_range(20, 100); |
| 2042 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2043 | value = tegra_sor_readl(sor, sor->soc->regs->pll3); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2044 | value &= ~SOR_PLL3_PLL_VDD_MODE_3V3; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2045 | tegra_sor_writel(sor, value, sor->soc->regs->pll3); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2046 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2047 | value = tegra_sor_readl(sor, sor->soc->regs->pll0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2048 | value &= ~SOR_PLL0_VCOPD; |
| 2049 | value &= ~SOR_PLL0_PWR; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2050 | tegra_sor_writel(sor, value, sor->soc->regs->pll0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2051 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2052 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2053 | value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2054 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2055 | |
| 2056 | usleep_range(200, 400); |
| 2057 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2058 | value = tegra_sor_readl(sor, sor->soc->regs->pll2); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2059 | value &= ~SOR_PLL2_POWERDOWN_OVERRIDE; |
| 2060 | value &= ~SOR_PLL2_PORT_POWERDOWN; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2061 | tegra_sor_writel(sor, value, sor->soc->regs->pll2); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2062 | |
| 2063 | usleep_range(20, 100); |
| 2064 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2065 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2066 | value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 | |
| 2067 | SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2068 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2069 | |
| 2070 | while (true) { |
| 2071 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 2072 | if ((value & SOR_LANE_SEQ_CTL_STATE_BUSY) == 0) |
| 2073 | break; |
| 2074 | |
| 2075 | usleep_range(250, 1000); |
| 2076 | } |
| 2077 | |
| 2078 | value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN | |
| 2079 | SOR_LANE_SEQ_CTL_POWER_STATE_UP | SOR_LANE_SEQ_CTL_DELAY(5); |
| 2080 | tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); |
| 2081 | |
| 2082 | while (true) { |
| 2083 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 2084 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) |
| 2085 | break; |
| 2086 | |
| 2087 | usleep_range(250, 1000); |
| 2088 | } |
| 2089 | |
| 2090 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 2091 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
| 2092 | value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; |
| 2093 | |
| 2094 | if (mode->clock < 340000) |
| 2095 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G2_70; |
| 2096 | else |
| 2097 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G5_40; |
| 2098 | |
| 2099 | value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK; |
| 2100 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 2101 | |
| 2102 | value = tegra_sor_readl(sor, SOR_DP_SPARE0); |
| 2103 | value |= SOR_DP_SPARE_DISP_VIDEO_PREAMBLE; |
| 2104 | value &= ~SOR_DP_SPARE_PANEL_INTERNAL; |
| 2105 | value |= SOR_DP_SPARE_SEQ_ENABLE; |
| 2106 | tegra_sor_writel(sor, value, SOR_DP_SPARE0); |
| 2107 | |
| 2108 | value = SOR_SEQ_CTL_PU_PC(0) | SOR_SEQ_CTL_PU_PC_ALT(0) | |
| 2109 | SOR_SEQ_CTL_PD_PC(8) | SOR_SEQ_CTL_PD_PC_ALT(8); |
| 2110 | tegra_sor_writel(sor, value, SOR_SEQ_CTL); |
| 2111 | |
| 2112 | value = SOR_SEQ_INST_DRIVE_PWM_OUT_LO | SOR_SEQ_INST_HALT | |
| 2113 | SOR_SEQ_INST_WAIT_VSYNC | SOR_SEQ_INST_WAIT(1); |
| 2114 | tegra_sor_writel(sor, value, SOR_SEQ_INST(0)); |
| 2115 | tegra_sor_writel(sor, value, SOR_SEQ_INST(8)); |
| 2116 | |
| 2117 | /* program the reference clock */ |
| 2118 | value = SOR_REFCLK_DIV_INT(div) | SOR_REFCLK_DIV_FRAC(div); |
| 2119 | tegra_sor_writel(sor, value, SOR_REFCLK); |
| 2120 | |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 2121 | /* XXX not in TRM */ |
| 2122 | for (value = 0, i = 0; i < 5; i++) |
| 2123 | value |= SOR_XBAR_CTRL_LINK0_XSEL(i, sor->soc->xbar_cfg[i]) | |
| 2124 | SOR_XBAR_CTRL_LINK1_XSEL(i, i); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2125 | |
| 2126 | tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL); |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 2127 | tegra_sor_writel(sor, value, SOR_XBAR_CTRL); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2128 | |
| Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 2129 | /* switch to parent clock */ |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2130 | err = clk_set_parent(sor->clk, sor->clk_parent); |
| 2131 | if (err < 0) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2132 | dev_err(sor->dev, "failed to set parent clock: %d\n", err); |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | err = tegra_sor_set_parent_clock(sor, sor->clk_pad); |
| 2137 | if (err < 0) { |
| 2138 | dev_err(sor->dev, "failed to set pad clock: %d\n", err); |
| 2139 | return; |
| 2140 | } |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2141 | |
| 2142 | value = SOR_INPUT_CONTROL_HDMI_SRC_SELECT(dc->pipe); |
| 2143 | |
| 2144 | /* XXX is this the proper check? */ |
| 2145 | if (mode->clock < 75000) |
| 2146 | value |= SOR_INPUT_CONTROL_ARM_VIDEO_RANGE_LIMITED; |
| 2147 | |
| 2148 | tegra_sor_writel(sor, value, SOR_INPUT_CONTROL); |
| 2149 | |
| 2150 | max_ac = ((mode->htotal - mode->hdisplay) - SOR_REKEY - 18) / 32; |
| 2151 | |
| 2152 | value = SOR_HDMI_CTRL_ENABLE | SOR_HDMI_CTRL_MAX_AC_PACKET(max_ac) | |
| 2153 | SOR_HDMI_CTRL_AUDIO_LAYOUT | SOR_HDMI_CTRL_REKEY(SOR_REKEY); |
| 2154 | tegra_sor_writel(sor, value, SOR_HDMI_CTRL); |
| 2155 | |
| 2156 | /* H_PULSE2 setup */ |
| 2157 | pulse_start = h_ref_to_sync + (mode->hsync_end - mode->hsync_start) + |
| 2158 | (mode->htotal - mode->hsync_end) - 10; |
| 2159 | |
| 2160 | value = PULSE_LAST_END_A | PULSE_QUAL_VACTIVE | |
| 2161 | PULSE_POLARITY_HIGH | PULSE_MODE_NORMAL; |
| 2162 | tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL); |
| 2163 | |
| 2164 | value = PULSE_END(pulse_start + 8) | PULSE_START(pulse_start); |
| 2165 | tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A); |
| 2166 | |
| 2167 | value = tegra_dc_readl(dc, DC_DISP_DISP_SIGNAL_OPTIONS0); |
| 2168 | value |= H_PULSE2_ENABLE; |
| 2169 | tegra_dc_writel(dc, value, DC_DISP_DISP_SIGNAL_OPTIONS0); |
| 2170 | |
| 2171 | /* infoframe setup */ |
| 2172 | err = tegra_sor_hdmi_setup_avi_infoframe(sor, mode); |
| 2173 | if (err < 0) |
| 2174 | dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err); |
| 2175 | |
| 2176 | /* XXX HDMI audio support not implemented yet */ |
| 2177 | tegra_sor_hdmi_disable_audio_infoframe(sor); |
| 2178 | |
| 2179 | /* use single TMDS protocol */ |
| 2180 | value = tegra_sor_readl(sor, SOR_STATE1); |
| 2181 | value &= ~SOR_STATE_ASY_PROTOCOL_MASK; |
| 2182 | value |= SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A; |
| 2183 | tegra_sor_writel(sor, value, SOR_STATE1); |
| 2184 | |
| 2185 | /* power up pad calibration */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2186 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2187 | value &= ~SOR_DP_PADCTL_PAD_CAL_PD; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2188 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2189 | |
| 2190 | /* production settings */ |
| 2191 | settings = tegra_sor_hdmi_find_settings(sor, mode->clock * 1000); |
| Dan Carpenter | db8b42f | 2015-08-17 17:37:03 +0300 | [diff] [blame] | 2192 | if (!settings) { |
| 2193 | dev_err(sor->dev, "no settings for pixel clock %d Hz\n", |
| 2194 | mode->clock * 1000); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2195 | return; |
| 2196 | } |
| 2197 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2198 | value = tegra_sor_readl(sor, sor->soc->regs->pll0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2199 | value &= ~SOR_PLL0_ICHPMP_MASK; |
| 2200 | value &= ~SOR_PLL0_VCOCAP_MASK; |
| 2201 | value |= SOR_PLL0_ICHPMP(settings->ichpmp); |
| 2202 | value |= SOR_PLL0_VCOCAP(settings->vcocap); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2203 | tegra_sor_writel(sor, value, sor->soc->regs->pll0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2204 | |
| 2205 | tegra_sor_dp_term_calibrate(sor); |
| 2206 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2207 | value = tegra_sor_readl(sor, sor->soc->regs->pll1); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2208 | value &= ~SOR_PLL1_LOADADJ_MASK; |
| 2209 | value |= SOR_PLL1_LOADADJ(settings->loadadj); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2210 | tegra_sor_writel(sor, value, sor->soc->regs->pll1); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2211 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2212 | value = tegra_sor_readl(sor, sor->soc->regs->pll3); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2213 | value &= ~SOR_PLL3_BG_VREF_LEVEL_MASK; |
| 2214 | value |= SOR_PLL3_BG_VREF_LEVEL(settings->bg_vref); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2215 | tegra_sor_writel(sor, value, sor->soc->regs->pll3); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2216 | |
| 2217 | value = settings->drive_current[0] << 24 | |
| 2218 | settings->drive_current[1] << 16 | |
| 2219 | settings->drive_current[2] << 8 | |
| 2220 | settings->drive_current[3] << 0; |
| 2221 | tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0); |
| 2222 | |
| 2223 | value = settings->preemphasis[0] << 24 | |
| 2224 | settings->preemphasis[1] << 16 | |
| 2225 | settings->preemphasis[2] << 8 | |
| 2226 | settings->preemphasis[3] << 0; |
| 2227 | tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0); |
| 2228 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2229 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2230 | value &= ~SOR_DP_PADCTL_TX_PU_MASK; |
| 2231 | value |= SOR_DP_PADCTL_TX_PU_ENABLE; |
| 2232 | value |= SOR_DP_PADCTL_TX_PU(settings->tx_pu); |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2233 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2234 | |
| 2235 | /* power down pad calibration */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2236 | value = tegra_sor_readl(sor, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2237 | value |= SOR_DP_PADCTL_PAD_CAL_PD; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2238 | tegra_sor_writel(sor, value, sor->soc->regs->dp_padctl0); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2239 | |
| 2240 | /* miscellaneous display controller settings */ |
| 2241 | value = VSYNC_H_POSITION(1); |
| 2242 | tegra_dc_writel(dc, value, DC_DISP_DISP_TIMING_OPTIONS); |
| 2243 | |
| 2244 | value = tegra_dc_readl(dc, DC_DISP_DISP_COLOR_CONTROL); |
| 2245 | value &= ~DITHER_CONTROL_MASK; |
| 2246 | value &= ~BASE_COLOR_SIZE_MASK; |
| 2247 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 2248 | switch (state->bpc) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2249 | case 6: |
| 2250 | value |= BASE_COLOR_SIZE_666; |
| 2251 | break; |
| 2252 | |
| 2253 | case 8: |
| 2254 | value |= BASE_COLOR_SIZE_888; |
| 2255 | break; |
| 2256 | |
| 2257 | default: |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 2258 | WARN(1, "%u bits-per-color not supported\n", state->bpc); |
| 2259 | value |= BASE_COLOR_SIZE_888; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2260 | break; |
| 2261 | } |
| 2262 | |
| 2263 | tegra_dc_writel(dc, value, DC_DISP_DISP_COLOR_CONTROL); |
| 2264 | |
| 2265 | err = tegra_sor_power_up(sor, 250); |
| 2266 | if (err < 0) |
| 2267 | dev_err(sor->dev, "failed to power up SOR: %d\n", err); |
| 2268 | |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 2269 | /* configure dynamic range of output */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2270 | value = tegra_sor_readl(sor, sor->soc->regs->head_state0 + dc->pipe); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2271 | value &= ~SOR_HEAD_STATE_RANGECOMPRESS_MASK; |
| 2272 | value &= ~SOR_HEAD_STATE_DYNRANGE_MASK; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2273 | tegra_sor_writel(sor, value, sor->soc->regs->head_state0 + dc->pipe); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2274 | |
| Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame] | 2275 | /* configure colorspace */ |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2276 | value = tegra_sor_readl(sor, sor->soc->regs->head_state0 + dc->pipe); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2277 | value &= ~SOR_HEAD_STATE_COLORSPACE_MASK; |
| 2278 | value |= SOR_HEAD_STATE_COLORSPACE_RGB; |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2279 | tegra_sor_writel(sor, value, sor->soc->regs->head_state0 + dc->pipe); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2280 | |
| Thierry Reding | c31efa7 | 2015-09-08 16:09:22 +0200 | [diff] [blame] | 2281 | tegra_sor_mode_set(sor, mode, state); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2282 | |
| 2283 | tegra_sor_update(sor); |
| 2284 | |
| 2285 | err = tegra_sor_attach(sor); |
| 2286 | if (err < 0) |
| 2287 | dev_err(sor->dev, "failed to attach SOR: %d\n", err); |
| 2288 | |
| 2289 | /* enable display to SOR clock and generate HDMI preamble */ |
| 2290 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 2291 | value |= SOR1_ENABLE | SOR1_TIMING_CYA; |
| 2292 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 2293 | |
| 2294 | tegra_dc_commit(dc); |
| 2295 | |
| 2296 | err = tegra_sor_wakeup(sor); |
| 2297 | if (err < 0) |
| 2298 | dev_err(sor->dev, "failed to wakeup SOR: %d\n", err); |
| 2299 | } |
| 2300 | |
| 2301 | static const struct drm_encoder_helper_funcs tegra_sor_hdmi_helpers = { |
| 2302 | .disable = tegra_sor_hdmi_disable, |
| 2303 | .enable = tegra_sor_hdmi_enable, |
| 2304 | .atomic_check = tegra_sor_encoder_atomic_check, |
| 2305 | }; |
| 2306 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2307 | static int tegra_sor_init(struct host1x_client *client) |
| 2308 | { |
| Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 2309 | struct drm_device *drm = dev_get_drvdata(client->parent); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2310 | const struct drm_encoder_helper_funcs *helpers = NULL; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2311 | struct tegra_sor *sor = host1x_client_to_sor(client); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2312 | int connector = DRM_MODE_CONNECTOR_Unknown; |
| 2313 | int encoder = DRM_MODE_ENCODER_NONE; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2314 | int err; |
| 2315 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2316 | if (!sor->aux) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2317 | if (sor->soc->supports_hdmi) { |
| 2318 | connector = DRM_MODE_CONNECTOR_HDMIA; |
| 2319 | encoder = DRM_MODE_ENCODER_TMDS; |
| 2320 | helpers = &tegra_sor_hdmi_helpers; |
| 2321 | } else if (sor->soc->supports_lvds) { |
| 2322 | connector = DRM_MODE_CONNECTOR_LVDS; |
| 2323 | encoder = DRM_MODE_ENCODER_LVDS; |
| 2324 | } |
| 2325 | } else { |
| 2326 | if (sor->soc->supports_edp) { |
| 2327 | connector = DRM_MODE_CONNECTOR_eDP; |
| 2328 | encoder = DRM_MODE_ENCODER_TMDS; |
| 2329 | helpers = &tegra_sor_edp_helpers; |
| 2330 | } else if (sor->soc->supports_dp) { |
| 2331 | connector = DRM_MODE_CONNECTOR_DisplayPort; |
| 2332 | encoder = DRM_MODE_ENCODER_TMDS; |
| 2333 | } |
| 2334 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2335 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2336 | sor->output.dev = sor->dev; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2337 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2338 | drm_connector_init(drm, &sor->output.connector, |
| 2339 | &tegra_sor_connector_funcs, |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2340 | connector); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2341 | drm_connector_helper_add(&sor->output.connector, |
| 2342 | &tegra_sor_connector_helper_funcs); |
| 2343 | sor->output.connector.dpms = DRM_MODE_DPMS_OFF; |
| 2344 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2345 | drm_encoder_init(drm, &sor->output.encoder, &tegra_sor_encoder_funcs, |
| Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 2346 | encoder, NULL); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2347 | drm_encoder_helper_add(&sor->output.encoder, helpers); |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2348 | |
| 2349 | drm_mode_connector_attach_encoder(&sor->output.connector, |
| 2350 | &sor->output.encoder); |
| 2351 | drm_connector_register(&sor->output.connector); |
| 2352 | |
| Thierry Reding | ea130b2 | 2014-12-19 15:51:35 +0100 | [diff] [blame] | 2353 | err = tegra_output_init(drm, &sor->output); |
| 2354 | if (err < 0) { |
| 2355 | dev_err(client->dev, "failed to initialize output: %d\n", err); |
| 2356 | return err; |
| 2357 | } |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2358 | |
| Thierry Reding | ea130b2 | 2014-12-19 15:51:35 +0100 | [diff] [blame] | 2359 | sor->output.encoder.possible_crtcs = 0x3; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2360 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2361 | if (sor->aux) { |
| 2362 | err = drm_dp_aux_attach(sor->aux, &sor->output); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2363 | if (err < 0) { |
| 2364 | dev_err(sor->dev, "failed to attach DP: %d\n", err); |
| 2365 | return err; |
| 2366 | } |
| 2367 | } |
| 2368 | |
| Tomeu Vizoso | 535a65d | 2015-03-30 10:33:03 +0200 | [diff] [blame] | 2369 | /* |
| 2370 | * XXX: Remove this reset once proper hand-over from firmware to |
| 2371 | * kernel is possible. |
| 2372 | */ |
| Jon Hunter | f8c7912 | 2016-07-01 14:21:38 +0100 | [diff] [blame] | 2373 | if (sor->rst) { |
| 2374 | err = reset_control_assert(sor->rst); |
| 2375 | if (err < 0) { |
| 2376 | dev_err(sor->dev, "failed to assert SOR reset: %d\n", |
| 2377 | err); |
| 2378 | return err; |
| 2379 | } |
| Tomeu Vizoso | 535a65d | 2015-03-30 10:33:03 +0200 | [diff] [blame] | 2380 | } |
| 2381 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2382 | err = clk_prepare_enable(sor->clk); |
| 2383 | if (err < 0) { |
| 2384 | dev_err(sor->dev, "failed to enable clock: %d\n", err); |
| 2385 | return err; |
| 2386 | } |
| 2387 | |
| Tomeu Vizoso | 535a65d | 2015-03-30 10:33:03 +0200 | [diff] [blame] | 2388 | usleep_range(1000, 3000); |
| 2389 | |
| Jon Hunter | f8c7912 | 2016-07-01 14:21:38 +0100 | [diff] [blame] | 2390 | if (sor->rst) { |
| 2391 | err = reset_control_deassert(sor->rst); |
| 2392 | if (err < 0) { |
| 2393 | dev_err(sor->dev, "failed to deassert SOR reset: %d\n", |
| 2394 | err); |
| 2395 | return err; |
| 2396 | } |
| Tomeu Vizoso | 535a65d | 2015-03-30 10:33:03 +0200 | [diff] [blame] | 2397 | } |
| 2398 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2399 | err = clk_prepare_enable(sor->clk_safe); |
| 2400 | if (err < 0) |
| 2401 | return err; |
| 2402 | |
| 2403 | err = clk_prepare_enable(sor->clk_dp); |
| 2404 | if (err < 0) |
| 2405 | return err; |
| 2406 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2407 | return 0; |
| 2408 | } |
| 2409 | |
| 2410 | static int tegra_sor_exit(struct host1x_client *client) |
| 2411 | { |
| 2412 | struct tegra_sor *sor = host1x_client_to_sor(client); |
| 2413 | int err; |
| 2414 | |
| Thierry Reding | 328ec69 | 2014-12-19 15:55:08 +0100 | [diff] [blame] | 2415 | tegra_output_exit(&sor->output); |
| 2416 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2417 | if (sor->aux) { |
| 2418 | err = drm_dp_aux_detach(sor->aux); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2419 | if (err < 0) { |
| 2420 | dev_err(sor->dev, "failed to detach DP: %d\n", err); |
| 2421 | return err; |
| 2422 | } |
| 2423 | } |
| 2424 | |
| Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2425 | clk_disable_unprepare(sor->clk_safe); |
| 2426 | clk_disable_unprepare(sor->clk_dp); |
| 2427 | clk_disable_unprepare(sor->clk); |
| 2428 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2429 | return 0; |
| 2430 | } |
| 2431 | |
| 2432 | static const struct host1x_client_ops sor_client_ops = { |
| 2433 | .init = tegra_sor_init, |
| 2434 | .exit = tegra_sor_exit, |
| 2435 | }; |
| 2436 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2437 | static const struct tegra_sor_ops tegra_sor_edp_ops = { |
| 2438 | .name = "eDP", |
| 2439 | }; |
| 2440 | |
| 2441 | static int tegra_sor_hdmi_probe(struct tegra_sor *sor) |
| 2442 | { |
| 2443 | int err; |
| 2444 | |
| 2445 | sor->avdd_io_supply = devm_regulator_get(sor->dev, "avdd-io"); |
| 2446 | if (IS_ERR(sor->avdd_io_supply)) { |
| 2447 | dev_err(sor->dev, "cannot get AVDD I/O supply: %ld\n", |
| 2448 | PTR_ERR(sor->avdd_io_supply)); |
| 2449 | return PTR_ERR(sor->avdd_io_supply); |
| 2450 | } |
| 2451 | |
| 2452 | err = regulator_enable(sor->avdd_io_supply); |
| 2453 | if (err < 0) { |
| 2454 | dev_err(sor->dev, "failed to enable AVDD I/O supply: %d\n", |
| 2455 | err); |
| 2456 | return err; |
| 2457 | } |
| 2458 | |
| 2459 | sor->vdd_pll_supply = devm_regulator_get(sor->dev, "vdd-pll"); |
| 2460 | if (IS_ERR(sor->vdd_pll_supply)) { |
| 2461 | dev_err(sor->dev, "cannot get VDD PLL supply: %ld\n", |
| 2462 | PTR_ERR(sor->vdd_pll_supply)); |
| 2463 | return PTR_ERR(sor->vdd_pll_supply); |
| 2464 | } |
| 2465 | |
| 2466 | err = regulator_enable(sor->vdd_pll_supply); |
| 2467 | if (err < 0) { |
| 2468 | dev_err(sor->dev, "failed to enable VDD PLL supply: %d\n", |
| 2469 | err); |
| 2470 | return err; |
| 2471 | } |
| 2472 | |
| 2473 | sor->hdmi_supply = devm_regulator_get(sor->dev, "hdmi"); |
| 2474 | if (IS_ERR(sor->hdmi_supply)) { |
| 2475 | dev_err(sor->dev, "cannot get HDMI supply: %ld\n", |
| 2476 | PTR_ERR(sor->hdmi_supply)); |
| 2477 | return PTR_ERR(sor->hdmi_supply); |
| 2478 | } |
| 2479 | |
| 2480 | err = regulator_enable(sor->hdmi_supply); |
| 2481 | if (err < 0) { |
| 2482 | dev_err(sor->dev, "failed to enable HDMI supply: %d\n", err); |
| 2483 | return err; |
| 2484 | } |
| 2485 | |
| 2486 | return 0; |
| 2487 | } |
| 2488 | |
| 2489 | static int tegra_sor_hdmi_remove(struct tegra_sor *sor) |
| 2490 | { |
| 2491 | regulator_disable(sor->hdmi_supply); |
| 2492 | regulator_disable(sor->vdd_pll_supply); |
| 2493 | regulator_disable(sor->avdd_io_supply); |
| 2494 | |
| 2495 | return 0; |
| 2496 | } |
| 2497 | |
| 2498 | static const struct tegra_sor_ops tegra_sor_hdmi_ops = { |
| 2499 | .name = "HDMI", |
| 2500 | .probe = tegra_sor_hdmi_probe, |
| 2501 | .remove = tegra_sor_hdmi_remove, |
| 2502 | }; |
| 2503 | |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 2504 | static const u8 tegra124_sor_xbar_cfg[5] = { |
| 2505 | 0, 1, 2, 3, 4 |
| 2506 | }; |
| 2507 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2508 | static const struct tegra_sor_regs tegra124_sor_regs = { |
| 2509 | .head_state0 = 0x05, |
| 2510 | .head_state1 = 0x07, |
| 2511 | .head_state2 = 0x09, |
| 2512 | .head_state3 = 0x0b, |
| 2513 | .head_state4 = 0x0d, |
| 2514 | .head_state5 = 0x0f, |
| 2515 | .pll0 = 0x17, |
| 2516 | .pll1 = 0x18, |
| 2517 | .pll2 = 0x19, |
| 2518 | .pll3 = 0x1a, |
| 2519 | .dp_padctl0 = 0x5c, |
| 2520 | .dp_padctl2 = 0x73, |
| 2521 | }; |
| 2522 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2523 | static const struct tegra_sor_soc tegra124_sor = { |
| 2524 | .supports_edp = true, |
| 2525 | .supports_lvds = true, |
| 2526 | .supports_hdmi = false, |
| 2527 | .supports_dp = false, |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2528 | .regs = &tegra124_sor_regs, |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 2529 | .xbar_cfg = tegra124_sor_xbar_cfg, |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2530 | }; |
| 2531 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2532 | static const struct tegra_sor_regs tegra210_sor_regs = { |
| 2533 | .head_state0 = 0x05, |
| 2534 | .head_state1 = 0x07, |
| 2535 | .head_state2 = 0x09, |
| 2536 | .head_state3 = 0x0b, |
| 2537 | .head_state4 = 0x0d, |
| 2538 | .head_state5 = 0x0f, |
| 2539 | .pll0 = 0x17, |
| 2540 | .pll1 = 0x18, |
| 2541 | .pll2 = 0x19, |
| 2542 | .pll3 = 0x1a, |
| 2543 | .dp_padctl0 = 0x5c, |
| 2544 | .dp_padctl2 = 0x73, |
| 2545 | }; |
| 2546 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2547 | static const struct tegra_sor_soc tegra210_sor = { |
| 2548 | .supports_edp = true, |
| 2549 | .supports_lvds = false, |
| 2550 | .supports_hdmi = false, |
| 2551 | .supports_dp = false, |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2552 | .regs = &tegra210_sor_regs, |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 2553 | .xbar_cfg = tegra124_sor_xbar_cfg, |
| 2554 | }; |
| 2555 | |
| 2556 | static const u8 tegra210_sor_xbar_cfg[5] = { |
| 2557 | 2, 1, 0, 3, 4 |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2558 | }; |
| 2559 | |
| 2560 | static const struct tegra_sor_soc tegra210_sor1 = { |
| 2561 | .supports_edp = false, |
| 2562 | .supports_lvds = false, |
| 2563 | .supports_hdmi = true, |
| 2564 | .supports_dp = true, |
| 2565 | |
| Thierry Reding | 880cee0 | 2017-10-12 19:04:17 +0200 | [diff] [blame^] | 2566 | .regs = &tegra210_sor_regs, |
| 2567 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2568 | .num_settings = ARRAY_SIZE(tegra210_sor_hdmi_defaults), |
| 2569 | .settings = tegra210_sor_hdmi_defaults, |
| Thierry Reding | 30b4943 | 2015-08-03 15:50:32 +0200 | [diff] [blame] | 2570 | |
| 2571 | .xbar_cfg = tegra210_sor_xbar_cfg, |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2572 | }; |
| 2573 | |
| 2574 | static const struct of_device_id tegra_sor_of_match[] = { |
| 2575 | { .compatible = "nvidia,tegra210-sor1", .data = &tegra210_sor1 }, |
| 2576 | { .compatible = "nvidia,tegra210-sor", .data = &tegra210_sor }, |
| 2577 | { .compatible = "nvidia,tegra124-sor", .data = &tegra124_sor }, |
| 2578 | { }, |
| 2579 | }; |
| 2580 | MODULE_DEVICE_TABLE(of, tegra_sor_of_match); |
| 2581 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2582 | static int tegra_sor_probe(struct platform_device *pdev) |
| 2583 | { |
| 2584 | struct device_node *np; |
| 2585 | struct tegra_sor *sor; |
| 2586 | struct resource *regs; |
| 2587 | int err; |
| 2588 | |
| 2589 | sor = devm_kzalloc(&pdev->dev, sizeof(*sor), GFP_KERNEL); |
| 2590 | if (!sor) |
| 2591 | return -ENOMEM; |
| 2592 | |
| Thierry Reding | 5faea3d | 2017-08-21 17:33:14 +0200 | [diff] [blame] | 2593 | sor->soc = of_device_get_match_data(&pdev->dev); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2594 | sor->output.dev = sor->dev = &pdev->dev; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2595 | |
| 2596 | sor->settings = devm_kmemdup(&pdev->dev, sor->soc->settings, |
| 2597 | sor->soc->num_settings * |
| 2598 | sizeof(*sor->settings), |
| 2599 | GFP_KERNEL); |
| 2600 | if (!sor->settings) |
| 2601 | return -ENOMEM; |
| 2602 | |
| 2603 | sor->num_settings = sor->soc->num_settings; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2604 | |
| 2605 | np = of_parse_phandle(pdev->dev.of_node, "nvidia,dpaux", 0); |
| 2606 | if (np) { |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2607 | sor->aux = drm_dp_aux_find_by_of_node(np); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2608 | of_node_put(np); |
| 2609 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2610 | if (!sor->aux) |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2611 | return -EPROBE_DEFER; |
| 2612 | } |
| 2613 | |
| Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2614 | if (!sor->aux) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2615 | if (sor->soc->supports_hdmi) { |
| 2616 | sor->ops = &tegra_sor_hdmi_ops; |
| 2617 | } else if (sor->soc->supports_lvds) { |
| 2618 | dev_err(&pdev->dev, "LVDS not supported yet\n"); |
| 2619 | return -ENODEV; |
| 2620 | } else { |
| 2621 | dev_err(&pdev->dev, "unknown (non-DP) support\n"); |
| 2622 | return -ENODEV; |
| 2623 | } |
| 2624 | } else { |
| 2625 | if (sor->soc->supports_edp) { |
| 2626 | sor->ops = &tegra_sor_edp_ops; |
| 2627 | } else if (sor->soc->supports_dp) { |
| 2628 | dev_err(&pdev->dev, "DisplayPort not supported yet\n"); |
| 2629 | return -ENODEV; |
| 2630 | } else { |
| 2631 | dev_err(&pdev->dev, "unknown (DP) support\n"); |
| 2632 | return -ENODEV; |
| 2633 | } |
| 2634 | } |
| 2635 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2636 | err = tegra_output_probe(&sor->output); |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2637 | if (err < 0) { |
| 2638 | dev_err(&pdev->dev, "failed to probe output: %d\n", err); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2639 | return err; |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2640 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2641 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2642 | if (sor->ops && sor->ops->probe) { |
| 2643 | err = sor->ops->probe(sor); |
| 2644 | if (err < 0) { |
| 2645 | dev_err(&pdev->dev, "failed to probe %s: %d\n", |
| 2646 | sor->ops->name, err); |
| 2647 | goto output; |
| 2648 | } |
| 2649 | } |
| 2650 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2651 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2652 | sor->regs = devm_ioremap_resource(&pdev->dev, regs); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2653 | if (IS_ERR(sor->regs)) { |
| 2654 | err = PTR_ERR(sor->regs); |
| 2655 | goto remove; |
| 2656 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2657 | |
| Jon Hunter | f8c7912 | 2016-07-01 14:21:38 +0100 | [diff] [blame] | 2658 | if (!pdev->dev.pm_domain) { |
| 2659 | sor->rst = devm_reset_control_get(&pdev->dev, "sor"); |
| 2660 | if (IS_ERR(sor->rst)) { |
| 2661 | err = PTR_ERR(sor->rst); |
| 2662 | dev_err(&pdev->dev, "failed to get reset control: %d\n", |
| 2663 | err); |
| 2664 | goto remove; |
| 2665 | } |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2666 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2667 | |
| 2668 | sor->clk = devm_clk_get(&pdev->dev, NULL); |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2669 | if (IS_ERR(sor->clk)) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2670 | err = PTR_ERR(sor->clk); |
| 2671 | dev_err(&pdev->dev, "failed to get module clock: %d\n", err); |
| 2672 | goto remove; |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2673 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2674 | |
| Thierry Reding | 618dee3 | 2016-06-09 17:53:57 +0200 | [diff] [blame] | 2675 | if (sor->soc->supports_hdmi || sor->soc->supports_dp) { |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2676 | struct device_node *np = pdev->dev.of_node; |
| 2677 | const char *name; |
| 2678 | |
| 2679 | /* |
| 2680 | * For backwards compatibility with Tegra210 device trees, |
| 2681 | * fall back to the old clock name "source" if the new "out" |
| 2682 | * clock is not available. |
| 2683 | */ |
| 2684 | if (of_property_match_string(np, "clock-names", "out") < 0) |
| 2685 | name = "source"; |
| 2686 | else |
| 2687 | name = "out"; |
| 2688 | |
| 2689 | sor->clk_out = devm_clk_get(&pdev->dev, name); |
| 2690 | if (IS_ERR(sor->clk_out)) { |
| 2691 | err = PTR_ERR(sor->clk_out); |
| 2692 | dev_err(sor->dev, "failed to get %s clock: %d\n", |
| 2693 | name, err); |
| Thierry Reding | 618dee3 | 2016-06-09 17:53:57 +0200 | [diff] [blame] | 2694 | goto remove; |
| 2695 | } |
| 2696 | } |
| 2697 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2698 | sor->clk_parent = devm_clk_get(&pdev->dev, "parent"); |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2699 | if (IS_ERR(sor->clk_parent)) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2700 | err = PTR_ERR(sor->clk_parent); |
| 2701 | dev_err(&pdev->dev, "failed to get parent clock: %d\n", err); |
| 2702 | goto remove; |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2703 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2704 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2705 | sor->clk_safe = devm_clk_get(&pdev->dev, "safe"); |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2706 | if (IS_ERR(sor->clk_safe)) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2707 | err = PTR_ERR(sor->clk_safe); |
| 2708 | dev_err(&pdev->dev, "failed to get safe clock: %d\n", err); |
| 2709 | goto remove; |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2710 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2711 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2712 | sor->clk_dp = devm_clk_get(&pdev->dev, "dp"); |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2713 | if (IS_ERR(sor->clk_dp)) { |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2714 | err = PTR_ERR(sor->clk_dp); |
| 2715 | dev_err(&pdev->dev, "failed to get DP clock: %d\n", err); |
| 2716 | goto remove; |
| Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2717 | } |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2718 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2719 | /* |
| 2720 | * Starting with Tegra186, the BPMP provides an implementation for |
| 2721 | * the pad output clock, so we have to look it up from device tree. |
| 2722 | */ |
| 2723 | sor->clk_pad = devm_clk_get(&pdev->dev, "pad"); |
| 2724 | if (IS_ERR(sor->clk_pad)) { |
| 2725 | if (sor->clk_pad != ERR_PTR(-ENOENT)) { |
| 2726 | err = PTR_ERR(sor->clk_pad); |
| 2727 | goto remove; |
| 2728 | } |
| 2729 | |
| 2730 | /* |
| 2731 | * If the pad output clock is not available, then we assume |
| 2732 | * we're on Tegra210 or earlier and have to provide our own |
| 2733 | * implementation. |
| 2734 | */ |
| 2735 | sor->clk_pad = NULL; |
| 2736 | } |
| 2737 | |
| 2738 | /* |
| 2739 | * The bootloader may have set up the SOR such that it's module clock |
| 2740 | * is sourced by one of the display PLLs. However, that doesn't work |
| 2741 | * without properly having set up other bits of the SOR. |
| 2742 | */ |
| 2743 | err = clk_set_parent(sor->clk_out, sor->clk_safe); |
| 2744 | if (err < 0) { |
| 2745 | dev_err(&pdev->dev, "failed to use safe clock: %d\n", err); |
| 2746 | goto remove; |
| 2747 | } |
| 2748 | |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2749 | platform_set_drvdata(pdev, sor); |
| 2750 | pm_runtime_enable(&pdev->dev); |
| 2751 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2752 | /* |
| 2753 | * On Tegra210 and earlier, provide our own implementation for the |
| 2754 | * pad output clock. |
| 2755 | */ |
| 2756 | if (!sor->clk_pad) { |
| 2757 | err = pm_runtime_get_sync(&pdev->dev); |
| 2758 | if (err < 0) { |
| 2759 | dev_err(&pdev->dev, "failed to get runtime PM: %d\n", |
| 2760 | err); |
| 2761 | goto remove; |
| 2762 | } |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 2763 | |
| Thierry Reding | e1335e2 | 2017-10-12 17:53:11 +0200 | [diff] [blame] | 2764 | sor->clk_pad = tegra_clk_sor_pad_register(sor, |
| 2765 | "sor1_pad_clkout"); |
| 2766 | pm_runtime_put(&pdev->dev); |
| 2767 | } |
| 2768 | |
| 2769 | if (IS_ERR(sor->clk_pad)) { |
| 2770 | err = PTR_ERR(sor->clk_pad); |
| 2771 | dev_err(&pdev->dev, "failed to register SOR pad clock: %d\n", |
| 2772 | err); |
| Thierry Reding | b299221 | 2015-10-01 14:25:03 +0200 | [diff] [blame] | 2773 | goto remove; |
| 2774 | } |
| 2775 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2776 | INIT_LIST_HEAD(&sor->client.list); |
| 2777 | sor->client.ops = &sor_client_ops; |
| 2778 | sor->client.dev = &pdev->dev; |
| 2779 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2780 | err = host1x_client_register(&sor->client); |
| 2781 | if (err < 0) { |
| 2782 | dev_err(&pdev->dev, "failed to register host1x client: %d\n", |
| 2783 | err); |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2784 | goto remove; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2785 | } |
| 2786 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2787 | return 0; |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2788 | |
| 2789 | remove: |
| 2790 | if (sor->ops && sor->ops->remove) |
| 2791 | sor->ops->remove(sor); |
| 2792 | output: |
| 2793 | tegra_output_remove(&sor->output); |
| 2794 | return err; |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | static int tegra_sor_remove(struct platform_device *pdev) |
| 2798 | { |
| 2799 | struct tegra_sor *sor = platform_get_drvdata(pdev); |
| 2800 | int err; |
| 2801 | |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2802 | pm_runtime_disable(&pdev->dev); |
| 2803 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2804 | err = host1x_client_unregister(&sor->client); |
| 2805 | if (err < 0) { |
| 2806 | dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", |
| 2807 | err); |
| 2808 | return err; |
| 2809 | } |
| 2810 | |
| Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2811 | if (sor->ops && sor->ops->remove) { |
| 2812 | err = sor->ops->remove(sor); |
| 2813 | if (err < 0) |
| 2814 | dev_err(&pdev->dev, "failed to remove SOR: %d\n", err); |
| 2815 | } |
| 2816 | |
| Thierry Reding | 328ec69 | 2014-12-19 15:55:08 +0100 | [diff] [blame] | 2817 | tegra_output_remove(&sor->output); |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2818 | |
| 2819 | return 0; |
| 2820 | } |
| 2821 | |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2822 | #ifdef CONFIG_PM |
| 2823 | static int tegra_sor_suspend(struct device *dev) |
| 2824 | { |
| 2825 | struct tegra_sor *sor = dev_get_drvdata(dev); |
| 2826 | int err; |
| 2827 | |
| Jon Hunter | f8c7912 | 2016-07-01 14:21:38 +0100 | [diff] [blame] | 2828 | if (sor->rst) { |
| 2829 | err = reset_control_assert(sor->rst); |
| 2830 | if (err < 0) { |
| 2831 | dev_err(dev, "failed to assert reset: %d\n", err); |
| 2832 | return err; |
| 2833 | } |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | usleep_range(1000, 2000); |
| 2837 | |
| 2838 | clk_disable_unprepare(sor->clk); |
| 2839 | |
| 2840 | return 0; |
| 2841 | } |
| 2842 | |
| 2843 | static int tegra_sor_resume(struct device *dev) |
| 2844 | { |
| 2845 | struct tegra_sor *sor = dev_get_drvdata(dev); |
| 2846 | int err; |
| 2847 | |
| 2848 | err = clk_prepare_enable(sor->clk); |
| 2849 | if (err < 0) { |
| 2850 | dev_err(dev, "failed to enable clock: %d\n", err); |
| 2851 | return err; |
| 2852 | } |
| 2853 | |
| 2854 | usleep_range(1000, 2000); |
| 2855 | |
| Jon Hunter | f8c7912 | 2016-07-01 14:21:38 +0100 | [diff] [blame] | 2856 | if (sor->rst) { |
| 2857 | err = reset_control_deassert(sor->rst); |
| 2858 | if (err < 0) { |
| 2859 | dev_err(dev, "failed to deassert reset: %d\n", err); |
| 2860 | clk_disable_unprepare(sor->clk); |
| 2861 | return err; |
| 2862 | } |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | return 0; |
| 2866 | } |
| 2867 | #endif |
| 2868 | |
| 2869 | static const struct dev_pm_ops tegra_sor_pm_ops = { |
| 2870 | SET_RUNTIME_PM_OPS(tegra_sor_suspend, tegra_sor_resume, NULL) |
| 2871 | }; |
| 2872 | |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2873 | struct platform_driver tegra_sor_driver = { |
| 2874 | .driver = { |
| 2875 | .name = "tegra-sor", |
| 2876 | .of_match_table = tegra_sor_of_match, |
| Thierry Reding | aaff8bd | 2015-08-07 16:04:54 +0200 | [diff] [blame] | 2877 | .pm = &tegra_sor_pm_ops, |
| Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2878 | }, |
| 2879 | .probe = tegra_sor_probe, |
| 2880 | .remove = tegra_sor_remove, |
| 2881 | }; |