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 <edid.h>
14
15#include "intel_extreme.h"
16
17#include "Pipes.h"
18#include "pll.h"
19
20
21#define MAX_PORTS	20	// a generous upper bound
22
23struct pll_limits;
24
25enum port_type {
26	INTEL_PORT_TYPE_ANY,		// wildcard for lookup functions
27	INTEL_PORT_TYPE_ANALOG,
28	INTEL_PORT_TYPE_DVI,
29	INTEL_PORT_TYPE_LVDS,
30	INTEL_PORT_TYPE_DP,
31	INTEL_PORT_TYPE_eDP,
32	INTEL_PORT_TYPE_HDMI
33};
34
35enum port_index {
36	INTEL_PORT_ANY,				// wildcard for lookup functions
37	INTEL_PORT_A,
38	INTEL_PORT_B,
39	INTEL_PORT_C,
40	INTEL_PORT_D,
41	INTEL_PORT_E
42};
43
44
45class Port {
46public:
47									Port(port_index index,
48										const char* baseName);
49virtual								~Port();
50
51virtual	uint32						Type() const = 0;
52		const char*					PortName() const
53										{ return fPortName; }
54
55		port_index					PortIndex() const
56										{ return fPortIndex; }
57
58virtual	bool						IsConnected() = 0;
59
60		status_t					SetPipe(Pipe* pipe);
61		::Pipe*						GetPipe()
62										{ return fPipe; };
63
64virtual	status_t					Power(bool enabled);
65
66		bool						HasEDID();
67virtual	status_t					GetEDID(edid1_info* edid,
68										bool forceRead = false);
69
70virtual	status_t					GetPLLLimits(pll_limits& limits);
71
72virtual status_t					SetDisplayMode(display_mode* mode,
73										uint32 colorMode) { return B_ERROR; };
74
75virtual pipe_index					PipePreference()
76										{ return INTEL_PIPE_ANY; };
77
78protected:
79		void						_SetName(const char* name);
80
81static	status_t					_GetI2CSignals(void* cookie, int* _clock,
82										int* _data);
83static	status_t					_SetI2CSignals(void* cookie, int clock,
84										int data);
85
86		display_mode				fCurrentMode;
87		Pipe*						fPipe;
88
89		status_t					fEDIDState;
90		edid1_info					fEDIDInfo;
91
92private:
93virtual	addr_t						_DDCRegister() = 0;
94virtual addr_t						_PortRegister() = 0;
95
96		port_index					fPortIndex;
97		char*						fPortName;
98};
99
100
101class AnalogPort : public Port {
102public:
103									AnalogPort();
104
105virtual	uint32						Type() const
106										{ return INTEL_PORT_TYPE_ANALOG; }
107
108virtual	bool						IsConnected();
109
110virtual status_t					SetDisplayMode(display_mode* mode,
111										uint32 colorMode);
112
113protected:
114virtual	addr_t						_DDCRegister();
115virtual addr_t						_PortRegister();
116};
117
118
119class LVDSPort : public Port {
120public:
121									LVDSPort();
122
123virtual	uint32						Type() const
124										{ return INTEL_PORT_TYPE_LVDS; }
125
126virtual	bool						IsConnected();
127
128virtual status_t					SetDisplayMode(display_mode* mode,
129										uint32 colorMode);
130
131virtual pipe_index					PipePreference();
132
133protected:
134virtual	addr_t						_DDCRegister();
135virtual addr_t						_PortRegister();
136};
137
138
139class DigitalPort : public Port {
140public:
141									DigitalPort(
142										port_index index = INTEL_PORT_B,
143										const char* baseName = "DVI");
144
145virtual	uint32						Type() const
146										{ return INTEL_PORT_TYPE_DVI; }
147
148virtual	bool						IsConnected();
149
150virtual status_t					SetDisplayMode(display_mode* mode,
151										uint32 colorMode);
152
153protected:
154virtual	addr_t						_DDCRegister();
155virtual addr_t						_PortRegister();
156};
157
158
159class HDMIPort : public DigitalPort {
160public:
161									HDMIPort(port_index index);
162
163virtual	uint32						Type() const
164										{ return INTEL_PORT_TYPE_HDMI; }
165
166virtual	bool						IsConnected();
167
168protected:
169virtual addr_t						_PortRegister();
170};
171
172
173class DisplayPort : public Port {
174public:
175									DisplayPort(port_index index,
176										const char* baseName = "DisplayPort");
177
178virtual	uint32						Type() const
179										{ return INTEL_PORT_TYPE_DP; }
180
181virtual	bool						IsConnected();
182
183virtual status_t					SetDisplayMode(display_mode* mode,
184										uint32 colorMode);
185
186protected:
187virtual	addr_t						_DDCRegister();
188virtual	addr_t						_PortRegister();
189};
190
191
192class EmbeddedDisplayPort : public DisplayPort {
193public:
194									EmbeddedDisplayPort();
195
196virtual	uint32						Type() const
197										{ return INTEL_PORT_TYPE_eDP; }
198
199virtual	bool						IsConnected();
200};
201
202
203class DigitalDisplayInterface : public Port {
204public:
205									DigitalDisplayInterface(
206										port_index index = INTEL_PORT_A,
207										const char* baseName = "Digital Display Interface");
208
209virtual	uint32						Type() const
210										{ return INTEL_PORT_TYPE_DVI; }
211
212virtual	status_t					Power(bool enabled);
213
214virtual	bool						IsConnected();
215
216virtual status_t					SetDisplayMode(display_mode* mode,
217										uint32 colorMode);
218
219protected:
220virtual	addr_t						_DDCRegister();
221virtual addr_t						_PortRegister();
222private:
223		uint8						fMaxLanes;
224};
225
226
227#endif // INTEL_PORTS_H
228