| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 2 | -- Copyright (C) 2016-2017 secunet Security Networks AG |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 3 | -- |
| 4 | -- This program is free software; you can redistribute it and/or modify |
| 5 | -- it under the terms of the GNU General Public License as published by |
| Nico Huber | 125a29e | 2016-10-18 00:23:54 +0200 | [diff] [blame] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 8 | -- |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | -- |
| 14 | |
| 15 | with HW.GFX.GMA.Config; |
| 16 | with HW.GFX.GMA.Registers; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 17 | with HW.GFX.GMA.Config_Helpers; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 18 | |
| 19 | package body HW.GFX.GMA.Port_Detect |
| 20 | is |
| 21 | |
| Nico Huber | 907e415 | 2017-07-29 21:18:59 +0200 | [diff] [blame] | 22 | DDI_BUF_CTL_A_LANE_CAPABILITY_X4 : constant := 1 * 2 ** 4; |
| 23 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 24 | SFUSE_STRAP_CRT_DAC_CAP_DISABLE : constant := 1 * 2 ** 6; |
| 25 | |
| 26 | HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE : constant := 1 * 2 ** 4; |
| 27 | HOTPLUG_CTL_DDI_A_HPD_STATUS : constant := 3 * 2 ** 0; |
| 28 | HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT : constant := 1 * 2 ** 1; |
| 29 | |
| 30 | SHOTPLUG_CTL_DETECT_MASK : constant := 16#0303_0303#; |
| 31 | |
| 32 | type Digital_Port_Value is array (Digital_Port) of Word32; |
| 33 | DDI_PORT_DETECTED : constant Digital_Port_Value := |
| 34 | (DIGI_B => 1 * 2 ** 2, |
| 35 | DIGI_C => 1 * 2 ** 1, |
| 36 | DIGI_D => 1 * 2 ** 0, |
| 37 | DIGI_A => 1 * 2 ** 0, |
| 38 | others => 0); |
| 39 | SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant Digital_Port_Value := |
| 40 | (DIGI_B => 1 * 2 ** 4, |
| 41 | DIGI_C => 1 * 2 ** 12, |
| 42 | DIGI_D => 1 * 2 ** 20, |
| 43 | DIGI_A => 1 * 2 ** 28, |
| 44 | others => 0); |
| 45 | SHOTPLUG_CTL_HPD_STATUS : constant Digital_Port_Value := |
| 46 | (DIGI_B => 3 * 2 ** 0, |
| 47 | DIGI_C => 3 * 2 ** 8, |
| 48 | DIGI_D => 3 * 2 ** 16, |
| 49 | DIGI_A => 3 * 2 ** 24, |
| 50 | others => 0); |
| 51 | SHOTPLUG_CTL_LONG_DETECT : constant Digital_Port_Value := |
| 52 | (DIGI_B => 1 * 2 ** 1, |
| 53 | DIGI_C => 1 * 2 ** 9, |
| 54 | DIGI_D => 1 * 2 ** 17, |
| 55 | DIGI_A => 1 * 2 ** 25, |
| 56 | others => 0); |
| 57 | |
| 58 | procedure Initialize |
| 59 | is |
| Nico Huber | 907e415 | 2017-07-29 21:18:59 +0200 | [diff] [blame] | 60 | DDI_A_X4, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 61 | DAC_Disabled, |
| 62 | Internal_Detected, |
| 63 | DDI_Detected : Boolean; |
| 64 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 65 | subtype Ext_Digital_Port is |
| 66 | Digital_Port range DIGI_B .. DIGI_D; |
| 67 | type Digital_Port_To_GMA_Port is array (Ext_Digital_Port) of Port_Type; |
| 68 | To_HDMI_Port : constant Digital_Port_To_GMA_Port := |
| Nico Huber | 0d454cd | 2016-11-21 13:33:43 +0100 | [diff] [blame] | 69 | (DIGI_B => HDMI1, |
| 70 | DIGI_C => HDMI2, |
| 71 | DIGI_D => HDMI3); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 72 | To_DP_Port : constant Digital_Port_To_GMA_Port := |
| 73 | (DIGI_B => DP1, |
| 74 | DIGI_C => DP2, |
| 75 | DIGI_D => DP3); |
| 76 | begin |
| Nico Huber | 907e415 | 2017-07-29 21:18:59 +0200 | [diff] [blame] | 77 | if Config.Has_DDI_E and Config.Has_PCH_DAC then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 78 | -- PCH_DAC (_A) |
| 79 | Registers.Is_Set_Mask |
| Nico Huber | 907e415 | 2017-07-29 21:18:59 +0200 | [diff] [blame] | 80 | (Register => Registers.DDI_BUF_CTL_A, |
| 81 | Mask => DDI_BUF_CTL_A_LANE_CAPABILITY_X4, |
| 82 | Result => DDI_A_X4); |
| 83 | Registers.Is_Set_Mask |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 84 | (Register => Registers.SFUSE_STRAP, |
| 85 | Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE, |
| 86 | Result => DAC_Disabled); |
| Nico Huber | 907e415 | 2017-07-29 21:18:59 +0200 | [diff] [blame] | 87 | Config.Valid_Port (Analog) := not (DDI_A_X4 or DAC_Disabled); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 88 | end if; |
| 89 | |
| 90 | if Config.Internal_Is_EDP then |
| 91 | -- DDI_A |
| Nico Huber | 1c3b928 | 2017-02-09 13:57:04 +0100 | [diff] [blame] | 92 | if Config.Has_Presence_Straps then |
| 93 | Registers.Is_Set_Mask |
| 94 | (Register => Registers.DDI_BUF_CTL_A, |
| 95 | Mask => DDI_PORT_DETECTED (DIGI_A), |
| 96 | Result => Internal_Detected); |
| 97 | else |
| 98 | Internal_Detected := True; -- XXX: Linux' i915 contains a fixme. |
| 99 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 100 | if Internal_Detected then |
| 101 | if Config.Has_HOTPLUG_CTL then |
| 102 | Registers.Set_Mask |
| 103 | (Register => Registers.HOTPLUG_CTL, |
| 104 | Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or |
| 105 | HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status |
| 106 | if Config.Has_SHOTPLUG_CTL_A then |
| 107 | -- Have to enable south hotplug too on SoCs. |
| 108 | Registers.Unset_And_Set_Mask |
| 109 | (Register => Registers.SHOTPLUG_CTL, |
| 110 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| 111 | Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A)); |
| 112 | end if; |
| 113 | else |
| 114 | Registers.Unset_And_Set_Mask |
| 115 | (Register => Registers.SHOTPLUG_CTL, |
| 116 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| 117 | Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A) or |
| 118 | SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear |
| 119 | end if; |
| 120 | end if; |
| 121 | else |
| 122 | Internal_Detected := False; |
| 123 | end if; |
| 124 | Config.Valid_Port (Internal) := Internal_Detected; |
| 125 | |
| 126 | -- DDI_[BCD] |
| Nico Huber | 208857d | 2017-07-29 21:30:24 +0200 | [diff] [blame] | 127 | for Port in Ext_Digital_Port range |
| 128 | DIGI_B .. Ext_Digital_Port'Min (DIGI_D, Config.Last_Digital_Port) |
| 129 | loop |
| Nico Huber | 1c3b928 | 2017-02-09 13:57:04 +0100 | [diff] [blame] | 130 | if Config.Has_Presence_Straps then |
| 131 | Registers.Is_Set_Mask |
| 132 | (Register => Registers.SFUSE_STRAP, |
| 133 | Mask => DDI_PORT_DETECTED (Port), |
| 134 | Result => DDI_Detected); |
| 135 | else |
| 136 | DDI_Detected := True; |
| 137 | end if; |
| Nico Huber | 318bca1 | 2018-06-09 19:22:52 +0200 | [diff] [blame] | 138 | Config.Valid_Port (To_HDMI_Port (Port)) := DDI_Detected; |
| 139 | Config.Valid_Port (To_DP_Port (Port)) := DDI_Detected; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 140 | |
| 141 | if DDI_Detected then |
| 142 | Registers.Unset_And_Set_Mask |
| 143 | (Register => Registers.SHOTPLUG_CTL, |
| 144 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| 145 | Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or |
| 146 | SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status |
| 147 | else |
| 148 | Registers.Unset_Mask |
| 149 | (Register => Registers.SHOTPLUG_CTL, |
| 150 | Mask => SHOTPLUG_CTL_DETECT_MASK or |
| 151 | SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port)); |
| 152 | end if; |
| 153 | end loop; |
| 154 | end Initialize; |
| 155 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 156 | procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 157 | is |
| 158 | Ctl32 : Word32; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 159 | GPU_Port : constant GMA.GPU_Port := |
| 160 | Config_Helpers.To_GPU_Port (Primary, Port); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 161 | begin |
| Nico Huber | 8fb0f31 | 2017-01-18 14:35:45 +0100 | [diff] [blame] | 162 | if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 163 | Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False); |
| 164 | Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0; |
| 165 | |
| 166 | if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then |
| 167 | Registers.Set_Mask |
| 168 | (Register => Registers.HOTPLUG_CTL, |
| 169 | Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS); |
| 170 | end if; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 171 | elsif GPU_Port in DIGI_A .. DIGI_D then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 172 | Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False); |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 173 | Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 174 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 175 | if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 176 | Registers.Unset_And_Set_Mask |
| 177 | (Register => Registers.SHOTPLUG_CTL, |
| 178 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 179 | Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 180 | end if; |
| 181 | else |
| 182 | Detected := False; |
| 183 | end if; |
| 184 | end Hotplug_Detect; |
| 185 | |
| Nico Huber | 4798c66 | 2017-01-11 12:44:48 +0100 | [diff] [blame] | 186 | procedure Clear_Hotplug_Detect (Port : Active_Port_Type) |
| 187 | is |
| 188 | Ignored_HPD : Boolean; |
| 189 | begin |
| 190 | pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""", |
| 191 | Reason => "We want to clear pending events only"); |
| 192 | Port_Detect.Hotplug_Detect (Port, Ignored_HPD); |
| 193 | pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD"""); |
| 194 | end Clear_Hotplug_Detect; |
| 195 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 196 | end HW.GFX.GMA.Port_Detect; |