blob: c3b1d2b1d24aa35a26d93f9a1bfddea3bf5872fa [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;
Nico Huberdea094a2024-08-19 21:31:23 +020017with HW.GFX.DP_Info;
18with HW.GFX.GMA.PCode;
Nico Huberc74eafd2024-07-23 12:38:02 +020019
20with HW.Debug;
21with GNAT.Source_Info;
22
Nico Huberdea094a2024-08-19 21:31:23 +020023use type HW.Word64;
24
Nico Huberc74eafd2024-07-23 12:38:02 +020025package body HW.GFX.GMA.Connectors.TC.Ownership is
26
Nico Huberdea094a2024-08-19 21:31:23 +020027 type Port_Regs_Array is array (Valid_TC_Port) of Registers.Registers_Index;
28
29 TCSS_DDI_STATUS : constant Port_Regs_Array :=
30 Port_Regs_Array'
31 (DDI_TC1 => Registers.TCSS_DDI_STATUS_1,
32 DDI_TC2 => Registers.TCSS_DDI_STATUS_2,
33 DDI_TC3 => Registers.TCSS_DDI_STATUS_3,
34 DDI_TC4 => Registers.TCSS_DDI_STATUS_4);
35
36 TCSS_DDI_STATUS_HPD_LIVE_STATUS_ALT : constant := 1 * 2 ** 0;
37 TCSS_DDI_STATUS_READY : constant := 1 * 2 ** 2;
38
Nico Huberc74eafd2024-07-23 12:38:02 +020039 procedure Claim
40 (Port : in USBC_Port;
41 DP_Alt : in Boolean;
42 Success : out Boolean)
43 is
44 begin
Nico Huberdea094a2024-08-19 21:31:23 +020045 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
46
47 if Port not in Valid_TC_Port then
48 Success := False;
49 return;
50 end if;
51
52 if not DP_Alt then
53 -- For legacy ports, this is supposed
54 -- to be initialized once during boot.
55 Registers.Wait_Set_Mask
56 (Register => TCSS_DDI_STATUS (Port),
57 Mask => TCSS_DDI_STATUS_READY,
58 TOut_MS => 100);
59 end if;
60
61 Registers.Is_Set_Mask
62 (Register => TCSS_DDI_STATUS (Port),
63 Mask => TCSS_DDI_STATUS_READY,
64 Result => Success);
65 if not Success then
66 pragma Debug (Debug.Put_Line ("DP PHY mode status not complete"));
67 return;
68 end if;
69
70 Registers.Set_Mask
71 (Register => DDI_BUF_CTL (Port),
72 Mask => DDI_BUF_CTL_TC_PHY_OWNERSHIP);
Nico Huberc74eafd2024-07-23 12:38:02 +020073 end Claim;
74
Nico Huberdea094a2024-08-19 21:31:23 +020075 procedure Claimed (Port : USBC_Port; Is_Claimed : out Boolean)
76 with
77 Refined_Post => (if Is_Claimed then Port in Valid_TC_Port)
78 is
Nico Huberc74eafd2024-07-23 12:38:02 +020079 begin
Nico Huberdea094a2024-08-19 21:31:23 +020080 if Port not in Valid_TC_Port then
81 Is_Claimed := False;
82 return;
83 end if;
84
85 Registers.Is_Set_Mask
86 (Register => DDI_BUF_CTL (Port),
87 Mask => DDI_BUF_CTL_TC_PHY_OWNERSHIP,
88 Result => Is_Claimed);
Nico Huberc74eafd2024-07-23 12:38:02 +020089 end Claimed;
90
91 ---------------------------------------------------------------------
92
93 procedure Connect
94 (Port : in USBC_Port;
95 DP_Alt : in Boolean;
96 Lanes : in DP_Lane_Count;
97 Success : out Boolean)
98 is
Nico Huberdea094a2024-08-19 21:31:23 +020099 Assigned_Lanes : DP_Lane_Count;
Nico Huberc74eafd2024-07-23 12:38:02 +0200100 begin
Nico Huberdea094a2024-08-19 21:31:23 +0200101 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
102
103 Claimed (Port, Success);
104 if not Success then
105 pragma Debug (Debug.Put_Line ("Tried to connect to unclaimed port."));
106 return;
107 end if;
108
109 if DP_Alt then
110 Registers.Is_Set_Mask
111 (Register => TCSS_DDI_STATUS (Port),
112 Mask => TCSS_DDI_STATUS_HPD_LIVE_STATUS_ALT,
113 Result => Success);
114 if not Success then
115 pragma Debug (Debug.Put_Line ("DP-Alt is not connected."));
116 return;
117 end if;
118
119 Get_Lane_Assignment_Count (Port, Assigned_Lanes);
120 Set_Lane_Count (Port, Assigned_Lanes);
121 else
122 Set_Lane_Count (Port, Lanes);
123 end if;
Nico Huberc74eafd2024-07-23 12:38:02 +0200124 end Connect;
125
Nico Huberdea094a2024-08-19 21:31:23 +0200126 procedure Disconnect (Port : USBC_Port) is
127 begin
128 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
129
130 if Port in Valid_TC_Port then
131 Registers.Unset_Mask
132 (Register => DDI_BUF_CTL (Port),
133 Mask => DDI_BUF_CTL_TC_PHY_OWNERSHIP);
134 end if;
135 end Disconnect;
Nico Huberc74eafd2024-07-23 12:38:02 +0200136
137end HW.GFX.GMA.Connectors.TC.Ownership;