18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2015 NVIDIA 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, sub license, 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 128c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 138c2ecf20Sopenharmony_ci * of the 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 NON-INFRINGEMENT. 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 208c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 218c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#ifndef DRM_SCDC_HELPER_H 258c2ecf20Sopenharmony_ci#define DRM_SCDC_HELPER_H 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include <linux/i2c.h> 288c2ecf20Sopenharmony_ci#include <linux/types.h> 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define SCDC_SINK_VERSION 0x01 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define SCDC_SOURCE_VERSION 0x02 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define SCDC_UPDATE_0 0x10 358c2ecf20Sopenharmony_ci#define SCDC_READ_REQUEST_TEST (1 << 2) 368c2ecf20Sopenharmony_ci#define SCDC_CED_UPDATE (1 << 1) 378c2ecf20Sopenharmony_ci#define SCDC_STATUS_UPDATE (1 << 0) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define SCDC_UPDATE_1 0x11 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define SCDC_TMDS_CONFIG 0x20 428c2ecf20Sopenharmony_ci#define SCDC_TMDS_BIT_CLOCK_RATIO_BY_40 (1 << 1) 438c2ecf20Sopenharmony_ci#define SCDC_TMDS_BIT_CLOCK_RATIO_BY_10 (0 << 1) 448c2ecf20Sopenharmony_ci#define SCDC_SCRAMBLING_ENABLE (1 << 0) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define SCDC_SCRAMBLER_STATUS 0x21 478c2ecf20Sopenharmony_ci#define SCDC_SCRAMBLING_STATUS (1 << 0) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define SCDC_CONFIG_0 0x30 508c2ecf20Sopenharmony_ci#define SCDC_READ_REQUEST_ENABLE (1 << 0) 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define SCDC_STATUS_FLAGS_0 0x40 538c2ecf20Sopenharmony_ci#define SCDC_CH2_LOCK (1 << 3) 548c2ecf20Sopenharmony_ci#define SCDC_CH1_LOCK (1 << 2) 558c2ecf20Sopenharmony_ci#define SCDC_CH0_LOCK (1 << 1) 568c2ecf20Sopenharmony_ci#define SCDC_CH_LOCK_MASK (SCDC_CH2_LOCK | SCDC_CH1_LOCK | SCDC_CH0_LOCK) 578c2ecf20Sopenharmony_ci#define SCDC_CLOCK_DETECT (1 << 0) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define SCDC_STATUS_FLAGS_1 0x41 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define SCDC_ERR_DET_0_L 0x50 628c2ecf20Sopenharmony_ci#define SCDC_ERR_DET_0_H 0x51 638c2ecf20Sopenharmony_ci#define SCDC_ERR_DET_1_L 0x52 648c2ecf20Sopenharmony_ci#define SCDC_ERR_DET_1_H 0x53 658c2ecf20Sopenharmony_ci#define SCDC_ERR_DET_2_L 0x54 668c2ecf20Sopenharmony_ci#define SCDC_ERR_DET_2_H 0x55 678c2ecf20Sopenharmony_ci#define SCDC_CHANNEL_VALID (1 << 7) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define SCDC_ERR_DET_CHECKSUM 0x56 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define SCDC_TEST_CONFIG_0 0xc0 728c2ecf20Sopenharmony_ci#define SCDC_TEST_READ_REQUEST (1 << 7) 738c2ecf20Sopenharmony_ci#define SCDC_TEST_READ_REQUEST_DELAY(x) ((x) & 0x7f) 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define SCDC_MANUFACTURER_IEEE_OUI 0xd0 768c2ecf20Sopenharmony_ci#define SCDC_MANUFACTURER_IEEE_OUI_SIZE 3 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#define SCDC_DEVICE_ID 0xd3 798c2ecf20Sopenharmony_ci#define SCDC_DEVICE_ID_SIZE 8 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define SCDC_DEVICE_HARDWARE_REVISION 0xdb 828c2ecf20Sopenharmony_ci#define SCDC_GET_DEVICE_HARDWARE_REVISION_MAJOR(x) (((x) >> 4) & 0xf) 838c2ecf20Sopenharmony_ci#define SCDC_GET_DEVICE_HARDWARE_REVISION_MINOR(x) (((x) >> 0) & 0xf) 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define SCDC_DEVICE_SOFTWARE_MAJOR_REVISION 0xdc 868c2ecf20Sopenharmony_ci#define SCDC_DEVICE_SOFTWARE_MINOR_REVISION 0xdd 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define SCDC_MANUFACTURER_SPECIFIC 0xde 898c2ecf20Sopenharmony_ci#define SCDC_MANUFACTURER_SPECIFIC_SIZE 34 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cissize_t drm_scdc_read(struct i2c_adapter *adapter, u8 offset, void *buffer, 928c2ecf20Sopenharmony_ci size_t size); 938c2ecf20Sopenharmony_cissize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset, 948c2ecf20Sopenharmony_ci const void *buffer, size_t size); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/** 978c2ecf20Sopenharmony_ci * drm_scdc_readb - read a single byte from SCDC 988c2ecf20Sopenharmony_ci * @adapter: I2C adapter 998c2ecf20Sopenharmony_ci * @offset: offset of register to read 1008c2ecf20Sopenharmony_ci * @value: return location for the register value 1018c2ecf20Sopenharmony_ci * 1028c2ecf20Sopenharmony_ci * Reads a single byte from SCDC. This is a convenience wrapper around the 1038c2ecf20Sopenharmony_ci * drm_scdc_read() function. 1048c2ecf20Sopenharmony_ci * 1058c2ecf20Sopenharmony_ci * Returns: 1068c2ecf20Sopenharmony_ci * 0 on success or a negative error code on failure. 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_cistatic inline int drm_scdc_readb(struct i2c_adapter *adapter, u8 offset, 1098c2ecf20Sopenharmony_ci u8 *value) 1108c2ecf20Sopenharmony_ci{ 1118c2ecf20Sopenharmony_ci return drm_scdc_read(adapter, offset, value, sizeof(*value)); 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/** 1158c2ecf20Sopenharmony_ci * drm_scdc_writeb - write a single byte to SCDC 1168c2ecf20Sopenharmony_ci * @adapter: I2C adapter 1178c2ecf20Sopenharmony_ci * @offset: offset of register to read 1188c2ecf20Sopenharmony_ci * @value: return location for the register value 1198c2ecf20Sopenharmony_ci * 1208c2ecf20Sopenharmony_ci * Writes a single byte to SCDC. This is a convenience wrapper around the 1218c2ecf20Sopenharmony_ci * drm_scdc_write() function. 1228c2ecf20Sopenharmony_ci * 1238c2ecf20Sopenharmony_ci * Returns: 1248c2ecf20Sopenharmony_ci * 0 on success or a negative error code on failure. 1258c2ecf20Sopenharmony_ci */ 1268c2ecf20Sopenharmony_cistatic inline int drm_scdc_writeb(struct i2c_adapter *adapter, u8 offset, 1278c2ecf20Sopenharmony_ci u8 value) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci return drm_scdc_write(adapter, offset, &value, sizeof(value)); 1308c2ecf20Sopenharmony_ci} 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cibool drm_scdc_get_scrambling_status(struct i2c_adapter *adapter); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cibool drm_scdc_set_scrambling(struct i2c_adapter *adapter, bool enable); 1358c2ecf20Sopenharmony_cibool drm_scdc_set_high_tmds_clock_ratio(struct i2c_adapter *adapter, bool set); 1368c2ecf20Sopenharmony_ci#endif 137