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 | 402f6bc | 2015-07-21 16:48:19 +0200 | [diff] [blame] | 681 | static void tegra_sor_apply_config(struct tegra_sor *sor, |
| 682 | const struct tegra_sor_config *config) |
| 683 | { |
| 684 | u32 value; |
| 685 | |
| 686 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
| 687 | value &= ~SOR_DP_LINKCTL_TU_SIZE_MASK; |
| 688 | value |= SOR_DP_LINKCTL_TU_SIZE(config->tu_size); |
| 689 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
| 690 | |
| 691 | value = tegra_sor_readl(sor, SOR_DP_CONFIG0); |
| 692 | value &= ~SOR_DP_CONFIG_WATERMARK_MASK; |
| 693 | value |= SOR_DP_CONFIG_WATERMARK(config->watermark); |
| 694 | |
| 695 | value &= ~SOR_DP_CONFIG_ACTIVE_SYM_COUNT_MASK; |
| 696 | value |= SOR_DP_CONFIG_ACTIVE_SYM_COUNT(config->active_count); |
| 697 | |
| 698 | value &= ~SOR_DP_CONFIG_ACTIVE_SYM_FRAC_MASK; |
| 699 | value |= SOR_DP_CONFIG_ACTIVE_SYM_FRAC(config->active_frac); |
| 700 | |
| 701 | if (config->active_polarity) |
| 702 | value |= SOR_DP_CONFIG_ACTIVE_SYM_POLARITY; |
| 703 | else |
| 704 | value &= ~SOR_DP_CONFIG_ACTIVE_SYM_POLARITY; |
| 705 | |
| 706 | value |= SOR_DP_CONFIG_ACTIVE_SYM_ENABLE; |
| 707 | value |= SOR_DP_CONFIG_DISPARITY_NEGATIVE; |
| 708 | tegra_sor_writel(sor, value, SOR_DP_CONFIG0); |
| 709 | |
| 710 | value = tegra_sor_readl(sor, SOR_DP_AUDIO_HBLANK_SYMBOLS); |
| 711 | value &= ~SOR_DP_AUDIO_HBLANK_SYMBOLS_MASK; |
| 712 | value |= config->hblank_symbols & 0xffff; |
| 713 | tegra_sor_writel(sor, value, SOR_DP_AUDIO_HBLANK_SYMBOLS); |
| 714 | |
| 715 | value = tegra_sor_readl(sor, SOR_DP_AUDIO_VBLANK_SYMBOLS); |
| 716 | value &= ~SOR_DP_AUDIO_VBLANK_SYMBOLS_MASK; |
| 717 | value |= config->vblank_symbols & 0xffff; |
| 718 | tegra_sor_writel(sor, value, SOR_DP_AUDIO_VBLANK_SYMBOLS); |
| 719 | } |
| 720 | |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 721 | static void tegra_sor_mode_set(struct tegra_sor *sor, |
| 722 | const struct drm_display_mode *mode, |
| 723 | const struct drm_display_info *info) |
| 724 | { |
| 725 | struct tegra_dc *dc = to_tegra_dc(sor->output.encoder.crtc); |
| 726 | unsigned int vbe, vse, hbe, hse, vbs, hbs; |
| 727 | u32 value; |
| 728 | |
| 729 | value = tegra_sor_readl(sor, SOR_STATE1); |
| 730 | value &= ~SOR_STATE_ASY_PIXELDEPTH_MASK; |
| 731 | value &= ~SOR_STATE_ASY_CRC_MODE_MASK; |
| 732 | value &= ~SOR_STATE_ASY_OWNER_MASK; |
| 733 | |
| 734 | value |= SOR_STATE_ASY_CRC_MODE_COMPLETE | |
| 735 | SOR_STATE_ASY_OWNER(dc->pipe + 1); |
| 736 | |
| 737 | if (mode->flags & DRM_MODE_FLAG_PHSYNC) |
| 738 | value &= ~SOR_STATE_ASY_HSYNCPOL; |
| 739 | |
| 740 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 741 | value |= SOR_STATE_ASY_HSYNCPOL; |
| 742 | |
| 743 | if (mode->flags & DRM_MODE_FLAG_PVSYNC) |
| 744 | value &= ~SOR_STATE_ASY_VSYNCPOL; |
| 745 | |
| 746 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 747 | value |= SOR_STATE_ASY_VSYNCPOL; |
| 748 | |
| 749 | switch (info->bpc) { |
| 750 | case 8: |
| 751 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_24_444; |
| 752 | break; |
| 753 | |
| 754 | case 6: |
| 755 | value |= SOR_STATE_ASY_PIXELDEPTH_BPP_18_444; |
| 756 | break; |
| 757 | |
| 758 | default: |
| 759 | BUG(); |
| 760 | break; |
| 761 | } |
| 762 | |
| 763 | tegra_sor_writel(sor, value, SOR_STATE1); |
| 764 | |
| 765 | /* |
| 766 | * TODO: The video timing programming below doesn't seem to match the |
| 767 | * register definitions. |
| 768 | */ |
| 769 | |
| 770 | value = ((mode->vtotal & 0x7fff) << 16) | (mode->htotal & 0x7fff); |
| 771 | tegra_sor_writel(sor, value, SOR_HEAD_STATE1(dc->pipe)); |
| 772 | |
| 773 | /* sync end = sync width - 1 */ |
| 774 | vse = mode->vsync_end - mode->vsync_start - 1; |
| 775 | hse = mode->hsync_end - mode->hsync_start - 1; |
| 776 | |
| 777 | value = ((vse & 0x7fff) << 16) | (hse & 0x7fff); |
| 778 | tegra_sor_writel(sor, value, SOR_HEAD_STATE2(dc->pipe)); |
| 779 | |
| 780 | /* blank end = sync end + back porch */ |
| 781 | vbe = vse + (mode->vtotal - mode->vsync_end); |
| 782 | hbe = hse + (mode->htotal - mode->hsync_end); |
| 783 | |
| 784 | value = ((vbe & 0x7fff) << 16) | (hbe & 0x7fff); |
| 785 | tegra_sor_writel(sor, value, SOR_HEAD_STATE3(dc->pipe)); |
| 786 | |
| 787 | /* blank start = blank end + active */ |
| 788 | vbs = vbe + mode->vdisplay; |
| 789 | hbs = hbe + mode->hdisplay; |
| 790 | |
| 791 | value = ((vbs & 0x7fff) << 16) | (hbs & 0x7fff); |
| 792 | tegra_sor_writel(sor, value, SOR_HEAD_STATE4(dc->pipe)); |
| 793 | |
| 794 | /* XXX interlacing support */ |
| 795 | tegra_sor_writel(sor, 0x001, SOR_HEAD_STATE5(dc->pipe)); |
| 796 | } |
| 797 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 798 | static int tegra_sor_detach(struct tegra_sor *sor) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 799 | { |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 800 | unsigned long value, timeout; |
| 801 | |
| 802 | /* switch to safe mode */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 803 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 804 | value &= ~SOR_SUPER_STATE_MODE_NORMAL; |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 805 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 806 | tegra_sor_super_update(sor); |
| 807 | |
| 808 | timeout = jiffies + msecs_to_jiffies(250); |
| 809 | |
| 810 | while (time_before(jiffies, timeout)) { |
| 811 | value = tegra_sor_readl(sor, SOR_PWR); |
| 812 | if (value & SOR_PWR_MODE_SAFE) |
| 813 | break; |
| 814 | } |
| 815 | |
| 816 | if ((value & SOR_PWR_MODE_SAFE) == 0) |
| 817 | return -ETIMEDOUT; |
| 818 | |
| 819 | /* go to sleep */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 820 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 821 | value &= ~SOR_SUPER_STATE_HEAD_MODE_MASK; |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 822 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 823 | tegra_sor_super_update(sor); |
| 824 | |
| 825 | /* detach */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 826 | value = tegra_sor_readl(sor, SOR_SUPER_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 827 | value &= ~SOR_SUPER_STATE_ATTACHED; |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 828 | tegra_sor_writel(sor, value, SOR_SUPER_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 829 | tegra_sor_super_update(sor); |
| 830 | |
| 831 | timeout = jiffies + msecs_to_jiffies(250); |
| 832 | |
| 833 | while (time_before(jiffies, timeout)) { |
| 834 | value = tegra_sor_readl(sor, SOR_TEST); |
| 835 | if ((value & SOR_TEST_ATTACHED) == 0) |
| 836 | break; |
| 837 | |
| 838 | usleep_range(25, 100); |
| 839 | } |
| 840 | |
| 841 | if ((value & SOR_TEST_ATTACHED) != 0) |
| 842 | return -ETIMEDOUT; |
| 843 | |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | static int tegra_sor_power_down(struct tegra_sor *sor) |
| 848 | { |
| 849 | unsigned long value, timeout; |
| 850 | int err; |
| 851 | |
| 852 | value = tegra_sor_readl(sor, SOR_PWR); |
| 853 | value &= ~SOR_PWR_NORMAL_STATE_PU; |
| 854 | value |= SOR_PWR_TRIGGER; |
| 855 | tegra_sor_writel(sor, value, SOR_PWR); |
| 856 | |
| 857 | timeout = jiffies + msecs_to_jiffies(250); |
| 858 | |
| 859 | while (time_before(jiffies, timeout)) { |
| 860 | value = tegra_sor_readl(sor, SOR_PWR); |
| 861 | if ((value & SOR_PWR_TRIGGER) == 0) |
| 862 | return 0; |
| 863 | |
| 864 | usleep_range(25, 100); |
| 865 | } |
| 866 | |
| 867 | if ((value & SOR_PWR_TRIGGER) != 0) |
| 868 | return -ETIMEDOUT; |
| 869 | |
Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 870 | /* switch to safe parent clock */ |
| 871 | err = tegra_sor_set_parent_clock(sor, sor->clk_safe); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 872 | if (err < 0) |
| 873 | dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); |
| 874 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 875 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 876 | value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 | |
| 877 | SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 878 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 879 | |
| 880 | /* stop lane sequencer */ |
| 881 | value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_UP | |
| 882 | SOR_LANE_SEQ_CTL_POWER_STATE_DOWN; |
| 883 | tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); |
| 884 | |
| 885 | timeout = jiffies + msecs_to_jiffies(250); |
| 886 | |
| 887 | while (time_before(jiffies, timeout)) { |
| 888 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 889 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) |
| 890 | break; |
| 891 | |
| 892 | usleep_range(25, 100); |
| 893 | } |
| 894 | |
| 895 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) != 0) |
| 896 | return -ETIMEDOUT; |
| 897 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 898 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 899 | value |= SOR_PLL2_PORT_POWERDOWN; |
| 900 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 901 | |
| 902 | usleep_range(20, 100); |
| 903 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 904 | value = tegra_sor_readl(sor, SOR_PLL0); |
| 905 | value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR; |
| 906 | tegra_sor_writel(sor, value, SOR_PLL0); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 907 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 908 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 909 | value |= SOR_PLL2_SEQ_PLLCAPPD; |
| 910 | value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| 911 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 912 | |
| 913 | usleep_range(20, 100); |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 918 | static int tegra_sor_crc_wait(struct tegra_sor *sor, unsigned long timeout) |
| 919 | { |
| 920 | u32 value; |
| 921 | |
| 922 | timeout = jiffies + msecs_to_jiffies(timeout); |
| 923 | |
| 924 | while (time_before(jiffies, timeout)) { |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 925 | value = tegra_sor_readl(sor, SOR_CRCA); |
| 926 | if (value & SOR_CRCA_VALID) |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 927 | return 0; |
| 928 | |
| 929 | usleep_range(100, 200); |
| 930 | } |
| 931 | |
| 932 | return -ETIMEDOUT; |
| 933 | } |
| 934 | |
Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 935 | static int tegra_sor_show_crc(struct seq_file *s, void *data) |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 936 | { |
Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 937 | struct drm_info_node *node = s->private; |
| 938 | struct tegra_sor *sor = node->info_ent->data; |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 939 | struct drm_crtc *crtc = sor->output.encoder.crtc; |
| 940 | struct drm_device *drm = node->minor->dev; |
Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 941 | int err = 0; |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 942 | u32 value; |
| 943 | |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 944 | drm_modeset_lock_all(drm); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 945 | |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 946 | if (!crtc || !crtc->state->active) { |
| 947 | err = -EBUSY; |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 948 | goto unlock; |
| 949 | } |
| 950 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 951 | value = tegra_sor_readl(sor, SOR_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 952 | value &= ~SOR_STATE_ASY_CRC_MODE_MASK; |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 953 | tegra_sor_writel(sor, value, SOR_STATE1); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 954 | |
| 955 | value = tegra_sor_readl(sor, SOR_CRC_CNTRL); |
| 956 | value |= SOR_CRC_CNTRL_ENABLE; |
| 957 | tegra_sor_writel(sor, value, SOR_CRC_CNTRL); |
| 958 | |
| 959 | value = tegra_sor_readl(sor, SOR_TEST); |
| 960 | value &= ~SOR_TEST_CRC_POST_SERIALIZE; |
| 961 | tegra_sor_writel(sor, value, SOR_TEST); |
| 962 | |
| 963 | err = tegra_sor_crc_wait(sor, 100); |
| 964 | if (err < 0) |
| 965 | goto unlock; |
| 966 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 967 | tegra_sor_writel(sor, SOR_CRCA_RESET, SOR_CRCA); |
| 968 | value = tegra_sor_readl(sor, SOR_CRCB); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 969 | |
Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 970 | seq_printf(s, "%08x\n", value); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 971 | |
| 972 | unlock: |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 973 | drm_modeset_unlock_all(drm); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 974 | return err; |
| 975 | } |
| 976 | |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 977 | static int tegra_sor_show_regs(struct seq_file *s, void *data) |
| 978 | { |
| 979 | struct drm_info_node *node = s->private; |
| 980 | struct tegra_sor *sor = node->info_ent->data; |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 981 | struct drm_crtc *crtc = sor->output.encoder.crtc; |
| 982 | struct drm_device *drm = node->minor->dev; |
| 983 | int err = 0; |
| 984 | |
| 985 | drm_modeset_lock_all(drm); |
| 986 | |
| 987 | if (!crtc || !crtc->state->active) { |
| 988 | err = -EBUSY; |
| 989 | goto unlock; |
| 990 | } |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 991 | |
| 992 | #define DUMP_REG(name) \ |
| 993 | seq_printf(s, "%-38s %#05x %08x\n", #name, name, \ |
| 994 | tegra_sor_readl(sor, name)) |
| 995 | |
| 996 | DUMP_REG(SOR_CTXSW); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 997 | DUMP_REG(SOR_SUPER_STATE0); |
| 998 | DUMP_REG(SOR_SUPER_STATE1); |
| 999 | DUMP_REG(SOR_STATE0); |
| 1000 | DUMP_REG(SOR_STATE1); |
| 1001 | DUMP_REG(SOR_HEAD_STATE0(0)); |
| 1002 | DUMP_REG(SOR_HEAD_STATE0(1)); |
| 1003 | DUMP_REG(SOR_HEAD_STATE1(0)); |
| 1004 | DUMP_REG(SOR_HEAD_STATE1(1)); |
| 1005 | DUMP_REG(SOR_HEAD_STATE2(0)); |
| 1006 | DUMP_REG(SOR_HEAD_STATE2(1)); |
| 1007 | DUMP_REG(SOR_HEAD_STATE3(0)); |
| 1008 | DUMP_REG(SOR_HEAD_STATE3(1)); |
| 1009 | DUMP_REG(SOR_HEAD_STATE4(0)); |
| 1010 | DUMP_REG(SOR_HEAD_STATE4(1)); |
| 1011 | DUMP_REG(SOR_HEAD_STATE5(0)); |
| 1012 | DUMP_REG(SOR_HEAD_STATE5(1)); |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1013 | DUMP_REG(SOR_CRC_CNTRL); |
| 1014 | DUMP_REG(SOR_DP_DEBUG_MVID); |
| 1015 | DUMP_REG(SOR_CLK_CNTRL); |
| 1016 | DUMP_REG(SOR_CAP); |
| 1017 | DUMP_REG(SOR_PWR); |
| 1018 | DUMP_REG(SOR_TEST); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1019 | DUMP_REG(SOR_PLL0); |
| 1020 | DUMP_REG(SOR_PLL1); |
| 1021 | DUMP_REG(SOR_PLL2); |
| 1022 | DUMP_REG(SOR_PLL3); |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1023 | DUMP_REG(SOR_CSTM); |
| 1024 | DUMP_REG(SOR_LVDS); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1025 | DUMP_REG(SOR_CRCA); |
| 1026 | DUMP_REG(SOR_CRCB); |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1027 | DUMP_REG(SOR_BLANK); |
| 1028 | DUMP_REG(SOR_SEQ_CTL); |
| 1029 | DUMP_REG(SOR_LANE_SEQ_CTL); |
| 1030 | DUMP_REG(SOR_SEQ_INST(0)); |
| 1031 | DUMP_REG(SOR_SEQ_INST(1)); |
| 1032 | DUMP_REG(SOR_SEQ_INST(2)); |
| 1033 | DUMP_REG(SOR_SEQ_INST(3)); |
| 1034 | DUMP_REG(SOR_SEQ_INST(4)); |
| 1035 | DUMP_REG(SOR_SEQ_INST(5)); |
| 1036 | DUMP_REG(SOR_SEQ_INST(6)); |
| 1037 | DUMP_REG(SOR_SEQ_INST(7)); |
| 1038 | DUMP_REG(SOR_SEQ_INST(8)); |
| 1039 | DUMP_REG(SOR_SEQ_INST(9)); |
| 1040 | DUMP_REG(SOR_SEQ_INST(10)); |
| 1041 | DUMP_REG(SOR_SEQ_INST(11)); |
| 1042 | DUMP_REG(SOR_SEQ_INST(12)); |
| 1043 | DUMP_REG(SOR_SEQ_INST(13)); |
| 1044 | DUMP_REG(SOR_SEQ_INST(14)); |
| 1045 | DUMP_REG(SOR_SEQ_INST(15)); |
| 1046 | DUMP_REG(SOR_PWM_DIV); |
| 1047 | DUMP_REG(SOR_PWM_CTL); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1048 | DUMP_REG(SOR_VCRC_A0); |
| 1049 | DUMP_REG(SOR_VCRC_A1); |
| 1050 | DUMP_REG(SOR_VCRC_B0); |
| 1051 | DUMP_REG(SOR_VCRC_B1); |
| 1052 | DUMP_REG(SOR_CCRC_A0); |
| 1053 | DUMP_REG(SOR_CCRC_A1); |
| 1054 | DUMP_REG(SOR_CCRC_B0); |
| 1055 | DUMP_REG(SOR_CCRC_B1); |
| 1056 | DUMP_REG(SOR_EDATA_A0); |
| 1057 | DUMP_REG(SOR_EDATA_A1); |
| 1058 | DUMP_REG(SOR_EDATA_B0); |
| 1059 | DUMP_REG(SOR_EDATA_B1); |
| 1060 | DUMP_REG(SOR_COUNT_A0); |
| 1061 | DUMP_REG(SOR_COUNT_A1); |
| 1062 | DUMP_REG(SOR_COUNT_B0); |
| 1063 | DUMP_REG(SOR_COUNT_B1); |
| 1064 | DUMP_REG(SOR_DEBUG_A0); |
| 1065 | DUMP_REG(SOR_DEBUG_A1); |
| 1066 | DUMP_REG(SOR_DEBUG_B0); |
| 1067 | DUMP_REG(SOR_DEBUG_B1); |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1068 | DUMP_REG(SOR_TRIG); |
| 1069 | DUMP_REG(SOR_MSCHECK); |
| 1070 | DUMP_REG(SOR_XBAR_CTRL); |
| 1071 | DUMP_REG(SOR_XBAR_POL); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1072 | DUMP_REG(SOR_DP_LINKCTL0); |
| 1073 | DUMP_REG(SOR_DP_LINKCTL1); |
| 1074 | DUMP_REG(SOR_LANE_DRIVE_CURRENT0); |
| 1075 | DUMP_REG(SOR_LANE_DRIVE_CURRENT1); |
| 1076 | DUMP_REG(SOR_LANE4_DRIVE_CURRENT0); |
| 1077 | DUMP_REG(SOR_LANE4_DRIVE_CURRENT1); |
| 1078 | DUMP_REG(SOR_LANE_PREEMPHASIS0); |
| 1079 | DUMP_REG(SOR_LANE_PREEMPHASIS1); |
| 1080 | DUMP_REG(SOR_LANE4_PREEMPHASIS0); |
| 1081 | DUMP_REG(SOR_LANE4_PREEMPHASIS1); |
| 1082 | DUMP_REG(SOR_LANE_POSTCURSOR0); |
| 1083 | DUMP_REG(SOR_LANE_POSTCURSOR1); |
| 1084 | DUMP_REG(SOR_DP_CONFIG0); |
| 1085 | DUMP_REG(SOR_DP_CONFIG1); |
| 1086 | DUMP_REG(SOR_DP_MN0); |
| 1087 | DUMP_REG(SOR_DP_MN1); |
| 1088 | DUMP_REG(SOR_DP_PADCTL0); |
| 1089 | DUMP_REG(SOR_DP_PADCTL1); |
| 1090 | DUMP_REG(SOR_DP_DEBUG0); |
| 1091 | DUMP_REG(SOR_DP_DEBUG1); |
| 1092 | DUMP_REG(SOR_DP_SPARE0); |
| 1093 | DUMP_REG(SOR_DP_SPARE1); |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1094 | DUMP_REG(SOR_DP_AUDIO_CTRL); |
| 1095 | DUMP_REG(SOR_DP_AUDIO_HBLANK_SYMBOLS); |
| 1096 | DUMP_REG(SOR_DP_AUDIO_VBLANK_SYMBOLS); |
| 1097 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_HEADER); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1098 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK0); |
| 1099 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK1); |
| 1100 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK2); |
| 1101 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK3); |
| 1102 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK4); |
| 1103 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK5); |
| 1104 | DUMP_REG(SOR_DP_GENERIC_INFOFRAME_SUBPACK6); |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1105 | DUMP_REG(SOR_DP_TPG); |
| 1106 | DUMP_REG(SOR_DP_TPG_CONFIG); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1107 | DUMP_REG(SOR_DP_LQ_CSTM0); |
| 1108 | DUMP_REG(SOR_DP_LQ_CSTM1); |
| 1109 | DUMP_REG(SOR_DP_LQ_CSTM2); |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1110 | |
| 1111 | #undef DUMP_REG |
| 1112 | |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1113 | unlock: |
| 1114 | drm_modeset_unlock_all(drm); |
| 1115 | return err; |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static const struct drm_info_list debugfs_files[] = { |
Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1119 | { "crc", tegra_sor_show_crc, 0, NULL }, |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1120 | { "regs", tegra_sor_show_regs, 0, NULL }, |
| 1121 | }; |
| 1122 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1123 | static int tegra_sor_debugfs_init(struct tegra_sor *sor, |
| 1124 | struct drm_minor *minor) |
| 1125 | { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1126 | const char *name = sor->soc->supports_dp ? "sor1" : "sor"; |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1127 | unsigned int i; |
Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1128 | int err; |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1129 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1130 | sor->debugfs = debugfs_create_dir(name, minor->debugfs_root); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1131 | if (!sor->debugfs) |
| 1132 | return -ENOMEM; |
| 1133 | |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1134 | sor->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), |
| 1135 | GFP_KERNEL); |
| 1136 | if (!sor->debugfs_files) { |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1137 | err = -ENOMEM; |
| 1138 | goto remove; |
| 1139 | } |
| 1140 | |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1141 | for (i = 0; i < ARRAY_SIZE(debugfs_files); i++) |
| 1142 | sor->debugfs_files[i].data = sor; |
| 1143 | |
| 1144 | err = drm_debugfs_create_files(sor->debugfs_files, |
| 1145 | ARRAY_SIZE(debugfs_files), |
| 1146 | sor->debugfs, minor); |
| 1147 | if (err < 0) |
| 1148 | goto free; |
| 1149 | |
Thierry Reding | 3ff1f22 | 2015-07-03 14:14:29 +0200 | [diff] [blame] | 1150 | sor->minor = minor; |
| 1151 | |
Thierry Reding | 530239a | 2015-08-06 11:04:54 +0200 | [diff] [blame] | 1152 | return 0; |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1153 | |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1154 | free: |
| 1155 | kfree(sor->debugfs_files); |
| 1156 | sor->debugfs_files = NULL; |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1157 | remove: |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1158 | debugfs_remove_recursive(sor->debugfs); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1159 | sor->debugfs = NULL; |
| 1160 | return err; |
| 1161 | } |
| 1162 | |
Thierry Reding | 4009c22 | 2014-12-19 15:47:30 +0100 | [diff] [blame] | 1163 | static void tegra_sor_debugfs_exit(struct tegra_sor *sor) |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1164 | { |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1165 | drm_debugfs_remove_files(sor->debugfs_files, ARRAY_SIZE(debugfs_files), |
| 1166 | sor->minor); |
| 1167 | sor->minor = NULL; |
| 1168 | |
| 1169 | kfree(sor->debugfs_files); |
Thierry Reding | 066d30f | 2015-07-03 14:16:30 +0200 | [diff] [blame] | 1170 | sor->debugfs_files = NULL; |
Thierry Reding | dab1633 | 2015-01-26 16:04:08 +0100 | [diff] [blame] | 1171 | |
| 1172 | debugfs_remove_recursive(sor->debugfs); |
Thierry Reding | 066d30f | 2015-07-03 14:16:30 +0200 | [diff] [blame] | 1173 | sor->debugfs = NULL; |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1174 | } |
| 1175 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1176 | static enum drm_connector_status |
| 1177 | tegra_sor_connector_detect(struct drm_connector *connector, bool force) |
| 1178 | { |
| 1179 | struct tegra_output *output = connector_to_output(connector); |
| 1180 | struct tegra_sor *sor = to_sor(output); |
| 1181 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1182 | if (sor->aux) |
| 1183 | return drm_dp_aux_detect(sor->aux); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1184 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1185 | return tegra_output_connector_detect(connector, force); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | static const struct drm_connector_funcs tegra_sor_connector_funcs = { |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1189 | .dpms = drm_atomic_helper_connector_dpms, |
Thierry Reding | 9d44189 | 2014-11-24 17:02:53 +0100 | [diff] [blame] | 1190 | .reset = drm_atomic_helper_connector_reset, |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1191 | .detect = tegra_sor_connector_detect, |
| 1192 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 1193 | .destroy = tegra_output_connector_destroy, |
Thierry Reding | 9d44189 | 2014-11-24 17:02:53 +0100 | [diff] [blame] | 1194 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
Thierry Reding | 4aa3df7 | 2014-11-24 16:27:13 +0100 | [diff] [blame] | 1195 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1196 | }; |
| 1197 | |
| 1198 | static int tegra_sor_connector_get_modes(struct drm_connector *connector) |
| 1199 | { |
| 1200 | struct tegra_output *output = connector_to_output(connector); |
| 1201 | struct tegra_sor *sor = to_sor(output); |
| 1202 | int err; |
| 1203 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1204 | if (sor->aux) |
| 1205 | drm_dp_aux_enable(sor->aux); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1206 | |
| 1207 | err = tegra_output_connector_get_modes(connector); |
| 1208 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1209 | if (sor->aux) |
| 1210 | drm_dp_aux_disable(sor->aux); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1211 | |
| 1212 | return err; |
| 1213 | } |
| 1214 | |
| 1215 | static enum drm_mode_status |
| 1216 | tegra_sor_connector_mode_valid(struct drm_connector *connector, |
| 1217 | struct drm_display_mode *mode) |
| 1218 | { |
| 1219 | return MODE_OK; |
| 1220 | } |
| 1221 | |
| 1222 | static const struct drm_connector_helper_funcs tegra_sor_connector_helper_funcs = { |
| 1223 | .get_modes = tegra_sor_connector_get_modes, |
| 1224 | .mode_valid = tegra_sor_connector_mode_valid, |
| 1225 | .best_encoder = tegra_output_connector_best_encoder, |
| 1226 | }; |
| 1227 | |
| 1228 | static const struct drm_encoder_funcs tegra_sor_encoder_funcs = { |
| 1229 | .destroy = tegra_output_encoder_destroy, |
| 1230 | }; |
| 1231 | |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1232 | static void tegra_sor_edp_disable(struct drm_encoder *encoder) |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1233 | { |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1234 | struct tegra_output *output = encoder_to_output(encoder); |
| 1235 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
| 1236 | struct tegra_sor *sor = to_sor(output); |
| 1237 | u32 value; |
| 1238 | int err; |
| 1239 | |
| 1240 | if (output->panel) |
| 1241 | drm_panel_disable(output->panel); |
| 1242 | |
| 1243 | err = tegra_sor_detach(sor); |
| 1244 | if (err < 0) |
| 1245 | dev_err(sor->dev, "failed to detach SOR: %d\n", err); |
| 1246 | |
| 1247 | tegra_sor_writel(sor, 0, SOR_STATE1); |
| 1248 | tegra_sor_update(sor); |
| 1249 | |
| 1250 | /* |
| 1251 | * The following accesses registers of the display controller, so make |
| 1252 | * sure it's only executed when the output is attached to one. |
| 1253 | */ |
| 1254 | if (dc) { |
| 1255 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 1256 | value &= ~SOR_ENABLE; |
| 1257 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 1258 | |
| 1259 | tegra_dc_commit(dc); |
| 1260 | } |
| 1261 | |
| 1262 | err = tegra_sor_power_down(sor); |
| 1263 | if (err < 0) |
| 1264 | dev_err(sor->dev, "failed to power down SOR: %d\n", err); |
| 1265 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 1266 | if (sor->aux) { |
| 1267 | err = drm_dp_aux_disable(sor->aux); |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1268 | if (err < 0) |
| 1269 | dev_err(sor->dev, "failed to disable DP: %d\n", err); |
| 1270 | } |
| 1271 | |
| 1272 | err = tegra_io_rail_power_off(TEGRA_IO_RAIL_LVDS); |
| 1273 | if (err < 0) |
| 1274 | dev_err(sor->dev, "failed to power off I/O rail: %d\n", err); |
| 1275 | |
| 1276 | if (output->panel) |
| 1277 | drm_panel_unprepare(output->panel); |
| 1278 | |
| 1279 | reset_control_assert(sor->rst); |
| 1280 | clk_disable_unprepare(sor->clk); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1283 | #if 0 |
| 1284 | static int calc_h_ref_to_sync(const struct drm_display_mode *mode, |
| 1285 | unsigned int *value) |
| 1286 | { |
| 1287 | unsigned int hfp, hsw, hbp, a = 0, b; |
| 1288 | |
| 1289 | hfp = mode->hsync_start - mode->hdisplay; |
| 1290 | hsw = mode->hsync_end - mode->hsync_start; |
| 1291 | hbp = mode->htotal - mode->hsync_end; |
| 1292 | |
| 1293 | pr_info("hfp: %u, hsw: %u, hbp: %u\n", hfp, hsw, hbp); |
| 1294 | |
| 1295 | b = hfp - 1; |
| 1296 | |
| 1297 | pr_info("a: %u, b: %u\n", a, b); |
| 1298 | pr_info("a + hsw + hbp = %u\n", a + hsw + hbp); |
| 1299 | |
| 1300 | if (a + hsw + hbp <= 11) { |
| 1301 | a = 1 + 11 - hsw - hbp; |
| 1302 | pr_info("a: %u\n", a); |
| 1303 | } |
| 1304 | |
| 1305 | if (a > b) |
| 1306 | return -EINVAL; |
| 1307 | |
| 1308 | if (hsw < 1) |
| 1309 | return -EINVAL; |
| 1310 | |
| 1311 | if (mode->hdisplay < 16) |
| 1312 | return -EINVAL; |
| 1313 | |
| 1314 | if (value) { |
| 1315 | if (b > a && a % 2) |
| 1316 | *value = a + 1; |
| 1317 | else |
| 1318 | *value = a; |
| 1319 | } |
| 1320 | |
| 1321 | return 0; |
| 1322 | } |
| 1323 | #endif |
| 1324 | |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1325 | static void tegra_sor_edp_enable(struct drm_encoder *encoder) |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1326 | { |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1327 | struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1328 | struct tegra_output *output = encoder_to_output(encoder); |
| 1329 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1330 | struct tegra_sor *sor = to_sor(output); |
Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1331 | struct tegra_sor_config config; |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 1332 | struct drm_display_info *info; |
Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1333 | struct drm_dp_link link; |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1334 | u8 rate, lanes; |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 1335 | unsigned int i; |
Thierry Reding | 86f5c52 | 2014-03-26 11:13:16 +0100 | [diff] [blame] | 1336 | int err = 0; |
Thierry Reding | 28fe207 | 2015-01-26 16:02:48 +0100 | [diff] [blame] | 1337 | u32 value; |
Thierry Reding | 86f5c52 | 2014-03-26 11:13:16 +0100 | [diff] [blame] | 1338 | |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 1339 | info = &output->connector.display_info; |
| 1340 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1341 | err = clk_prepare_enable(sor->clk); |
| 1342 | if (err < 0) |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1343 | dev_err(sor->dev, "failed to enable clock: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1344 | |
| 1345 | reset_control_deassert(sor->rst); |
| 1346 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1347 | if (output->panel) |
| 1348 | drm_panel_prepare(output->panel); |
| 1349 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1350 | err = drm_dp_aux_enable(sor->aux); |
| 1351 | if (err < 0) |
| 1352 | dev_err(sor->dev, "failed to enable DP: %d\n", err); |
Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1353 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1354 | err = drm_dp_link_probe(sor->aux, &link); |
| 1355 | if (err < 0) { |
| 1356 | dev_err(sor->dev, "failed to probe eDP link: %d\n", err); |
| 1357 | return; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1358 | } |
| 1359 | |
Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1360 | /* switch to safe parent clock */ |
| 1361 | err = tegra_sor_set_parent_clock(sor, sor->clk_safe); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1362 | if (err < 0) |
| 1363 | dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); |
| 1364 | |
Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1365 | memset(&config, 0, sizeof(config)); |
Stéphane Marchesin | 054b1bd | 2014-06-19 18:18:29 -0700 | [diff] [blame] | 1366 | config.bits_per_pixel = output->connector.display_info.bpc * 3; |
Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1367 | |
Thierry Reding | a198359 | 2015-07-21 16:46:52 +0200 | [diff] [blame] | 1368 | err = tegra_sor_compute_config(sor, mode, &config, &link); |
Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1369 | if (err < 0) |
Thierry Reding | a198359 | 2015-07-21 16:46:52 +0200 | [diff] [blame] | 1370 | dev_err(sor->dev, "failed to compute configuration: %d\n", err); |
Thierry Reding | 34fa183 | 2014-06-05 16:31:10 +0200 | [diff] [blame] | 1371 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1372 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1373 | value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; |
| 1374 | value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_DPCLK; |
| 1375 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 1376 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1377 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1378 | value &= ~SOR_PLL2_BANDGAP_POWERDOWN; |
| 1379 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1380 | usleep_range(20, 100); |
| 1381 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1382 | value = tegra_sor_readl(sor, SOR_PLL3); |
| 1383 | value |= SOR_PLL3_PLL_VDD_MODE_3V3; |
| 1384 | tegra_sor_writel(sor, value, SOR_PLL3); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1385 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1386 | value = SOR_PLL0_ICHPMP(0xf) | SOR_PLL0_VCOCAP_RST | |
| 1387 | SOR_PLL0_PLLREG_LEVEL_V45 | SOR_PLL0_RESISTOR_EXT; |
| 1388 | tegra_sor_writel(sor, value, SOR_PLL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1389 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1390 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1391 | value |= SOR_PLL2_SEQ_PLLCAPPD; |
| 1392 | value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| 1393 | value |= SOR_PLL2_LVDS_ENABLE; |
| 1394 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1395 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1396 | value = SOR_PLL1_TERM_COMPOUT | SOR_PLL1_TMDS_TERM; |
| 1397 | tegra_sor_writel(sor, value, SOR_PLL1); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1398 | |
| 1399 | while (true) { |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1400 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1401 | if ((value & SOR_PLL2_SEQ_PLLCAPPD_ENFORCE) == 0) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1402 | break; |
| 1403 | |
| 1404 | usleep_range(250, 1000); |
| 1405 | } |
| 1406 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1407 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1408 | value &= ~SOR_PLL2_POWERDOWN_OVERRIDE; |
| 1409 | value &= ~SOR_PLL2_PORT_POWERDOWN; |
| 1410 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1411 | |
| 1412 | /* |
| 1413 | * power up |
| 1414 | */ |
| 1415 | |
| 1416 | /* set safe link bandwidth (1.62 Gbps) */ |
| 1417 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1418 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
| 1419 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G1_62; |
| 1420 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 1421 | |
| 1422 | /* step 1 */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1423 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1424 | value |= SOR_PLL2_SEQ_PLLCAPPD_ENFORCE | SOR_PLL2_PORT_POWERDOWN | |
| 1425 | SOR_PLL2_BANDGAP_POWERDOWN; |
| 1426 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1427 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1428 | value = tegra_sor_readl(sor, SOR_PLL0); |
| 1429 | value |= SOR_PLL0_VCOPD | SOR_PLL0_PWR; |
| 1430 | tegra_sor_writel(sor, value, SOR_PLL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1431 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1432 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1433 | value &= ~SOR_DP_PADCTL_PAD_CAL_PD; |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1434 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1435 | |
| 1436 | /* step 2 */ |
| 1437 | err = tegra_io_rail_power_on(TEGRA_IO_RAIL_LVDS); |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1438 | if (err < 0) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1439 | 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] | 1440 | |
| 1441 | usleep_range(5, 100); |
| 1442 | |
| 1443 | /* step 3 */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1444 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1445 | value &= ~SOR_PLL2_BANDGAP_POWERDOWN; |
| 1446 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1447 | |
| 1448 | usleep_range(20, 100); |
| 1449 | |
| 1450 | /* step 4 */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1451 | value = tegra_sor_readl(sor, SOR_PLL0); |
| 1452 | value &= ~SOR_PLL0_VCOPD; |
| 1453 | value &= ~SOR_PLL0_PWR; |
| 1454 | tegra_sor_writel(sor, value, SOR_PLL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1455 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1456 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1457 | value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| 1458 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1459 | |
| 1460 | usleep_range(200, 1000); |
| 1461 | |
| 1462 | /* step 5 */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1463 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1464 | value &= ~SOR_PLL2_PORT_POWERDOWN; |
| 1465 | tegra_sor_writel(sor, value, SOR_PLL2); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1466 | |
Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1467 | /* switch to DP parent clock */ |
| 1468 | err = tegra_sor_set_parent_clock(sor, sor->clk_dp); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1469 | if (err < 0) |
Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1470 | dev_err(sor->dev, "failed to set parent clock: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1471 | |
Thierry Reding | 899451b | 2014-06-05 16:19:48 +0200 | [diff] [blame] | 1472 | /* power DP lanes */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1473 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
Thierry Reding | 899451b | 2014-06-05 16:19:48 +0200 | [diff] [blame] | 1474 | |
| 1475 | if (link.num_lanes <= 2) |
| 1476 | value &= ~(SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2); |
| 1477 | else |
| 1478 | value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_2; |
| 1479 | |
| 1480 | if (link.num_lanes <= 1) |
| 1481 | value &= ~SOR_DP_PADCTL_PD_TXD_1; |
| 1482 | else |
| 1483 | value |= SOR_DP_PADCTL_PD_TXD_1; |
| 1484 | |
| 1485 | if (link.num_lanes == 0) |
| 1486 | value &= ~SOR_DP_PADCTL_PD_TXD_0; |
| 1487 | else |
| 1488 | value |= SOR_DP_PADCTL_PD_TXD_0; |
| 1489 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1490 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1491 | |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1492 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1493 | value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK; |
Thierry Reding | 0c90a18 | 2014-06-05 16:29:46 +0200 | [diff] [blame] | 1494 | value |= SOR_DP_LINKCTL_LANE_COUNT(link.num_lanes); |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1495 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1496 | |
| 1497 | /* start lane sequencer */ |
| 1498 | value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN | |
| 1499 | SOR_LANE_SEQ_CTL_POWER_STATE_UP; |
| 1500 | tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); |
| 1501 | |
| 1502 | while (true) { |
| 1503 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 1504 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) |
| 1505 | break; |
| 1506 | |
| 1507 | usleep_range(250, 1000); |
| 1508 | } |
| 1509 | |
Thierry Reding | a4263fe | 2014-06-05 16:16:23 +0200 | [diff] [blame] | 1510 | /* set link bandwidth */ |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1511 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1512 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
Thierry Reding | a4263fe | 2014-06-05 16:16:23 +0200 | [diff] [blame] | 1513 | value |= drm_dp_link_rate_to_bw_code(link.rate) << 2; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1514 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 1515 | |
Thierry Reding | 402f6bc | 2015-07-21 16:48:19 +0200 | [diff] [blame] | 1516 | tegra_sor_apply_config(sor, &config); |
| 1517 | |
| 1518 | /* enable link */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1519 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1520 | value |= SOR_DP_LINKCTL_ENABLE; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1521 | value |= SOR_DP_LINKCTL_ENHANCED_FRAME; |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1522 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1523 | |
| 1524 | for (i = 0, value = 0; i < 4; i++) { |
| 1525 | unsigned long lane = SOR_DP_TPG_CHANNEL_CODING | |
| 1526 | SOR_DP_TPG_SCRAMBLER_GALIOS | |
| 1527 | SOR_DP_TPG_PATTERN_NONE; |
| 1528 | value = (value << 8) | lane; |
| 1529 | } |
| 1530 | |
| 1531 | tegra_sor_writel(sor, value, SOR_DP_TPG); |
| 1532 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1533 | /* enable pad calibration logic */ |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1534 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1535 | value |= SOR_DP_PADCTL_PAD_CAL_PD; |
Thierry Reding | a9a9e4f | 2015-04-27 15:01:14 +0200 | [diff] [blame] | 1536 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1537 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1538 | err = drm_dp_link_probe(sor->aux, &link); |
| 1539 | if (err < 0) |
| 1540 | dev_err(sor->dev, "failed to probe eDP link: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1541 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1542 | err = drm_dp_link_power_up(sor->aux, &link); |
| 1543 | if (err < 0) |
| 1544 | 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] | 1545 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1546 | err = drm_dp_link_configure(sor->aux, &link); |
| 1547 | if (err < 0) |
| 1548 | dev_err(sor->dev, "failed to configure eDP link: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1549 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1550 | rate = drm_dp_link_rate_to_bw_code(link.rate); |
| 1551 | lanes = link.num_lanes; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1552 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1553 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1554 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
| 1555 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED(rate); |
| 1556 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1557 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1558 | value = tegra_sor_readl(sor, SOR_DP_LINKCTL0); |
| 1559 | value &= ~SOR_DP_LINKCTL_LANE_COUNT_MASK; |
| 1560 | value |= SOR_DP_LINKCTL_LANE_COUNT(lanes); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1561 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1562 | if (link.capabilities & DP_LINK_CAP_ENHANCED_FRAMING) |
| 1563 | value |= SOR_DP_LINKCTL_ENHANCED_FRAME; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1564 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1565 | tegra_sor_writel(sor, value, SOR_DP_LINKCTL0); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1566 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1567 | /* disable training pattern generator */ |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1568 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1569 | for (i = 0; i < link.num_lanes; i++) { |
| 1570 | unsigned long lane = SOR_DP_TPG_CHANNEL_CODING | |
| 1571 | SOR_DP_TPG_SCRAMBLER_GALIOS | |
| 1572 | SOR_DP_TPG_PATTERN_NONE; |
| 1573 | value = (value << 8) | lane; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
Thierry Reding | 01b9bea | 2015-11-11 17:15:29 +0100 | [diff] [blame] | 1576 | tegra_sor_writel(sor, value, SOR_DP_TPG); |
| 1577 | |
| 1578 | err = tegra_sor_dp_train_fast(sor, &link); |
| 1579 | if (err < 0) |
| 1580 | dev_err(sor->dev, "DP fast link training failed: %d\n", err); |
| 1581 | |
| 1582 | dev_dbg(sor->dev, "fast link training succeeded\n"); |
| 1583 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1584 | err = tegra_sor_power_up(sor, 250); |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1585 | if (err < 0) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1586 | dev_err(sor->dev, "failed to power up SOR: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1587 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1588 | /* CSTM (LVDS, link A/B, upper) */ |
Stéphane Marchesin | 143b1df | 2014-05-22 20:32:47 -0700 | [diff] [blame] | 1589 | 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] | 1590 | SOR_CSTM_UPPER; |
| 1591 | tegra_sor_writel(sor, value, SOR_CSTM); |
| 1592 | |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 1593 | /* use DP-A protocol */ |
| 1594 | value = tegra_sor_readl(sor, SOR_STATE1); |
| 1595 | value &= ~SOR_STATE_ASY_PROTOCOL_MASK; |
| 1596 | value |= SOR_STATE_ASY_PROTOCOL_DP_A; |
| 1597 | tegra_sor_writel(sor, value, SOR_STATE1); |
| 1598 | |
| 1599 | tegra_sor_mode_set(sor, mode, info); |
| 1600 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1601 | /* PWM setup */ |
| 1602 | err = tegra_sor_setup_pwm(sor, 250); |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1603 | if (err < 0) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1604 | dev_err(sor->dev, "failed to setup PWM: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1605 | |
Thierry Reding | 666cb87 | 2014-12-08 16:32:47 +0100 | [diff] [blame] | 1606 | tegra_sor_update(sor); |
| 1607 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1608 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 1609 | value |= SOR_ENABLE; |
| 1610 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 1611 | |
Thierry Reding | 666cb87 | 2014-12-08 16:32:47 +0100 | [diff] [blame] | 1612 | tegra_dc_commit(dc); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1613 | |
| 1614 | err = tegra_sor_attach(sor); |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1615 | if (err < 0) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1616 | dev_err(sor->dev, "failed to attach SOR: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1617 | |
| 1618 | err = tegra_sor_wakeup(sor); |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1619 | if (err < 0) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1620 | dev_err(sor->dev, "failed to enable DC: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1621 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 1622 | if (output->panel) |
| 1623 | drm_panel_enable(output->panel); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1624 | } |
| 1625 | |
Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1626 | static int |
| 1627 | tegra_sor_encoder_atomic_check(struct drm_encoder *encoder, |
| 1628 | struct drm_crtc_state *crtc_state, |
| 1629 | struct drm_connector_state *conn_state) |
| 1630 | { |
| 1631 | struct tegra_output *output = encoder_to_output(encoder); |
| 1632 | struct tegra_dc *dc = to_tegra_dc(conn_state->crtc); |
| 1633 | unsigned long pclk = crtc_state->mode.clock * 1000; |
| 1634 | struct tegra_sor *sor = to_sor(output); |
| 1635 | int err; |
| 1636 | |
| 1637 | err = tegra_dc_state_setup_clock(dc, crtc_state, sor->clk_parent, |
| 1638 | pclk, 0); |
| 1639 | if (err < 0) { |
| 1640 | dev_err(output->dev, "failed to setup CRTC state: %d\n", err); |
| 1641 | return err; |
| 1642 | } |
| 1643 | |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1647 | static const struct drm_encoder_helper_funcs tegra_sor_edp_helpers = { |
Thierry Reding | 850bab4 | 2015-07-29 17:58:41 +0200 | [diff] [blame] | 1648 | .disable = tegra_sor_edp_disable, |
| 1649 | .enable = tegra_sor_edp_enable, |
Thierry Reding | 82f1511 | 2014-12-08 17:26:46 +0100 | [diff] [blame] | 1650 | .atomic_check = tegra_sor_encoder_atomic_check, |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 1651 | }; |
| 1652 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1653 | static inline u32 tegra_sor_hdmi_subpack(const u8 *ptr, size_t size) |
| 1654 | { |
| 1655 | u32 value = 0; |
| 1656 | size_t i; |
| 1657 | |
| 1658 | for (i = size; i > 0; i--) |
| 1659 | value = (value << 8) | ptr[i - 1]; |
| 1660 | |
| 1661 | return value; |
| 1662 | } |
| 1663 | |
| 1664 | static void tegra_sor_hdmi_write_infopack(struct tegra_sor *sor, |
| 1665 | const void *data, size_t size) |
| 1666 | { |
| 1667 | const u8 *ptr = data; |
| 1668 | unsigned long offset; |
| 1669 | size_t i, j; |
| 1670 | u32 value; |
| 1671 | |
| 1672 | switch (ptr[0]) { |
| 1673 | case HDMI_INFOFRAME_TYPE_AVI: |
| 1674 | offset = SOR_HDMI_AVI_INFOFRAME_HEADER; |
| 1675 | break; |
| 1676 | |
| 1677 | case HDMI_INFOFRAME_TYPE_AUDIO: |
| 1678 | offset = SOR_HDMI_AUDIO_INFOFRAME_HEADER; |
| 1679 | break; |
| 1680 | |
| 1681 | case HDMI_INFOFRAME_TYPE_VENDOR: |
| 1682 | offset = SOR_HDMI_VSI_INFOFRAME_HEADER; |
| 1683 | break; |
| 1684 | |
| 1685 | default: |
| 1686 | dev_err(sor->dev, "unsupported infoframe type: %02x\n", |
| 1687 | ptr[0]); |
| 1688 | return; |
| 1689 | } |
| 1690 | |
| 1691 | value = INFOFRAME_HEADER_TYPE(ptr[0]) | |
| 1692 | INFOFRAME_HEADER_VERSION(ptr[1]) | |
| 1693 | INFOFRAME_HEADER_LEN(ptr[2]); |
| 1694 | tegra_sor_writel(sor, value, offset); |
| 1695 | offset++; |
| 1696 | |
| 1697 | /* |
| 1698 | * Each subpack contains 7 bytes, divided into: |
| 1699 | * - subpack_low: bytes 0 - 3 |
| 1700 | * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00) |
| 1701 | */ |
| 1702 | for (i = 3, j = 0; i < size; i += 7, j += 8) { |
| 1703 | size_t rem = size - i, num = min_t(size_t, rem, 4); |
| 1704 | |
| 1705 | value = tegra_sor_hdmi_subpack(&ptr[i], num); |
| 1706 | tegra_sor_writel(sor, value, offset++); |
| 1707 | |
| 1708 | num = min_t(size_t, rem - num, 3); |
| 1709 | |
| 1710 | value = tegra_sor_hdmi_subpack(&ptr[i + 4], num); |
| 1711 | tegra_sor_writel(sor, value, offset++); |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | static int |
| 1716 | tegra_sor_hdmi_setup_avi_infoframe(struct tegra_sor *sor, |
| 1717 | const struct drm_display_mode *mode) |
| 1718 | { |
| 1719 | u8 buffer[HDMI_INFOFRAME_SIZE(AVI)]; |
| 1720 | struct hdmi_avi_infoframe frame; |
| 1721 | u32 value; |
| 1722 | int err; |
| 1723 | |
| 1724 | /* disable AVI infoframe */ |
| 1725 | value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL); |
| 1726 | value &= ~INFOFRAME_CTRL_SINGLE; |
| 1727 | value &= ~INFOFRAME_CTRL_OTHER; |
| 1728 | value &= ~INFOFRAME_CTRL_ENABLE; |
| 1729 | tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL); |
| 1730 | |
| 1731 | err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); |
| 1732 | if (err < 0) { |
| 1733 | dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err); |
| 1734 | return err; |
| 1735 | } |
| 1736 | |
| 1737 | err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer)); |
| 1738 | if (err < 0) { |
| 1739 | dev_err(sor->dev, "failed to pack AVI infoframe: %d\n", err); |
| 1740 | return err; |
| 1741 | } |
| 1742 | |
| 1743 | tegra_sor_hdmi_write_infopack(sor, buffer, err); |
| 1744 | |
| 1745 | /* enable AVI infoframe */ |
| 1746 | value = tegra_sor_readl(sor, SOR_HDMI_AVI_INFOFRAME_CTRL); |
| 1747 | value |= INFOFRAME_CTRL_CHECKSUM_ENABLE; |
| 1748 | value |= INFOFRAME_CTRL_ENABLE; |
| 1749 | tegra_sor_writel(sor, value, SOR_HDMI_AVI_INFOFRAME_CTRL); |
| 1750 | |
| 1751 | return 0; |
| 1752 | } |
| 1753 | |
| 1754 | static void tegra_sor_hdmi_disable_audio_infoframe(struct tegra_sor *sor) |
| 1755 | { |
| 1756 | u32 value; |
| 1757 | |
| 1758 | value = tegra_sor_readl(sor, SOR_HDMI_AUDIO_INFOFRAME_CTRL); |
| 1759 | value &= ~INFOFRAME_CTRL_ENABLE; |
| 1760 | tegra_sor_writel(sor, value, SOR_HDMI_AUDIO_INFOFRAME_CTRL); |
| 1761 | } |
| 1762 | |
| 1763 | static struct tegra_sor_hdmi_settings * |
| 1764 | tegra_sor_hdmi_find_settings(struct tegra_sor *sor, unsigned long frequency) |
| 1765 | { |
| 1766 | unsigned int i; |
| 1767 | |
| 1768 | for (i = 0; i < sor->num_settings; i++) |
| 1769 | if (frequency <= sor->settings[i].frequency) |
| 1770 | return &sor->settings[i]; |
| 1771 | |
| 1772 | return NULL; |
| 1773 | } |
| 1774 | |
| 1775 | static void tegra_sor_hdmi_disable(struct drm_encoder *encoder) |
| 1776 | { |
| 1777 | struct tegra_output *output = encoder_to_output(encoder); |
| 1778 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
| 1779 | struct tegra_sor *sor = to_sor(output); |
| 1780 | u32 value; |
| 1781 | int err; |
| 1782 | |
| 1783 | err = tegra_sor_detach(sor); |
| 1784 | if (err < 0) |
| 1785 | dev_err(sor->dev, "failed to detach SOR: %d\n", err); |
| 1786 | |
| 1787 | tegra_sor_writel(sor, 0, SOR_STATE1); |
| 1788 | tegra_sor_update(sor); |
| 1789 | |
| 1790 | /* disable display to SOR clock */ |
| 1791 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 1792 | value &= ~SOR1_TIMING_CYA; |
| 1793 | value &= ~SOR1_ENABLE; |
| 1794 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 1795 | |
| 1796 | tegra_dc_commit(dc); |
| 1797 | |
| 1798 | err = tegra_sor_power_down(sor); |
| 1799 | if (err < 0) |
| 1800 | dev_err(sor->dev, "failed to power down SOR: %d\n", err); |
| 1801 | |
| 1802 | err = tegra_io_rail_power_off(TEGRA_IO_RAIL_HDMI); |
| 1803 | if (err < 0) |
| 1804 | dev_err(sor->dev, "failed to power off HDMI rail: %d\n", err); |
| 1805 | |
| 1806 | reset_control_assert(sor->rst); |
| 1807 | usleep_range(1000, 2000); |
| 1808 | clk_disable_unprepare(sor->clk); |
| 1809 | } |
| 1810 | |
| 1811 | static void tegra_sor_hdmi_enable(struct drm_encoder *encoder) |
| 1812 | { |
| 1813 | struct tegra_output *output = encoder_to_output(encoder); |
| 1814 | unsigned int h_ref_to_sync = 1, pulse_start, max_ac; |
| 1815 | struct tegra_dc *dc = to_tegra_dc(encoder->crtc); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1816 | struct tegra_sor_hdmi_settings *settings; |
| 1817 | struct tegra_sor *sor = to_sor(output); |
| 1818 | struct drm_display_mode *mode; |
| 1819 | struct drm_display_info *info; |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 1820 | unsigned int div; |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1821 | u32 value; |
| 1822 | int err; |
| 1823 | |
| 1824 | mode = &encoder->crtc->state->adjusted_mode; |
| 1825 | info = &output->connector.display_info; |
| 1826 | |
| 1827 | err = clk_prepare_enable(sor->clk); |
| 1828 | if (err < 0) |
| 1829 | dev_err(sor->dev, "failed to enable clock: %d\n", err); |
| 1830 | |
| 1831 | usleep_range(1000, 2000); |
| 1832 | |
| 1833 | reset_control_deassert(sor->rst); |
| 1834 | |
Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1835 | /* switch to safe parent clock */ |
| 1836 | err = tegra_sor_set_parent_clock(sor, sor->clk_safe); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1837 | if (err < 0) |
| 1838 | dev_err(sor->dev, "failed to set safe parent clock: %d\n", err); |
| 1839 | |
| 1840 | div = clk_get_rate(sor->clk) / 1000000 * 4; |
| 1841 | |
| 1842 | err = tegra_io_rail_power_on(TEGRA_IO_RAIL_HDMI); |
| 1843 | if (err < 0) |
| 1844 | dev_err(sor->dev, "failed to power on HDMI rail: %d\n", err); |
| 1845 | |
| 1846 | usleep_range(20, 100); |
| 1847 | |
| 1848 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1849 | value &= ~SOR_PLL2_BANDGAP_POWERDOWN; |
| 1850 | tegra_sor_writel(sor, value, SOR_PLL2); |
| 1851 | |
| 1852 | usleep_range(20, 100); |
| 1853 | |
| 1854 | value = tegra_sor_readl(sor, SOR_PLL3); |
| 1855 | value &= ~SOR_PLL3_PLL_VDD_MODE_3V3; |
| 1856 | tegra_sor_writel(sor, value, SOR_PLL3); |
| 1857 | |
| 1858 | value = tegra_sor_readl(sor, SOR_PLL0); |
| 1859 | value &= ~SOR_PLL0_VCOPD; |
| 1860 | value &= ~SOR_PLL0_PWR; |
| 1861 | tegra_sor_writel(sor, value, SOR_PLL0); |
| 1862 | |
| 1863 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1864 | value &= ~SOR_PLL2_SEQ_PLLCAPPD_ENFORCE; |
| 1865 | tegra_sor_writel(sor, value, SOR_PLL2); |
| 1866 | |
| 1867 | usleep_range(200, 400); |
| 1868 | |
| 1869 | value = tegra_sor_readl(sor, SOR_PLL2); |
| 1870 | value &= ~SOR_PLL2_POWERDOWN_OVERRIDE; |
| 1871 | value &= ~SOR_PLL2_PORT_POWERDOWN; |
| 1872 | tegra_sor_writel(sor, value, SOR_PLL2); |
| 1873 | |
| 1874 | usleep_range(20, 100); |
| 1875 | |
| 1876 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
| 1877 | value |= SOR_DP_PADCTL_PD_TXD_3 | SOR_DP_PADCTL_PD_TXD_0 | |
| 1878 | SOR_DP_PADCTL_PD_TXD_1 | SOR_DP_PADCTL_PD_TXD_2; |
| 1879 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
| 1880 | |
| 1881 | while (true) { |
| 1882 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 1883 | if ((value & SOR_LANE_SEQ_CTL_STATE_BUSY) == 0) |
| 1884 | break; |
| 1885 | |
| 1886 | usleep_range(250, 1000); |
| 1887 | } |
| 1888 | |
| 1889 | value = SOR_LANE_SEQ_CTL_TRIGGER | SOR_LANE_SEQ_CTL_SEQUENCE_DOWN | |
| 1890 | SOR_LANE_SEQ_CTL_POWER_STATE_UP | SOR_LANE_SEQ_CTL_DELAY(5); |
| 1891 | tegra_sor_writel(sor, value, SOR_LANE_SEQ_CTL); |
| 1892 | |
| 1893 | while (true) { |
| 1894 | value = tegra_sor_readl(sor, SOR_LANE_SEQ_CTL); |
| 1895 | if ((value & SOR_LANE_SEQ_CTL_TRIGGER) == 0) |
| 1896 | break; |
| 1897 | |
| 1898 | usleep_range(250, 1000); |
| 1899 | } |
| 1900 | |
| 1901 | value = tegra_sor_readl(sor, SOR_CLK_CNTRL); |
| 1902 | value &= ~SOR_CLK_CNTRL_DP_LINK_SPEED_MASK; |
| 1903 | value &= ~SOR_CLK_CNTRL_DP_CLK_SEL_MASK; |
| 1904 | |
| 1905 | if (mode->clock < 340000) |
| 1906 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G2_70; |
| 1907 | else |
| 1908 | value |= SOR_CLK_CNTRL_DP_LINK_SPEED_G5_40; |
| 1909 | |
| 1910 | value |= SOR_CLK_CNTRL_DP_CLK_SEL_SINGLE_PCLK; |
| 1911 | tegra_sor_writel(sor, value, SOR_CLK_CNTRL); |
| 1912 | |
| 1913 | value = tegra_sor_readl(sor, SOR_DP_SPARE0); |
| 1914 | value |= SOR_DP_SPARE_DISP_VIDEO_PREAMBLE; |
| 1915 | value &= ~SOR_DP_SPARE_PANEL_INTERNAL; |
| 1916 | value |= SOR_DP_SPARE_SEQ_ENABLE; |
| 1917 | tegra_sor_writel(sor, value, SOR_DP_SPARE0); |
| 1918 | |
| 1919 | value = SOR_SEQ_CTL_PU_PC(0) | SOR_SEQ_CTL_PU_PC_ALT(0) | |
| 1920 | SOR_SEQ_CTL_PD_PC(8) | SOR_SEQ_CTL_PD_PC_ALT(8); |
| 1921 | tegra_sor_writel(sor, value, SOR_SEQ_CTL); |
| 1922 | |
| 1923 | value = SOR_SEQ_INST_DRIVE_PWM_OUT_LO | SOR_SEQ_INST_HALT | |
| 1924 | SOR_SEQ_INST_WAIT_VSYNC | SOR_SEQ_INST_WAIT(1); |
| 1925 | tegra_sor_writel(sor, value, SOR_SEQ_INST(0)); |
| 1926 | tegra_sor_writel(sor, value, SOR_SEQ_INST(8)); |
| 1927 | |
| 1928 | /* program the reference clock */ |
| 1929 | value = SOR_REFCLK_DIV_INT(div) | SOR_REFCLK_DIV_FRAC(div); |
| 1930 | tegra_sor_writel(sor, value, SOR_REFCLK); |
| 1931 | |
| 1932 | /* XXX don't hardcode */ |
| 1933 | value = SOR_XBAR_CTRL_LINK1_XSEL(4, 4) | |
| 1934 | SOR_XBAR_CTRL_LINK1_XSEL(3, 3) | |
| 1935 | SOR_XBAR_CTRL_LINK1_XSEL(2, 2) | |
| 1936 | SOR_XBAR_CTRL_LINK1_XSEL(1, 1) | |
| 1937 | SOR_XBAR_CTRL_LINK1_XSEL(0, 0) | |
| 1938 | SOR_XBAR_CTRL_LINK0_XSEL(4, 4) | |
| 1939 | SOR_XBAR_CTRL_LINK0_XSEL(3, 3) | |
| 1940 | SOR_XBAR_CTRL_LINK0_XSEL(2, 0) | |
| 1941 | SOR_XBAR_CTRL_LINK0_XSEL(1, 1) | |
| 1942 | SOR_XBAR_CTRL_LINK0_XSEL(0, 2); |
| 1943 | tegra_sor_writel(sor, value, SOR_XBAR_CTRL); |
| 1944 | |
| 1945 | tegra_sor_writel(sor, 0x00000000, SOR_XBAR_POL); |
| 1946 | |
Thierry Reding | 25bb2ce | 2015-08-03 14:23:29 +0200 | [diff] [blame] | 1947 | /* switch to parent clock */ |
| 1948 | err = tegra_sor_set_parent_clock(sor, sor->clk_parent); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 1949 | if (err < 0) |
| 1950 | dev_err(sor->dev, "failed to set parent clock: %d\n", err); |
| 1951 | |
| 1952 | value = SOR_INPUT_CONTROL_HDMI_SRC_SELECT(dc->pipe); |
| 1953 | |
| 1954 | /* XXX is this the proper check? */ |
| 1955 | if (mode->clock < 75000) |
| 1956 | value |= SOR_INPUT_CONTROL_ARM_VIDEO_RANGE_LIMITED; |
| 1957 | |
| 1958 | tegra_sor_writel(sor, value, SOR_INPUT_CONTROL); |
| 1959 | |
| 1960 | max_ac = ((mode->htotal - mode->hdisplay) - SOR_REKEY - 18) / 32; |
| 1961 | |
| 1962 | value = SOR_HDMI_CTRL_ENABLE | SOR_HDMI_CTRL_MAX_AC_PACKET(max_ac) | |
| 1963 | SOR_HDMI_CTRL_AUDIO_LAYOUT | SOR_HDMI_CTRL_REKEY(SOR_REKEY); |
| 1964 | tegra_sor_writel(sor, value, SOR_HDMI_CTRL); |
| 1965 | |
| 1966 | /* H_PULSE2 setup */ |
| 1967 | pulse_start = h_ref_to_sync + (mode->hsync_end - mode->hsync_start) + |
| 1968 | (mode->htotal - mode->hsync_end) - 10; |
| 1969 | |
| 1970 | value = PULSE_LAST_END_A | PULSE_QUAL_VACTIVE | |
| 1971 | PULSE_POLARITY_HIGH | PULSE_MODE_NORMAL; |
| 1972 | tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL); |
| 1973 | |
| 1974 | value = PULSE_END(pulse_start + 8) | PULSE_START(pulse_start); |
| 1975 | tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A); |
| 1976 | |
| 1977 | value = tegra_dc_readl(dc, DC_DISP_DISP_SIGNAL_OPTIONS0); |
| 1978 | value |= H_PULSE2_ENABLE; |
| 1979 | tegra_dc_writel(dc, value, DC_DISP_DISP_SIGNAL_OPTIONS0); |
| 1980 | |
| 1981 | /* infoframe setup */ |
| 1982 | err = tegra_sor_hdmi_setup_avi_infoframe(sor, mode); |
| 1983 | if (err < 0) |
| 1984 | dev_err(sor->dev, "failed to setup AVI infoframe: %d\n", err); |
| 1985 | |
| 1986 | /* XXX HDMI audio support not implemented yet */ |
| 1987 | tegra_sor_hdmi_disable_audio_infoframe(sor); |
| 1988 | |
| 1989 | /* use single TMDS protocol */ |
| 1990 | value = tegra_sor_readl(sor, SOR_STATE1); |
| 1991 | value &= ~SOR_STATE_ASY_PROTOCOL_MASK; |
| 1992 | value |= SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A; |
| 1993 | tegra_sor_writel(sor, value, SOR_STATE1); |
| 1994 | |
| 1995 | /* power up pad calibration */ |
| 1996 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
| 1997 | value &= ~SOR_DP_PADCTL_PAD_CAL_PD; |
| 1998 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
| 1999 | |
| 2000 | /* production settings */ |
| 2001 | settings = tegra_sor_hdmi_find_settings(sor, mode->clock * 1000); |
Dan Carpenter | db8b42f | 2015-08-17 17:37:03 +0300 | [diff] [blame] | 2002 | if (!settings) { |
| 2003 | dev_err(sor->dev, "no settings for pixel clock %d Hz\n", |
| 2004 | mode->clock * 1000); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2005 | return; |
| 2006 | } |
| 2007 | |
| 2008 | value = tegra_sor_readl(sor, SOR_PLL0); |
| 2009 | value &= ~SOR_PLL0_ICHPMP_MASK; |
| 2010 | value &= ~SOR_PLL0_VCOCAP_MASK; |
| 2011 | value |= SOR_PLL0_ICHPMP(settings->ichpmp); |
| 2012 | value |= SOR_PLL0_VCOCAP(settings->vcocap); |
| 2013 | tegra_sor_writel(sor, value, SOR_PLL0); |
| 2014 | |
| 2015 | tegra_sor_dp_term_calibrate(sor); |
| 2016 | |
| 2017 | value = tegra_sor_readl(sor, SOR_PLL1); |
| 2018 | value &= ~SOR_PLL1_LOADADJ_MASK; |
| 2019 | value |= SOR_PLL1_LOADADJ(settings->loadadj); |
| 2020 | tegra_sor_writel(sor, value, SOR_PLL1); |
| 2021 | |
| 2022 | value = tegra_sor_readl(sor, SOR_PLL3); |
| 2023 | value &= ~SOR_PLL3_BG_VREF_LEVEL_MASK; |
| 2024 | value |= SOR_PLL3_BG_VREF_LEVEL(settings->bg_vref); |
| 2025 | tegra_sor_writel(sor, value, SOR_PLL3); |
| 2026 | |
| 2027 | value = settings->drive_current[0] << 24 | |
| 2028 | settings->drive_current[1] << 16 | |
| 2029 | settings->drive_current[2] << 8 | |
| 2030 | settings->drive_current[3] << 0; |
| 2031 | tegra_sor_writel(sor, value, SOR_LANE_DRIVE_CURRENT0); |
| 2032 | |
| 2033 | value = settings->preemphasis[0] << 24 | |
| 2034 | settings->preemphasis[1] << 16 | |
| 2035 | settings->preemphasis[2] << 8 | |
| 2036 | settings->preemphasis[3] << 0; |
| 2037 | tegra_sor_writel(sor, value, SOR_LANE_PREEMPHASIS0); |
| 2038 | |
| 2039 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
| 2040 | value &= ~SOR_DP_PADCTL_TX_PU_MASK; |
| 2041 | value |= SOR_DP_PADCTL_TX_PU_ENABLE; |
| 2042 | value |= SOR_DP_PADCTL_TX_PU(settings->tx_pu); |
| 2043 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
| 2044 | |
| 2045 | /* power down pad calibration */ |
| 2046 | value = tegra_sor_readl(sor, SOR_DP_PADCTL0); |
| 2047 | value |= SOR_DP_PADCTL_PAD_CAL_PD; |
| 2048 | tegra_sor_writel(sor, value, SOR_DP_PADCTL0); |
| 2049 | |
| 2050 | /* miscellaneous display controller settings */ |
| 2051 | value = VSYNC_H_POSITION(1); |
| 2052 | tegra_dc_writel(dc, value, DC_DISP_DISP_TIMING_OPTIONS); |
| 2053 | |
| 2054 | value = tegra_dc_readl(dc, DC_DISP_DISP_COLOR_CONTROL); |
| 2055 | value &= ~DITHER_CONTROL_MASK; |
| 2056 | value &= ~BASE_COLOR_SIZE_MASK; |
| 2057 | |
| 2058 | switch (info->bpc) { |
| 2059 | case 6: |
| 2060 | value |= BASE_COLOR_SIZE_666; |
| 2061 | break; |
| 2062 | |
| 2063 | case 8: |
| 2064 | value |= BASE_COLOR_SIZE_888; |
| 2065 | break; |
| 2066 | |
| 2067 | default: |
| 2068 | WARN(1, "%u bits-per-color not supported\n", info->bpc); |
| 2069 | break; |
| 2070 | } |
| 2071 | |
| 2072 | tegra_dc_writel(dc, value, DC_DISP_DISP_COLOR_CONTROL); |
| 2073 | |
| 2074 | err = tegra_sor_power_up(sor, 250); |
| 2075 | if (err < 0) |
| 2076 | dev_err(sor->dev, "failed to power up SOR: %d\n", err); |
| 2077 | |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 2078 | /* configure dynamic range of output */ |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2079 | value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe)); |
| 2080 | value &= ~SOR_HEAD_STATE_RANGECOMPRESS_MASK; |
| 2081 | value &= ~SOR_HEAD_STATE_DYNRANGE_MASK; |
| 2082 | tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe)); |
| 2083 | |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 2084 | /* configure colorspace */ |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2085 | value = tegra_sor_readl(sor, SOR_HEAD_STATE0(dc->pipe)); |
| 2086 | value &= ~SOR_HEAD_STATE_COLORSPACE_MASK; |
| 2087 | value |= SOR_HEAD_STATE_COLORSPACE_RGB; |
| 2088 | tegra_sor_writel(sor, value, SOR_HEAD_STATE0(dc->pipe)); |
| 2089 | |
Thierry Reding | 2bd1dd3 | 2015-08-03 15:46:15 +0200 | [diff] [blame^] | 2090 | tegra_sor_mode_set(sor, mode, info); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2091 | |
| 2092 | tegra_sor_update(sor); |
| 2093 | |
| 2094 | err = tegra_sor_attach(sor); |
| 2095 | if (err < 0) |
| 2096 | dev_err(sor->dev, "failed to attach SOR: %d\n", err); |
| 2097 | |
| 2098 | /* enable display to SOR clock and generate HDMI preamble */ |
| 2099 | value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS); |
| 2100 | value |= SOR1_ENABLE | SOR1_TIMING_CYA; |
| 2101 | tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS); |
| 2102 | |
| 2103 | tegra_dc_commit(dc); |
| 2104 | |
| 2105 | err = tegra_sor_wakeup(sor); |
| 2106 | if (err < 0) |
| 2107 | dev_err(sor->dev, "failed to wakeup SOR: %d\n", err); |
| 2108 | } |
| 2109 | |
| 2110 | static const struct drm_encoder_helper_funcs tegra_sor_hdmi_helpers = { |
| 2111 | .disable = tegra_sor_hdmi_disable, |
| 2112 | .enable = tegra_sor_hdmi_enable, |
| 2113 | .atomic_check = tegra_sor_encoder_atomic_check, |
| 2114 | }; |
| 2115 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2116 | static int tegra_sor_init(struct host1x_client *client) |
| 2117 | { |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 2118 | struct drm_device *drm = dev_get_drvdata(client->parent); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2119 | const struct drm_encoder_helper_funcs *helpers = NULL; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2120 | struct tegra_sor *sor = host1x_client_to_sor(client); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2121 | int connector = DRM_MODE_CONNECTOR_Unknown; |
| 2122 | int encoder = DRM_MODE_ENCODER_NONE; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2123 | int err; |
| 2124 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2125 | if (!sor->aux) { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2126 | if (sor->soc->supports_hdmi) { |
| 2127 | connector = DRM_MODE_CONNECTOR_HDMIA; |
| 2128 | encoder = DRM_MODE_ENCODER_TMDS; |
| 2129 | helpers = &tegra_sor_hdmi_helpers; |
| 2130 | } else if (sor->soc->supports_lvds) { |
| 2131 | connector = DRM_MODE_CONNECTOR_LVDS; |
| 2132 | encoder = DRM_MODE_ENCODER_LVDS; |
| 2133 | } |
| 2134 | } else { |
| 2135 | if (sor->soc->supports_edp) { |
| 2136 | connector = DRM_MODE_CONNECTOR_eDP; |
| 2137 | encoder = DRM_MODE_ENCODER_TMDS; |
| 2138 | helpers = &tegra_sor_edp_helpers; |
| 2139 | } else if (sor->soc->supports_dp) { |
| 2140 | connector = DRM_MODE_CONNECTOR_DisplayPort; |
| 2141 | encoder = DRM_MODE_ENCODER_TMDS; |
| 2142 | } |
| 2143 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2144 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2145 | sor->output.dev = sor->dev; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2146 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2147 | drm_connector_init(drm, &sor->output.connector, |
| 2148 | &tegra_sor_connector_funcs, |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2149 | connector); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2150 | drm_connector_helper_add(&sor->output.connector, |
| 2151 | &tegra_sor_connector_helper_funcs); |
| 2152 | sor->output.connector.dpms = DRM_MODE_DPMS_OFF; |
| 2153 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2154 | drm_encoder_init(drm, &sor->output.encoder, &tegra_sor_encoder_funcs, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 2155 | encoder, NULL); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2156 | drm_encoder_helper_add(&sor->output.encoder, helpers); |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2157 | |
| 2158 | drm_mode_connector_attach_encoder(&sor->output.connector, |
| 2159 | &sor->output.encoder); |
| 2160 | drm_connector_register(&sor->output.connector); |
| 2161 | |
Thierry Reding | ea130b2 | 2014-12-19 15:51:35 +0100 | [diff] [blame] | 2162 | err = tegra_output_init(drm, &sor->output); |
| 2163 | if (err < 0) { |
| 2164 | dev_err(client->dev, "failed to initialize output: %d\n", err); |
| 2165 | return err; |
| 2166 | } |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2167 | |
Thierry Reding | ea130b2 | 2014-12-19 15:51:35 +0100 | [diff] [blame] | 2168 | sor->output.encoder.possible_crtcs = 0x3; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2169 | |
Thierry Reding | a82752e | 2014-01-31 10:02:15 +0100 | [diff] [blame] | 2170 | if (IS_ENABLED(CONFIG_DEBUG_FS)) { |
Thierry Reding | 1b0c7b4 | 2014-05-28 13:46:12 +0200 | [diff] [blame] | 2171 | err = tegra_sor_debugfs_init(sor, drm->primary); |
Thierry Reding | a82752e | 2014-01-31 10:02:15 +0100 | [diff] [blame] | 2172 | if (err < 0) |
| 2173 | dev_err(sor->dev, "debugfs setup failed: %d\n", err); |
| 2174 | } |
| 2175 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2176 | if (sor->aux) { |
| 2177 | err = drm_dp_aux_attach(sor->aux, &sor->output); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2178 | if (err < 0) { |
| 2179 | dev_err(sor->dev, "failed to attach DP: %d\n", err); |
| 2180 | return err; |
| 2181 | } |
| 2182 | } |
| 2183 | |
Tomeu Vizoso | 535a65d | 2015-03-30 10:33:03 +0200 | [diff] [blame] | 2184 | /* |
| 2185 | * XXX: Remove this reset once proper hand-over from firmware to |
| 2186 | * kernel is possible. |
| 2187 | */ |
| 2188 | err = reset_control_assert(sor->rst); |
| 2189 | if (err < 0) { |
| 2190 | dev_err(sor->dev, "failed to assert SOR reset: %d\n", err); |
| 2191 | return err; |
| 2192 | } |
| 2193 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2194 | err = clk_prepare_enable(sor->clk); |
| 2195 | if (err < 0) { |
| 2196 | dev_err(sor->dev, "failed to enable clock: %d\n", err); |
| 2197 | return err; |
| 2198 | } |
| 2199 | |
Tomeu Vizoso | 535a65d | 2015-03-30 10:33:03 +0200 | [diff] [blame] | 2200 | usleep_range(1000, 3000); |
| 2201 | |
| 2202 | err = reset_control_deassert(sor->rst); |
| 2203 | if (err < 0) { |
| 2204 | dev_err(sor->dev, "failed to deassert SOR reset: %d\n", err); |
| 2205 | return err; |
| 2206 | } |
| 2207 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2208 | err = clk_prepare_enable(sor->clk_safe); |
| 2209 | if (err < 0) |
| 2210 | return err; |
| 2211 | |
| 2212 | err = clk_prepare_enable(sor->clk_dp); |
| 2213 | if (err < 0) |
| 2214 | return err; |
| 2215 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2216 | return 0; |
| 2217 | } |
| 2218 | |
| 2219 | static int tegra_sor_exit(struct host1x_client *client) |
| 2220 | { |
| 2221 | struct tegra_sor *sor = host1x_client_to_sor(client); |
| 2222 | int err; |
| 2223 | |
Thierry Reding | 328ec69 | 2014-12-19 15:55:08 +0100 | [diff] [blame] | 2224 | tegra_output_exit(&sor->output); |
| 2225 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2226 | if (sor->aux) { |
| 2227 | err = drm_dp_aux_detach(sor->aux); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2228 | if (err < 0) { |
| 2229 | dev_err(sor->dev, "failed to detach DP: %d\n", err); |
| 2230 | return err; |
| 2231 | } |
| 2232 | } |
| 2233 | |
Thierry Reding | 6fad8f6 | 2014-11-28 15:41:34 +0100 | [diff] [blame] | 2234 | clk_disable_unprepare(sor->clk_safe); |
| 2235 | clk_disable_unprepare(sor->clk_dp); |
| 2236 | clk_disable_unprepare(sor->clk); |
| 2237 | |
Thierry Reding | 4009c22 | 2014-12-19 15:47:30 +0100 | [diff] [blame] | 2238 | if (IS_ENABLED(CONFIG_DEBUG_FS)) |
| 2239 | tegra_sor_debugfs_exit(sor); |
Thierry Reding | a82752e | 2014-01-31 10:02:15 +0100 | [diff] [blame] | 2240 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2241 | return 0; |
| 2242 | } |
| 2243 | |
| 2244 | static const struct host1x_client_ops sor_client_ops = { |
| 2245 | .init = tegra_sor_init, |
| 2246 | .exit = tegra_sor_exit, |
| 2247 | }; |
| 2248 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2249 | static const struct tegra_sor_ops tegra_sor_edp_ops = { |
| 2250 | .name = "eDP", |
| 2251 | }; |
| 2252 | |
| 2253 | static int tegra_sor_hdmi_probe(struct tegra_sor *sor) |
| 2254 | { |
| 2255 | int err; |
| 2256 | |
| 2257 | sor->avdd_io_supply = devm_regulator_get(sor->dev, "avdd-io"); |
| 2258 | if (IS_ERR(sor->avdd_io_supply)) { |
| 2259 | dev_err(sor->dev, "cannot get AVDD I/O supply: %ld\n", |
| 2260 | PTR_ERR(sor->avdd_io_supply)); |
| 2261 | return PTR_ERR(sor->avdd_io_supply); |
| 2262 | } |
| 2263 | |
| 2264 | err = regulator_enable(sor->avdd_io_supply); |
| 2265 | if (err < 0) { |
| 2266 | dev_err(sor->dev, "failed to enable AVDD I/O supply: %d\n", |
| 2267 | err); |
| 2268 | return err; |
| 2269 | } |
| 2270 | |
| 2271 | sor->vdd_pll_supply = devm_regulator_get(sor->dev, "vdd-pll"); |
| 2272 | if (IS_ERR(sor->vdd_pll_supply)) { |
| 2273 | dev_err(sor->dev, "cannot get VDD PLL supply: %ld\n", |
| 2274 | PTR_ERR(sor->vdd_pll_supply)); |
| 2275 | return PTR_ERR(sor->vdd_pll_supply); |
| 2276 | } |
| 2277 | |
| 2278 | err = regulator_enable(sor->vdd_pll_supply); |
| 2279 | if (err < 0) { |
| 2280 | dev_err(sor->dev, "failed to enable VDD PLL supply: %d\n", |
| 2281 | err); |
| 2282 | return err; |
| 2283 | } |
| 2284 | |
| 2285 | sor->hdmi_supply = devm_regulator_get(sor->dev, "hdmi"); |
| 2286 | if (IS_ERR(sor->hdmi_supply)) { |
| 2287 | dev_err(sor->dev, "cannot get HDMI supply: %ld\n", |
| 2288 | PTR_ERR(sor->hdmi_supply)); |
| 2289 | return PTR_ERR(sor->hdmi_supply); |
| 2290 | } |
| 2291 | |
| 2292 | err = regulator_enable(sor->hdmi_supply); |
| 2293 | if (err < 0) { |
| 2294 | dev_err(sor->dev, "failed to enable HDMI supply: %d\n", err); |
| 2295 | return err; |
| 2296 | } |
| 2297 | |
| 2298 | return 0; |
| 2299 | } |
| 2300 | |
| 2301 | static int tegra_sor_hdmi_remove(struct tegra_sor *sor) |
| 2302 | { |
| 2303 | regulator_disable(sor->hdmi_supply); |
| 2304 | regulator_disable(sor->vdd_pll_supply); |
| 2305 | regulator_disable(sor->avdd_io_supply); |
| 2306 | |
| 2307 | return 0; |
| 2308 | } |
| 2309 | |
| 2310 | static const struct tegra_sor_ops tegra_sor_hdmi_ops = { |
| 2311 | .name = "HDMI", |
| 2312 | .probe = tegra_sor_hdmi_probe, |
| 2313 | .remove = tegra_sor_hdmi_remove, |
| 2314 | }; |
| 2315 | |
| 2316 | static const struct tegra_sor_soc tegra124_sor = { |
| 2317 | .supports_edp = true, |
| 2318 | .supports_lvds = true, |
| 2319 | .supports_hdmi = false, |
| 2320 | .supports_dp = false, |
| 2321 | }; |
| 2322 | |
| 2323 | static const struct tegra_sor_soc tegra210_sor = { |
| 2324 | .supports_edp = true, |
| 2325 | .supports_lvds = false, |
| 2326 | .supports_hdmi = false, |
| 2327 | .supports_dp = false, |
| 2328 | }; |
| 2329 | |
| 2330 | static const struct tegra_sor_soc tegra210_sor1 = { |
| 2331 | .supports_edp = false, |
| 2332 | .supports_lvds = false, |
| 2333 | .supports_hdmi = true, |
| 2334 | .supports_dp = true, |
| 2335 | |
| 2336 | .num_settings = ARRAY_SIZE(tegra210_sor_hdmi_defaults), |
| 2337 | .settings = tegra210_sor_hdmi_defaults, |
| 2338 | }; |
| 2339 | |
| 2340 | static const struct of_device_id tegra_sor_of_match[] = { |
| 2341 | { .compatible = "nvidia,tegra210-sor1", .data = &tegra210_sor1 }, |
| 2342 | { .compatible = "nvidia,tegra210-sor", .data = &tegra210_sor }, |
| 2343 | { .compatible = "nvidia,tegra124-sor", .data = &tegra124_sor }, |
| 2344 | { }, |
| 2345 | }; |
| 2346 | MODULE_DEVICE_TABLE(of, tegra_sor_of_match); |
| 2347 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2348 | static int tegra_sor_probe(struct platform_device *pdev) |
| 2349 | { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2350 | const struct of_device_id *match; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2351 | struct device_node *np; |
| 2352 | struct tegra_sor *sor; |
| 2353 | struct resource *regs; |
| 2354 | int err; |
| 2355 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2356 | match = of_match_device(tegra_sor_of_match, &pdev->dev); |
| 2357 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2358 | sor = devm_kzalloc(&pdev->dev, sizeof(*sor), GFP_KERNEL); |
| 2359 | if (!sor) |
| 2360 | return -ENOMEM; |
| 2361 | |
| 2362 | sor->output.dev = sor->dev = &pdev->dev; |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2363 | sor->soc = match->data; |
| 2364 | |
| 2365 | sor->settings = devm_kmemdup(&pdev->dev, sor->soc->settings, |
| 2366 | sor->soc->num_settings * |
| 2367 | sizeof(*sor->settings), |
| 2368 | GFP_KERNEL); |
| 2369 | if (!sor->settings) |
| 2370 | return -ENOMEM; |
| 2371 | |
| 2372 | sor->num_settings = sor->soc->num_settings; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2373 | |
| 2374 | np = of_parse_phandle(pdev->dev.of_node, "nvidia,dpaux", 0); |
| 2375 | if (np) { |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2376 | sor->aux = drm_dp_aux_find_by_of_node(np); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2377 | of_node_put(np); |
| 2378 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2379 | if (!sor->aux) |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2380 | return -EPROBE_DEFER; |
| 2381 | } |
| 2382 | |
Thierry Reding | 9542c23 | 2015-07-08 13:39:09 +0200 | [diff] [blame] | 2383 | if (!sor->aux) { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2384 | if (sor->soc->supports_hdmi) { |
| 2385 | sor->ops = &tegra_sor_hdmi_ops; |
| 2386 | } else if (sor->soc->supports_lvds) { |
| 2387 | dev_err(&pdev->dev, "LVDS not supported yet\n"); |
| 2388 | return -ENODEV; |
| 2389 | } else { |
| 2390 | dev_err(&pdev->dev, "unknown (non-DP) support\n"); |
| 2391 | return -ENODEV; |
| 2392 | } |
| 2393 | } else { |
| 2394 | if (sor->soc->supports_edp) { |
| 2395 | sor->ops = &tegra_sor_edp_ops; |
| 2396 | } else if (sor->soc->supports_dp) { |
| 2397 | dev_err(&pdev->dev, "DisplayPort not supported yet\n"); |
| 2398 | return -ENODEV; |
| 2399 | } else { |
| 2400 | dev_err(&pdev->dev, "unknown (DP) support\n"); |
| 2401 | return -ENODEV; |
| 2402 | } |
| 2403 | } |
| 2404 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2405 | err = tegra_output_probe(&sor->output); |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2406 | if (err < 0) { |
| 2407 | dev_err(&pdev->dev, "failed to probe output: %d\n", err); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2408 | return err; |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2409 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2410 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2411 | if (sor->ops && sor->ops->probe) { |
| 2412 | err = sor->ops->probe(sor); |
| 2413 | if (err < 0) { |
| 2414 | dev_err(&pdev->dev, "failed to probe %s: %d\n", |
| 2415 | sor->ops->name, err); |
| 2416 | goto output; |
| 2417 | } |
| 2418 | } |
| 2419 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2420 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2421 | sor->regs = devm_ioremap_resource(&pdev->dev, regs); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2422 | if (IS_ERR(sor->regs)) { |
| 2423 | err = PTR_ERR(sor->regs); |
| 2424 | goto remove; |
| 2425 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2426 | |
| 2427 | sor->rst = devm_reset_control_get(&pdev->dev, "sor"); |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2428 | if (IS_ERR(sor->rst)) { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2429 | err = PTR_ERR(sor->rst); |
| 2430 | dev_err(&pdev->dev, "failed to get reset control: %d\n", err); |
| 2431 | goto remove; |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2432 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2433 | |
| 2434 | sor->clk = devm_clk_get(&pdev->dev, NULL); |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2435 | if (IS_ERR(sor->clk)) { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2436 | err = PTR_ERR(sor->clk); |
| 2437 | dev_err(&pdev->dev, "failed to get module clock: %d\n", err); |
| 2438 | goto remove; |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2439 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2440 | |
| 2441 | sor->clk_parent = devm_clk_get(&pdev->dev, "parent"); |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2442 | if (IS_ERR(sor->clk_parent)) { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2443 | err = PTR_ERR(sor->clk_parent); |
| 2444 | dev_err(&pdev->dev, "failed to get parent clock: %d\n", err); |
| 2445 | goto remove; |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2446 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2447 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2448 | sor->clk_safe = devm_clk_get(&pdev->dev, "safe"); |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2449 | if (IS_ERR(sor->clk_safe)) { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2450 | err = PTR_ERR(sor->clk_safe); |
| 2451 | dev_err(&pdev->dev, "failed to get safe clock: %d\n", err); |
| 2452 | goto remove; |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2453 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2454 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2455 | sor->clk_dp = devm_clk_get(&pdev->dev, "dp"); |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2456 | if (IS_ERR(sor->clk_dp)) { |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2457 | err = PTR_ERR(sor->clk_dp); |
| 2458 | dev_err(&pdev->dev, "failed to get DP clock: %d\n", err); |
| 2459 | goto remove; |
Thierry Reding | 4dbdc74 | 2015-04-27 15:04:26 +0200 | [diff] [blame] | 2460 | } |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2461 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2462 | INIT_LIST_HEAD(&sor->client.list); |
| 2463 | sor->client.ops = &sor_client_ops; |
| 2464 | sor->client.dev = &pdev->dev; |
| 2465 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2466 | err = host1x_client_register(&sor->client); |
| 2467 | if (err < 0) { |
| 2468 | dev_err(&pdev->dev, "failed to register host1x client: %d\n", |
| 2469 | err); |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2470 | goto remove; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | platform_set_drvdata(pdev, sor); |
| 2474 | |
| 2475 | return 0; |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2476 | |
| 2477 | remove: |
| 2478 | if (sor->ops && sor->ops->remove) |
| 2479 | sor->ops->remove(sor); |
| 2480 | output: |
| 2481 | tegra_output_remove(&sor->output); |
| 2482 | return err; |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | static int tegra_sor_remove(struct platform_device *pdev) |
| 2486 | { |
| 2487 | struct tegra_sor *sor = platform_get_drvdata(pdev); |
| 2488 | int err; |
| 2489 | |
| 2490 | err = host1x_client_unregister(&sor->client); |
| 2491 | if (err < 0) { |
| 2492 | dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", |
| 2493 | err); |
| 2494 | return err; |
| 2495 | } |
| 2496 | |
Thierry Reding | 459cc2c | 2015-07-30 10:34:24 +0200 | [diff] [blame] | 2497 | if (sor->ops && sor->ops->remove) { |
| 2498 | err = sor->ops->remove(sor); |
| 2499 | if (err < 0) |
| 2500 | dev_err(&pdev->dev, "failed to remove SOR: %d\n", err); |
| 2501 | } |
| 2502 | |
Thierry Reding | 328ec69 | 2014-12-19 15:55:08 +0100 | [diff] [blame] | 2503 | tegra_output_remove(&sor->output); |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2504 | |
| 2505 | return 0; |
| 2506 | } |
| 2507 | |
Thierry Reding | 6b6b604 | 2013-11-15 16:06:05 +0100 | [diff] [blame] | 2508 | struct platform_driver tegra_sor_driver = { |
| 2509 | .driver = { |
| 2510 | .name = "tegra-sor", |
| 2511 | .of_match_table = tegra_sor_of_match, |
| 2512 | }, |
| 2513 | .probe = tegra_sor_probe, |
| 2514 | .remove = tegra_sor_remove, |
| 2515 | }; |