Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eugeni Dodonov <eugeni.dodonov@intel.com> |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include "i915_drv.h" |
| 29 | #include "intel_drv.h" |
| 30 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 31 | struct ddi_buf_trans { |
| 32 | u32 trans1; /* balance leg enable, de-emph level */ |
| 33 | u32 trans2; /* vref sel, vswing */ |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 34 | u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 35 | }; |
| 36 | |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 37 | /* HDMI/DVI modes ignore everything but the last 2 items. So we share |
| 38 | * them for both DP and FDI transports, allowing those ports to |
| 39 | * automatically adapt to HDMI connections as well |
| 40 | */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 41 | static const struct ddi_buf_trans hsw_ddi_translations_dp[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 42 | { 0x00FFFFFF, 0x0006000E, 0x0 }, |
| 43 | { 0x00D75FFF, 0x0005000A, 0x0 }, |
| 44 | { 0x00C30FFF, 0x00040006, 0x0 }, |
| 45 | { 0x80AAAFFF, 0x000B0000, 0x0 }, |
| 46 | { 0x00FFFFFF, 0x0005000A, 0x0 }, |
| 47 | { 0x00D75FFF, 0x000C0004, 0x0 }, |
| 48 | { 0x80C30FFF, 0x000B0000, 0x0 }, |
| 49 | { 0x00FFFFFF, 0x00040006, 0x0 }, |
| 50 | { 0x80D75FFF, 0x000B0000, 0x0 }, |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 51 | }; |
| 52 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 53 | static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 54 | { 0x00FFFFFF, 0x0007000E, 0x0 }, |
| 55 | { 0x00D75FFF, 0x000F000A, 0x0 }, |
| 56 | { 0x00C30FFF, 0x00060006, 0x0 }, |
| 57 | { 0x00AAAFFF, 0x001E0000, 0x0 }, |
| 58 | { 0x00FFFFFF, 0x000F000A, 0x0 }, |
| 59 | { 0x00D75FFF, 0x00160004, 0x0 }, |
| 60 | { 0x00C30FFF, 0x001E0000, 0x0 }, |
| 61 | { 0x00FFFFFF, 0x00060006, 0x0 }, |
| 62 | { 0x00D75FFF, 0x001E0000, 0x0 }, |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 63 | }; |
| 64 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 65 | static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = { |
| 66 | /* Idx NT mV d T mV d db */ |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 67 | { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */ |
| 68 | { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */ |
| 69 | { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */ |
| 70 | { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */ |
| 71 | { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */ |
| 72 | { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */ |
| 73 | { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */ |
| 74 | { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */ |
| 75 | { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */ |
| 76 | { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */ |
| 77 | { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */ |
| 78 | { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */ |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 79 | }; |
| 80 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 81 | static const struct ddi_buf_trans bdw_ddi_translations_edp[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 82 | { 0x00FFFFFF, 0x00000012, 0x0 }, |
| 83 | { 0x00EBAFFF, 0x00020011, 0x0 }, |
| 84 | { 0x00C71FFF, 0x0006000F, 0x0 }, |
| 85 | { 0x00AAAFFF, 0x000E000A, 0x0 }, |
| 86 | { 0x00FFFFFF, 0x00020011, 0x0 }, |
| 87 | { 0x00DB6FFF, 0x0005000F, 0x0 }, |
| 88 | { 0x00BEEFFF, 0x000A000C, 0x0 }, |
| 89 | { 0x00FFFFFF, 0x0005000F, 0x0 }, |
| 90 | { 0x00DB6FFF, 0x000A000C, 0x0 }, |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 93 | static const struct ddi_buf_trans bdw_ddi_translations_dp[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 94 | { 0x00FFFFFF, 0x0007000E, 0x0 }, |
| 95 | { 0x00D75FFF, 0x000E000A, 0x0 }, |
| 96 | { 0x00BEFFFF, 0x00140006, 0x0 }, |
| 97 | { 0x80B2CFFF, 0x001B0002, 0x0 }, |
| 98 | { 0x00FFFFFF, 0x000E000A, 0x0 }, |
| 99 | { 0x00DB6FFF, 0x00160005, 0x0 }, |
| 100 | { 0x80C71FFF, 0x001A0002, 0x0 }, |
| 101 | { 0x00F7DFFF, 0x00180004, 0x0 }, |
| 102 | { 0x80D75FFF, 0x001B0002, 0x0 }, |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 105 | static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 106 | { 0x00FFFFFF, 0x0001000E, 0x0 }, |
| 107 | { 0x00D75FFF, 0x0004000A, 0x0 }, |
| 108 | { 0x00C30FFF, 0x00070006, 0x0 }, |
| 109 | { 0x00AAAFFF, 0x000C0000, 0x0 }, |
| 110 | { 0x00FFFFFF, 0x0004000A, 0x0 }, |
| 111 | { 0x00D75FFF, 0x00090004, 0x0 }, |
| 112 | { 0x00C30FFF, 0x000C0000, 0x0 }, |
| 113 | { 0x00FFFFFF, 0x00070006, 0x0 }, |
| 114 | { 0x00D75FFF, 0x000C0000, 0x0 }, |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 117 | static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = { |
| 118 | /* Idx NT mV d T mV df db */ |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 119 | { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */ |
| 120 | { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */ |
| 121 | { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */ |
| 122 | { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */ |
| 123 | { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */ |
| 124 | { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */ |
| 125 | { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */ |
| 126 | { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */ |
| 127 | { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */ |
| 128 | { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */ |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 131 | /* Skylake H and S */ |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 132 | static const struct ddi_buf_trans skl_ddi_translations_dp[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 133 | { 0x00002016, 0x000000A0, 0x0 }, |
| 134 | { 0x00005012, 0x0000009B, 0x0 }, |
| 135 | { 0x00007011, 0x00000088, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 136 | { 0x80009010, 0x000000C0, 0x1 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 137 | { 0x00002016, 0x0000009B, 0x0 }, |
| 138 | { 0x00005012, 0x00000088, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 139 | { 0x80007011, 0x000000C0, 0x1 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 140 | { 0x00002016, 0x000000DF, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 141 | { 0x80005012, 0x000000C0, 0x1 }, |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 144 | /* Skylake U */ |
| 145 | static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = { |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 146 | { 0x0000201B, 0x000000A2, 0x0 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 147 | { 0x00005012, 0x00000088, 0x0 }, |
Rodrigo Vivi | 63ebce1 | 2016-01-05 07:58:31 -0800 | [diff] [blame] | 148 | { 0x80007011, 0x000000CD, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 149 | { 0x80009010, 0x000000C0, 0x1 }, |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 150 | { 0x0000201B, 0x0000009D, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 151 | { 0x80005012, 0x000000C0, 0x1 }, |
| 152 | { 0x80007011, 0x000000C0, 0x1 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 153 | { 0x00002016, 0x00000088, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 154 | { 0x80005012, 0x000000C0, 0x1 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 155 | }; |
| 156 | |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 157 | /* Skylake Y */ |
| 158 | static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 159 | { 0x00000018, 0x000000A2, 0x0 }, |
| 160 | { 0x00005012, 0x00000088, 0x0 }, |
Rodrigo Vivi | 63ebce1 | 2016-01-05 07:58:31 -0800 | [diff] [blame] | 161 | { 0x80007011, 0x000000CD, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 162 | { 0x80009010, 0x000000C0, 0x3 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 163 | { 0x00000018, 0x0000009D, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 164 | { 0x80005012, 0x000000C0, 0x3 }, |
| 165 | { 0x80007011, 0x000000C0, 0x3 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 166 | { 0x00000018, 0x00000088, 0x0 }, |
Rodrigo Vivi | d7097cf | 2016-01-05 11:18:55 -0800 | [diff] [blame] | 167 | { 0x80005012, 0x000000C0, 0x3 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | /* |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 171 | * Skylake H and S |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 172 | * eDP 1.4 low vswing translation parameters |
| 173 | */ |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 174 | static const struct ddi_buf_trans skl_ddi_translations_edp[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 175 | { 0x00000018, 0x000000A8, 0x0 }, |
| 176 | { 0x00004013, 0x000000A9, 0x0 }, |
| 177 | { 0x00007011, 0x000000A2, 0x0 }, |
| 178 | { 0x00009010, 0x0000009C, 0x0 }, |
| 179 | { 0x00000018, 0x000000A9, 0x0 }, |
| 180 | { 0x00006013, 0x000000A2, 0x0 }, |
| 181 | { 0x00007011, 0x000000A6, 0x0 }, |
| 182 | { 0x00000018, 0x000000AB, 0x0 }, |
| 183 | { 0x00007013, 0x0000009F, 0x0 }, |
| 184 | { 0x00000018, 0x000000DF, 0x0 }, |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 185 | }; |
| 186 | |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 187 | /* |
| 188 | * Skylake U |
| 189 | * eDP 1.4 low vswing translation parameters |
| 190 | */ |
| 191 | static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = { |
| 192 | { 0x00000018, 0x000000A8, 0x0 }, |
| 193 | { 0x00004013, 0x000000A9, 0x0 }, |
| 194 | { 0x00007011, 0x000000A2, 0x0 }, |
| 195 | { 0x00009010, 0x0000009C, 0x0 }, |
| 196 | { 0x00000018, 0x000000A9, 0x0 }, |
| 197 | { 0x00006013, 0x000000A2, 0x0 }, |
| 198 | { 0x00007011, 0x000000A6, 0x0 }, |
| 199 | { 0x00002016, 0x000000AB, 0x0 }, |
| 200 | { 0x00005013, 0x0000009F, 0x0 }, |
| 201 | { 0x00000018, 0x000000DF, 0x0 }, |
| 202 | }; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 203 | |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 204 | /* |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 205 | * Skylake Y |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 206 | * eDP 1.4 low vswing translation parameters |
| 207 | */ |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 208 | static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 209 | { 0x00000018, 0x000000A8, 0x0 }, |
| 210 | { 0x00004013, 0x000000AB, 0x0 }, |
| 211 | { 0x00007011, 0x000000A4, 0x0 }, |
| 212 | { 0x00009010, 0x000000DF, 0x0 }, |
| 213 | { 0x00000018, 0x000000AA, 0x0 }, |
| 214 | { 0x00006013, 0x000000A4, 0x0 }, |
| 215 | { 0x00007011, 0x0000009D, 0x0 }, |
| 216 | { 0x00000018, 0x000000A0, 0x0 }, |
| 217 | { 0x00006012, 0x000000DF, 0x0 }, |
| 218 | { 0x00000018, 0x0000008A, 0x0 }, |
| 219 | }; |
| 220 | |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 221 | /* Skylake U, H and S */ |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 222 | static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 223 | { 0x00000018, 0x000000AC, 0x0 }, |
| 224 | { 0x00005012, 0x0000009D, 0x0 }, |
| 225 | { 0x00007011, 0x00000088, 0x0 }, |
| 226 | { 0x00000018, 0x000000A1, 0x0 }, |
| 227 | { 0x00000018, 0x00000098, 0x0 }, |
| 228 | { 0x00004013, 0x00000088, 0x0 }, |
Rodrigo Vivi | 2e78416 | 2016-01-05 11:11:27 -0800 | [diff] [blame] | 229 | { 0x80006012, 0x000000CD, 0x1 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 230 | { 0x00000018, 0x000000DF, 0x0 }, |
Rodrigo Vivi | 2e78416 | 2016-01-05 11:11:27 -0800 | [diff] [blame] | 231 | { 0x80003015, 0x000000CD, 0x1 }, /* Default */ |
| 232 | { 0x80003015, 0x000000C0, 0x1 }, |
| 233 | { 0x80000018, 0x000000C0, 0x1 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 234 | }; |
| 235 | |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 236 | /* Skylake Y */ |
| 237 | static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 238 | { 0x00000018, 0x000000A1, 0x0 }, |
| 239 | { 0x00005012, 0x000000DF, 0x0 }, |
Rodrigo Vivi | 2e78416 | 2016-01-05 11:11:27 -0800 | [diff] [blame] | 240 | { 0x80007011, 0x000000CB, 0x3 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 241 | { 0x00000018, 0x000000A4, 0x0 }, |
| 242 | { 0x00000018, 0x0000009D, 0x0 }, |
| 243 | { 0x00004013, 0x00000080, 0x0 }, |
Rodrigo Vivi | 2e78416 | 2016-01-05 11:11:27 -0800 | [diff] [blame] | 244 | { 0x80006013, 0x000000C0, 0x3 }, |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 245 | { 0x00000018, 0x0000008A, 0x0 }, |
Rodrigo Vivi | 2e78416 | 2016-01-05 11:11:27 -0800 | [diff] [blame] | 246 | { 0x80003015, 0x000000C0, 0x3 }, /* Default */ |
| 247 | { 0x80003015, 0x000000C0, 0x3 }, |
| 248 | { 0x80000018, 0x000000C0, 0x3 }, |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 251 | struct bxt_ddi_buf_trans { |
| 252 | u32 margin; /* swing value */ |
| 253 | u32 scale; /* scale value */ |
| 254 | u32 enable; /* scale enable */ |
| 255 | u32 deemphasis; |
| 256 | bool default_index; /* true if the entry represents default value */ |
| 257 | }; |
| 258 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 259 | static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = { |
| 260 | /* Idx NT mV diff db */ |
Imre Deak | fe4c63c | 2015-06-04 18:01:35 +0300 | [diff] [blame] | 261 | { 52, 0x9A, 0, 128, true }, /* 0: 400 0 */ |
| 262 | { 78, 0x9A, 0, 85, false }, /* 1: 400 3.5 */ |
| 263 | { 104, 0x9A, 0, 64, false }, /* 2: 400 6 */ |
| 264 | { 154, 0x9A, 0, 43, false }, /* 3: 400 9.5 */ |
| 265 | { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */ |
| 266 | { 116, 0x9A, 0, 85, false }, /* 5: 600 3.5 */ |
| 267 | { 154, 0x9A, 0, 64, false }, /* 6: 600 6 */ |
| 268 | { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */ |
| 269 | { 154, 0x9A, 0, 85, false }, /* 8: 800 3.5 */ |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 270 | { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */ |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 271 | }; |
| 272 | |
Sonika Jindal | d9d7000 | 2015-09-24 10:24:56 +0530 | [diff] [blame] | 273 | static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = { |
| 274 | /* Idx NT mV diff db */ |
| 275 | { 26, 0, 0, 128, false }, /* 0: 200 0 */ |
| 276 | { 38, 0, 0, 112, false }, /* 1: 200 1.5 */ |
| 277 | { 48, 0, 0, 96, false }, /* 2: 200 4 */ |
| 278 | { 54, 0, 0, 69, false }, /* 3: 200 6 */ |
| 279 | { 32, 0, 0, 128, false }, /* 4: 250 0 */ |
| 280 | { 48, 0, 0, 104, false }, /* 5: 250 1.5 */ |
| 281 | { 54, 0, 0, 85, false }, /* 6: 250 4 */ |
| 282 | { 43, 0, 0, 128, false }, /* 7: 300 0 */ |
| 283 | { 54, 0, 0, 101, false }, /* 8: 300 1.5 */ |
| 284 | { 48, 0, 0, 128, false }, /* 9: 300 0 */ |
| 285 | }; |
| 286 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 287 | /* BSpec has 2 recommended values - entries 0 and 8. |
| 288 | * Using the entry with higher vswing. |
| 289 | */ |
| 290 | static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = { |
| 291 | /* Idx NT mV diff db */ |
Imre Deak | fe4c63c | 2015-06-04 18:01:35 +0300 | [diff] [blame] | 292 | { 52, 0x9A, 0, 128, false }, /* 0: 400 0 */ |
| 293 | { 52, 0x9A, 0, 85, false }, /* 1: 400 3.5 */ |
| 294 | { 52, 0x9A, 0, 64, false }, /* 2: 400 6 */ |
| 295 | { 42, 0x9A, 0, 43, false }, /* 3: 400 9.5 */ |
| 296 | { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */ |
| 297 | { 77, 0x9A, 0, 85, false }, /* 5: 600 3.5 */ |
| 298 | { 77, 0x9A, 0, 64, false }, /* 6: 600 6 */ |
| 299 | { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */ |
| 300 | { 102, 0x9A, 0, 85, false }, /* 8: 800 3.5 */ |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 301 | { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */ |
| 302 | }; |
| 303 | |
Ville Syrjälä | 5a5d24d | 2016-07-12 15:59:35 +0300 | [diff] [blame] | 304 | enum port intel_ddi_get_encoder_port(struct intel_encoder *encoder) |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 305 | { |
Ville Syrjälä | 5a5d24d | 2016-07-12 15:59:35 +0300 | [diff] [blame] | 306 | switch (encoder->type) { |
Jani Nikula | 8cd21b7 | 2015-09-29 10:24:26 +0300 | [diff] [blame] | 307 | case INTEL_OUTPUT_DP_MST: |
Ville Syrjälä | 5a5d24d | 2016-07-12 15:59:35 +0300 | [diff] [blame] | 308 | return enc_to_mst(&encoder->base)->primary->port; |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 309 | case INTEL_OUTPUT_DP: |
Jani Nikula | 8cd21b7 | 2015-09-29 10:24:26 +0300 | [diff] [blame] | 310 | case INTEL_OUTPUT_EDP: |
| 311 | case INTEL_OUTPUT_HDMI: |
| 312 | case INTEL_OUTPUT_UNKNOWN: |
Ville Syrjälä | 5a5d24d | 2016-07-12 15:59:35 +0300 | [diff] [blame] | 313 | return enc_to_dig_port(&encoder->base)->port; |
Jani Nikula | 8cd21b7 | 2015-09-29 10:24:26 +0300 | [diff] [blame] | 314 | case INTEL_OUTPUT_ANALOG: |
Ville Syrjälä | 5a5d24d | 2016-07-12 15:59:35 +0300 | [diff] [blame] | 315 | return PORT_E; |
| 316 | default: |
| 317 | MISSING_CASE(encoder->type); |
| 318 | return PORT_A; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 322 | static const struct ddi_buf_trans * |
Ville Syrjälä | a930acd | 2016-07-12 15:59:36 +0300 | [diff] [blame] | 323 | bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries) |
| 324 | { |
| 325 | if (dev_priv->vbt.edp.low_vswing) { |
| 326 | *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp); |
| 327 | return bdw_ddi_translations_edp; |
| 328 | } else { |
| 329 | *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp); |
| 330 | return bdw_ddi_translations_dp; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | static const struct ddi_buf_trans * |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 335 | skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries) |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 336 | { |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 337 | if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) { |
Rodrigo Vivi | 5f8b253 | 2015-08-24 16:48:44 -0700 | [diff] [blame] | 338 | *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp); |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 339 | return skl_y_ddi_translations_dp; |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 340 | } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 341 | *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp); |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 342 | return skl_u_ddi_translations_dp; |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 343 | } else { |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 344 | *n_entries = ARRAY_SIZE(skl_ddi_translations_dp); |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 345 | return skl_ddi_translations_dp; |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 346 | } |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | static const struct ddi_buf_trans * |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 350 | skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries) |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 351 | { |
Jani Nikula | 06411f0 | 2016-03-24 17:50:21 +0200 | [diff] [blame] | 352 | if (dev_priv->vbt.edp.low_vswing) { |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 353 | if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) { |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 354 | *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp); |
| 355 | return skl_y_ddi_translations_edp; |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 356 | } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) { |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 357 | *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp); |
| 358 | return skl_u_ddi_translations_edp; |
| 359 | } else { |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 360 | *n_entries = ARRAY_SIZE(skl_ddi_translations_edp); |
| 361 | return skl_ddi_translations_edp; |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 362 | } |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 363 | } |
Ville Syrjälä | cd1101c | 2015-12-08 19:59:40 +0200 | [diff] [blame] | 364 | |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 365 | return skl_get_buf_trans_dp(dev_priv, n_entries); |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 366 | } |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 367 | |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 368 | static const struct ddi_buf_trans * |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 369 | skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries) |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 370 | { |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 371 | if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) { |
Ville Syrjälä | acee299 | 2015-12-08 19:59:39 +0200 | [diff] [blame] | 372 | *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi); |
| 373 | return skl_y_ddi_translations_hdmi; |
| 374 | } else { |
| 375 | *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi); |
| 376 | return skl_ddi_translations_hdmi; |
| 377 | } |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 378 | } |
| 379 | |
Ville Syrjälä | 8d8bb85 | 2016-07-12 15:59:30 +0300 | [diff] [blame] | 380 | static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port) |
| 381 | { |
| 382 | int n_hdmi_entries; |
| 383 | int hdmi_level; |
| 384 | int hdmi_default_entry; |
| 385 | |
| 386 | hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift; |
| 387 | |
| 388 | if (IS_BROXTON(dev_priv)) |
| 389 | return hdmi_level; |
| 390 | |
| 391 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
| 392 | skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries); |
| 393 | hdmi_default_entry = 8; |
| 394 | } else if (IS_BROADWELL(dev_priv)) { |
| 395 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
| 396 | hdmi_default_entry = 7; |
| 397 | } else if (IS_HASWELL(dev_priv)) { |
| 398 | n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); |
| 399 | hdmi_default_entry = 6; |
| 400 | } else { |
| 401 | WARN(1, "ddi translation table missing\n"); |
| 402 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
| 403 | hdmi_default_entry = 7; |
| 404 | } |
| 405 | |
| 406 | /* Choose a good default if VBT is badly populated */ |
| 407 | if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN || |
| 408 | hdmi_level >= n_hdmi_entries) |
| 409 | hdmi_level = hdmi_default_entry; |
| 410 | |
| 411 | return hdmi_level; |
| 412 | } |
| 413 | |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 414 | /* |
| 415 | * Starting with Haswell, DDI port buffers must be programmed with correct |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 416 | * values in advance. This function programs the correct values for |
| 417 | * DP/eDP/FDI use cases. |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 418 | */ |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 419 | void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder) |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 420 | { |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 421 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 422 | u32 iboost_bit = 0; |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 423 | int i, n_dp_entries, n_edp_entries, size; |
| 424 | enum port port = intel_ddi_get_encoder_port(encoder); |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 425 | const struct ddi_buf_trans *ddi_translations_fdi; |
| 426 | const struct ddi_buf_trans *ddi_translations_dp; |
| 427 | const struct ddi_buf_trans *ddi_translations_edp; |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 428 | const struct ddi_buf_trans *ddi_translations; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 429 | |
Ville Syrjälä | 9f33243 | 2016-07-12 15:59:31 +0300 | [diff] [blame] | 430 | if (IS_BROXTON(dev_priv)) |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 431 | return; |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 432 | |
| 433 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Paulo Zanoni | c30400f | 2015-07-03 12:31:30 -0300 | [diff] [blame] | 434 | ddi_translations_fdi = NULL; |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 435 | ddi_translations_dp = |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 436 | skl_get_buf_trans_dp(dev_priv, &n_dp_entries); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 437 | ddi_translations_edp = |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 438 | skl_get_buf_trans_edp(dev_priv, &n_edp_entries); |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 439 | |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 440 | /* If we're boosting the current, set bit 31 of trans1 */ |
Ville Syrjälä | 1edaaa2 | 2016-07-12 15:59:34 +0300 | [diff] [blame] | 441 | if (dev_priv->vbt.ddi_port_info[port].dp_boost_level) |
Ville Syrjälä | c110ae6 | 2016-07-12 15:59:29 +0300 | [diff] [blame] | 442 | iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; |
Ville Syrjälä | 10afa0b | 2015-12-08 19:59:43 +0200 | [diff] [blame] | 443 | |
Ville Syrjälä | ceccad5 | 2016-01-12 17:28:16 +0200 | [diff] [blame] | 444 | if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP && |
| 445 | port != PORT_A && port != PORT_E && |
| 446 | n_edp_entries > 9)) |
Ville Syrjälä | 10afa0b | 2015-12-08 19:59:43 +0200 | [diff] [blame] | 447 | n_edp_entries = 9; |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 448 | } else if (IS_BROADWELL(dev_priv)) { |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 449 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 450 | ddi_translations_dp = bdw_ddi_translations_dp; |
Ville Syrjälä | a930acd | 2016-07-12 15:59:36 +0300 | [diff] [blame] | 451 | ddi_translations_edp = bdw_get_buf_trans_edp(dev_priv, &n_edp_entries); |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 452 | n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 453 | } else if (IS_HASWELL(dev_priv)) { |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 454 | ddi_translations_fdi = hsw_ddi_translations_fdi; |
| 455 | ddi_translations_dp = hsw_ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 456 | ddi_translations_edp = hsw_ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 457 | n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp); |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 458 | } else { |
| 459 | WARN(1, "ddi translation table missing\n"); |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 460 | ddi_translations_edp = bdw_ddi_translations_dp; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 461 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 462 | ddi_translations_dp = bdw_ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 463 | n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp); |
| 464 | n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 467 | switch (encoder->type) { |
| 468 | case INTEL_OUTPUT_EDP: |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 469 | ddi_translations = ddi_translations_edp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 470 | size = n_edp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 471 | break; |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 472 | case INTEL_OUTPUT_DP: |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 473 | ddi_translations = ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 474 | size = n_dp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 475 | break; |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 476 | case INTEL_OUTPUT_ANALOG: |
| 477 | ddi_translations = ddi_translations_fdi; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 478 | size = n_dp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 479 | break; |
| 480 | default: |
| 481 | BUG(); |
| 482 | } |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 483 | |
Ville Syrjälä | 9712e68 | 2015-09-18 20:03:22 +0300 | [diff] [blame] | 484 | for (i = 0; i < size; i++) { |
| 485 | I915_WRITE(DDI_BUF_TRANS_LO(port, i), |
| 486 | ddi_translations[i].trans1 | iboost_bit); |
| 487 | I915_WRITE(DDI_BUF_TRANS_HI(port, i), |
| 488 | ddi_translations[i].trans2); |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 489 | } |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 490 | } |
Damien Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 491 | |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 492 | /* |
| 493 | * Starting with Haswell, DDI port buffers must be programmed with correct |
| 494 | * values in advance. This function programs the correct values for |
| 495 | * HDMI/DVI use cases. |
| 496 | */ |
| 497 | static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder) |
| 498 | { |
| 499 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 500 | u32 iboost_bit = 0; |
| 501 | int n_hdmi_entries, hdmi_level; |
| 502 | enum port port = intel_ddi_get_encoder_port(encoder); |
| 503 | const struct ddi_buf_trans *ddi_translations_hdmi; |
| 504 | |
| 505 | if (IS_BROXTON(dev_priv)) |
Damien Lespiau | ce3b7e9 | 2014-08-04 15:04:43 +0100 | [diff] [blame] | 506 | return; |
| 507 | |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 508 | hdmi_level = intel_ddi_hdmi_level(dev_priv, port); |
| 509 | |
| 510 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
| 511 | ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries); |
Ville Syrjälä | 1edaaa2 | 2016-07-12 15:59:34 +0300 | [diff] [blame] | 512 | |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 513 | /* If we're boosting the current, set bit 31 of trans1 */ |
Ville Syrjälä | 1edaaa2 | 2016-07-12 15:59:34 +0300 | [diff] [blame] | 514 | if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level) |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 515 | iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; |
| 516 | } else if (IS_BROADWELL(dev_priv)) { |
| 517 | ddi_translations_hdmi = bdw_ddi_translations_hdmi; |
| 518 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
| 519 | } else if (IS_HASWELL(dev_priv)) { |
| 520 | ddi_translations_hdmi = hsw_ddi_translations_hdmi; |
| 521 | n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); |
| 522 | } else { |
| 523 | WARN(1, "ddi translation table missing\n"); |
| 524 | ddi_translations_hdmi = bdw_ddi_translations_hdmi; |
| 525 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
| 526 | } |
| 527 | |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 528 | /* Entry 9 is for HDMI: */ |
Ville Syrjälä | ed9c77d | 2016-07-12 15:59:32 +0300 | [diff] [blame] | 529 | I915_WRITE(DDI_BUF_TRANS_LO(port, 9), |
Ville Syrjälä | 9712e68 | 2015-09-18 20:03:22 +0300 | [diff] [blame] | 530 | ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit); |
Ville Syrjälä | ed9c77d | 2016-07-12 15:59:32 +0300 | [diff] [blame] | 531 | I915_WRITE(DDI_BUF_TRANS_HI(port, 9), |
Ville Syrjälä | 9712e68 | 2015-09-18 20:03:22 +0300 | [diff] [blame] | 532 | ddi_translations_hdmi[hdmi_level].trans2); |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 533 | } |
| 534 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 535 | static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, |
| 536 | enum port port) |
| 537 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 538 | i915_reg_t reg = DDI_BUF_CTL(port); |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 539 | int i; |
| 540 | |
Vandana Kannan | 3449ca8 | 2015-03-27 14:19:09 +0200 | [diff] [blame] | 541 | for (i = 0; i < 16; i++) { |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 542 | udelay(1); |
| 543 | if (I915_READ(reg) & DDI_BUF_IS_IDLE) |
| 544 | return; |
| 545 | } |
| 546 | DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port)); |
| 547 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 548 | |
| 549 | /* Starting with Haswell, different DDI ports can work in FDI mode for |
| 550 | * connection to the PCH-located connectors. For this, it is necessary to train |
| 551 | * both the DDI port and PCH receiver for the desired DDI buffer settings. |
| 552 | * |
| 553 | * The recommended port to work in FDI mode is DDI E, which we use here. Also, |
| 554 | * please note that when FDI mode is active on DDI E, it shares 2 lines with |
| 555 | * DDI A (which is used for eDP) |
| 556 | */ |
| 557 | |
| 558 | void hsw_fdi_link_train(struct drm_crtc *crtc) |
| 559 | { |
| 560 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 561 | struct drm_i915_private *dev_priv = to_i915(dev); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 562 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 563 | struct intel_encoder *encoder; |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 564 | u32 temp, i, rx_ctl_val; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 565 | |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 566 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 567 | WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG); |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 568 | intel_prepare_dp_ddi_buffers(encoder); |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 571 | /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the |
| 572 | * mode set "sequence for CRT port" document: |
| 573 | * - TP1 to TP2 time with the default value |
| 574 | * - FDI delay to 90h |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 575 | * |
| 576 | * WaFDIAutoLinkSetTimingOverrride:hsw |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 577 | */ |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 578 | I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 579 | FDI_RX_PWRDN_LANE0_VAL(2) | |
| 580 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 581 | |
| 582 | /* Enable the PCH Receiver FDI PLL */ |
Damien Lespiau | 3e68320 | 2012-12-11 18:48:29 +0000 | [diff] [blame] | 583 | rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE | |
Daniel Vetter | 33d29b1 | 2013-02-13 18:04:45 +0100 | [diff] [blame] | 584 | FDI_RX_PLL_ENABLE | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 585 | FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 586 | I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); |
| 587 | POSTING_READ(FDI_RX_CTL(PIPE_A)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 588 | udelay(220); |
| 589 | |
| 590 | /* Switch from Rawclk to PCDclk */ |
| 591 | rx_ctl_val |= FDI_PCDCLK; |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 592 | I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 593 | |
| 594 | /* Configure Port Clock Select */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 595 | I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config->ddi_pll_sel); |
| 596 | WARN_ON(intel_crtc->config->ddi_pll_sel != PORT_CLK_SEL_SPLL); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 597 | |
| 598 | /* Start the training iterating through available voltages and emphasis, |
| 599 | * testing each value twice. */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 600 | for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) { |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 601 | /* Configure DP_TP_CTL with auto-training */ |
| 602 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 603 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 604 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 605 | DP_TP_CTL_LINK_TRAIN_PAT1 | |
| 606 | DP_TP_CTL_ENABLE); |
| 607 | |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 608 | /* Configure and enable DDI_BUF_CTL for DDI E with next voltage. |
| 609 | * DDI E does not support port reversal, the functionality is |
| 610 | * achieved on the PCH side in FDI_RX_CTL, so no need to set the |
| 611 | * port reversal bit */ |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 612 | I915_WRITE(DDI_BUF_CTL(PORT_E), |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 613 | DDI_BUF_CTL_ENABLE | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 614 | ((intel_crtc->config->fdi_lanes - 1) << 1) | |
Sonika Jindal | c5fe6a0 | 2014-08-11 08:57:36 +0530 | [diff] [blame] | 615 | DDI_BUF_TRANS_SELECT(i / 2)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 616 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 617 | |
| 618 | udelay(600); |
| 619 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 620 | /* Program PCH FDI Receiver TU */ |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 621 | I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64)); |
Eugeni Dodonov | 4acf518 | 2012-07-04 20:15:16 -0300 | [diff] [blame] | 622 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 623 | /* Enable PCH FDI Receiver with auto-training */ |
| 624 | rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO; |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 625 | I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); |
| 626 | POSTING_READ(FDI_RX_CTL(PIPE_A)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 627 | |
| 628 | /* Wait for FDI receiver lane calibration */ |
| 629 | udelay(30); |
| 630 | |
| 631 | /* Unset FDI_RX_MISC pwrdn lanes */ |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 632 | temp = I915_READ(FDI_RX_MISC(PIPE_A)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 633 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 634 | I915_WRITE(FDI_RX_MISC(PIPE_A), temp); |
| 635 | POSTING_READ(FDI_RX_MISC(PIPE_A)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 636 | |
| 637 | /* Wait for FDI auto training time */ |
| 638 | udelay(5); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 639 | |
| 640 | temp = I915_READ(DP_TP_STATUS(PORT_E)); |
| 641 | if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 642 | DRM_DEBUG_KMS("FDI link training done on step %d\n", i); |
Ville Syrjälä | a308ccb | 2015-12-04 22:22:50 +0200 | [diff] [blame] | 643 | break; |
| 644 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 645 | |
Ville Syrjälä | a308ccb | 2015-12-04 22:22:50 +0200 | [diff] [blame] | 646 | /* |
| 647 | * Leave things enabled even if we failed to train FDI. |
| 648 | * Results in less fireworks from the state checker. |
| 649 | */ |
| 650 | if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) { |
| 651 | DRM_ERROR("FDI link training failed!\n"); |
| 652 | break; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 653 | } |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 654 | |
Ville Syrjälä | 5b421c5 | 2016-03-01 16:16:23 +0200 | [diff] [blame] | 655 | rx_ctl_val &= ~FDI_RX_ENABLE; |
| 656 | I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); |
| 657 | POSTING_READ(FDI_RX_CTL(PIPE_A)); |
| 658 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 659 | temp = I915_READ(DDI_BUF_CTL(PORT_E)); |
| 660 | temp &= ~DDI_BUF_CTL_ENABLE; |
| 661 | I915_WRITE(DDI_BUF_CTL(PORT_E), temp); |
| 662 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
| 663 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 664 | /* Disable DP_TP_CTL and FDI_RX_CTL and retry */ |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 665 | temp = I915_READ(DP_TP_CTL(PORT_E)); |
| 666 | temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 667 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 668 | I915_WRITE(DP_TP_CTL(PORT_E), temp); |
| 669 | POSTING_READ(DP_TP_CTL(PORT_E)); |
| 670 | |
| 671 | intel_wait_ddi_buf_idle(dev_priv, PORT_E); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 672 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 673 | /* Reset FDI_RX_MISC pwrdn lanes */ |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 674 | temp = I915_READ(FDI_RX_MISC(PIPE_A)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 675 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 676 | temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 677 | I915_WRITE(FDI_RX_MISC(PIPE_A), temp); |
| 678 | POSTING_READ(FDI_RX_MISC(PIPE_A)); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 679 | } |
| 680 | |
Ville Syrjälä | a308ccb | 2015-12-04 22:22:50 +0200 | [diff] [blame] | 681 | /* Enable normal pixel sending for FDI */ |
| 682 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 683 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 684 | DP_TP_CTL_LINK_TRAIN_NORMAL | |
| 685 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 686 | DP_TP_CTL_ENABLE); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 687 | } |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 688 | |
Dave Airlie | 44905a27 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 689 | void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder) |
| 690 | { |
| 691 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 692 | struct intel_digital_port *intel_dig_port = |
| 693 | enc_to_dig_port(&encoder->base); |
| 694 | |
| 695 | intel_dp->DP = intel_dig_port->saved_port_bits | |
Sonika Jindal | c5fe6a0 | 2014-08-11 08:57:36 +0530 | [diff] [blame] | 696 | DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0); |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 697 | intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count); |
Dave Airlie | 44905a27 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 698 | } |
| 699 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 700 | static struct intel_encoder * |
| 701 | intel_ddi_get_crtc_encoder(struct drm_crtc *crtc) |
| 702 | { |
| 703 | struct drm_device *dev = crtc->dev; |
| 704 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 705 | struct intel_encoder *intel_encoder, *ret = NULL; |
| 706 | int num_encoders = 0; |
| 707 | |
| 708 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 709 | ret = intel_encoder; |
| 710 | num_encoders++; |
| 711 | } |
| 712 | |
| 713 | if (num_encoders != 1) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 714 | WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders, |
| 715 | pipe_name(intel_crtc->pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 716 | |
| 717 | BUG_ON(ret == NULL); |
| 718 | return ret; |
| 719 | } |
| 720 | |
Satheeshakrishna M | bcddf61 | 2014-08-22 09:49:10 +0530 | [diff] [blame] | 721 | struct intel_encoder * |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 722 | intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 723 | { |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 724 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 725 | struct intel_encoder *ret = NULL; |
| 726 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 727 | struct drm_connector *connector; |
| 728 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 729 | int num_encoders = 0; |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 730 | int i; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 731 | |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 732 | state = crtc_state->base.state; |
| 733 | |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 734 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 735 | if (connector_state->crtc != crtc_state->base.crtc) |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 736 | continue; |
| 737 | |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 738 | ret = to_intel_encoder(connector_state->best_encoder); |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 739 | num_encoders++; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders, |
| 743 | pipe_name(crtc->pipe)); |
| 744 | |
| 745 | BUG_ON(ret == NULL); |
| 746 | return ret; |
| 747 | } |
| 748 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 749 | #define LC_FREQ 2700 |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 750 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 751 | static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv, |
| 752 | i915_reg_t reg) |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 753 | { |
| 754 | int refclk = LC_FREQ; |
| 755 | int n, p, r; |
| 756 | u32 wrpll; |
| 757 | |
| 758 | wrpll = I915_READ(reg); |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 759 | switch (wrpll & WRPLL_PLL_REF_MASK) { |
| 760 | case WRPLL_PLL_SSC: |
| 761 | case WRPLL_PLL_NON_SSC: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 762 | /* |
| 763 | * We could calculate spread here, but our checking |
| 764 | * code only cares about 5% accuracy, and spread is a max of |
| 765 | * 0.5% downspread. |
| 766 | */ |
| 767 | refclk = 135; |
| 768 | break; |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 769 | case WRPLL_PLL_LCPLL: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 770 | refclk = LC_FREQ; |
| 771 | break; |
| 772 | default: |
| 773 | WARN(1, "bad wrpll refclk\n"); |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | r = wrpll & WRPLL_DIVIDER_REF_MASK; |
| 778 | p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT; |
| 779 | n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT; |
| 780 | |
Jesse Barnes | 20f0ec1 | 2014-01-22 12:58:04 -0800 | [diff] [blame] | 781 | /* Convert to KHz, p & r have a fixed point portion */ |
| 782 | return (refclk * n * 100) / (p * r); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 785 | static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv, |
| 786 | uint32_t dpll) |
| 787 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 788 | i915_reg_t cfgcr1_reg, cfgcr2_reg; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 789 | uint32_t cfgcr1_val, cfgcr2_val; |
| 790 | uint32_t p0, p1, p2, dco_freq; |
| 791 | |
Ville Syrjälä | 923c1241 | 2015-09-30 17:06:43 +0300 | [diff] [blame] | 792 | cfgcr1_reg = DPLL_CFGCR1(dpll); |
| 793 | cfgcr2_reg = DPLL_CFGCR2(dpll); |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 794 | |
| 795 | cfgcr1_val = I915_READ(cfgcr1_reg); |
| 796 | cfgcr2_val = I915_READ(cfgcr2_reg); |
| 797 | |
| 798 | p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK; |
| 799 | p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK; |
| 800 | |
| 801 | if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1)) |
| 802 | p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8; |
| 803 | else |
| 804 | p1 = 1; |
| 805 | |
| 806 | |
| 807 | switch (p0) { |
| 808 | case DPLL_CFGCR2_PDIV_1: |
| 809 | p0 = 1; |
| 810 | break; |
| 811 | case DPLL_CFGCR2_PDIV_2: |
| 812 | p0 = 2; |
| 813 | break; |
| 814 | case DPLL_CFGCR2_PDIV_3: |
| 815 | p0 = 3; |
| 816 | break; |
| 817 | case DPLL_CFGCR2_PDIV_7: |
| 818 | p0 = 7; |
| 819 | break; |
| 820 | } |
| 821 | |
| 822 | switch (p2) { |
| 823 | case DPLL_CFGCR2_KDIV_5: |
| 824 | p2 = 5; |
| 825 | break; |
| 826 | case DPLL_CFGCR2_KDIV_2: |
| 827 | p2 = 2; |
| 828 | break; |
| 829 | case DPLL_CFGCR2_KDIV_3: |
| 830 | p2 = 3; |
| 831 | break; |
| 832 | case DPLL_CFGCR2_KDIV_1: |
| 833 | p2 = 1; |
| 834 | break; |
| 835 | } |
| 836 | |
| 837 | dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000; |
| 838 | |
| 839 | dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 * |
| 840 | 1000) / 0x8000; |
| 841 | |
| 842 | return dco_freq / (p0 * p1 * p2 * 5); |
| 843 | } |
| 844 | |
Ville Syrjälä | 398a017 | 2015-06-30 15:33:51 +0300 | [diff] [blame] | 845 | static void ddi_dotclock_get(struct intel_crtc_state *pipe_config) |
| 846 | { |
| 847 | int dotclock; |
| 848 | |
| 849 | if (pipe_config->has_pch_encoder) |
| 850 | dotclock = intel_dotclock_calculate(pipe_config->port_clock, |
| 851 | &pipe_config->fdi_m_n); |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 852 | else if (intel_crtc_has_dp_encoder(pipe_config)) |
Ville Syrjälä | 398a017 | 2015-06-30 15:33:51 +0300 | [diff] [blame] | 853 | dotclock = intel_dotclock_calculate(pipe_config->port_clock, |
| 854 | &pipe_config->dp_m_n); |
| 855 | else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36) |
| 856 | dotclock = pipe_config->port_clock * 2 / 3; |
| 857 | else |
| 858 | dotclock = pipe_config->port_clock; |
| 859 | |
| 860 | if (pipe_config->pixel_multiplier) |
| 861 | dotclock /= pipe_config->pixel_multiplier; |
| 862 | |
| 863 | pipe_config->base.adjusted_mode.crtc_clock = dotclock; |
| 864 | } |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 865 | |
| 866 | static void skl_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 867 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 868 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 869 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 870 | int link_clock = 0; |
| 871 | uint32_t dpll_ctl1, dpll; |
| 872 | |
Damien Lespiau | 134ffa4 | 2014-11-14 17:24:34 +0000 | [diff] [blame] | 873 | dpll = pipe_config->ddi_pll_sel; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 874 | |
| 875 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 876 | |
| 877 | if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) { |
| 878 | link_clock = skl_calc_wrpll_link(dev_priv, dpll); |
| 879 | } else { |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 880 | link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll); |
| 881 | link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll); |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 882 | |
| 883 | switch (link_clock) { |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 884 | case DPLL_CTRL1_LINK_RATE_810: |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 885 | link_clock = 81000; |
| 886 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 887 | case DPLL_CTRL1_LINK_RATE_1080: |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 888 | link_clock = 108000; |
| 889 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 890 | case DPLL_CTRL1_LINK_RATE_1350: |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 891 | link_clock = 135000; |
| 892 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 893 | case DPLL_CTRL1_LINK_RATE_1620: |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 894 | link_clock = 162000; |
| 895 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 896 | case DPLL_CTRL1_LINK_RATE_2160: |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 897 | link_clock = 216000; |
| 898 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 899 | case DPLL_CTRL1_LINK_RATE_2700: |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 900 | link_clock = 270000; |
| 901 | break; |
| 902 | default: |
| 903 | WARN(1, "Unsupported link rate\n"); |
| 904 | break; |
| 905 | } |
| 906 | link_clock *= 2; |
| 907 | } |
| 908 | |
| 909 | pipe_config->port_clock = link_clock; |
| 910 | |
Ville Syrjälä | 398a017 | 2015-06-30 15:33:51 +0300 | [diff] [blame] | 911 | ddi_dotclock_get(pipe_config); |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 914 | static void hsw_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 915 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 916 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 917 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 918 | int link_clock = 0; |
| 919 | u32 val, pll; |
| 920 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 921 | val = pipe_config->ddi_pll_sel; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 922 | switch (val & PORT_CLK_SEL_MASK) { |
| 923 | case PORT_CLK_SEL_LCPLL_810: |
| 924 | link_clock = 81000; |
| 925 | break; |
| 926 | case PORT_CLK_SEL_LCPLL_1350: |
| 927 | link_clock = 135000; |
| 928 | break; |
| 929 | case PORT_CLK_SEL_LCPLL_2700: |
| 930 | link_clock = 270000; |
| 931 | break; |
| 932 | case PORT_CLK_SEL_WRPLL1: |
Ville Syrjälä | 01403de | 2015-09-18 20:03:33 +0300 | [diff] [blame] | 933 | link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0)); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 934 | break; |
| 935 | case PORT_CLK_SEL_WRPLL2: |
Ville Syrjälä | 01403de | 2015-09-18 20:03:33 +0300 | [diff] [blame] | 936 | link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1)); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 937 | break; |
| 938 | case PORT_CLK_SEL_SPLL: |
| 939 | pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK; |
| 940 | if (pll == SPLL_PLL_FREQ_810MHz) |
| 941 | link_clock = 81000; |
| 942 | else if (pll == SPLL_PLL_FREQ_1350MHz) |
| 943 | link_clock = 135000; |
| 944 | else if (pll == SPLL_PLL_FREQ_2700MHz) |
| 945 | link_clock = 270000; |
| 946 | else { |
| 947 | WARN(1, "bad spll freq\n"); |
| 948 | return; |
| 949 | } |
| 950 | break; |
| 951 | default: |
| 952 | WARN(1, "bad port clock sel\n"); |
| 953 | return; |
| 954 | } |
| 955 | |
| 956 | pipe_config->port_clock = link_clock * 2; |
| 957 | |
Ville Syrjälä | 398a017 | 2015-06-30 15:33:51 +0300 | [diff] [blame] | 958 | ddi_dotclock_get(pipe_config); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 961 | static int bxt_calc_pll_link(struct drm_i915_private *dev_priv, |
| 962 | enum intel_dpll_id dpll) |
| 963 | { |
Imre Deak | aa610dc | 2015-06-22 23:35:52 +0300 | [diff] [blame] | 964 | struct intel_shared_dpll *pll; |
| 965 | struct intel_dpll_hw_state *state; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 966 | struct dpll clock; |
Imre Deak | aa610dc | 2015-06-22 23:35:52 +0300 | [diff] [blame] | 967 | |
| 968 | /* For DDI ports we always use a shared PLL. */ |
| 969 | if (WARN_ON(dpll == DPLL_ID_PRIVATE)) |
| 970 | return 0; |
| 971 | |
| 972 | pll = &dev_priv->shared_dplls[dpll]; |
| 973 | state = &pll->config.hw_state; |
| 974 | |
| 975 | clock.m1 = 2; |
| 976 | clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22; |
| 977 | if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE) |
| 978 | clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK; |
| 979 | clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT; |
| 980 | clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT; |
| 981 | clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT; |
| 982 | |
| 983 | return chv_calc_dpll_params(100000, &clock); |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | static void bxt_ddi_clock_get(struct intel_encoder *encoder, |
| 987 | struct intel_crtc_state *pipe_config) |
| 988 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 989 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 990 | enum port port = intel_ddi_get_encoder_port(encoder); |
| 991 | uint32_t dpll = port; |
| 992 | |
Ville Syrjälä | 398a017 | 2015-06-30 15:33:51 +0300 | [diff] [blame] | 993 | pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll); |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 994 | |
Ville Syrjälä | 398a017 | 2015-06-30 15:33:51 +0300 | [diff] [blame] | 995 | ddi_dotclock_get(pipe_config); |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 996 | } |
| 997 | |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 998 | void intel_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 999 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 1000 | { |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 1001 | struct drm_device *dev = encoder->base.dev; |
| 1002 | |
| 1003 | if (INTEL_INFO(dev)->gen <= 8) |
| 1004 | hsw_ddi_clock_get(encoder, pipe_config); |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 1005 | else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 1006 | skl_ddi_clock_get(encoder, pipe_config); |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 1007 | else if (IS_BROXTON(dev)) |
| 1008 | bxt_ddi_clock_get(encoder, pipe_config); |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 1009 | } |
| 1010 | |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1011 | static bool |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 1012 | hsw_ddi_pll_select(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1013 | struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 96f3f1f | 2015-07-06 15:10:02 +0300 | [diff] [blame] | 1014 | struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1015 | { |
Ander Conselvan de Oliveira | daedf20 | 2016-03-08 17:46:23 +0200 | [diff] [blame] | 1016 | struct intel_shared_dpll *pll; |
Ville Syrjälä | 96f3f1f | 2015-07-06 15:10:02 +0300 | [diff] [blame] | 1017 | |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 1018 | pll = intel_get_shared_dpll(intel_crtc, crtc_state, |
| 1019 | intel_encoder); |
| 1020 | if (!pll) |
| 1021 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 1022 | pipe_name(intel_crtc->pipe)); |
| 1023 | |
| 1024 | return pll; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1025 | } |
| 1026 | |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1027 | static bool |
| 1028 | skl_ddi_pll_select(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1029 | struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 96f3f1f | 2015-07-06 15:10:02 +0300 | [diff] [blame] | 1030 | struct intel_encoder *intel_encoder) |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1031 | { |
| 1032 | struct intel_shared_dpll *pll; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1033 | |
Ander Conselvan de Oliveira | daedf20 | 2016-03-08 17:46:23 +0200 | [diff] [blame] | 1034 | pll = intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1035 | if (pll == NULL) { |
| 1036 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 1037 | pipe_name(intel_crtc->pipe)); |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1041 | return true; |
| 1042 | } |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1043 | |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1044 | static bool |
| 1045 | bxt_ddi_pll_select(struct intel_crtc *intel_crtc, |
| 1046 | struct intel_crtc_state *crtc_state, |
Ville Syrjälä | 96f3f1f | 2015-07-06 15:10:02 +0300 | [diff] [blame] | 1047 | struct intel_encoder *intel_encoder) |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1048 | { |
Ander Conselvan de Oliveira | 34177c2 | 2016-03-08 17:46:25 +0200 | [diff] [blame] | 1049 | return !!intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder); |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1050 | } |
| 1051 | |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1052 | /* |
| 1053 | * Tries to find a *shared* PLL for the CRTC and store it in |
| 1054 | * intel_crtc->ddi_pll_sel. |
| 1055 | * |
| 1056 | * For private DPLLs, compute_config() should do the selection for us. This |
| 1057 | * function should be folded into compute_config() eventually. |
| 1058 | */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1059 | bool intel_ddi_pll_select(struct intel_crtc *intel_crtc, |
| 1060 | struct intel_crtc_state *crtc_state) |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1061 | { |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1062 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 1063 | struct intel_encoder *intel_encoder = |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 1064 | intel_ddi_get_crtc_new_encoder(crtc_state); |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1065 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 1066 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1067 | return skl_ddi_pll_select(intel_crtc, crtc_state, |
Ville Syrjälä | 96f3f1f | 2015-07-06 15:10:02 +0300 | [diff] [blame] | 1068 | intel_encoder); |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1069 | else if (IS_BROXTON(dev)) |
| 1070 | return bxt_ddi_pll_select(intel_crtc, crtc_state, |
Ville Syrjälä | 96f3f1f | 2015-07-06 15:10:02 +0300 | [diff] [blame] | 1071 | intel_encoder); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1072 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1073 | return hsw_ddi_pll_select(intel_crtc, crtc_state, |
Ville Syrjälä | 96f3f1f | 2015-07-06 15:10:02 +0300 | [diff] [blame] | 1074 | intel_encoder); |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1075 | } |
| 1076 | |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1077 | void intel_ddi_set_pipe_settings(struct drm_crtc *crtc) |
| 1078 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1079 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1080 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1081 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1082 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1083 | int type = intel_encoder->type; |
| 1084 | uint32_t temp; |
| 1085 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 1086 | if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 1087 | WARN_ON(transcoder_is_dsi(cpu_transcoder)); |
| 1088 | |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1089 | temp = TRANS_MSA_SYNC_CLK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1090 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1091 | case 18: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1092 | temp |= TRANS_MSA_6_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1093 | break; |
| 1094 | case 24: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1095 | temp |= TRANS_MSA_8_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1096 | break; |
| 1097 | case 30: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1098 | temp |= TRANS_MSA_10_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1099 | break; |
| 1100 | case 36: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1101 | temp |= TRANS_MSA_12_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1102 | break; |
| 1103 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 1104 | BUG(); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1105 | } |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1106 | I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1110 | void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state) |
| 1111 | { |
| 1112 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1113 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1114 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1115 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1116 | uint32_t temp; |
| 1117 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1118 | if (state == true) |
| 1119 | temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC; |
| 1120 | else |
| 1121 | temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC; |
| 1122 | I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); |
| 1123 | } |
| 1124 | |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 1125 | void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1126 | { |
| 1127 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1128 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 1129 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1130 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1131 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1132 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1133 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1134 | int type = intel_encoder->type; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1135 | uint32_t temp; |
| 1136 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1137 | /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */ |
| 1138 | temp = TRANS_DDI_FUNC_ENABLE; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1139 | temp |= TRANS_DDI_SELECT_PORT(port); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1140 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1141 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1142 | case 18: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1143 | temp |= TRANS_DDI_BPC_6; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1144 | break; |
| 1145 | case 24: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1146 | temp |= TRANS_DDI_BPC_8; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1147 | break; |
| 1148 | case 30: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1149 | temp |= TRANS_DDI_BPC_10; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1150 | break; |
| 1151 | case 36: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1152 | temp |= TRANS_DDI_BPC_12; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1153 | break; |
| 1154 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 1155 | BUG(); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1156 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1157 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1158 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1159 | temp |= TRANS_DDI_PVSYNC; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1160 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1161 | temp |= TRANS_DDI_PHSYNC; |
Paulo Zanoni | f63eb7c4 | 2012-08-08 14:15:28 -0300 | [diff] [blame] | 1162 | |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 1163 | if (cpu_transcoder == TRANSCODER_EDP) { |
| 1164 | switch (pipe) { |
| 1165 | case PIPE_A: |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 1166 | /* On Haswell, can only use the always-on power well for |
| 1167 | * eDP when not using the panel fitter, and when not |
| 1168 | * using motion blur mitigation (which we don't |
| 1169 | * support). */ |
Daniel Vetter | fabf6e5 | 2014-05-29 14:10:22 +0200 | [diff] [blame] | 1170 | if (IS_HASWELL(dev) && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1171 | (intel_crtc->config->pch_pfit.enabled || |
| 1172 | intel_crtc->config->pch_pfit.force_thru)) |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 1173 | temp |= TRANS_DDI_EDP_INPUT_A_ONOFF; |
| 1174 | else |
| 1175 | temp |= TRANS_DDI_EDP_INPUT_A_ON; |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 1176 | break; |
| 1177 | case PIPE_B: |
| 1178 | temp |= TRANS_DDI_EDP_INPUT_B_ONOFF; |
| 1179 | break; |
| 1180 | case PIPE_C: |
| 1181 | temp |= TRANS_DDI_EDP_INPUT_C_ONOFF; |
| 1182 | break; |
| 1183 | default: |
| 1184 | BUG(); |
| 1185 | break; |
| 1186 | } |
| 1187 | } |
| 1188 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1189 | if (type == INTEL_OUTPUT_HDMI) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1190 | if (intel_crtc->config->has_hdmi_sink) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1191 | temp |= TRANS_DDI_MODE_SELECT_HDMI; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1192 | else |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1193 | temp |= TRANS_DDI_MODE_SELECT_DVI; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1194 | } else if (type == INTEL_OUTPUT_ANALOG) { |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1195 | temp |= TRANS_DDI_MODE_SELECT_FDI; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1196 | temp |= (intel_crtc->config->fdi_lanes - 1) << 1; |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 1197 | } else if (type == INTEL_OUTPUT_DP || |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1198 | type == INTEL_OUTPUT_EDP) { |
Ville Syrjälä | 64ee2fd | 2016-07-28 17:50:39 +0300 | [diff] [blame] | 1199 | temp |= TRANS_DDI_MODE_SELECT_DP_SST; |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1200 | temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1201 | } else if (type == INTEL_OUTPUT_DP_MST) { |
Ville Syrjälä | 64ee2fd | 2016-07-28 17:50:39 +0300 | [diff] [blame] | 1202 | temp |= TRANS_DDI_MODE_SELECT_DP_MST; |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 1203 | temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1204 | } else { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1205 | WARN(1, "Invalid encoder type %d for pipe %c\n", |
| 1206 | intel_encoder->type, pipe_name(pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1207 | } |
| 1208 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1209 | I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1210 | } |
| 1211 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1212 | void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv, |
| 1213 | enum transcoder cpu_transcoder) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1214 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1215 | i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1216 | uint32_t val = I915_READ(reg); |
| 1217 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1218 | val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1219 | val |= TRANS_DDI_PORT_NONE; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1220 | I915_WRITE(reg, val); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1221 | } |
| 1222 | |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1223 | bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector) |
| 1224 | { |
| 1225 | struct drm_device *dev = intel_connector->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1226 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1227 | struct intel_encoder *intel_encoder = intel_connector->encoder; |
| 1228 | int type = intel_connector->base.connector_type; |
| 1229 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1230 | enum pipe pipe = 0; |
| 1231 | enum transcoder cpu_transcoder; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1232 | enum intel_display_power_domain power_domain; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1233 | uint32_t tmp; |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1234 | bool ret; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1235 | |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1236 | power_domain = intel_display_port_power_domain(intel_encoder); |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1237 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1238 | return false; |
| 1239 | |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1240 | if (!intel_encoder->get_hw_state(intel_encoder, &pipe)) { |
| 1241 | ret = false; |
| 1242 | goto out; |
| 1243 | } |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1244 | |
| 1245 | if (port == PORT_A) |
| 1246 | cpu_transcoder = TRANSCODER_EDP; |
| 1247 | else |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1248 | cpu_transcoder = (enum transcoder) pipe; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1249 | |
| 1250 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1251 | |
| 1252 | switch (tmp & TRANS_DDI_MODE_SELECT_MASK) { |
| 1253 | case TRANS_DDI_MODE_SELECT_HDMI: |
| 1254 | case TRANS_DDI_MODE_SELECT_DVI: |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1255 | ret = type == DRM_MODE_CONNECTOR_HDMIA; |
| 1256 | break; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1257 | |
| 1258 | case TRANS_DDI_MODE_SELECT_DP_SST: |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1259 | ret = type == DRM_MODE_CONNECTOR_eDP || |
| 1260 | type == DRM_MODE_CONNECTOR_DisplayPort; |
| 1261 | break; |
| 1262 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1263 | case TRANS_DDI_MODE_SELECT_DP_MST: |
| 1264 | /* if the transcoder is in MST state then |
| 1265 | * connector isn't connected */ |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1266 | ret = false; |
| 1267 | break; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1268 | |
| 1269 | case TRANS_DDI_MODE_SELECT_FDI: |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1270 | ret = type == DRM_MODE_CONNECTOR_VGA; |
| 1271 | break; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1272 | |
| 1273 | default: |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1274 | ret = false; |
| 1275 | break; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1276 | } |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1277 | |
| 1278 | out: |
| 1279 | intel_display_power_put(dev_priv, power_domain); |
| 1280 | |
| 1281 | return ret; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1282 | } |
| 1283 | |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1284 | bool intel_ddi_get_hw_state(struct intel_encoder *encoder, |
| 1285 | enum pipe *pipe) |
| 1286 | { |
| 1287 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1288 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1289 | enum port port = intel_ddi_get_encoder_port(encoder); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1290 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1291 | u32 tmp; |
| 1292 | int i; |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1293 | bool ret; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1294 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1295 | power_domain = intel_display_port_power_domain(encoder); |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1296 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1297 | return false; |
| 1298 | |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1299 | ret = false; |
| 1300 | |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1301 | tmp = I915_READ(DDI_BUF_CTL(port)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1302 | |
| 1303 | if (!(tmp & DDI_BUF_CTL_ENABLE)) |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1304 | goto out; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1305 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1306 | if (port == PORT_A) { |
| 1307 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1308 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1309 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 1310 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 1311 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 1312 | *pipe = PIPE_A; |
| 1313 | break; |
| 1314 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 1315 | *pipe = PIPE_B; |
| 1316 | break; |
| 1317 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 1318 | *pipe = PIPE_C; |
| 1319 | break; |
| 1320 | } |
| 1321 | |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1322 | ret = true; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1323 | |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1324 | goto out; |
| 1325 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1326 | |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1327 | for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) { |
| 1328 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(i)); |
| 1329 | |
| 1330 | if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) { |
| 1331 | if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == |
| 1332 | TRANS_DDI_MODE_SELECT_DP_MST) |
| 1333 | goto out; |
| 1334 | |
| 1335 | *pipe = i; |
| 1336 | ret = true; |
| 1337 | |
| 1338 | goto out; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1342 | DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1343 | |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1344 | out: |
Imre Deak | e93da0a | 2016-06-13 16:44:37 +0300 | [diff] [blame] | 1345 | if (ret && IS_BROXTON(dev_priv)) { |
| 1346 | tmp = I915_READ(BXT_PHY_CTL(port)); |
| 1347 | if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK | |
| 1348 | BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED) |
| 1349 | DRM_ERROR("Port %c enabled but PHY powered down? " |
| 1350 | "(PHY_CTL %08x)\n", port_name(port), tmp); |
| 1351 | } |
| 1352 | |
Imre Deak | e27daab | 2016-02-12 18:55:16 +0200 | [diff] [blame] | 1353 | intel_display_power_put(dev_priv, power_domain); |
| 1354 | |
| 1355 | return ret; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1356 | } |
| 1357 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1358 | void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1359 | { |
| 1360 | struct drm_crtc *crtc = &intel_crtc->base; |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 1361 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1362 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1363 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 1364 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1365 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1366 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1367 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1368 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1369 | TRANS_CLK_SEL_PORT(port)); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1373 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1374 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1375 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1376 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1377 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1378 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1379 | TRANS_CLK_SEL_DISABLED); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1380 | } |
| 1381 | |
Ville Syrjälä | a7d8dbc | 2016-07-12 15:59:28 +0300 | [diff] [blame] | 1382 | static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv, |
| 1383 | enum port port, uint8_t iboost) |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1384 | { |
Ville Syrjälä | a7d8dbc | 2016-07-12 15:59:28 +0300 | [diff] [blame] | 1385 | u32 tmp; |
| 1386 | |
| 1387 | tmp = I915_READ(DISPIO_CR_TX_BMU_CR0); |
| 1388 | tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port)); |
| 1389 | if (iboost) |
| 1390 | tmp |= iboost << BALANCE_LEG_SHIFT(port); |
| 1391 | else |
| 1392 | tmp |= BALANCE_LEG_DISABLE(port); |
| 1393 | I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp); |
| 1394 | } |
| 1395 | |
| 1396 | static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level) |
| 1397 | { |
| 1398 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base); |
| 1399 | struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); |
| 1400 | enum port port = intel_dig_port->port; |
| 1401 | int type = encoder->type; |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1402 | const struct ddi_buf_trans *ddi_translations; |
| 1403 | uint8_t iboost; |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1404 | uint8_t dp_iboost, hdmi_iboost; |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1405 | int n_entries; |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1406 | |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1407 | /* VBT may override standard boost values */ |
| 1408 | dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level; |
| 1409 | hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level; |
| 1410 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 1411 | if (type == INTEL_OUTPUT_DP) { |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1412 | if (dp_iboost) { |
| 1413 | iboost = dp_iboost; |
| 1414 | } else { |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 1415 | ddi_translations = skl_get_buf_trans_dp(dev_priv, &n_entries); |
Ander Conselvan de Oliveira | e4d4c05 | 2015-11-11 15:15:54 +0200 | [diff] [blame] | 1416 | iboost = ddi_translations[level].i_boost; |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1417 | } |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1418 | } else if (type == INTEL_OUTPUT_EDP) { |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1419 | if (dp_iboost) { |
| 1420 | iboost = dp_iboost; |
| 1421 | } else { |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 1422 | ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries); |
Ville Syrjälä | 10afa0b | 2015-12-08 19:59:43 +0200 | [diff] [blame] | 1423 | |
| 1424 | if (WARN_ON(port != PORT_A && |
| 1425 | port != PORT_E && n_entries > 9)) |
| 1426 | n_entries = 9; |
| 1427 | |
Ander Conselvan de Oliveira | e4d4c05 | 2015-11-11 15:15:54 +0200 | [diff] [blame] | 1428 | iboost = ddi_translations[level].i_boost; |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1429 | } |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1430 | } else if (type == INTEL_OUTPUT_HDMI) { |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1431 | if (hdmi_iboost) { |
| 1432 | iboost = hdmi_iboost; |
| 1433 | } else { |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 1434 | ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries); |
Ander Conselvan de Oliveira | e4d4c05 | 2015-11-11 15:15:54 +0200 | [diff] [blame] | 1435 | iboost = ddi_translations[level].i_boost; |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1436 | } |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1437 | } else { |
| 1438 | return; |
| 1439 | } |
| 1440 | |
| 1441 | /* Make sure that the requested I_boost is valid */ |
| 1442 | if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) { |
| 1443 | DRM_ERROR("Invalid I_boost value %u\n", iboost); |
| 1444 | return; |
| 1445 | } |
| 1446 | |
Ville Syrjälä | a7d8dbc | 2016-07-12 15:59:28 +0300 | [diff] [blame] | 1447 | _skl_ddi_set_iboost(dev_priv, port, iboost); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1448 | |
Ville Syrjälä | a7d8dbc | 2016-07-12 15:59:28 +0300 | [diff] [blame] | 1449 | if (port == PORT_A && intel_dig_port->max_lanes == 4) |
| 1450 | _skl_ddi_set_iboost(dev_priv, PORT_E, iboost); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1451 | } |
| 1452 | |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 1453 | static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv, |
| 1454 | u32 level, enum port port, int type) |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1455 | { |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1456 | const struct bxt_ddi_buf_trans *ddi_translations; |
| 1457 | u32 n_entries, i; |
| 1458 | uint32_t val; |
| 1459 | |
Jani Nikula | 06411f0 | 2016-03-24 17:50:21 +0200 | [diff] [blame] | 1460 | if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) { |
Sonika Jindal | d9d7000 | 2015-09-24 10:24:56 +0530 | [diff] [blame] | 1461 | n_entries = ARRAY_SIZE(bxt_ddi_translations_edp); |
| 1462 | ddi_translations = bxt_ddi_translations_edp; |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 1463 | } else if (type == INTEL_OUTPUT_DP |
Sonika Jindal | d9d7000 | 2015-09-24 10:24:56 +0530 | [diff] [blame] | 1464 | || type == INTEL_OUTPUT_EDP) { |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1465 | n_entries = ARRAY_SIZE(bxt_ddi_translations_dp); |
| 1466 | ddi_translations = bxt_ddi_translations_dp; |
| 1467 | } else if (type == INTEL_OUTPUT_HDMI) { |
| 1468 | n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi); |
| 1469 | ddi_translations = bxt_ddi_translations_hdmi; |
| 1470 | } else { |
| 1471 | DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n", |
| 1472 | type); |
| 1473 | return; |
| 1474 | } |
| 1475 | |
| 1476 | /* Check if default value has to be used */ |
| 1477 | if (level >= n_entries || |
| 1478 | (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) { |
| 1479 | for (i = 0; i < n_entries; i++) { |
| 1480 | if (ddi_translations[i].default_index) { |
| 1481 | level = i; |
| 1482 | break; |
| 1483 | } |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | /* |
| 1488 | * While we write to the group register to program all lanes at once we |
| 1489 | * can read only lane registers and we pick lanes 0/1 for that. |
| 1490 | */ |
| 1491 | val = I915_READ(BXT_PORT_PCS_DW10_LN01(port)); |
| 1492 | val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT); |
| 1493 | I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val); |
| 1494 | |
| 1495 | val = I915_READ(BXT_PORT_TX_DW2_LN0(port)); |
| 1496 | val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE); |
| 1497 | val |= ddi_translations[level].margin << MARGIN_000_SHIFT | |
| 1498 | ddi_translations[level].scale << UNIQ_TRANS_SCALE_SHIFT; |
| 1499 | I915_WRITE(BXT_PORT_TX_DW2_GRP(port), val); |
| 1500 | |
| 1501 | val = I915_READ(BXT_PORT_TX_DW3_LN0(port)); |
Sonika Jindal | 9c58a04 | 2015-09-24 10:22:54 +0530 | [diff] [blame] | 1502 | val &= ~SCALE_DCOMP_METHOD; |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1503 | if (ddi_translations[level].enable) |
Sonika Jindal | 9c58a04 | 2015-09-24 10:22:54 +0530 | [diff] [blame] | 1504 | val |= SCALE_DCOMP_METHOD; |
| 1505 | |
| 1506 | if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD)) |
| 1507 | DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set"); |
| 1508 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1509 | I915_WRITE(BXT_PORT_TX_DW3_GRP(port), val); |
| 1510 | |
| 1511 | val = I915_READ(BXT_PORT_TX_DW4_LN0(port)); |
| 1512 | val &= ~DE_EMPHASIS; |
| 1513 | val |= ddi_translations[level].deemphasis << DEEMPH_SHIFT; |
| 1514 | I915_WRITE(BXT_PORT_TX_DW4_GRP(port), val); |
| 1515 | |
| 1516 | val = I915_READ(BXT_PORT_PCS_DW10_LN01(port)); |
| 1517 | val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT; |
| 1518 | I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val); |
| 1519 | } |
| 1520 | |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1521 | static uint32_t translate_signal_level(int signal_levels) |
| 1522 | { |
| 1523 | uint32_t level; |
| 1524 | |
| 1525 | switch (signal_levels) { |
| 1526 | default: |
| 1527 | DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level: 0x%x\n", |
| 1528 | signal_levels); |
| 1529 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 1530 | level = 0; |
| 1531 | break; |
| 1532 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 1533 | level = 1; |
| 1534 | break; |
| 1535 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 1536 | level = 2; |
| 1537 | break; |
| 1538 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3: |
| 1539 | level = 3; |
| 1540 | break; |
| 1541 | |
| 1542 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 1543 | level = 4; |
| 1544 | break; |
| 1545 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 1546 | level = 5; |
| 1547 | break; |
| 1548 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2: |
| 1549 | level = 6; |
| 1550 | break; |
| 1551 | |
| 1552 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 1553 | level = 7; |
| 1554 | break; |
| 1555 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1: |
| 1556 | level = 8; |
| 1557 | break; |
| 1558 | |
| 1559 | case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0: |
| 1560 | level = 9; |
| 1561 | break; |
| 1562 | } |
| 1563 | |
| 1564 | return level; |
| 1565 | } |
| 1566 | |
| 1567 | uint32_t ddi_signal_levels(struct intel_dp *intel_dp) |
| 1568 | { |
| 1569 | struct intel_digital_port *dport = dp_to_dig_port(intel_dp); |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 1570 | struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1571 | struct intel_encoder *encoder = &dport->base; |
| 1572 | uint8_t train_set = intel_dp->train_set[0]; |
| 1573 | int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | |
| 1574 | DP_TRAIN_PRE_EMPHASIS_MASK); |
| 1575 | enum port port = dport->port; |
| 1576 | uint32_t level; |
| 1577 | |
| 1578 | level = translate_signal_level(signal_levels); |
| 1579 | |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 1580 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Ville Syrjälä | a7d8dbc | 2016-07-12 15:59:28 +0300 | [diff] [blame] | 1581 | skl_ddi_set_iboost(encoder, level); |
Ville Syrjälä | 78ab0ba | 2015-12-08 19:59:41 +0200 | [diff] [blame] | 1582 | else if (IS_BROXTON(dev_priv)) |
| 1583 | bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type); |
David Weinehall | f8896f5 | 2015-06-25 11:11:03 +0300 | [diff] [blame] | 1584 | |
| 1585 | return DDI_BUF_TRANS_SELECT(level); |
| 1586 | } |
| 1587 | |
Ville Syrjälä | e404ba8d | 2015-08-17 18:46:20 +0300 | [diff] [blame] | 1588 | void intel_ddi_clk_select(struct intel_encoder *encoder, |
| 1589 | const struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1590 | { |
Ville Syrjälä | e404ba8d | 2015-08-17 18:46:20 +0300 | [diff] [blame] | 1591 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
| 1592 | enum port port = intel_ddi_get_encoder_port(encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1593 | |
Ville Syrjälä | e404ba8d | 2015-08-17 18:46:20 +0300 | [diff] [blame] | 1594 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
| 1595 | uint32_t dpll = pipe_config->ddi_pll_sel; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1596 | uint32_t val; |
| 1597 | |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1598 | /* DDI -> PLL mapping */ |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1599 | val = I915_READ(DPLL_CTRL2); |
| 1600 | |
| 1601 | val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) | |
| 1602 | DPLL_CTRL2_DDI_CLK_SEL_MASK(port)); |
| 1603 | val |= (DPLL_CTRL2_DDI_CLK_SEL(dpll, port) | |
| 1604 | DPLL_CTRL2_DDI_SEL_OVERRIDE(port)); |
| 1605 | |
| 1606 | I915_WRITE(DPLL_CTRL2, val); |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1607 | |
Ville Syrjälä | e404ba8d | 2015-08-17 18:46:20 +0300 | [diff] [blame] | 1608 | } else if (INTEL_INFO(dev_priv)->gen < 9) { |
| 1609 | WARN_ON(pipe_config->ddi_pll_sel == PORT_CLK_SEL_NONE); |
| 1610 | I915_WRITE(PORT_CLK_SEL(port), pipe_config->ddi_pll_sel); |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1611 | } |
Ville Syrjälä | e404ba8d | 2015-08-17 18:46:20 +0300 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder) |
| 1615 | { |
| 1616 | struct drm_encoder *encoder = &intel_encoder->base; |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 1617 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
Ville Syrjälä | e404ba8d | 2015-08-17 18:46:20 +0300 | [diff] [blame] | 1618 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
| 1619 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1620 | int type = intel_encoder->type; |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 1621 | |
Ville Syrjälä | b2ccb82 | 2016-05-02 22:08:24 +0300 | [diff] [blame] | 1622 | if (type == INTEL_OUTPUT_HDMI) { |
| 1623 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 1624 | |
| 1625 | intel_dp_dual_mode_set_tmds_output(intel_hdmi, true); |
| 1626 | } |
| 1627 | |
Ville Syrjälä | e404ba8d | 2015-08-17 18:46:20 +0300 | [diff] [blame] | 1628 | if (type == INTEL_OUTPUT_EDP) { |
| 1629 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1630 | intel_edp_panel_on(intel_dp); |
| 1631 | } |
| 1632 | |
| 1633 | intel_ddi_clk_select(intel_encoder, crtc->config); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1634 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 1635 | if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1636 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1637 | |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 1638 | intel_prepare_dp_ddi_buffers(intel_encoder); |
| 1639 | |
Ville Syrjälä | 901c2da | 2015-08-17 18:05:12 +0300 | [diff] [blame] | 1640 | intel_dp_set_link_params(intel_dp, crtc->config); |
| 1641 | |
Dave Airlie | 44905a27 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 1642 | intel_ddi_init_dp_buf_reg(intel_encoder); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1643 | |
Ville Syrjälä | f64425a | 2016-07-28 17:50:41 +0300 | [diff] [blame^] | 1644 | WARN_ON(intel_dp->active_streams != 0); |
| 1645 | intel_dp->active_streams++; |
| 1646 | |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1647 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 1648 | intel_dp_start_link_train(intel_dp); |
Ville Syrjälä | 6a7e4f9 | 2015-12-08 19:59:44 +0200 | [diff] [blame] | 1649 | if (port != PORT_A || INTEL_INFO(dev_priv)->gen >= 9) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 1650 | intel_dp_stop_link_train(intel_dp); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1651 | } else if (type == INTEL_OUTPUT_HDMI) { |
| 1652 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Ville Syrjälä | 8d8bb85 | 2016-07-12 15:59:30 +0300 | [diff] [blame] | 1653 | int level = intel_ddi_hdmi_level(dev_priv, port); |
| 1654 | |
Ville Syrjälä | 32bdc40 | 2016-07-12 15:59:33 +0300 | [diff] [blame] | 1655 | intel_prepare_hdmi_ddi_buffers(intel_encoder); |
| 1656 | |
Ville Syrjälä | 8d8bb85 | 2016-07-12 15:59:30 +0300 | [diff] [blame] | 1657 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
| 1658 | skl_ddi_set_iboost(intel_encoder, level); |
Ville Syrjälä | 9f33243 | 2016-07-12 15:59:31 +0300 | [diff] [blame] | 1659 | else if (IS_BROXTON(dev_priv)) |
| 1660 | bxt_ddi_vswing_sequence(dev_priv, level, port, |
| 1661 | INTEL_OUTPUT_HDMI); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1662 | |
| 1663 | intel_hdmi->set_infoframes(encoder, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1664 | crtc->config->has_hdmi_sink, |
| 1665 | &crtc->config->base.adjusted_mode); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1666 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1667 | } |
| 1668 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1669 | static void intel_ddi_post_disable(struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1670 | { |
| 1671 | struct drm_encoder *encoder = &intel_encoder->base; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1672 | struct drm_device *dev = encoder->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1673 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1674 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1675 | int type = intel_encoder->type; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1676 | uint32_t val; |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1677 | bool wait = false; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1678 | |
| 1679 | val = I915_READ(DDI_BUF_CTL(port)); |
| 1680 | if (val & DDI_BUF_CTL_ENABLE) { |
| 1681 | val &= ~DDI_BUF_CTL_ENABLE; |
| 1682 | I915_WRITE(DDI_BUF_CTL(port), val); |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1683 | wait = true; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1684 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1685 | |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1686 | val = I915_READ(DP_TP_CTL(port)); |
| 1687 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 1688 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 1689 | I915_WRITE(DP_TP_CTL(port), val); |
| 1690 | |
| 1691 | if (wait) |
| 1692 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 1693 | |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 1694 | if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1695 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Jani Nikula | 76bb80e | 2013-11-15 15:29:57 +0200 | [diff] [blame] | 1696 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 1697 | intel_edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1698 | intel_edp_panel_off(intel_dp); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1699 | } |
| 1700 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 1701 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1702 | I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) | |
| 1703 | DPLL_CTRL2_DDI_CLK_OFF(port))); |
Satheeshakrishna M | 1ab2338 | 2014-08-22 09:49:06 +0530 | [diff] [blame] | 1704 | else if (INTEL_INFO(dev)->gen < 9) |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1705 | I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE); |
Ville Syrjälä | b2ccb82 | 2016-05-02 22:08:24 +0300 | [diff] [blame] | 1706 | |
| 1707 | if (type == INTEL_OUTPUT_HDMI) { |
| 1708 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 1709 | |
| 1710 | intel_dp_dual_mode_set_tmds_output(intel_hdmi, false); |
| 1711 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1712 | } |
| 1713 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1714 | static void intel_enable_ddi(struct intel_encoder *intel_encoder) |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1715 | { |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1716 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1717 | struct drm_crtc *crtc = encoder->crtc; |
| 1718 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1719 | struct drm_device *dev = encoder->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1720 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1721 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1722 | int type = intel_encoder->type; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1723 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1724 | if (type == INTEL_OUTPUT_HDMI) { |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1725 | struct intel_digital_port *intel_dig_port = |
| 1726 | enc_to_dig_port(encoder); |
| 1727 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1728 | /* In HDMI/DVI mode, the port width, and swing/emphasis values |
| 1729 | * are ignored so nothing special needs to be done besides |
| 1730 | * enabling the port. |
| 1731 | */ |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1732 | I915_WRITE(DDI_BUF_CTL(port), |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 1733 | intel_dig_port->saved_port_bits | |
| 1734 | DDI_BUF_CTL_ENABLE); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1735 | } else if (type == INTEL_OUTPUT_EDP) { |
| 1736 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1737 | |
Vandana Kannan | 23f08d8 | 2014-11-13 14:55:22 +0000 | [diff] [blame] | 1738 | if (port == PORT_A && INTEL_INFO(dev)->gen < 9) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 1739 | intel_dp_stop_link_train(intel_dp); |
| 1740 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1741 | intel_edp_backlight_on(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 1742 | intel_psr_enable(intel_dp); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 1743 | intel_edp_drrs_enable(intel_dp); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1744 | } |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1745 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1746 | if (intel_crtc->config->has_audio) { |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 1747 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 1748 | intel_audio_codec_enable(intel_encoder); |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1749 | } |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1752 | static void intel_disable_ddi(struct intel_encoder *intel_encoder) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1753 | { |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1754 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1755 | struct drm_crtc *crtc = encoder->crtc; |
| 1756 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1757 | int type = intel_encoder->type; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1758 | struct drm_device *dev = encoder->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1759 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1760 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1761 | if (intel_crtc->config->has_audio) { |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 1762 | intel_audio_codec_disable(intel_encoder); |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 1763 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
| 1764 | } |
Paulo Zanoni | 2831d842 | 2013-03-06 20:03:09 -0300 | [diff] [blame] | 1765 | |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1766 | if (type == INTEL_OUTPUT_EDP) { |
| 1767 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1768 | |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 1769 | intel_edp_drrs_disable(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 1770 | intel_psr_disable(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1771 | intel_edp_backlight_off(intel_dp); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1772 | } |
Ville Syrjälä | f64425a | 2016-07-28 17:50:41 +0300 | [diff] [blame^] | 1773 | |
| 1774 | if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) { |
| 1775 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1776 | |
| 1777 | intel_dp->active_streams--; |
| 1778 | WARN_ON(intel_dp->active_streams != 0); |
| 1779 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1780 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1781 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1782 | bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv, |
| 1783 | enum dpio_phy phy) |
Imre Deak | bd48006 | 2016-04-01 16:02:44 +0300 | [diff] [blame] | 1784 | { |
Imre Deak | e93da0a | 2016-06-13 16:44:37 +0300 | [diff] [blame] | 1785 | enum port port; |
| 1786 | |
Imre Deak | bd48006 | 2016-04-01 16:02:44 +0300 | [diff] [blame] | 1787 | if (!(I915_READ(BXT_P_CR_GT_DISP_PWRON) & GT_DISPLAY_POWER_ON(phy))) |
| 1788 | return false; |
| 1789 | |
| 1790 | if ((I915_READ(BXT_PORT_CL1CM_DW0(phy)) & |
| 1791 | (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) { |
| 1792 | DRM_DEBUG_DRIVER("DDI PHY %d powered, but power hasn't settled\n", |
| 1793 | phy); |
| 1794 | |
| 1795 | return false; |
| 1796 | } |
| 1797 | |
| 1798 | if (phy == DPIO_PHY1 && |
| 1799 | !(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE)) { |
| 1800 | DRM_DEBUG_DRIVER("DDI PHY 1 powered, but GRC isn't done\n"); |
| 1801 | |
| 1802 | return false; |
| 1803 | } |
| 1804 | |
| 1805 | if (!(I915_READ(BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) { |
| 1806 | DRM_DEBUG_DRIVER("DDI PHY %d powered, but still in reset\n", |
| 1807 | phy); |
| 1808 | |
| 1809 | return false; |
| 1810 | } |
| 1811 | |
Imre Deak | e93da0a | 2016-06-13 16:44:37 +0300 | [diff] [blame] | 1812 | for_each_port_masked(port, |
| 1813 | phy == DPIO_PHY0 ? BIT(PORT_B) | BIT(PORT_C) : |
| 1814 | BIT(PORT_A)) { |
| 1815 | u32 tmp = I915_READ(BXT_PHY_CTL(port)); |
| 1816 | |
| 1817 | if (tmp & BXT_PHY_CMNLANE_POWERDOWN_ACK) { |
| 1818 | DRM_DEBUG_DRIVER("DDI PHY %d powered, but common lane " |
| 1819 | "for port %c powered down " |
| 1820 | "(PHY_CTL %08x)\n", |
| 1821 | phy, port_name(port), tmp); |
| 1822 | |
| 1823 | return false; |
| 1824 | } |
| 1825 | } |
| 1826 | |
Imre Deak | bd48006 | 2016-04-01 16:02:44 +0300 | [diff] [blame] | 1827 | return true; |
| 1828 | } |
| 1829 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 1830 | static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy) |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 1831 | { |
| 1832 | u32 val = I915_READ(BXT_PORT_REF_DW6(phy)); |
| 1833 | |
| 1834 | return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT; |
| 1835 | } |
| 1836 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 1837 | static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv, |
| 1838 | enum dpio_phy phy) |
Imre Deak | 01a01ef | 2016-04-21 19:19:21 +0300 | [diff] [blame] | 1839 | { |
Chris Wilson | 058fee9 | 2016-06-30 15:32:52 +0100 | [diff] [blame] | 1840 | if (intel_wait_for_register(dev_priv, |
| 1841 | BXT_PORT_REF_DW3(phy), |
| 1842 | GRC_DONE, GRC_DONE, |
| 1843 | 10)) |
Imre Deak | 01a01ef | 2016-04-21 19:19:21 +0300 | [diff] [blame] | 1844 | DRM_ERROR("timeout waiting for PHY%d GRC\n", phy); |
| 1845 | } |
| 1846 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1847 | void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy) |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1848 | { |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 1849 | u32 val; |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1850 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1851 | if (bxt_ddi_phy_is_enabled(dev_priv, phy)) { |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 1852 | /* Still read out the GRC value for state verification */ |
Imre Deak | 67856d4 | 2016-04-20 20:46:04 +0300 | [diff] [blame] | 1853 | if (phy == DPIO_PHY0) |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 1854 | dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy); |
Imre Deak | bd48006 | 2016-04-01 16:02:44 +0300 | [diff] [blame] | 1855 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1856 | if (bxt_ddi_phy_verify_state(dev_priv, phy)) { |
Imre Deak | 47baf2a | 2016-04-20 20:46:06 +0300 | [diff] [blame] | 1857 | DRM_DEBUG_DRIVER("DDI PHY %d already enabled, " |
| 1858 | "won't reprogram it\n", phy); |
Imre Deak | bd48006 | 2016-04-01 16:02:44 +0300 | [diff] [blame] | 1859 | |
Imre Deak | 47baf2a | 2016-04-20 20:46:06 +0300 | [diff] [blame] | 1860 | return; |
| 1861 | } |
| 1862 | |
| 1863 | DRM_DEBUG_DRIVER("DDI PHY %d enabled with invalid state, " |
| 1864 | "force reprogramming it\n", phy); |
Imre Deak | 47baf2a | 2016-04-20 20:46:06 +0300 | [diff] [blame] | 1865 | } |
Imre Deak | bd48006 | 2016-04-01 16:02:44 +0300 | [diff] [blame] | 1866 | |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1867 | val = I915_READ(BXT_P_CR_GT_DISP_PWRON); |
| 1868 | val |= GT_DISPLAY_POWER_ON(phy); |
| 1869 | I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val); |
| 1870 | |
Vandana Kannan | b61e799 | 2016-03-31 23:15:54 +0530 | [diff] [blame] | 1871 | /* |
| 1872 | * The PHY registers start out inaccessible and respond to reads with |
| 1873 | * all 1s. Eventually they become accessible as they power up, then |
| 1874 | * the reserved bit will give the default 0. Poll on the reserved bit |
| 1875 | * becoming 0 to find when the PHY is accessible. |
| 1876 | * HW team confirmed that the time to reach phypowergood status is |
| 1877 | * anywhere between 50 us and 100us. |
| 1878 | */ |
| 1879 | if (wait_for_us(((I915_READ(BXT_PORT_CL1CM_DW0(phy)) & |
| 1880 | (PHY_RESERVED | PHY_POWER_GOOD)) == PHY_POWER_GOOD), 100)) { |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1881 | DRM_ERROR("timeout during PHY%d power on\n", phy); |
Vandana Kannan | b61e799 | 2016-03-31 23:15:54 +0530 | [diff] [blame] | 1882 | } |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1883 | |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1884 | /* Program PLL Rcomp code offset */ |
| 1885 | val = I915_READ(BXT_PORT_CL1CM_DW9(phy)); |
| 1886 | val &= ~IREF0RC_OFFSET_MASK; |
| 1887 | val |= 0xE4 << IREF0RC_OFFSET_SHIFT; |
| 1888 | I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val); |
| 1889 | |
| 1890 | val = I915_READ(BXT_PORT_CL1CM_DW10(phy)); |
| 1891 | val &= ~IREF1RC_OFFSET_MASK; |
| 1892 | val |= 0xE4 << IREF1RC_OFFSET_SHIFT; |
| 1893 | I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val); |
| 1894 | |
| 1895 | /* Program power gating */ |
| 1896 | val = I915_READ(BXT_PORT_CL1CM_DW28(phy)); |
| 1897 | val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | |
| 1898 | SUS_CLK_CONFIG; |
| 1899 | I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val); |
| 1900 | |
| 1901 | if (phy == DPIO_PHY0) { |
| 1902 | val = I915_READ(BXT_PORT_CL2CM_DW6_BC); |
| 1903 | val |= DW6_OLDO_DYN_PWR_DOWN_EN; |
| 1904 | I915_WRITE(BXT_PORT_CL2CM_DW6_BC, val); |
| 1905 | } |
| 1906 | |
| 1907 | val = I915_READ(BXT_PORT_CL1CM_DW30(phy)); |
| 1908 | val &= ~OCL2_LDOFUSE_PWR_DIS; |
| 1909 | /* |
| 1910 | * On PHY1 disable power on the second channel, since no port is |
| 1911 | * connected there. On PHY0 both channels have a port, so leave it |
| 1912 | * enabled. |
| 1913 | * TODO: port C is only connected on BXT-P, so on BXT0/1 we should |
| 1914 | * power down the second channel on PHY0 as well. |
Imre Deak | 28ca693 | 2016-04-01 16:02:34 +0300 | [diff] [blame] | 1915 | * |
| 1916 | * FIXME: Clarify programming of the following, the register is |
| 1917 | * read-only with bit 6 fixed at 0 at least in stepping A. |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1918 | */ |
| 1919 | if (phy == DPIO_PHY1) |
| 1920 | val |= OCL2_LDOFUSE_PWR_DIS; |
| 1921 | I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val); |
| 1922 | |
| 1923 | if (phy == DPIO_PHY0) { |
| 1924 | uint32_t grc_code; |
| 1925 | /* |
| 1926 | * PHY0 isn't connected to an RCOMP resistor so copy over |
| 1927 | * the corresponding calibrated value from PHY1, and disable |
| 1928 | * the automatic calibration on PHY0. |
| 1929 | */ |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 1930 | val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, DPIO_PHY1); |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1931 | grc_code = val << GRC_CODE_FAST_SHIFT | |
| 1932 | val << GRC_CODE_SLOW_SHIFT | |
| 1933 | val; |
| 1934 | I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code); |
| 1935 | |
| 1936 | val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0)); |
| 1937 | val |= GRC_DIS | GRC_RDY_OVRD; |
| 1938 | I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val); |
| 1939 | } |
| 1940 | |
| 1941 | val = I915_READ(BXT_PHY_CTL_FAMILY(phy)); |
| 1942 | val |= COMMON_RESET_DIS; |
| 1943 | I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val); |
Imre Deak | e4c49e0 | 2016-06-13 16:44:32 +0300 | [diff] [blame] | 1944 | |
| 1945 | if (phy == DPIO_PHY1) |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 1946 | bxt_phy_wait_grc_done(dev_priv, DPIO_PHY1); |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1947 | } |
| 1948 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1949 | void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy) |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1950 | { |
| 1951 | uint32_t val; |
| 1952 | |
| 1953 | val = I915_READ(BXT_PHY_CTL_FAMILY(phy)); |
| 1954 | val &= ~COMMON_RESET_DIS; |
| 1955 | I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val); |
Imre Deak | d7d33fd | 2016-04-01 16:02:41 +0300 | [diff] [blame] | 1956 | |
| 1957 | val = I915_READ(BXT_P_CR_GT_DISP_PWRON); |
| 1958 | val &= ~GT_DISPLAY_POWER_ON(phy); |
| 1959 | I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val); |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 1960 | } |
| 1961 | |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 1962 | static bool __printf(6, 7) |
| 1963 | __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy, |
| 1964 | i915_reg_t reg, u32 mask, u32 expected, |
| 1965 | const char *reg_fmt, ...) |
| 1966 | { |
| 1967 | struct va_format vaf; |
| 1968 | va_list args; |
| 1969 | u32 val; |
| 1970 | |
| 1971 | val = I915_READ(reg); |
| 1972 | if ((val & mask) == expected) |
| 1973 | return true; |
| 1974 | |
| 1975 | va_start(args, reg_fmt); |
| 1976 | vaf.fmt = reg_fmt; |
| 1977 | vaf.va = &args; |
| 1978 | |
| 1979 | DRM_DEBUG_DRIVER("DDI PHY %d reg %pV [%08x] state mismatch: " |
| 1980 | "current %08x, expected %08x (mask %08x)\n", |
| 1981 | phy, &vaf, reg.reg, val, (val & ~mask) | expected, |
| 1982 | mask); |
| 1983 | |
| 1984 | va_end(args); |
| 1985 | |
| 1986 | return false; |
| 1987 | } |
| 1988 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1989 | bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv, |
| 1990 | enum dpio_phy phy) |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 1991 | { |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 1992 | uint32_t mask; |
| 1993 | bool ok; |
| 1994 | |
| 1995 | #define _CHK(reg, mask, exp, fmt, ...) \ |
| 1996 | __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \ |
| 1997 | ## __VA_ARGS__) |
| 1998 | |
Imre Deak | 9c8d0b8 | 2016-06-13 16:44:34 +0300 | [diff] [blame] | 1999 | if (!bxt_ddi_phy_is_enabled(dev_priv, phy)) |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 2000 | return false; |
| 2001 | |
| 2002 | ok = true; |
| 2003 | |
Imre Deak | adc7f04 | 2016-04-04 17:27:10 +0300 | [diff] [blame] | 2004 | /* PLL Rcomp code offset */ |
| 2005 | ok &= _CHK(BXT_PORT_CL1CM_DW9(phy), |
| 2006 | IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT, |
| 2007 | "BXT_PORT_CL1CM_DW9(%d)", phy); |
| 2008 | ok &= _CHK(BXT_PORT_CL1CM_DW10(phy), |
| 2009 | IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT, |
| 2010 | "BXT_PORT_CL1CM_DW10(%d)", phy); |
| 2011 | |
| 2012 | /* Power gating */ |
| 2013 | mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG; |
| 2014 | ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask, |
| 2015 | "BXT_PORT_CL1CM_DW28(%d)", phy); |
| 2016 | |
| 2017 | if (phy == DPIO_PHY0) |
| 2018 | ok &= _CHK(BXT_PORT_CL2CM_DW6_BC, |
| 2019 | DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN, |
| 2020 | "BXT_PORT_CL2CM_DW6_BC"); |
| 2021 | |
| 2022 | /* |
| 2023 | * TODO: Verify BXT_PORT_CL1CM_DW30 bit OCL2_LDOFUSE_PWR_DIS, |
| 2024 | * at least on stepping A this bit is read-only and fixed at 0. |
| 2025 | */ |
| 2026 | |
| 2027 | if (phy == DPIO_PHY0) { |
| 2028 | u32 grc_code = dev_priv->bxt_phy_grc; |
| 2029 | |
| 2030 | grc_code = grc_code << GRC_CODE_FAST_SHIFT | |
| 2031 | grc_code << GRC_CODE_SLOW_SHIFT | |
| 2032 | grc_code; |
| 2033 | mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK | |
| 2034 | GRC_CODE_NOM_MASK; |
| 2035 | ok &= _CHK(BXT_PORT_REF_DW6(DPIO_PHY0), mask, grc_code, |
| 2036 | "BXT_PORT_REF_DW6(%d)", DPIO_PHY0); |
| 2037 | |
| 2038 | mask = GRC_DIS | GRC_RDY_OVRD; |
| 2039 | ok &= _CHK(BXT_PORT_REF_DW8(DPIO_PHY0), mask, mask, |
| 2040 | "BXT_PORT_REF_DW8(%d)", DPIO_PHY0); |
| 2041 | } |
| 2042 | |
| 2043 | return ok; |
| 2044 | #undef _CHK |
| 2045 | } |
| 2046 | |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 2047 | static uint8_t |
| 2048 | bxt_ddi_phy_calc_lane_lat_optim_mask(struct intel_encoder *encoder, |
| 2049 | struct intel_crtc_state *pipe_config) |
| 2050 | { |
| 2051 | switch (pipe_config->lane_count) { |
| 2052 | case 1: |
| 2053 | return 0; |
| 2054 | case 2: |
| 2055 | return BIT(2) | BIT(0); |
| 2056 | case 4: |
| 2057 | return BIT(3) | BIT(2) | BIT(0); |
| 2058 | default: |
| 2059 | MISSING_CASE(pipe_config->lane_count); |
| 2060 | |
| 2061 | return 0; |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder) |
| 2066 | { |
| 2067 | struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); |
| 2068 | struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev); |
| 2069 | enum port port = dport->port; |
| 2070 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 2071 | int lane; |
| 2072 | |
| 2073 | for (lane = 0; lane < 4; lane++) { |
| 2074 | u32 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane)); |
| 2075 | |
| 2076 | /* |
| 2077 | * Note that on CHV this flag is called UPAR, but has |
| 2078 | * the same function. |
| 2079 | */ |
| 2080 | val &= ~LATENCY_OPTIM; |
| 2081 | if (intel_crtc->config->lane_lat_optim_mask & BIT(lane)) |
| 2082 | val |= LATENCY_OPTIM; |
| 2083 | |
| 2084 | I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val); |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | static uint8_t |
| 2089 | bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder) |
| 2090 | { |
| 2091 | struct intel_digital_port *dport = enc_to_dig_port(&encoder->base); |
| 2092 | struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev); |
| 2093 | enum port port = dport->port; |
| 2094 | int lane; |
| 2095 | uint8_t mask; |
| 2096 | |
| 2097 | mask = 0; |
| 2098 | for (lane = 0; lane < 4; lane++) { |
| 2099 | u32 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane)); |
| 2100 | |
| 2101 | if (val & LATENCY_OPTIM) |
| 2102 | mask |= BIT(lane); |
| 2103 | } |
| 2104 | |
| 2105 | return mask; |
| 2106 | } |
| 2107 | |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 2108 | void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2109 | { |
Ander Conselvan de Oliveira | ad64217 | 2015-10-23 13:01:49 +0300 | [diff] [blame] | 2110 | struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); |
| 2111 | struct drm_i915_private *dev_priv = |
| 2112 | to_i915(intel_dig_port->base.base.dev); |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 2113 | enum port port = intel_dig_port->port; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2114 | uint32_t val; |
Syam Sidhardhan | f3e227d | 2013-02-25 04:05:38 +0530 | [diff] [blame] | 2115 | bool wait = false; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2116 | |
| 2117 | if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) { |
| 2118 | val = I915_READ(DDI_BUF_CTL(port)); |
| 2119 | if (val & DDI_BUF_CTL_ENABLE) { |
| 2120 | val &= ~DDI_BUF_CTL_ENABLE; |
| 2121 | I915_WRITE(DDI_BUF_CTL(port), val); |
| 2122 | wait = true; |
| 2123 | } |
| 2124 | |
| 2125 | val = I915_READ(DP_TP_CTL(port)); |
| 2126 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 2127 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2128 | I915_WRITE(DP_TP_CTL(port), val); |
| 2129 | POSTING_READ(DP_TP_CTL(port)); |
| 2130 | |
| 2131 | if (wait) |
| 2132 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 2133 | } |
| 2134 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2135 | val = DP_TP_CTL_ENABLE | |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2136 | DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE; |
Ville Syrjälä | 64ee2fd | 2016-07-28 17:50:39 +0300 | [diff] [blame] | 2137 | if (intel_dp->link_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2138 | val |= DP_TP_CTL_MODE_MST; |
| 2139 | else { |
| 2140 | val |= DP_TP_CTL_MODE_SST; |
| 2141 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 2142 | val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE; |
| 2143 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2144 | I915_WRITE(DP_TP_CTL(port), val); |
| 2145 | POSTING_READ(DP_TP_CTL(port)); |
| 2146 | |
| 2147 | intel_dp->DP |= DDI_BUF_CTL_ENABLE; |
| 2148 | I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP); |
| 2149 | POSTING_READ(DDI_BUF_CTL(port)); |
| 2150 | |
| 2151 | udelay(600); |
| 2152 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2153 | |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2154 | void intel_ddi_fdi_disable(struct drm_crtc *crtc) |
| 2155 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2156 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2157 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 2158 | uint32_t val; |
| 2159 | |
Ville Syrjälä | 5b421c5 | 2016-03-01 16:16:23 +0200 | [diff] [blame] | 2160 | /* |
| 2161 | * Bspec lists this as both step 13 (before DDI_BUF_CTL disable) |
| 2162 | * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN, |
| 2163 | * step 13 is the correct place for it. Step 18 is where it was |
| 2164 | * originally before the BUN. |
| 2165 | */ |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2166 | val = I915_READ(FDI_RX_CTL(PIPE_A)); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2167 | val &= ~FDI_RX_ENABLE; |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2168 | I915_WRITE(FDI_RX_CTL(PIPE_A), val); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2169 | |
Ville Syrjälä | 5b421c5 | 2016-03-01 16:16:23 +0200 | [diff] [blame] | 2170 | intel_ddi_post_disable(intel_encoder); |
| 2171 | |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2172 | val = I915_READ(FDI_RX_MISC(PIPE_A)); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2173 | val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 2174 | val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2175 | I915_WRITE(FDI_RX_MISC(PIPE_A), val); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2176 | |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2177 | val = I915_READ(FDI_RX_CTL(PIPE_A)); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2178 | val &= ~FDI_PCDCLK; |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2179 | I915_WRITE(FDI_RX_CTL(PIPE_A), val); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2180 | |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2181 | val = I915_READ(FDI_RX_CTL(PIPE_A)); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2182 | val &= ~FDI_RX_PLL_ENABLE; |
Ville Syrjälä | eede3b5 | 2015-09-18 20:03:30 +0300 | [diff] [blame] | 2183 | I915_WRITE(FDI_RX_CTL(PIPE_A), val); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2184 | } |
| 2185 | |
Ville Syrjälä | 6801c18 | 2013-09-24 14:24:05 +0300 | [diff] [blame] | 2186 | void intel_ddi_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2187 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2188 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2189 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2190 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Ander Conselvan de Oliveira | 0cb09a9 | 2015-01-30 12:17:23 +0200 | [diff] [blame] | 2191 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Daniel Vetter | bbd440f | 2014-11-20 22:33:59 +0100 | [diff] [blame] | 2192 | struct intel_hdmi *intel_hdmi; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2193 | u32 temp, flags = 0; |
| 2194 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 2195 | /* XXX: DSI transcoder paranoia */ |
| 2196 | if (WARN_ON(transcoder_is_dsi(cpu_transcoder))) |
| 2197 | return; |
| 2198 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2199 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 2200 | if (temp & TRANS_DDI_PHSYNC) |
| 2201 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2202 | else |
| 2203 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2204 | if (temp & TRANS_DDI_PVSYNC) |
| 2205 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2206 | else |
| 2207 | flags |= DRM_MODE_FLAG_NVSYNC; |
| 2208 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2209 | pipe_config->base.adjusted_mode.flags |= flags; |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 2210 | |
| 2211 | switch (temp & TRANS_DDI_BPC_MASK) { |
| 2212 | case TRANS_DDI_BPC_6: |
| 2213 | pipe_config->pipe_bpp = 18; |
| 2214 | break; |
| 2215 | case TRANS_DDI_BPC_8: |
| 2216 | pipe_config->pipe_bpp = 24; |
| 2217 | break; |
| 2218 | case TRANS_DDI_BPC_10: |
| 2219 | pipe_config->pipe_bpp = 30; |
| 2220 | break; |
| 2221 | case TRANS_DDI_BPC_12: |
| 2222 | pipe_config->pipe_bpp = 36; |
| 2223 | break; |
| 2224 | default: |
| 2225 | break; |
| 2226 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2227 | |
| 2228 | switch (temp & TRANS_DDI_MODE_SELECT_MASK) { |
| 2229 | case TRANS_DDI_MODE_SELECT_HDMI: |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 2230 | pipe_config->has_hdmi_sink = true; |
Daniel Vetter | bbd440f | 2014-11-20 22:33:59 +0100 | [diff] [blame] | 2231 | intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
| 2232 | |
Ville Syrjälä | cda0aaa | 2015-11-26 18:27:07 +0200 | [diff] [blame] | 2233 | if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config)) |
Daniel Vetter | bbd440f | 2014-11-20 22:33:59 +0100 | [diff] [blame] | 2234 | pipe_config->has_infoframe = true; |
Ander Conselvan de Oliveira | d4d6279 | 2016-04-27 15:44:16 +0300 | [diff] [blame] | 2235 | /* fall through */ |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2236 | case TRANS_DDI_MODE_SELECT_DVI: |
Ander Conselvan de Oliveira | d4d6279 | 2016-04-27 15:44:16 +0300 | [diff] [blame] | 2237 | pipe_config->lane_count = 4; |
| 2238 | break; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2239 | case TRANS_DDI_MODE_SELECT_FDI: |
| 2240 | break; |
| 2241 | case TRANS_DDI_MODE_SELECT_DP_SST: |
| 2242 | case TRANS_DDI_MODE_SELECT_DP_MST: |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 2243 | pipe_config->lane_count = |
| 2244 | ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2245 | intel_dp_get_m_n(intel_crtc, pipe_config); |
| 2246 | break; |
| 2247 | default: |
| 2248 | break; |
| 2249 | } |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 2250 | |
Lyude | 5a8f97e | 2016-05-03 11:01:32 -0400 | [diff] [blame] | 2251 | if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) { |
| 2252 | temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
| 2253 | if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe)) |
| 2254 | pipe_config->has_audio = true; |
| 2255 | } |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2256 | |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2257 | if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp && |
| 2258 | pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 2259 | /* |
| 2260 | * This is a big fat ugly hack. |
| 2261 | * |
| 2262 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2263 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2264 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2265 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2266 | * max, not what it tells us to use. |
| 2267 | * |
| 2268 | * Note: This will still be broken if the eDP panel is not lit |
| 2269 | * up by the BIOS, and thus we can't get the mode at module |
| 2270 | * load. |
| 2271 | */ |
| 2272 | DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", |
Jani Nikula | 6aa23e6 | 2016-03-24 17:50:20 +0200 | [diff] [blame] | 2273 | pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); |
| 2274 | dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 2275 | } |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 2276 | |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 2277 | intel_ddi_clock_get(encoder, pipe_config); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 2278 | |
| 2279 | if (IS_BROXTON(dev_priv)) |
| 2280 | pipe_config->lane_lat_optim_mask = |
| 2281 | bxt_ddi_phy_get_lane_lat_optim_mask(encoder); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2284 | static bool intel_ddi_compute_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2285 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2286 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2287 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2288 | int type = encoder->type; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 2289 | int port = intel_ddi_get_encoder_port(encoder); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 2290 | int ret; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2291 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2292 | WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n"); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2293 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 2294 | if (port == PORT_A) |
| 2295 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 2296 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2297 | if (type == INTEL_OUTPUT_HDMI) |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 2298 | ret = intel_hdmi_compute_config(encoder, pipe_config); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2299 | else |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 2300 | ret = intel_dp_compute_config(encoder, pipe_config); |
| 2301 | |
| 2302 | if (IS_BROXTON(dev_priv) && ret) |
| 2303 | pipe_config->lane_lat_optim_mask = |
| 2304 | bxt_ddi_phy_calc_lane_lat_optim_mask(encoder, |
| 2305 | pipe_config); |
| 2306 | |
| 2307 | return ret; |
| 2308 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | static const struct drm_encoder_funcs intel_ddi_funcs = { |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 2312 | .reset = intel_dp_encoder_reset, |
| 2313 | .destroy = intel_dp_encoder_destroy, |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2314 | }; |
| 2315 | |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 2316 | static struct intel_connector * |
| 2317 | intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port) |
| 2318 | { |
| 2319 | struct intel_connector *connector; |
| 2320 | enum port port = intel_dig_port->port; |
| 2321 | |
Ander Conselvan de Oliveira | 9bdbd0b | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 2322 | connector = intel_connector_alloc(); |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 2323 | if (!connector) |
| 2324 | return NULL; |
| 2325 | |
| 2326 | intel_dig_port->dp.output_reg = DDI_BUF_CTL(port); |
| 2327 | if (!intel_dp_init_connector(intel_dig_port, connector)) { |
| 2328 | kfree(connector); |
| 2329 | return NULL; |
| 2330 | } |
| 2331 | |
| 2332 | return connector; |
| 2333 | } |
| 2334 | |
| 2335 | static struct intel_connector * |
| 2336 | intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port) |
| 2337 | { |
| 2338 | struct intel_connector *connector; |
| 2339 | enum port port = intel_dig_port->port; |
| 2340 | |
Ander Conselvan de Oliveira | 9bdbd0b | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 2341 | connector = intel_connector_alloc(); |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 2342 | if (!connector) |
| 2343 | return NULL; |
| 2344 | |
| 2345 | intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port); |
| 2346 | intel_hdmi_init_connector(intel_dig_port, connector); |
| 2347 | |
| 2348 | return connector; |
| 2349 | } |
| 2350 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2351 | void intel_ddi_init(struct drm_device *dev, enum port port) |
| 2352 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2353 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2354 | struct intel_digital_port *intel_dig_port; |
| 2355 | struct intel_encoder *intel_encoder; |
| 2356 | struct drm_encoder *encoder; |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2357 | bool init_hdmi, init_dp; |
Ville Syrjälä | 10e7bec | 2015-12-08 19:59:37 +0200 | [diff] [blame] | 2358 | int max_lanes; |
| 2359 | |
| 2360 | if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) { |
| 2361 | switch (port) { |
| 2362 | case PORT_A: |
| 2363 | max_lanes = 4; |
| 2364 | break; |
| 2365 | case PORT_E: |
| 2366 | max_lanes = 0; |
| 2367 | break; |
| 2368 | default: |
| 2369 | max_lanes = 4; |
| 2370 | break; |
| 2371 | } |
| 2372 | } else { |
| 2373 | switch (port) { |
| 2374 | case PORT_A: |
| 2375 | max_lanes = 2; |
| 2376 | break; |
| 2377 | case PORT_E: |
| 2378 | max_lanes = 2; |
| 2379 | break; |
| 2380 | default: |
| 2381 | max_lanes = 4; |
| 2382 | break; |
| 2383 | } |
| 2384 | } |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2385 | |
| 2386 | init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi || |
| 2387 | dev_priv->vbt.ddi_port_info[port].supports_hdmi); |
| 2388 | init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp; |
| 2389 | if (!init_dp && !init_hdmi) { |
Rodrigo Vivi | 500ea70 | 2015-08-07 17:01:16 -0700 | [diff] [blame] | 2390 | DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n", |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2391 | port_name(port)); |
Rodrigo Vivi | 500ea70 | 2015-08-07 17:01:16 -0700 | [diff] [blame] | 2392 | return; |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2393 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2394 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 2395 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2396 | if (!intel_dig_port) |
| 2397 | return; |
| 2398 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2399 | intel_encoder = &intel_dig_port->base; |
| 2400 | encoder = &intel_encoder->base; |
| 2401 | |
| 2402 | drm_encoder_init(dev, encoder, &intel_ddi_funcs, |
Ville Syrjälä | 580d8ed | 2016-05-27 20:59:24 +0300 | [diff] [blame] | 2403 | DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port)); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2404 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2405 | intel_encoder->compute_config = intel_ddi_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2406 | intel_encoder->enable = intel_enable_ddi; |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 2407 | if (IS_BROXTON(dev_priv)) |
| 2408 | intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2409 | intel_encoder->pre_enable = intel_ddi_pre_enable; |
| 2410 | intel_encoder->disable = intel_disable_ddi; |
| 2411 | intel_encoder->post_disable = intel_ddi_post_disable; |
| 2412 | intel_encoder->get_hw_state = intel_ddi_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2413 | intel_encoder->get_config = intel_ddi_get_config; |
Imre Deak | bf93ba6 | 2016-04-18 10:04:21 +0300 | [diff] [blame] | 2414 | intel_encoder->suspend = intel_dp_encoder_suspend; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2415 | |
| 2416 | intel_dig_port->port = port; |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 2417 | intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) & |
| 2418 | (DDI_BUF_PORT_REVERSAL | |
| 2419 | DDI_A_4_LANES); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2420 | |
Matt Roper | 6c566dc | 2015-11-05 14:53:32 -0800 | [diff] [blame] | 2421 | /* |
| 2422 | * Bspec says that DDI_A_4_LANES is the only supported configuration |
| 2423 | * for Broxton. Yet some BIOS fail to set this bit on port A if eDP |
| 2424 | * wasn't lit up at boot. Force this bit on in our internal |
| 2425 | * configuration so that we use the proper lane count for our |
| 2426 | * calculations. |
| 2427 | */ |
| 2428 | if (IS_BROXTON(dev) && port == PORT_A) { |
| 2429 | if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) { |
| 2430 | DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n"); |
| 2431 | intel_dig_port->saved_port_bits |= DDI_A_4_LANES; |
Matt Roper | ed8d60f | 2016-01-28 15:09:37 -0800 | [diff] [blame] | 2432 | max_lanes = 4; |
Matt Roper | 6c566dc | 2015-11-05 14:53:32 -0800 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | |
Matt Roper | ed8d60f | 2016-01-28 15:09:37 -0800 | [diff] [blame] | 2436 | intel_dig_port->max_lanes = max_lanes; |
| 2437 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2438 | intel_encoder->type = INTEL_OUTPUT_UNKNOWN; |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2439 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 2440 | intel_encoder->cloneable = 0; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2441 | |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2442 | if (init_dp) { |
| 2443 | if (!intel_ddi_init_dp_connector(intel_dig_port)) |
| 2444 | goto err; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 2445 | |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2446 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
Sonika Jindal | cf1d588 | 2015-08-10 10:35:36 +0530 | [diff] [blame] | 2447 | /* |
| 2448 | * On BXT A0/A1, sw needs to activate DDIA HPD logic and |
| 2449 | * interrupts to check the external panel connection. |
| 2450 | */ |
Jani Nikula | e87a005 | 2015-10-20 15:22:02 +0300 | [diff] [blame] | 2451 | if (IS_BXT_REVID(dev, 0, BXT_REVID_A1) && port == PORT_B) |
Sonika Jindal | cf1d588 | 2015-08-10 10:35:36 +0530 | [diff] [blame] | 2452 | dev_priv->hotplug.irq_port[PORT_A] = intel_dig_port; |
| 2453 | else |
| 2454 | dev_priv->hotplug.irq_port[port] = intel_dig_port; |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2455 | } |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 2456 | |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2457 | /* In theory we don't need the encoder->type check, but leave it just in |
| 2458 | * case we have some really bad VBTs... */ |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2459 | if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) { |
| 2460 | if (!intel_ddi_init_hdmi_connector(intel_dig_port)) |
| 2461 | goto err; |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 2462 | } |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2463 | |
| 2464 | return; |
| 2465 | |
| 2466 | err: |
| 2467 | drm_encoder_cleanup(encoder); |
| 2468 | kfree(intel_dig_port); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2469 | } |