18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 138c2ecf20Sopenharmony_ci * Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 208c2ecf20Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 218c2ecf20Sopenharmony_ci * SOFTWARE. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Authors: 248c2ecf20Sopenharmony_ci * Ke Yu 258c2ecf20Sopenharmony_ci * Zhiyuan Lv <zhiyuan.lv@intel.com> 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * Contributors: 288c2ecf20Sopenharmony_ci * Terrence Xu <terrence.xu@intel.com> 298c2ecf20Sopenharmony_ci * Changbin Du <changbin.du@intel.com> 308c2ecf20Sopenharmony_ci * Bing Niu <bing.niu@intel.com> 318c2ecf20Sopenharmony_ci * Zhi Wang <zhi.a.wang@intel.com> 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#ifndef _GVT_EDID_H_ 368c2ecf20Sopenharmony_ci#define _GVT_EDID_H_ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/types.h> 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct intel_vgpu; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define EDID_SIZE 128 438c2ecf20Sopenharmony_ci#define EDID_ADDR 0x50 /* Linux hvm EDID addr */ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define GVT_AUX_NATIVE_WRITE 0x8 468c2ecf20Sopenharmony_ci#define GVT_AUX_NATIVE_READ 0x9 478c2ecf20Sopenharmony_ci#define GVT_AUX_I2C_WRITE 0x0 488c2ecf20Sopenharmony_ci#define GVT_AUX_I2C_READ 0x1 498c2ecf20Sopenharmony_ci#define GVT_AUX_I2C_STATUS 0x2 508c2ecf20Sopenharmony_ci#define GVT_AUX_I2C_MOT 0x4 518c2ecf20Sopenharmony_ci#define GVT_AUX_I2C_REPLY_ACK 0x0 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistruct intel_vgpu_edid_data { 548c2ecf20Sopenharmony_ci bool data_valid; 558c2ecf20Sopenharmony_ci unsigned char edid_block[EDID_SIZE]; 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cienum gmbus_cycle_type { 598c2ecf20Sopenharmony_ci GMBUS_NOCYCLE = 0x0, 608c2ecf20Sopenharmony_ci NIDX_NS_W = 0x1, 618c2ecf20Sopenharmony_ci IDX_NS_W = 0x3, 628c2ecf20Sopenharmony_ci GMBUS_STOP = 0x4, 638c2ecf20Sopenharmony_ci NIDX_STOP = 0x5, 648c2ecf20Sopenharmony_ci IDX_STOP = 0x7 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* 688c2ecf20Sopenharmony_ci * States of GMBUS 698c2ecf20Sopenharmony_ci * 708c2ecf20Sopenharmony_ci * GMBUS0-3 could be related to the EDID virtualization. Another two GMBUS 718c2ecf20Sopenharmony_ci * registers, GMBUS4 (interrupt mask) and GMBUS5 (2 byte indes register), are 728c2ecf20Sopenharmony_ci * not considered here. Below describes the usage of GMBUS registers that are 738c2ecf20Sopenharmony_ci * cared by the EDID virtualization 748c2ecf20Sopenharmony_ci * 758c2ecf20Sopenharmony_ci * GMBUS0: 768c2ecf20Sopenharmony_ci * R/W 778c2ecf20Sopenharmony_ci * port selection. value of bit0 - bit2 corresponds to the GPIO registers. 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * GMBUS1: 808c2ecf20Sopenharmony_ci * R/W Protect 818c2ecf20Sopenharmony_ci * Command and Status. 828c2ecf20Sopenharmony_ci * bit0 is the direction bit: 1 is read; 0 is write. 838c2ecf20Sopenharmony_ci * bit1 - bit7 is slave 7-bit address. 848c2ecf20Sopenharmony_ci * bit16 - bit24 total byte count (ignore?) 858c2ecf20Sopenharmony_ci * 868c2ecf20Sopenharmony_ci * GMBUS2: 878c2ecf20Sopenharmony_ci * Most of bits are read only except bit 15 (IN_USE) 888c2ecf20Sopenharmony_ci * Status register 898c2ecf20Sopenharmony_ci * bit0 - bit8 current byte count 908c2ecf20Sopenharmony_ci * bit 11: hardware ready; 918c2ecf20Sopenharmony_ci * 928c2ecf20Sopenharmony_ci * GMBUS3: 938c2ecf20Sopenharmony_ci * Read/Write 948c2ecf20Sopenharmony_ci * Data for transfer 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* From hw specs, Other phases like START, ADDRESS, INDEX 988c2ecf20Sopenharmony_ci * are invisible to GMBUS MMIO interface. So no definitions 998c2ecf20Sopenharmony_ci * in below enum types 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_cienum gvt_gmbus_phase { 1028c2ecf20Sopenharmony_ci GMBUS_IDLE_PHASE = 0, 1038c2ecf20Sopenharmony_ci GMBUS_DATA_PHASE, 1048c2ecf20Sopenharmony_ci GMBUS_WAIT_PHASE, 1058c2ecf20Sopenharmony_ci //GMBUS_STOP_PHASE, 1068c2ecf20Sopenharmony_ci GMBUS_MAX_PHASE 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistruct intel_vgpu_i2c_gmbus { 1108c2ecf20Sopenharmony_ci unsigned int total_byte_count; /* from GMBUS1 */ 1118c2ecf20Sopenharmony_ci enum gmbus_cycle_type cycle_type; 1128c2ecf20Sopenharmony_ci enum gvt_gmbus_phase phase; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct intel_vgpu_i2c_aux_ch { 1168c2ecf20Sopenharmony_ci bool i2c_over_aux_ch; 1178c2ecf20Sopenharmony_ci bool aux_ch_mot; 1188c2ecf20Sopenharmony_ci}; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cienum i2c_state { 1218c2ecf20Sopenharmony_ci I2C_NOT_SPECIFIED = 0, 1228c2ecf20Sopenharmony_ci I2C_GMBUS = 1, 1238c2ecf20Sopenharmony_ci I2C_AUX_CH = 2 1248c2ecf20Sopenharmony_ci}; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci/* I2C sequences cannot interleave. 1278c2ecf20Sopenharmony_ci * GMBUS and AUX_CH sequences cannot interleave. 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_cistruct intel_vgpu_i2c_edid { 1308c2ecf20Sopenharmony_ci enum i2c_state state; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci unsigned int port; 1338c2ecf20Sopenharmony_ci bool slave_selected; 1348c2ecf20Sopenharmony_ci bool edid_available; 1358c2ecf20Sopenharmony_ci unsigned int current_edid_read; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci struct intel_vgpu_i2c_gmbus gmbus; 1388c2ecf20Sopenharmony_ci struct intel_vgpu_i2c_aux_ch aux_ch; 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_civoid intel_vgpu_init_i2c_edid(struct intel_vgpu *vgpu); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ciint intel_gvt_i2c_handle_gmbus_read(struct intel_vgpu *vgpu, 1448c2ecf20Sopenharmony_ci unsigned int offset, void *p_data, unsigned int bytes); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ciint intel_gvt_i2c_handle_gmbus_write(struct intel_vgpu *vgpu, 1478c2ecf20Sopenharmony_ci unsigned int offset, void *p_data, unsigned int bytes); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_civoid intel_gvt_i2c_handle_aux_ch_write(struct intel_vgpu *vgpu, 1508c2ecf20Sopenharmony_ci int port_idx, 1518c2ecf20Sopenharmony_ci unsigned int offset, 1528c2ecf20Sopenharmony_ci void *p_data); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci#endif /*_GVT_EDID_H_*/ 155