| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2015-2016 secunet Security Networks AG |
| 3 | -- Copyright (C) 2016 Nico Huber <nico.h@gmx.de> |
| 4 | -- |
| 5 | -- This program is free software; you can redistribute it and/or modify |
| 6 | -- 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] | 7 | -- the Free Software Foundation; either version 2 of the License, or |
| 8 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 9 | -- |
| 10 | -- This program is distributed in the hope that it will be useful, |
| 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | -- GNU General Public License for more details. |
| 14 | -- |
| 15 | |
| 16 | with HW.GFX.GMA.Config; |
| Nico Huber | 005f9ca | 2024-07-03 16:57:56 +0200 | [diff] [blame] | 17 | with HW.GFX.GMA.DP_Info; |
| 18 | with HW.GFX.GMA.Registers; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 19 | with HW.GFX.GMA.Panel; |
| 20 | with HW.GFX.GMA.Connectors.EDP; |
| 21 | with HW.GFX.GMA.Connectors.FDI; |
| 22 | with HW.GFX.GMA.PCH.VGA; |
| 23 | with HW.GFX.GMA.PCH.LVDS; |
| 24 | with HW.GFX.GMA.PCH.HDMI; |
| 25 | with HW.GFX.GMA.PCH.DP; |
| 26 | with HW.GFX.GMA.PCH.Transcoder; |
| 27 | |
| 28 | with HW.Debug; |
| 29 | with GNAT.Source_Info; |
| 30 | |
| 31 | package body HW.GFX.GMA.Connectors |
| 32 | is |
| 33 | |
| Nico Huber | 3a0e2a0 | 2017-07-19 14:41:46 +0200 | [diff] [blame] | 34 | procedure Post_Reset_Off is null; |
| 35 | procedure Initialize is null; |
| Nico Huber | 0923b79 | 2017-06-09 15:28:41 +0200 | [diff] [blame] | 36 | |
| Nico Huber | a825448 | 2024-07-03 12:23:00 +0200 | [diff] [blame] | 37 | ---------------------------------------------------------------------------- |
| 38 | |
| 39 | procedure Prepare |
| 40 | (Port : in Active_Port_Type; |
| 41 | Port_Cfg : in out Port_Config; |
| 42 | Success : out Boolean) |
| 43 | is |
| Nico Huber | 005f9ca | 2024-07-03 16:57:56 +0200 | [diff] [blame] | 44 | -- Override lane count for FDI_B if FDI_C is used |
| 45 | procedure Override_FDI_Link |
| 46 | with |
| 47 | Post => Port_Cfg.Mode = Port_Cfg'Old.Mode |
| 48 | is |
| Nico Huber | f84bb89 | 2026-04-08 10:33:22 +0000 | [diff] [blame^] | 49 | FDI_TX_CTL_FDI_TX_ENABLE : constant := 1 * 2 ** 31; |
| 50 | FDI_TX_CTL_PORT_WIDTH_SEL_4 : constant := 3 * 2 ** 19; |
| Nico Huber | 005f9ca | 2024-07-03 16:57:56 +0200 | [diff] [blame] | 51 | Enabled : Boolean; |
| 52 | begin |
| Nico Huber | f84bb89 | 2026-04-08 10:33:22 +0000 | [diff] [blame^] | 53 | if Config.Has_FDI_C and then Port_Cfg.Port = DIGI_D then |
| 54 | -- if DIGI_C (FDI_B) is enabled w/ 4 lanes, DIGI_D can't be used: |
| 55 | Registers.Is_Set_Mask |
| 56 | (Register => Registers.FDI_TX_CTL_B, |
| 57 | Mask => FDI_TX_CTL_FDI_TX_ENABLE or |
| 58 | FDI_TX_CTL_PORT_WIDTH_SEL_4, |
| 59 | Result => Enabled); |
| 60 | if Enabled then |
| 61 | Success := False; |
| 62 | return; |
| 63 | end if; |
| 64 | end if; |
| 65 | |
| Nico Huber | 005f9ca | 2024-07-03 16:57:56 +0200 | [diff] [blame] | 66 | if Config.Has_FDI_C and then Port_Cfg.Port = DIGI_C then |
| 67 | -- if DIGI_D enabled: (FDI names are off by one) |
| 68 | Registers.Is_Set_Mask |
| 69 | (Register => Registers.FDI_TX_CTL_C, |
| 70 | Mask => FDI_TX_CTL_FDI_TX_ENABLE, |
| 71 | Result => Enabled); |
| 72 | if Enabled then |
| 73 | Port_Cfg.FDI.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_2; |
| 74 | end if; |
| 75 | end if; |
| 76 | |
| 77 | DP_Info.Preferred_Link_Setting (Port_Cfg.FDI, Port_Cfg.Mode, Success); |
| 78 | end Override_FDI_Link; |
| Nico Huber | a825448 | 2024-07-03 12:23:00 +0200 | [diff] [blame] | 79 | begin |
| Nico Huber | 005f9ca | 2024-07-03 16:57:56 +0200 | [diff] [blame] | 80 | if Port_Cfg.Is_FDI then |
| 81 | Override_FDI_Link; |
| 82 | else |
| 83 | Success := True; |
| 84 | end if; |
| Nico Huber | a825448 | 2024-07-03 12:23:00 +0200 | [diff] [blame] | 85 | end Prepare; |
| 86 | |
| 87 | ---------------------------------------------------------------------------- |
| 88 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 89 | function Is_Internal (Port_Cfg : Port_Config) return Boolean |
| 90 | is |
| 91 | begin |
| 92 | return |
| 93 | Port_Cfg.Port = DIGI_A or |
| 94 | (Port_Cfg.Is_FDI and Port_Cfg.PCH_Port = PCH_LVDS); |
| 95 | end Is_Internal; |
| 96 | |
| 97 | ---------------------------------------------------------------------------- |
| 98 | |
| 99 | procedure Pre_On |
| Nico Huber | 6e327c9 | 2016-12-21 14:45:45 +0100 | [diff] [blame] | 100 | (Pipe : in Pipe_Index; |
| 101 | Port_Cfg : in Port_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 102 | PLL_Hint : in Word32; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 103 | Success : out Boolean) |
| 104 | is |
| 105 | begin |
| 106 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 107 | |
| 108 | if Port_Cfg.Port = DIGI_A then |
| Nico Huber | 6e327c9 | 2016-12-21 14:45:45 +0100 | [diff] [blame] | 109 | EDP.Pre_On (Pipe, Port_Cfg); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 110 | elsif Port_Cfg.Port in FDI.GPU_FDI_Port then |
| 111 | FDI.Pre_On (Port_Cfg); |
| 112 | end if; |
| 113 | Success := True; |
| 114 | end Pre_On; |
| 115 | |
| 116 | procedure Post_On |
| Arthur Heymans | 60d0e5f | 2018-03-28 17:08:27 +0200 | [diff] [blame] | 117 | (Pipe : in Pipe_Index; |
| 118 | Port_Cfg : in Port_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 119 | PLL_Hint : in Word32; |
| 120 | Success : out Boolean) |
| 121 | is |
| 122 | begin |
| 123 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 124 | |
| 125 | if Port_Cfg.Port = DIGI_A then |
| 126 | EDP.Pre_Training; |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 127 | Panel.On (Port_Cfg.Panel, Wait => True); |
| Nico Huber | 7892ff6 | 2016-11-21 23:26:00 +0100 | [diff] [blame] | 128 | EDP.Post_On (Port_Cfg.DP, Success); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 129 | elsif Port_Cfg.Port in FDI.GPU_FDI_Port then |
| 130 | declare |
| 131 | FDI_Port : constant PCH.FDI_Port_Type := |
| 132 | FDI.PCH_FDIs (Port_Cfg.Port); |
| 133 | begin |
| 134 | FDI.Post_On (Port_Cfg, Success); |
| 135 | |
| 136 | if Success then |
| 137 | PCH.Transcoder.On (Port_Cfg, FDI_Port, PLL_Hint); |
| 138 | if Port_Cfg.PCH_Port = PCH_DAC then |
| 139 | PCH.VGA.On (FDI_Port, Port_Cfg.Mode); |
| 140 | elsif Port_Cfg.PCH_Port = PCH_LVDS then |
| 141 | PCH.LVDS.On (Port_Cfg, FDI_Port); |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 142 | elsif Port_Cfg.PCH_Port in PCH.HDMI.IRL_PCH_HDMI_Port then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 143 | PCH.HDMI.On (Port_Cfg, FDI_Port); |
| 144 | elsif Port_Cfg.PCH_Port in PCH_DP_Port then |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 145 | PCH.DP.On (Port_Cfg, FDI_Port, Success); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 146 | end if; |
| 147 | end if; |
| 148 | end; |
| 149 | else |
| 150 | Success := False; |
| 151 | end if; |
| 152 | |
| 153 | if Success and Is_Internal (Port_Cfg) then |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 154 | Panel.On (Port_Cfg.Panel, Wait => False); |
| 155 | Panel.Backlight_On (Port_Cfg.Panel); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 156 | end if; |
| 157 | end Post_On; |
| 158 | |
| 159 | ---------------------------------------------------------------------------- |
| 160 | |
| Nico Huber | bfea6a3 | 2024-03-07 15:22:36 +0000 | [diff] [blame] | 161 | procedure Pre_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 162 | is |
| 163 | begin |
| 164 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 165 | |
| 166 | if Is_Internal (Port_Cfg) then |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 167 | Panel.Backlight_Off (Port_Cfg.Panel); |
| 168 | Panel.Off (Port_Cfg.Panel); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 169 | end if; |
| 170 | end Pre_Off; |
| 171 | |
| Nico Huber | bfea6a3 | 2024-03-07 15:22:36 +0000 | [diff] [blame] | 172 | procedure Post_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 173 | is |
| 174 | begin |
| 175 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 176 | |
| 177 | if Port_Cfg.Port = DIGI_A then |
| 178 | EDP.Off (Port_Cfg.Port); |
| 179 | elsif Port_Cfg.Port in FDI.GPU_FDI_Port then |
| 180 | declare |
| 181 | FDI_Port : constant PCH.FDI_Port_Type := |
| 182 | FDI.PCH_FDIs (Port_Cfg.Port); |
| 183 | begin |
| 184 | if Port_Cfg.PCH_Port in PCH_DP_Port then |
| 185 | PCH.DP.Off (Port_Cfg.PCH_Port); |
| 186 | end if; |
| 187 | |
| 188 | FDI.Off (Port_Cfg.Port, FDI.Link_Off); |
| 189 | |
| 190 | if Port_Cfg.PCH_Port = PCH_DAC then |
| 191 | PCH.VGA.Off; |
| 192 | elsif Port_Cfg.PCH_Port = PCH_LVDS then |
| 193 | PCH.LVDS.Off; |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 194 | elsif Port_Cfg.PCH_Port in PCH.HDMI.IRL_PCH_HDMI_Port then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 195 | PCH.HDMI.Off (Port_Cfg.PCH_Port); |
| 196 | end if; |
| 197 | PCH.Transcoder.Off (FDI_Port); |
| 198 | |
| 199 | FDI.Off (Port_Cfg.Port, FDI.Clock_Off); |
| 200 | end; |
| 201 | end if; |
| 202 | end Post_Off; |
| 203 | |
| 204 | ---------------------------------------------------------------------------- |
| 205 | |
| 206 | procedure Pre_All_Off |
| 207 | is |
| 208 | begin |
| 209 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 210 | |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 211 | for P in Valid_Panels loop |
| 212 | Panel.Backlight_Off (P); |
| 213 | Panel.Off (P); |
| 214 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 215 | end Pre_All_Off; |
| 216 | |
| 217 | procedure Post_All_Off |
| 218 | is |
| 219 | begin |
| 220 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 221 | |
| 222 | EDP.Off (DIGI_A); |
| 223 | |
| 224 | for Port in FDI.GPU_FDI_Port loop |
| 225 | FDI.Off (Port, FDI.Link_Off); |
| 226 | end loop; |
| 227 | PCH.VGA.Off; |
| 228 | PCH.LVDS.Off; |
| 229 | PCH.HDMI.All_Off; |
| 230 | PCH.DP.All_Off; |
| 231 | for Port in PCH.FDI_Port_Type loop |
| 232 | PCH.Transcoder.Off (Port); |
| 233 | end loop; |
| 234 | for Port in FDI.GPU_FDI_Port loop |
| 235 | FDI.Off (Port, FDI.Clock_Off); |
| 236 | end loop; |
| 237 | end Post_All_Off; |
| 238 | |
| 239 | end HW.GFX.GMA.Connectors; |