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 status_t _SetupDpAuxI2c(struct i2c_bus *bus); 84 85 ssize_t _DpAuxTransfer(dp_aux_msg* message); 86 ssize_t _DpAuxTransfer(uint8* transmitBuffer, uint8 transmitSize, 87 uint8* receiveBuffer, uint8 receiveSize); 88 status_t _DpAuxSendReceive(uint32 slave_address, 89 const uint8 *writeBuffer, size_t writeLength, 90 uint8 *readBuffer, size_t readLength); 91 static status_t _DpAuxSendReceiveHook(const struct i2c_bus *bus, 92 uint32 slave_address, const uint8 *writeBuffer, 93 size_t writeLength, uint8 *readBuffer, 94 size_t readLength); 95 aux_channel _DpAuxChannel(); 96 97 display_mode fCurrentMode; 98 Pipe* fPipe; 99 100 status_t fEDIDState; 101 edid1_info fEDIDInfo; 102 103 private: 104 virtual addr_t _DDCRegister() = 0; 105 virtual addr_t _PortRegister() = 0; 106 107 port_index fPortIndex; 108 char* fPortName; 109 }; 110 111 112 class AnalogPort : public Port { 113 public: 114 AnalogPort(); 115 116 virtual uint32 Type() const 117 { return INTEL_PORT_TYPE_ANALOG; } 118 119 virtual bool IsConnected(); 120 121 virtual status_t SetDisplayMode(display_mode* mode, 122 uint32 colorMode); 123 124 protected: 125 virtual addr_t _DDCRegister(); 126 virtual addr_t _PortRegister(); 127 }; 128 129 130 class LVDSPort : public Port { 131 public: 132 LVDSPort(); 133 134 virtual uint32 Type() const 135 { return INTEL_PORT_TYPE_LVDS; } 136 137 virtual bool IsConnected(); 138 139 virtual status_t SetDisplayMode(display_mode* mode, 140 uint32 colorMode); 141 142 virtual pipe_index PipePreference(); 143 144 protected: 145 virtual addr_t _DDCRegister(); 146 virtual addr_t _PortRegister(); 147 }; 148 149 150 class DigitalPort : public Port { 151 public: 152 DigitalPort( 153 port_index index = INTEL_PORT_B, 154 const char* baseName = "DVI"); 155 156 virtual uint32 Type() const 157 { return INTEL_PORT_TYPE_DVI; } 158 159 virtual bool IsConnected(); 160 161 virtual status_t SetDisplayMode(display_mode* mode, 162 uint32 colorMode); 163 164 protected: 165 virtual addr_t _DDCRegister(); 166 virtual addr_t _PortRegister(); 167 }; 168 169 170 class HDMIPort : public DigitalPort { 171 public: 172 HDMIPort(port_index index); 173 174 virtual uint32 Type() const 175 { return INTEL_PORT_TYPE_HDMI; } 176 177 virtual bool IsConnected(); 178 179 protected: 180 virtual addr_t _PortRegister(); 181 }; 182 183 184 class DisplayPort : public Port { 185 public: 186 DisplayPort(port_index index, 187 const char* baseName = "DisplayPort"); 188 189 virtual uint32 Type() const 190 { return INTEL_PORT_TYPE_DP; } 191 192 virtual status_t SetPipe(Pipe* pipe); 193 virtual status_t SetupI2c(i2c_bus *bus); 194 195 virtual bool IsConnected(); 196 197 virtual status_t SetDisplayMode(display_mode* mode, 198 uint32 colorMode); 199 200 virtual pipe_index PipePreference(); 201 202 protected: 203 virtual addr_t _DDCRegister(); 204 virtual addr_t _PortRegister(); 205 206 private: 207 status_t _SetPortLinkGen4(const display_timing& timing); 208 status_t _SetPortLinkGen6(const display_timing& timing); 209 }; 210 211 212 class EmbeddedDisplayPort : public DisplayPort { 213 public: 214 EmbeddedDisplayPort(); 215 216 virtual uint32 Type() const 217 { return INTEL_PORT_TYPE_eDP; } 218 219 virtual bool IsConnected(); 220 }; 221 222 223 class DigitalDisplayInterface : public Port { 224 public: 225 DigitalDisplayInterface( 226 port_index index = INTEL_PORT_A, 227 const char* baseName = "Digital Display Interface"); 228 229 virtual uint32 Type() const 230 { return INTEL_PORT_TYPE_DVI; } 231 232 virtual status_t Power(bool enabled); 233 234 virtual status_t SetPipe(Pipe* pipe); 235 virtual status_t SetupI2c(i2c_bus *bus); 236 virtual status_t SetupI2cFallback(struct i2c_bus *bus); 237 238 virtual bool IsConnected(); 239 240 virtual status_t SetDisplayMode(display_mode* mode, 241 uint32 colorMode); 242 243 protected: 244 virtual addr_t _DDCRegister(); 245 virtual addr_t _PortRegister(); 246 private: 247 uint8 fMaxLanes; 248 249 status_t _SetPortLinkGen8(const display_timing& timing, 250 uint32 pllSel); 251 }; 252 253 254 #endif // INTEL_PORTS_H 255