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