| 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 |
| 49 | FDI_TX_CTL_FDI_TX_ENABLE : constant := 1 * 2 ** 31; |
| 50 | Enabled : Boolean; |
| 51 | begin |
| 52 | if Config.Has_FDI_C and then Port_Cfg.Port = DIGI_C then |
| 53 | -- if DIGI_D enabled: (FDI names are off by one) |
| 54 | Registers.Is_Set_Mask |
| 55 | (Register => Registers.FDI_TX_CTL_C, |
| 56 | Mask => FDI_TX_CTL_FDI_TX_ENABLE, |
| 57 | Result => Enabled); |
| 58 | if Enabled then |
| 59 | Port_Cfg.FDI.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_2; |
| 60 | end if; |
| 61 | end if; |
| 62 | |
| 63 | DP_Info.Preferred_Link_Setting (Port_Cfg.FDI, Port_Cfg.Mode, Success); |
| 64 | end Override_FDI_Link; |
| Nico Huber | a825448 | 2024-07-03 12:23:00 +0200 | [diff] [blame] | 65 | begin |
| Nico Huber | 005f9ca | 2024-07-03 16:57:56 +0200 | [diff] [blame^] | 66 | if Port_Cfg.Is_FDI then |
| 67 | Override_FDI_Link; |
| 68 | else |
| 69 | Success := True; |
| 70 | end if; |
| Nico Huber | a825448 | 2024-07-03 12:23:00 +0200 | [diff] [blame] | 71 | end Prepare; |
| 72 | |
| 73 | ---------------------------------------------------------------------------- |
| 74 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 75 | function Is_Internal (Port_Cfg : Port_Config) return Boolean |
| 76 | is |
| 77 | begin |
| 78 | return |
| 79 | Port_Cfg.Port = DIGI_A or |
| 80 | (Port_Cfg.Is_FDI and Port_Cfg.PCH_Port = PCH_LVDS); |
| 81 | end Is_Internal; |
| 82 | |
| 83 | ---------------------------------------------------------------------------- |
| 84 | |
| 85 | procedure Pre_On |
| Nico Huber | 6e327c9 | 2016-12-21 14:45:45 +0100 | [diff] [blame] | 86 | (Pipe : in Pipe_Index; |
| 87 | Port_Cfg : in Port_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 88 | PLL_Hint : in Word32; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 89 | Success : out Boolean) |
| 90 | is |
| 91 | begin |
| 92 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 93 | |
| 94 | if Port_Cfg.Port = DIGI_A then |
| Nico Huber | 6e327c9 | 2016-12-21 14:45:45 +0100 | [diff] [blame] | 95 | EDP.Pre_On (Pipe, Port_Cfg); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 96 | elsif Port_Cfg.Port in FDI.GPU_FDI_Port then |
| 97 | FDI.Pre_On (Port_Cfg); |
| 98 | end if; |
| 99 | Success := True; |
| 100 | end Pre_On; |
| 101 | |
| 102 | procedure Post_On |
| Arthur Heymans | 60d0e5f | 2018-03-28 17:08:27 +0200 | [diff] [blame] | 103 | (Pipe : in Pipe_Index; |
| 104 | Port_Cfg : in Port_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 105 | PLL_Hint : in Word32; |
| 106 | Success : out Boolean) |
| 107 | is |
| 108 | begin |
| 109 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 110 | |
| 111 | if Port_Cfg.Port = DIGI_A then |
| 112 | EDP.Pre_Training; |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 113 | Panel.On (Port_Cfg.Panel, Wait => True); |
| Nico Huber | 7892ff6 | 2016-11-21 23:26:00 +0100 | [diff] [blame] | 114 | EDP.Post_On (Port_Cfg.DP, Success); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 115 | elsif Port_Cfg.Port in FDI.GPU_FDI_Port then |
| 116 | declare |
| 117 | FDI_Port : constant PCH.FDI_Port_Type := |
| 118 | FDI.PCH_FDIs (Port_Cfg.Port); |
| 119 | begin |
| 120 | FDI.Post_On (Port_Cfg, Success); |
| 121 | |
| 122 | if Success then |
| 123 | PCH.Transcoder.On (Port_Cfg, FDI_Port, PLL_Hint); |
| 124 | if Port_Cfg.PCH_Port = PCH_DAC then |
| 125 | PCH.VGA.On (FDI_Port, Port_Cfg.Mode); |
| 126 | elsif Port_Cfg.PCH_Port = PCH_LVDS then |
| 127 | PCH.LVDS.On (Port_Cfg, FDI_Port); |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 128 | 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] | 129 | PCH.HDMI.On (Port_Cfg, FDI_Port); |
| 130 | elsif Port_Cfg.PCH_Port in PCH_DP_Port then |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 131 | PCH.DP.On (Port_Cfg, FDI_Port, Success); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 132 | end if; |
| 133 | end if; |
| 134 | end; |
| 135 | else |
| 136 | Success := False; |
| 137 | end if; |
| 138 | |
| 139 | if Success and Is_Internal (Port_Cfg) then |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 140 | Panel.On (Port_Cfg.Panel, Wait => False); |
| 141 | Panel.Backlight_On (Port_Cfg.Panel); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 142 | end if; |
| 143 | end Post_On; |
| 144 | |
| 145 | ---------------------------------------------------------------------------- |
| 146 | |
| Nico Huber | bfea6a3 | 2024-03-07 15:22:36 +0000 | [diff] [blame] | 147 | procedure Pre_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 148 | is |
| 149 | begin |
| 150 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 151 | |
| 152 | if Is_Internal (Port_Cfg) then |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 153 | Panel.Backlight_Off (Port_Cfg.Panel); |
| 154 | Panel.Off (Port_Cfg.Panel); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 155 | end if; |
| 156 | end Pre_Off; |
| 157 | |
| Nico Huber | bfea6a3 | 2024-03-07 15:22:36 +0000 | [diff] [blame] | 158 | procedure Post_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 159 | is |
| 160 | begin |
| 161 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 162 | |
| 163 | if Port_Cfg.Port = DIGI_A then |
| 164 | EDP.Off (Port_Cfg.Port); |
| 165 | elsif Port_Cfg.Port in FDI.GPU_FDI_Port then |
| 166 | declare |
| 167 | FDI_Port : constant PCH.FDI_Port_Type := |
| 168 | FDI.PCH_FDIs (Port_Cfg.Port); |
| 169 | begin |
| 170 | if Port_Cfg.PCH_Port in PCH_DP_Port then |
| 171 | PCH.DP.Off (Port_Cfg.PCH_Port); |
| 172 | end if; |
| 173 | |
| 174 | FDI.Off (Port_Cfg.Port, FDI.Link_Off); |
| 175 | |
| 176 | if Port_Cfg.PCH_Port = PCH_DAC then |
| 177 | PCH.VGA.Off; |
| 178 | elsif Port_Cfg.PCH_Port = PCH_LVDS then |
| 179 | PCH.LVDS.Off; |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 180 | 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] | 181 | PCH.HDMI.Off (Port_Cfg.PCH_Port); |
| 182 | end if; |
| 183 | PCH.Transcoder.Off (FDI_Port); |
| 184 | |
| 185 | FDI.Off (Port_Cfg.Port, FDI.Clock_Off); |
| 186 | end; |
| 187 | end if; |
| 188 | end Post_Off; |
| 189 | |
| 190 | ---------------------------------------------------------------------------- |
| 191 | |
| 192 | procedure Pre_All_Off |
| 193 | is |
| 194 | begin |
| 195 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 196 | |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 197 | for P in Valid_Panels loop |
| 198 | Panel.Backlight_Off (P); |
| 199 | Panel.Off (P); |
| 200 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 201 | end Pre_All_Off; |
| 202 | |
| 203 | procedure Post_All_Off |
| 204 | is |
| 205 | begin |
| 206 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 207 | |
| 208 | EDP.Off (DIGI_A); |
| 209 | |
| 210 | for Port in FDI.GPU_FDI_Port loop |
| 211 | FDI.Off (Port, FDI.Link_Off); |
| 212 | end loop; |
| 213 | PCH.VGA.Off; |
| 214 | PCH.LVDS.Off; |
| 215 | PCH.HDMI.All_Off; |
| 216 | PCH.DP.All_Off; |
| 217 | for Port in PCH.FDI_Port_Type loop |
| 218 | PCH.Transcoder.Off (Port); |
| 219 | end loop; |
| 220 | for Port in FDI.GPU_FDI_Port loop |
| 221 | FDI.Off (Port, FDI.Clock_Off); |
| 222 | end loop; |
| 223 | end Post_All_Off; |
| 224 | |
| 225 | end HW.GFX.GMA.Connectors; |