Home | History | Annotate | Line # | Download | only in gvt
      1  1.1  riastrad /*	$NetBSD: edid.h,v 1.2 2021/12/18 23:45:31 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     14  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     15  1.1  riastrad  * Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     22  1.1  riastrad  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     23  1.1  riastrad  * SOFTWARE.
     24  1.1  riastrad  *
     25  1.1  riastrad  * Authors:
     26  1.1  riastrad  *    Ke Yu
     27  1.1  riastrad  *    Zhiyuan Lv <zhiyuan.lv (at) intel.com>
     28  1.1  riastrad  *
     29  1.1  riastrad  * Contributors:
     30  1.1  riastrad  *    Terrence Xu <terrence.xu (at) intel.com>
     31  1.1  riastrad  *    Changbin Du <changbin.du (at) intel.com>
     32  1.1  riastrad  *    Bing Niu <bing.niu (at) intel.com>
     33  1.1  riastrad  *    Zhi Wang <zhi.a.wang (at) intel.com>
     34  1.1  riastrad  *
     35  1.1  riastrad  */
     36  1.1  riastrad 
     37  1.1  riastrad #ifndef _GVT_EDID_H_
     38  1.1  riastrad #define _GVT_EDID_H_
     39  1.1  riastrad 
     40  1.1  riastrad #include <linux/types.h>
     41  1.1  riastrad 
     42  1.1  riastrad struct intel_vgpu;
     43  1.1  riastrad 
     44  1.1  riastrad #define EDID_SIZE		128
     45  1.1  riastrad #define EDID_ADDR		0x50 /* Linux hvm EDID addr */
     46  1.1  riastrad 
     47  1.1  riastrad #define GVT_AUX_NATIVE_WRITE			0x8
     48  1.1  riastrad #define GVT_AUX_NATIVE_READ			0x9
     49  1.1  riastrad #define GVT_AUX_I2C_WRITE			0x0
     50  1.1  riastrad #define GVT_AUX_I2C_READ			0x1
     51  1.1  riastrad #define GVT_AUX_I2C_STATUS			0x2
     52  1.1  riastrad #define GVT_AUX_I2C_MOT				0x4
     53  1.1  riastrad #define GVT_AUX_I2C_REPLY_ACK			0x0
     54  1.1  riastrad 
     55  1.1  riastrad struct intel_vgpu_edid_data {
     56  1.1  riastrad 	bool data_valid;
     57  1.1  riastrad 	unsigned char edid_block[EDID_SIZE];
     58  1.1  riastrad };
     59  1.1  riastrad 
     60  1.1  riastrad enum gmbus_cycle_type {
     61  1.1  riastrad 	GMBUS_NOCYCLE	= 0x0,
     62  1.1  riastrad 	NIDX_NS_W	= 0x1,
     63  1.1  riastrad 	IDX_NS_W	= 0x3,
     64  1.1  riastrad 	GMBUS_STOP	= 0x4,
     65  1.1  riastrad 	NIDX_STOP	= 0x5,
     66  1.1  riastrad 	IDX_STOP	= 0x7
     67  1.1  riastrad };
     68  1.1  riastrad 
     69  1.1  riastrad /*
     70  1.1  riastrad  * States of GMBUS
     71  1.1  riastrad  *
     72  1.1  riastrad  * GMBUS0-3 could be related to the EDID virtualization. Another two GMBUS
     73  1.1  riastrad  * registers, GMBUS4 (interrupt mask) and GMBUS5 (2 byte indes register), are
     74  1.1  riastrad  * not considered here. Below describes the usage of GMBUS registers that are
     75  1.1  riastrad  * cared by the EDID virtualization
     76  1.1  riastrad  *
     77  1.1  riastrad  * GMBUS0:
     78  1.1  riastrad  *      R/W
     79  1.1  riastrad  *      port selection. value of bit0 - bit2 corresponds to the GPIO registers.
     80  1.1  riastrad  *
     81  1.1  riastrad  * GMBUS1:
     82  1.1  riastrad  *      R/W Protect
     83  1.1  riastrad  *      Command and Status.
     84  1.1  riastrad  *      bit0 is the direction bit: 1 is read; 0 is write.
     85  1.1  riastrad  *      bit1 - bit7 is slave 7-bit address.
     86  1.1  riastrad  *      bit16 - bit24 total byte count (ignore?)
     87  1.1  riastrad  *
     88  1.1  riastrad  * GMBUS2:
     89  1.1  riastrad  *      Most of bits are read only except bit 15 (IN_USE)
     90  1.1  riastrad  *      Status register
     91  1.1  riastrad  *      bit0 - bit8 current byte count
     92  1.1  riastrad  *      bit 11: hardware ready;
     93  1.1  riastrad  *
     94  1.1  riastrad  * GMBUS3:
     95  1.1  riastrad  *      Read/Write
     96  1.1  riastrad  *      Data for transfer
     97  1.1  riastrad  */
     98  1.1  riastrad 
     99  1.1  riastrad /* From hw specs, Other phases like START, ADDRESS, INDEX
    100  1.1  riastrad  * are invisible to GMBUS MMIO interface. So no definitions
    101  1.1  riastrad  * in below enum types
    102  1.1  riastrad  */
    103  1.1  riastrad enum gvt_gmbus_phase {
    104  1.1  riastrad 	GMBUS_IDLE_PHASE = 0,
    105  1.1  riastrad 	GMBUS_DATA_PHASE,
    106  1.1  riastrad 	GMBUS_WAIT_PHASE,
    107  1.1  riastrad 	//GMBUS_STOP_PHASE,
    108  1.1  riastrad 	GMBUS_MAX_PHASE
    109  1.1  riastrad };
    110  1.1  riastrad 
    111  1.1  riastrad struct intel_vgpu_i2c_gmbus {
    112  1.1  riastrad 	unsigned int total_byte_count; /* from GMBUS1 */
    113  1.1  riastrad 	enum gmbus_cycle_type cycle_type;
    114  1.1  riastrad 	enum gvt_gmbus_phase phase;
    115  1.1  riastrad };
    116  1.1  riastrad 
    117  1.1  riastrad struct intel_vgpu_i2c_aux_ch {
    118  1.1  riastrad 	bool i2c_over_aux_ch;
    119  1.1  riastrad 	bool aux_ch_mot;
    120  1.1  riastrad };
    121  1.1  riastrad 
    122  1.1  riastrad enum i2c_state {
    123  1.1  riastrad 	I2C_NOT_SPECIFIED = 0,
    124  1.1  riastrad 	I2C_GMBUS = 1,
    125  1.1  riastrad 	I2C_AUX_CH = 2
    126  1.1  riastrad };
    127  1.1  riastrad 
    128  1.1  riastrad /* I2C sequences cannot interleave.
    129  1.1  riastrad  * GMBUS and AUX_CH sequences cannot interleave.
    130  1.1  riastrad  */
    131  1.1  riastrad struct intel_vgpu_i2c_edid {
    132  1.1  riastrad 	enum i2c_state state;
    133  1.1  riastrad 
    134  1.1  riastrad 	unsigned int port;
    135  1.1  riastrad 	bool slave_selected;
    136  1.1  riastrad 	bool edid_available;
    137  1.1  riastrad 	unsigned int current_edid_read;
    138  1.1  riastrad 
    139  1.1  riastrad 	struct intel_vgpu_i2c_gmbus gmbus;
    140  1.1  riastrad 	struct intel_vgpu_i2c_aux_ch aux_ch;
    141  1.1  riastrad };
    142  1.1  riastrad 
    143  1.1  riastrad void intel_vgpu_init_i2c_edid(struct intel_vgpu *vgpu);
    144  1.1  riastrad 
    145  1.1  riastrad int intel_gvt_i2c_handle_gmbus_read(struct intel_vgpu *vgpu,
    146  1.1  riastrad 		unsigned int offset, void *p_data, unsigned int bytes);
    147  1.1  riastrad 
    148  1.1  riastrad int intel_gvt_i2c_handle_gmbus_write(struct intel_vgpu *vgpu,
    149  1.1  riastrad 		unsigned int offset, void *p_data, unsigned int bytes);
    150  1.1  riastrad 
    151  1.1  riastrad void intel_gvt_i2c_handle_aux_ch_write(struct intel_vgpu *vgpu,
    152  1.1  riastrad 		int port_idx,
    153  1.1  riastrad 		unsigned int offset,
    154  1.1  riastrad 		void *p_data);
    155  1.1  riastrad 
    156  1.1  riastrad #endif /*_GVT_EDID_H_*/
    157