xref: /haiku/src/add-ons/accelerants/intel_extreme/Ports.h (revision dd2a1e350b303b855a50fd64e6cb55618be1ae6a)
1 /*
2  * Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz, mmlr@mlotz.ch
7  *		Alexander von Gluck IV, kallisti5@unixzen.com
8  */
9 #ifndef INTEL_PORTS_H
10 #define INTEL_PORTS_H
11 
12 
13 #include <dp.h>
14 #include <edid.h>
15 
16 #include "intel_extreme.h"
17 
18 #include "Pipes.h"
19 #include "pll.h"
20 
21 
22 #define MAX_PORTS	20	// a generous upper bound
23 
24 struct pll_limits;
25 struct i2c_bus;
26 
27 enum port_type {
28 	INTEL_PORT_TYPE_ANY,		// wildcard for lookup functions
29 	INTEL_PORT_TYPE_ANALOG,
30 	INTEL_PORT_TYPE_DVI,
31 	INTEL_PORT_TYPE_LVDS,
32 	INTEL_PORT_TYPE_DP,
33 	INTEL_PORT_TYPE_eDP,
34 	INTEL_PORT_TYPE_HDMI
35 };
36 
37 
38 class Port {
39 public:
40 									Port(port_index index,
41 										const char* baseName);
42 virtual								~Port();
43 
44 virtual	uint32						Type() const = 0;
45 		const char*					PortName() const
46 										{ return fPortName; }
47 
48 		port_index					PortIndex() const
49 										{ return fPortIndex; }
50 
51 virtual	bool						IsConnected() = 0;
52 
53 virtual	status_t					SetPipe(Pipe* pipe);
54 		::Pipe*						GetPipe()
55 										{ return fPipe; };
56 
57 virtual	status_t					Power(bool enabled);
58 
59 		bool						HasEDID();
60 virtual	status_t					GetEDID(edid1_info* edid,
61 										bool forceRead = false);
62 virtual	status_t					SetupI2c(struct i2c_bus *bus);
63 virtual status_t					SetupI2cFallback(struct i2c_bus *bus);
64 
65 virtual	status_t					GetPLLLimits(pll_limits& limits);
66 
67 virtual status_t					SetDisplayMode(display_mode* mode,
68 										uint32 colorMode) { return B_ERROR; };
69 
70 virtual pipe_index					PipePreference();
71 
72 protected:
73 		void						_SetName(const char* name);
74 
75 static	status_t					_GetI2CSignals(void* cookie, int* _clock,
76 										int* _data);
77 static	status_t					_SetI2CSignals(void* cookie, int clock,
78 										int data);
79 		bool						_IsPortInVBT(uint32* foundIndex = NULL);
80 		bool						_IsDisplayPortInVBT();
81 		bool						_IsHdmiInVBT();
82 		bool						_IsEDPPort();
83 		addr_t						_DDCPin();
84 		status_t					_SetupDpAuxI2c(struct i2c_bus *bus);
85 
86 		ssize_t						_DpAuxTransfer(dp_aux_msg* message);
87 		ssize_t						_DpAuxTransfer(uint8* transmitBuffer, uint8 transmitSize,
88 										uint8* receiveBuffer, uint8 receiveSize);
89 		status_t					_DpAuxSendReceive(uint32 slave_address,
90 										const uint8 *writeBuffer, size_t writeLength,
91 										uint8 *readBuffer, size_t readLength);
92 static 	status_t					_DpAuxSendReceiveHook(const struct i2c_bus *bus,
93 										uint32 slave_address, const uint8 *writeBuffer,
94 										size_t writeLength, uint8 *readBuffer,
95 										size_t readLength);
96 		aux_channel					_DpAuxChannel();
97 
98 		display_mode				fCurrentMode;
99 		Pipe*						fPipe;
100 
101 		status_t					fEDIDState;
102 		edid1_info					fEDIDInfo;
103 
104 private:
105 virtual	addr_t						_DDCRegister() = 0;
106 virtual addr_t						_PortRegister() = 0;
107 
108 		port_index					fPortIndex;
109 		char*						fPortName;
110 };
111 
112 
113 class AnalogPort : public Port {
114 public:
115 									AnalogPort();
116 
117 virtual	uint32						Type() const
118 										{ return INTEL_PORT_TYPE_ANALOG; }
119 
120 virtual	bool						IsConnected();
121 
122 virtual status_t					SetDisplayMode(display_mode* mode,
123 										uint32 colorMode);
124 
125 protected:
126 virtual	addr_t						_DDCRegister();
127 virtual addr_t						_PortRegister();
128 };
129 
130 
131 class LVDSPort : public Port {
132 public:
133 									LVDSPort();
134 
135 virtual	uint32						Type() const
136 										{ return INTEL_PORT_TYPE_LVDS; }
137 
138 virtual	bool						IsConnected();
139 
140 virtual status_t					SetDisplayMode(display_mode* mode,
141 										uint32 colorMode);
142 
143 virtual pipe_index					PipePreference();
144 
145 protected:
146 virtual	addr_t						_DDCRegister();
147 virtual addr_t						_PortRegister();
148 };
149 
150 
151 class DigitalPort : public Port {
152 public:
153 									DigitalPort(
154 										port_index index = INTEL_PORT_B,
155 										const char* baseName = "DVI");
156 
157 virtual	uint32						Type() const
158 										{ return INTEL_PORT_TYPE_DVI; }
159 
160 virtual	bool						IsConnected();
161 
162 virtual status_t					SetDisplayMode(display_mode* mode,
163 										uint32 colorMode);
164 
165 protected:
166 virtual	addr_t						_DDCRegister();
167 virtual addr_t						_PortRegister();
168 };
169 
170 
171 class HDMIPort : public DigitalPort {
172 public:
173 									HDMIPort(port_index index);
174 
175 virtual	uint32						Type() const
176 										{ return INTEL_PORT_TYPE_HDMI; }
177 
178 virtual	bool						IsConnected();
179 
180 protected:
181 virtual addr_t						_PortRegister();
182 };
183 
184 
185 class DisplayPort : public Port {
186 public:
187 									DisplayPort(port_index index,
188 										const char* baseName = "DisplayPort");
189 
190 virtual	uint32						Type() const
191 										{ return INTEL_PORT_TYPE_DP; }
192 
193 virtual	status_t					SetPipe(Pipe* pipe);
194 virtual	status_t					SetupI2c(i2c_bus *bus);
195 
196 virtual	bool						IsConnected();
197 
198 virtual status_t					SetDisplayMode(display_mode* mode,
199 										uint32 colorMode);
200 
201 virtual pipe_index					PipePreference();
202 
203 protected:
204 virtual	addr_t						_DDCRegister();
205 virtual	addr_t						_PortRegister();
206 
207 private:
208 		status_t					_SetPortLinkGen4(const display_timing& timing);
209 		status_t					_SetPortLinkGen6(const display_timing& timing);
210 };
211 
212 
213 class EmbeddedDisplayPort : public DisplayPort {
214 public:
215 									EmbeddedDisplayPort();
216 
217 virtual	uint32						Type() const
218 										{ return INTEL_PORT_TYPE_eDP; }
219 
220 virtual	bool						IsConnected();
221 };
222 
223 
224 class DigitalDisplayInterface : public Port {
225 public:
226 									DigitalDisplayInterface(
227 										port_index index = INTEL_PORT_A,
228 										const char* baseName = "Digital Display Interface");
229 
230 virtual	uint32						Type() const
231 										{ return INTEL_PORT_TYPE_DVI; }
232 
233 virtual	status_t					Power(bool enabled);
234 
235 virtual	status_t					SetPipe(Pipe* pipe);
236 virtual	status_t					SetupI2c(i2c_bus *bus);
237 virtual status_t					SetupI2cFallback(struct i2c_bus *bus);
238 
239 virtual	bool						IsConnected();
240 
241 virtual status_t					SetDisplayMode(display_mode* mode,
242 										uint32 colorMode);
243 
244 protected:
245 virtual	addr_t						_DDCRegister();
246 virtual addr_t						_PortRegister();
247 private:
248 		uint8						fMaxLanes;
249 
250 		status_t					_SetPortLinkGen8(const display_timing& timing,
251 										uint32 pllSel);
252 };
253 
254 
255 #endif // INTEL_PORTS_H
256