| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2026 Arthur Heymans <arthur@aheymans.xyz> |
| 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; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| 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; |
| 17 | |
| 18 | package body HW.GFX.GMA.Port_Detect |
| 19 | is |
| 20 | |
| 21 | CRT_HOTPLUG_INT_EN : constant := 1 * 2 ** 9; |
| 22 | CRT_HOTPLUG_ACTIVATION_PERIOD_64 : constant := 1 * 2 ** 8; |
| 23 | |
| 24 | HOTPLUG_INT_STATUS : constant array (Active_Port_Type) of Word32 := |
| 25 | (Analog => 1 * 2 ** 11, |
| 26 | others => 0); |
| 27 | |
| 28 | procedure Initialize |
| 29 | is |
| 30 | begin |
| 31 | -- i945: VGA (ADPA) is always present |
| 32 | Config.Valid_Port (Analog) := True; |
| 33 | |
| 34 | -- LVDS is only present on mobile (i945GM) |
| 35 | Config.Valid_Port (LVDS) := Config.GMCH_I945GM; |
| 36 | |
| 37 | -- Enable CRT hotplug detection |
| 38 | Registers.Write |
| 39 | (Register => Registers.PORT_HOTPLUG_EN, |
| 40 | Value => CRT_HOTPLUG_INT_EN or CRT_HOTPLUG_ACTIVATION_PERIOD_64); |
| 41 | end Initialize; |
| 42 | |
| 43 | procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean) |
| 44 | is |
| 45 | Ctl32 : Word32; |
| 46 | begin |
| 47 | Registers.Read (Register => Registers.PORT_HOTPLUG_STAT, |
| 48 | Value => Ctl32); |
| 49 | Detected := (Ctl32 and HOTPLUG_INT_STATUS (Port)) /= 0; |
| 50 | |
| 51 | if Detected then |
| 52 | Registers.Set_Mask |
| 53 | (Register => Registers.PORT_HOTPLUG_STAT, |
| 54 | Mask => HOTPLUG_INT_STATUS (Port)); |
| 55 | end if; |
| 56 | end Hotplug_Detect; |
| 57 | |
| 58 | procedure Clear_Hotplug_Detect (Port : Active_Port_Type) |
| 59 | is |
| 60 | Ignored_HPD : Boolean; |
| 61 | begin |
| 62 | pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""", |
| 63 | Reason => "We want to clear pending events only"); |
| 64 | Port_Detect.Hotplug_Detect (Port, Ignored_HPD); |
| 65 | pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD"""); |
| 66 | end Clear_Hotplug_Detect; |
| 67 | |
| 68 | end HW.GFX.GMA.Port_Detect; |