blob: b7095bcd80dcb9e626e44a326fc0176dfedf851f [file] [log] [blame]
Nico Huberc74eafd2024-07-23 12:38:02 +02001--
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
15with HW.GFX.GMA.Config;
16with HW.GFX.GMA.Registers;
17
18with HW.Debug;
19with GNAT.Source_Info;
20
21package body HW.GFX.GMA.Connectors.TC.Ownership is
22
23 procedure Claim
24 (Port : in USBC_Port;
25 DP_Alt : in Boolean;
26 Success : out Boolean)
27 is
28 begin
29 -- For legacy ports, this is supposed to be
30 -- initialized once during boot, hence wait.
31 Registers.Wait_Set_Mask
32 (Register => Fia_Regs (Port).PORT_TX_DFLEXDPPMS,
33 Mask => DP_PHY_MODE_STATUS_COMPLETE (Port),
34 TOut_MS => (if DP_Alt then 0 else 100),
35 Success => Success);
36 if not Success then
37 pragma Debug (Debug.Put_Line ("DP PHY mode status not complete"));
38 return;
39 end if;
40
41 Registers.Set_Mask
42 (Register => Fia_Regs (Port).PORT_TX_DFLEXDPCSSS,
43 Mask => DP_PHY_MODE_STATUS_NOT_SAFE (Port));
44 end Claim;
45
46 procedure Claimed (Port : USBC_Port; Is_Claimed : out Boolean) is
47 begin
48 if Port not in Valid_TC_Port then
49 Is_Claimed := False;
50 return;
51 end if;
52
53 Registers.Is_Set_Mask
54 (Register => Fia_Regs (Port).PORT_TX_DFLEXDPCSSS,
55 Mask => DP_PHY_MODE_STATUS_NOT_SAFE (Port),
56 Result => Is_Claimed);
57 end Claimed;
58
59 ---------------------------------------------------------------------
60
61 procedure Connect
62 (Port : in USBC_Port;
63 DP_Alt : in Boolean;
64 Lanes : in DP_Lane_Count;
65 Success : out Boolean)
66 is
67 Assigned_Lanes : DP_Lane_Count;
68 begin
69 Claimed (Port, Success);
70 if not Success then
71 pragma Debug (Debug.Put_Line ("Tried to connect to unclaimed port."));
72 return;
73 end if;
74
75 if DP_Alt then
76 Registers.Is_Set_Mask
77 (Register => Fia_Regs (Port).PORT_TX_DFLEXDPSP,
78 Mask => TC_LIVE_STATE_TC (Port),
79 Result => Success);
80 if not Success then
81 pragma Debug (Debug.Put_Line ("DP-Alt is not connected."));
82 return;
83 end if;
84
85 Get_Lane_Assignment_Count (Port, Assigned_Lanes);
86 Set_Lane_Count (Port, Assigned_Lanes);
87 else
88 Set_Lane_Count (Port, Lanes);
89 end if;
90 end Connect;
91
92 procedure Disconnect (Port : USBC_Port) is
93 begin
94 if Port in Valid_TC_Port then
95 Registers.Unset_Mask
96 (Register => Fia_Regs (Port).PORT_TX_DFLEXDPCSSS,
97 Mask => DP_PHY_MODE_STATUS_NOT_SAFE (Port));
98 end if;
99 end Disconnect;
100
101end HW.GFX.GMA.Connectors.TC.Ownership;