| Nico Huber | ab70886 | 2026-05-27 19:22:57 +0200 | [diff] [blame^] | 1 | -- |
| 2 | -- Copyright (C) 2022 Google, LLC |
| 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 GNAT.Source_Info; |
| 16 | with HW.Debug; |
| 17 | with HW.GFX.GMA.Config_Helpers; |
| 18 | with HW.GFX.GMA.Connectors.TC.Ownership; |
| 19 | with HW.GFX.GMA.Power_Domains_Common; |
| 20 | use HW.GFX.GMA.Power_Domains_Common; |
| 21 | |
| 22 | package body HW.GFX.GMA.Power_Domains is |
| 23 | |
| 24 | function Need_PW (PW : Dynamic_Well; Configs : Pipe_Configs) return Boolean |
| 25 | is |
| 26 | function Any_PW2_Combo_Port return Boolean is |
| 27 | (for some Pipe in Pipe_Index => |
| 28 | Configs (Pipe).Port /= Disabled and then |
| 29 | Config_Helpers.To_GPU_Port (Pipe, Configs (Pipe).Port) in DIGI_C .. DIGI_E); |
| 30 | |
| 31 | function Any_TC_Port return Boolean is |
| 32 | (for some Pipe in Pipe_Index => |
| 33 | Configs (Pipe).Port /= Disabled and then |
| 34 | Config_Helpers.To_GPU_Port (Pipe, Configs (Pipe).Port) in USBC_Port); |
| 35 | |
| 36 | function Any_Pipe_From (First : Pipe_Index) return Boolean is |
| 37 | (for some Pipe in First .. Pipe_Index'Last => Configs (Pipe).Port /= Disabled); |
| 38 | |
| 39 | function VGA return Boolean is |
| 40 | (Configs (Primary).Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET); |
| 41 | begin |
| 42 | case PW is |
| 43 | when PW2 => |
| 44 | return Any_Pipe_From (Secondary) or Any_PW2_Combo_Port or Any_TC_Port or VGA; |
| 45 | when PWA => |
| 46 | return Configs (Primary).Port /= Disabled; |
| 47 | when PWB => |
| 48 | return Configs (Secondary).Port /= Disabled; |
| 49 | when PWC => |
| 50 | return Configs (Tertiary).Port /= Disabled; |
| 51 | when PWD => |
| 52 | return False; -- Fourth pipe not supported yet. |
| 53 | end case; |
| 54 | end Need_PW; |
| 55 | |
| 56 | procedure Power_Up (Port : Active_Port_Type; Success : out Boolean) |
| 57 | is |
| 58 | GPU_Port : constant GMA.GPU_Port := |
| 59 | Config_Helpers.To_GPU_Port (Pipe_Index'First, Port); |
| 60 | |
| 61 | procedure On (Aux : AUX_Domain; DDI : DDI_Domain) is |
| 62 | begin |
| 63 | PD_On (PW1); |
| 64 | if DDI in DDI_PW2_Domain then |
| 65 | PD_On (PW2); |
| 66 | end if; |
| 67 | PD_On (DDI); |
| 68 | |
| 69 | if GPU_Port in USBC_Port then |
| 70 | Connectors.TC.Ownership.Claim |
| 71 | (Port => GPU_Port, |
| 72 | DP_Alt => Port in Physical_USBC_Ports, |
| 73 | Success => Success); |
| 74 | if not Success then |
| 75 | return; |
| 76 | end if; |
| 77 | end if; |
| 78 | PD_On (Aux); |
| 79 | |
| 80 | Success := True; |
| 81 | end On; |
| 82 | begin |
| 83 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 84 | |
| 85 | case GPU_Port is |
| 86 | when GMA.DIGI_A => On (AUX_A, DDI_A); |
| 87 | when GMA.DIGI_B => On (AUX_B, DDI_B); |
| 88 | when GMA.DIGI_C => On (AUX_C, DDI_C); |
| 89 | when GMA.DIGI_D => On (AUX_D, DDI_D); |
| 90 | when GMA.DIGI_E => On (AUX_E, DDI_E); |
| 91 | when GMA.DDI_TC1 => On (AUX_USBC1, DDI_USBC1); |
| 92 | when GMA.DDI_TC2 => On (AUX_USBC2, DDI_USBC2); |
| 93 | when GMA.DDI_TC3 => On (AUX_USBC3, DDI_USBC3); |
| 94 | when GMA.DDI_TC4 => On (AUX_USBC4, DDI_USBC4); |
| 95 | when others => Success := True; |
| 96 | end case; |
| 97 | end Power_Up; |
| 98 | |
| 99 | end HW.GFX.GMA.Power_Domains; |