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