| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2016 secunet Security Networks AG |
| 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 |
| 6 | -- the Free Software Foundation; version 2 of the License. |
| 7 | -- |
| 8 | -- This program is distributed in the hope that it will be useful, |
| 9 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | -- GNU General Public License for more details. |
| 12 | -- |
| 13 | |
| 14 | with HW.GFX.GMA.Config; |
| 15 | with HW.GFX.GMA.Registers; |
| 16 | |
| 17 | package body HW.GFX.GMA.Port_Detect |
| 18 | is |
| 19 | |
| 20 | PCH_ADPA_CRT_HPD_CHANNEL_MASK : constant := 3 * 2 ** 24; |
| 21 | PCH_ADPA_CRT_HPD_ENABLE : constant := 1 * 2 ** 23; |
| 22 | |
| 23 | DP_PORT_DETECTED : constant := 1 * 2 ** 2; |
| 24 | PCH_DIGI_PORT_DETECTED : constant := 1 * 2 ** 2; |
| 25 | PCH_LVDS_PORT_DETECTED : constant := 1 * 2 ** 1; |
| 26 | |
| 27 | SHOTPLUG_CTL_DETECT_MASK : constant := 16#0003_0303#; |
| 28 | |
| 29 | type PCH_Digital_Port_Value is array (PCH_HDMI_Port) of Word32; |
| 30 | SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant PCH_Digital_Port_Value := |
| 31 | (PCH_HDMI_B => 1 * 2 ** 4, |
| 32 | PCH_HDMI_C => 1 * 2 ** 12, |
| 33 | PCH_HDMI_D => 1 * 2 ** 20); |
| 34 | SHOTPLUG_CTL_SHORT_PULSE_MASK : constant PCH_Digital_Port_Value := |
| 35 | (PCH_HDMI_B => 3 * 2 ** 2, |
| 36 | PCH_HDMI_C => 3 * 2 ** 10, |
| 37 | PCH_HDMI_D => 3 * 2 ** 18); |
| 38 | SHOTPLUG_CTL_HPD_STATUS : constant PCH_Digital_Port_Value := |
| 39 | (PCH_HDMI_B => 3 * 2 ** 0, |
| 40 | PCH_HDMI_C => 3 * 2 ** 8, |
| 41 | PCH_HDMI_D => 3 * 2 ** 16); |
| 42 | SHOTPLUG_CTL_LONG_DETECT : constant PCH_Digital_Port_Value := |
| 43 | (PCH_HDMI_B => 1 * 2 ** 1, |
| 44 | PCH_HDMI_C => 1 * 2 ** 9, |
| 45 | PCH_HDMI_D => 1 * 2 ** 17); |
| 46 | |
| 47 | type PCH_Digital_Regs is array (PCH_HDMI_Port) of Registers.Registers_Index; |
| 48 | PCH_HDMI : constant PCH_Digital_Regs := |
| 49 | (PCH_HDMI_B => Registers.PCH_HDMIB, |
| 50 | PCH_HDMI_C => Registers.PCH_HDMIC, |
| 51 | PCH_HDMI_D => Registers.PCH_HDMID); |
| 52 | PCH_DP : constant PCH_Digital_Regs := |
| 53 | (PCH_HDMI_B => Registers.PCH_DP_B, |
| 54 | PCH_HDMI_C => Registers.PCH_DP_C, |
| 55 | PCH_HDMI_D => Registers.PCH_DP_D); |
| 56 | |
| 57 | procedure Initialize |
| 58 | is |
| 59 | Internal_Detected, |
| 60 | HDMI_Detected, |
| 61 | DP_Detected : Boolean; |
| 62 | |
| 63 | type PCH_Port_To_GMA_Port is array (PCH_HDMI_Port) of Port_Type; |
| 64 | To_Digital_Port : constant PCH_Port_To_GMA_Port := |
| 65 | (PCH_HDMI_B => Digital1, |
| 66 | PCH_HDMI_C => Digital2, |
| 67 | PCH_HDMI_D => Digital3); |
| 68 | To_DP_Port : constant PCH_Port_To_GMA_Port := |
| 69 | (PCH_HDMI_B => DP1, |
| 70 | PCH_HDMI_C => DP2, |
| 71 | PCH_HDMI_D => DP3); |
| 72 | begin |
| 73 | -- PCH_DAC (_A) |
| 74 | Registers.Set_Mask |
| 75 | (Register => Registers.PCH_ADPA, |
| 76 | Mask => PCH_ADPA_CRT_HPD_CHANNEL_MASK or -- clear status |
| 77 | PCH_ADPA_CRT_HPD_ENABLE); |
| 78 | |
| 79 | case Config.Internal_Display is |
| 80 | when LVDS => |
| 81 | -- PCH_LVDS |
| 82 | Registers.Is_Set_Mask |
| 83 | (Register => Registers.PCH_LVDS, |
| 84 | Mask => PCH_LVDS_PORT_DETECTED, |
| 85 | Result => Internal_Detected); |
| 86 | when DP => |
| 87 | -- eDP |
| 88 | Registers.Is_Set_Mask |
| 89 | (Register => Registers.DP_CTL_A, |
| 90 | Mask => DP_PORT_DETECTED, |
| 91 | Result => Internal_Detected); |
| 92 | when None => |
| 93 | Internal_Detected := False; |
| 94 | end case; |
| 95 | Config.Valid_Port (Internal) := Internal_Detected; |
| 96 | |
| 97 | -- PCH_HDMI_[BCD], PCH_DP_[BCD] share hotplug registers |
| 98 | for PCH_Port in PCH_HDMI_Port loop |
| 99 | Registers.Is_Set_Mask |
| 100 | (Register => PCH_HDMI (PCH_Port), |
| 101 | Mask => PCH_DIGI_PORT_DETECTED, |
| 102 | Result => HDMI_Detected); |
| 103 | Config.Valid_Port (To_Digital_Port (PCH_Port)) := HDMI_Detected; |
| 104 | |
| 105 | Registers.Is_Set_Mask |
| 106 | (Register => PCH_DP (PCH_Port), |
| 107 | Mask => PCH_DIGI_PORT_DETECTED, |
| 108 | Result => DP_Detected); |
| 109 | Config.Valid_Port (To_DP_Port (PCH_Port)) := DP_Detected; |
| 110 | |
| 111 | if HDMI_Detected or DP_Detected then |
| 112 | Registers.Unset_And_Set_Mask |
| 113 | (Register => Registers.SHOTPLUG_CTL, |
| 114 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK or |
| 115 | SHOTPLUG_CTL_SHORT_PULSE_MASK (PCH_Port), |
| 116 | Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (PCH_Port) or |
| 117 | SHOTPLUG_CTL_HPD_STATUS (PCH_Port)); -- clear |
| 118 | else |
| 119 | Registers.Unset_Mask |
| 120 | (Register => Registers.SHOTPLUG_CTL, |
| 121 | Mask => SHOTPLUG_CTL_DETECT_MASK or |
| 122 | SHOTPLUG_CTL_HPD_INPUT_ENABLE (PCH_Port)); |
| 123 | end if; |
| 124 | end loop; |
| 125 | end Initialize; |
| 126 | |
| 127 | procedure Hotplug_Detect (Port_Cfg : in Port_Config; Detected : out Boolean) |
| 128 | is |
| 129 | Ctl32 : Word32; |
| 130 | PCH_Port : constant GMA.PCH_Port := |
| 131 | (case Port_Cfg.PCH_Port is |
| 132 | when PCH_DP_B => PCH_HDMI_B, |
| 133 | when PCH_DP_C => PCH_HDMI_C, |
| 134 | when PCH_DP_D => PCH_HDMI_D, |
| 135 | when others => Port_Cfg.PCH_Port); |
| 136 | begin |
| 137 | case PCH_Port is |
| 138 | when PCH_DAC => |
| 139 | Registers.Read (Registers.PCH_ADPA, Ctl32, Verbose => False); |
| 140 | Ctl32 := Ctl32 and PCH_ADPA_CRT_HPD_CHANNEL_MASK; |
| 141 | Detected := Ctl32 = PCH_ADPA_CRT_HPD_CHANNEL_MASK; |
| 142 | if Ctl32 /= 0 then |
| 143 | Registers.Set_Mask (Registers.PCH_ADPA, Ctl32); |
| 144 | end if; |
| 145 | when PCH_HDMI_B .. PCH_HDMI_D => |
| 146 | Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False); |
| 147 | Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (PCH_Port)) /= 0; |
| 148 | |
| 149 | if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (PCH_Port)) /= 0 then |
| 150 | Registers.Unset_And_Set_Mask |
| 151 | (Register => Registers.SHOTPLUG_CTL, |
| 152 | Mask_Unset => SHOTPLUG_CTL_DETECT_MASK, |
| 153 | Mask_Set => SHOTPLUG_CTL_HPD_STATUS (PCH_Port)); |
| 154 | end if; |
| 155 | when others => |
| 156 | Detected := False; |
| 157 | end case; |
| 158 | end Hotplug_Detect; |
| 159 | |
| 160 | end HW.GFX.GMA.Port_Detect; |