| 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 | |
| 22 | PCH_ADPA_CRT_HPD_CHANNEL_MASK : constant := 3 * 2 ** 24; |
| 23 | PCH_ADPA_CRT_HPD_ENABLE : constant := 1 * 2 ** 23; |
| 24 | |
| 25 | SFUSE_STRAP_CRT_DAC_CAP_DISABLE : constant := 1 * 2 ** 6; |
| 26 | |
| 27 | HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE : constant := 1 * 2 ** 4; |
| 28 | HOTPLUG_CTL_DDI_A_HPD_STATUS : constant := 3 * 2 ** 0; |
| 29 | HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT : constant := 1 * 2 ** 1; |
| 30 | |
| 31 | SHOTPLUG_CTL_DETECT_MASK : constant := 16#0303_0303#; |
| 32 | |
| 33 | type Digital_Port_Value is array (Digital_Port) of Word32; |
| 34 | DDI_PORT_DETECTED : constant Digital_Port_Value := |
| 35 | (DIGI_B => 1 * 2 ** 2, |
| 36 | DIGI_C => 1 * 2 ** 1, |
| 37 | DIGI_D => 1 * 2 ** 0, |
| 38 | DIGI_A => 1 * 2 ** 0, |
| 39 | others => 0); |
| 40 | SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant Digital_Port_Value := |
| 41 | (DIGI_B => 1 * 2 ** 4, |
| 42 | DIGI_C => 1 * 2 ** 12, |
| 43 | DIGI_D => 1 * 2 ** 20, |
| 44 | DIGI_A => 1 * 2 ** 28, |
| 45 | others => 0); |
| 46 | SHOTPLUG_CTL_HPD_STATUS : constant Digital_Port_Value := |
| 47 | (DIGI_B => 3 * 2 ** 0, |
| 48 | DIGI_C => 3 * 2 ** 8, |
| 49 | DIGI_D => 3 * 2 ** 16, |
| 50 | DIGI_A => 3 * 2 ** 24, |
| 51 | others => 0); |
| 52 | SHOTPLUG_CTL_LONG_DETECT : constant Digital_Port_Value := |
| 53 | (DIGI_B => 1 * 2 ** 1, |
| 54 | DIGI_C => 1 * 2 ** 9, |
| 55 | DIGI_D => 1 * 2 ** 17, |
| 56 | DIGI_A => 1 * 2 ** 25, |
| 57 | others => 0); |
| 58 | |
| 59 | procedure Initialize |
| 60 | is |
| 61 | DAC_Disabled, |
| 62 | Internal_Detected, |
| 63 | DDI_Detected : Boolean; |
| 64 | |
| 65 | Last_Digital_Port : constant Digital_Port := |
| 66 | (if Config.Has_DDI_D then DIGI_D else DIGI_C); |
| 67 | |
| 68 | subtype Ext_Digital_Port is |
| 69 | Digital_Port range DIGI_B .. DIGI_D; |
| 70 | type Digital_Port_To_GMA_Port is array (Ext_Digital_Port) of Port_Type; |
| 71 | To_HDMI_Port : constant Digital_Port_To_GMA_Port := |
| Nico Huber | 0d454cd | 2016-11-21 13:33:43 +0100 | [diff] [blame] | 72 | (DIGI_B => HDMI1, |
| 73 | DIGI_C => HDMI2, |
| 74 | DIGI_D => HDMI3); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 75 | To_DP_Port : constant Digital_Port_To_GMA_Port := |
| 76 | (DIGI_B => DP1, |
| 77 | DIGI_C => DP2, |
| 78 | DIGI_D => DP3); |
| 79 | begin |
| 80 | if Config.Has_PCH_DAC then |
| 81 | -- PCH_DAC (_A) |
| 82 | Registers.Is_Set_Mask |
| 83 | (Register => Registers.SFUSE_STRAP, |
| 84 | Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE, |
| 85 | Result => DAC_Disabled); |
| 86 | if not DAC_Disabled then |
| 87 | Registers.Set_Mask |
| 88 | (Register => Registers.PCH_ADPA, |
| 89 | Mask => PCH_ADPA_CRT_HPD_CHANNEL_MASK or -- clear status |
| 90 | PCH_ADPA_CRT_HPD_ENABLE); |
| 91 | end if; |
| 92 | Config.Valid_Port (Analog) := not DAC_Disabled; |
| 93 | end if; |
| 94 | |
| 95 | if Config.Internal_Is_EDP then |
| 96 | -- DDI_A |
| 97 | Registers.Is_Set_Mask |
| 98 | (Register => Registers.DDI_BUF_CTL_A, |
| 99 | Mask => DDI_PORT_DETECTED (DIGI_A), |
| 100 | Result => Internal_Detected); |
| 101 | if Internal_Detected then |
| 102 | if Config.Has_HOTPLUG_CTL then |
| 103 | Registers.Set_Mask |
| 104 | (Register => Registers.HOTPLUG_CTL, |
| 105 | Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or |
| 106 | HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status |
| 107 | if Config.Has_SHOTPLUG_CTL_A then |
| 108 | -- Have to enable south hotplug too on SoCs. |
| 109 | Registers.Unset_And_Set_Mask |
| 110 | (Register => Registers.SHOTPLUG_CTL, |
| 111 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| 112 | Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A)); |
| 113 | end if; |
| 114 | else |
| 115 | Registers.Unset_And_Set_Mask |
| 116 | (Register => Registers.SHOTPLUG_CTL, |
| 117 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| 118 | Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A) or |
| 119 | SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear |
| 120 | end if; |
| 121 | end if; |
| 122 | else |
| 123 | Internal_Detected := False; |
| 124 | end if; |
| 125 | Config.Valid_Port (Internal) := Internal_Detected; |
| 126 | |
| 127 | -- DDI_[BCD] |
| 128 | for Port in Ext_Digital_Port range DIGI_B .. Last_Digital_Port loop |
| 129 | Registers.Is_Set_Mask |
| 130 | (Register => Registers.SFUSE_STRAP, |
| 131 | Mask => DDI_PORT_DETECTED (Port), |
| 132 | Result => DDI_Detected); |
| 133 | Config.Valid_Port (To_HDMI_Port (Port)) := |
| 134 | Config.Valid_Port (To_HDMI_Port (Port)) and DDI_Detected; |
| 135 | Config.Valid_Port (To_DP_Port (Port)) := |
| 136 | Config.Valid_Port (To_DP_Port (Port)) and DDI_Detected; |
| 137 | |
| 138 | if DDI_Detected then |
| 139 | Registers.Unset_And_Set_Mask |
| 140 | (Register => Registers.SHOTPLUG_CTL, |
| 141 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| 142 | Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or |
| 143 | SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status |
| 144 | else |
| 145 | Registers.Unset_Mask |
| 146 | (Register => Registers.SHOTPLUG_CTL, |
| 147 | Mask => SHOTPLUG_CTL_DETECT_MASK or |
| 148 | SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port)); |
| 149 | end if; |
| 150 | end loop; |
| 151 | end Initialize; |
| 152 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 153 | procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 154 | is |
| 155 | Ctl32 : Word32; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 156 | GPU_Port : constant GMA.GPU_Port := |
| 157 | Config_Helpers.To_GPU_Port (Primary, Port); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 158 | begin |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 159 | if Port = Analog then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 160 | Registers.Read (Registers.PCH_ADPA, Ctl32, Verbose => False); |
| 161 | Ctl32 := Ctl32 and PCH_ADPA_CRT_HPD_CHANNEL_MASK; |
| 162 | Detected := Ctl32 = PCH_ADPA_CRT_HPD_CHANNEL_MASK; |
| 163 | if Ctl32 /= 0 then |
| 164 | Registers.Set_Mask |
| 165 | (Register => Registers.PCH_ADPA, |
| 166 | Mask => PCH_ADPA_CRT_HPD_CHANNEL_MASK); |
| 167 | end if; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 168 | elsif Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 169 | Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False); |
| 170 | Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0; |
| 171 | |
| 172 | if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then |
| 173 | Registers.Set_Mask |
| 174 | (Register => Registers.HOTPLUG_CTL, |
| 175 | Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS); |
| 176 | end if; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 177 | elsif GPU_Port in DIGI_A .. DIGI_D then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 178 | Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False); |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 179 | Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 180 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 181 | if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 182 | Registers.Unset_And_Set_Mask |
| 183 | (Register => Registers.SHOTPLUG_CTL, |
| 184 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 185 | Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 186 | end if; |
| 187 | else |
| 188 | Detected := False; |
| 189 | end if; |
| 190 | end Hotplug_Detect; |
| 191 | |
| 192 | end HW.GFX.GMA.Port_Detect; |