xref: /openbmc/linux/drivers/gpu/drm/i915/gvt/edid.h (revision 8dd06ef34b6e2f41b29fbf5fc1663780f2524285)
104d348aeSZhi Wang /*
204d348aeSZhi Wang  * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
304d348aeSZhi Wang  *
404d348aeSZhi Wang  * Permission is hereby granted, free of charge, to any person obtaining a
504d348aeSZhi Wang  * copy of this software and associated documentation files (the "Software"),
604d348aeSZhi Wang  * to deal in the Software without restriction, including without limitation
704d348aeSZhi Wang  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
804d348aeSZhi Wang  * and/or sell copies of the Software, and to permit persons to whom the
904d348aeSZhi Wang  * Software is furnished to do so, subject to the following conditions:
1004d348aeSZhi Wang  *
1104d348aeSZhi Wang  * The above copyright notice and this permission notice (including the next
1204d348aeSZhi Wang  * paragraph) shall be included in all copies or substantial portions of the
1304d348aeSZhi Wang  * Software.
1404d348aeSZhi Wang  *
1504d348aeSZhi Wang  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1604d348aeSZhi Wang  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1704d348aeSZhi Wang  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1804d348aeSZhi Wang  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1904d348aeSZhi Wang  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2004d348aeSZhi Wang  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2104d348aeSZhi Wang  * SOFTWARE.
2204d348aeSZhi Wang  *
2304d348aeSZhi Wang  * Authors:
2404d348aeSZhi Wang  *    Ke Yu
2504d348aeSZhi Wang  *    Zhiyuan Lv <zhiyuan.lv@intel.com>
2604d348aeSZhi Wang  *
2704d348aeSZhi Wang  * Contributors:
2804d348aeSZhi Wang  *    Terrence Xu <terrence.xu@intel.com>
2904d348aeSZhi Wang  *    Changbin Du <changbin.du@intel.com>
3004d348aeSZhi Wang  *    Bing Niu <bing.niu@intel.com>
3104d348aeSZhi Wang  *    Zhi Wang <zhi.a.wang@intel.com>
3204d348aeSZhi Wang  *
3304d348aeSZhi Wang  */
3404d348aeSZhi Wang 
3504d348aeSZhi Wang #ifndef _GVT_EDID_H_
3604d348aeSZhi Wang #define _GVT_EDID_H_
3704d348aeSZhi Wang 
38*ab11a927SMasahiro Yamada #include <linux/types.h>
39*ab11a927SMasahiro Yamada 
40*ab11a927SMasahiro Yamada struct intel_vgpu;
41*ab11a927SMasahiro Yamada 
4204d348aeSZhi Wang #define EDID_SIZE		128
4304d348aeSZhi Wang #define EDID_ADDR		0x50 /* Linux hvm EDID addr */
4404d348aeSZhi Wang 
4504d348aeSZhi Wang #define GVT_AUX_NATIVE_WRITE			0x8
4604d348aeSZhi Wang #define GVT_AUX_NATIVE_READ			0x9
4704d348aeSZhi Wang #define GVT_AUX_I2C_WRITE			0x0
4804d348aeSZhi Wang #define GVT_AUX_I2C_READ			0x1
4904d348aeSZhi Wang #define GVT_AUX_I2C_STATUS			0x2
5004d348aeSZhi Wang #define GVT_AUX_I2C_MOT				0x4
51ee145f66SZhenyu Wang #define GVT_AUX_I2C_REPLY_ACK			0x0
5204d348aeSZhi Wang 
5304d348aeSZhi Wang struct intel_vgpu_edid_data {
5404d348aeSZhi Wang 	bool data_valid;
5504d348aeSZhi Wang 	unsigned char edid_block[EDID_SIZE];
5604d348aeSZhi Wang };
5704d348aeSZhi Wang 
5804d348aeSZhi Wang enum gmbus_cycle_type {
5904d348aeSZhi Wang 	GMBUS_NOCYCLE	= 0x0,
6004d348aeSZhi Wang 	NIDX_NS_W	= 0x1,
6104d348aeSZhi Wang 	IDX_NS_W	= 0x3,
6204d348aeSZhi Wang 	GMBUS_STOP	= 0x4,
6304d348aeSZhi Wang 	NIDX_STOP	= 0x5,
6404d348aeSZhi Wang 	IDX_STOP	= 0x7
6504d348aeSZhi Wang };
6604d348aeSZhi Wang 
6704d348aeSZhi Wang /*
6804d348aeSZhi Wang  * States of GMBUS
6904d348aeSZhi Wang  *
7004d348aeSZhi Wang  * GMBUS0-3 could be related to the EDID virtualization. Another two GMBUS
7104d348aeSZhi Wang  * registers, GMBUS4 (interrupt mask) and GMBUS5 (2 byte indes register), are
7204d348aeSZhi Wang  * not considered here. Below describes the usage of GMBUS registers that are
7304d348aeSZhi Wang  * cared by the EDID virtualization
7404d348aeSZhi Wang  *
7504d348aeSZhi Wang  * GMBUS0:
7604d348aeSZhi Wang  *      R/W
7704d348aeSZhi Wang  *      port selection. value of bit0 - bit2 corresponds to the GPIO registers.
7804d348aeSZhi Wang  *
7904d348aeSZhi Wang  * GMBUS1:
8004d348aeSZhi Wang  *      R/W Protect
8104d348aeSZhi Wang  *      Command and Status.
8204d348aeSZhi Wang  *      bit0 is the direction bit: 1 is read; 0 is write.
8304d348aeSZhi Wang  *      bit1 - bit7 is slave 7-bit address.
8404d348aeSZhi Wang  *      bit16 - bit24 total byte count (ignore?)
8504d348aeSZhi Wang  *
8604d348aeSZhi Wang  * GMBUS2:
8704d348aeSZhi Wang  *      Most of bits are read only except bit 15 (IN_USE)
8804d348aeSZhi Wang  *      Status register
8904d348aeSZhi Wang  *      bit0 - bit8 current byte count
9004d348aeSZhi Wang  *      bit 11: hardware ready;
9104d348aeSZhi Wang  *
9204d348aeSZhi Wang  * GMBUS3:
9304d348aeSZhi Wang  *      Read/Write
9404d348aeSZhi Wang  *      Data for transfer
9504d348aeSZhi Wang  */
9604d348aeSZhi Wang 
9704d348aeSZhi Wang /* From hw specs, Other phases like START, ADDRESS, INDEX
9804d348aeSZhi Wang  * are invisible to GMBUS MMIO interface. So no definitions
9904d348aeSZhi Wang  * in below enum types
10004d348aeSZhi Wang  */
10104d348aeSZhi Wang enum gvt_gmbus_phase {
10204d348aeSZhi Wang 	GMBUS_IDLE_PHASE = 0,
10304d348aeSZhi Wang 	GMBUS_DATA_PHASE,
10404d348aeSZhi Wang 	GMBUS_WAIT_PHASE,
10504d348aeSZhi Wang 	//GMBUS_STOP_PHASE,
10604d348aeSZhi Wang 	GMBUS_MAX_PHASE
10704d348aeSZhi Wang };
10804d348aeSZhi Wang 
10904d348aeSZhi Wang struct intel_vgpu_i2c_gmbus {
11004d348aeSZhi Wang 	unsigned int total_byte_count; /* from GMBUS1 */
11104d348aeSZhi Wang 	enum gmbus_cycle_type cycle_type;
11204d348aeSZhi Wang 	enum gvt_gmbus_phase phase;
11304d348aeSZhi Wang };
11404d348aeSZhi Wang 
11504d348aeSZhi Wang struct intel_vgpu_i2c_aux_ch {
11604d348aeSZhi Wang 	bool i2c_over_aux_ch;
11704d348aeSZhi Wang 	bool aux_ch_mot;
11804d348aeSZhi Wang };
11904d348aeSZhi Wang 
12004d348aeSZhi Wang enum i2c_state {
12104d348aeSZhi Wang 	I2C_NOT_SPECIFIED = 0,
12204d348aeSZhi Wang 	I2C_GMBUS = 1,
12304d348aeSZhi Wang 	I2C_AUX_CH = 2
12404d348aeSZhi Wang };
12504d348aeSZhi Wang 
12604d348aeSZhi Wang /* I2C sequences cannot interleave.
12704d348aeSZhi Wang  * GMBUS and AUX_CH sequences cannot interleave.
12804d348aeSZhi Wang  */
12904d348aeSZhi Wang struct intel_vgpu_i2c_edid {
13004d348aeSZhi Wang 	enum i2c_state state;
13104d348aeSZhi Wang 
13204d348aeSZhi Wang 	unsigned int port;
13304d348aeSZhi Wang 	bool slave_selected;
13404d348aeSZhi Wang 	bool edid_available;
13504d348aeSZhi Wang 	unsigned int current_edid_read;
13604d348aeSZhi Wang 
13704d348aeSZhi Wang 	struct intel_vgpu_i2c_gmbus gmbus;
13804d348aeSZhi Wang 	struct intel_vgpu_i2c_aux_ch aux_ch;
13904d348aeSZhi Wang };
14004d348aeSZhi Wang 
14104d348aeSZhi Wang void intel_vgpu_init_i2c_edid(struct intel_vgpu *vgpu);
14204d348aeSZhi Wang 
14304d348aeSZhi Wang int intel_gvt_i2c_handle_gmbus_read(struct intel_vgpu *vgpu,
14404d348aeSZhi Wang 		unsigned int offset, void *p_data, unsigned int bytes);
14504d348aeSZhi Wang 
14604d348aeSZhi Wang int intel_gvt_i2c_handle_gmbus_write(struct intel_vgpu *vgpu,
14704d348aeSZhi Wang 		unsigned int offset, void *p_data, unsigned int bytes);
14804d348aeSZhi Wang 
14904d348aeSZhi Wang void intel_gvt_i2c_handle_aux_ch_write(struct intel_vgpu *vgpu,
15004d348aeSZhi Wang 		int port_idx,
15104d348aeSZhi Wang 		unsigned int offset,
15204d348aeSZhi Wang 		void *p_data);
15304d348aeSZhi Wang 
15404d348aeSZhi Wang #endif /*_GVT_EDID_H_*/
155