1 1.1 riastrad /* $NetBSD: drm_scdc_helper.h,v 1.2 2021/12/18 23:45:46 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright (c) 2015 NVIDIA 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, sub license, 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 14 1.1 riastrad * next paragraph) shall be included in all copies or substantial portions 15 1.1 riastrad * of the 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 NON-INFRINGEMENT. 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 22 1.1 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 1.1 riastrad * DEALINGS IN THE SOFTWARE. 24 1.1 riastrad */ 25 1.1 riastrad 26 1.1 riastrad #ifndef DRM_SCDC_HELPER_H 27 1.1 riastrad #define DRM_SCDC_HELPER_H 28 1.1 riastrad 29 1.1 riastrad #include <linux/i2c.h> 30 1.1 riastrad #include <linux/types.h> 31 1.1 riastrad 32 1.1 riastrad #define SCDC_SINK_VERSION 0x01 33 1.1 riastrad 34 1.1 riastrad #define SCDC_SOURCE_VERSION 0x02 35 1.1 riastrad 36 1.1 riastrad #define SCDC_UPDATE_0 0x10 37 1.1 riastrad #define SCDC_READ_REQUEST_TEST (1 << 2) 38 1.1 riastrad #define SCDC_CED_UPDATE (1 << 1) 39 1.1 riastrad #define SCDC_STATUS_UPDATE (1 << 0) 40 1.1 riastrad 41 1.1 riastrad #define SCDC_UPDATE_1 0x11 42 1.1 riastrad 43 1.1 riastrad #define SCDC_TMDS_CONFIG 0x20 44 1.1 riastrad #define SCDC_TMDS_BIT_CLOCK_RATIO_BY_40 (1 << 1) 45 1.1 riastrad #define SCDC_TMDS_BIT_CLOCK_RATIO_BY_10 (0 << 1) 46 1.1 riastrad #define SCDC_SCRAMBLING_ENABLE (1 << 0) 47 1.1 riastrad 48 1.1 riastrad #define SCDC_SCRAMBLER_STATUS 0x21 49 1.1 riastrad #define SCDC_SCRAMBLING_STATUS (1 << 0) 50 1.1 riastrad 51 1.1 riastrad #define SCDC_CONFIG_0 0x30 52 1.1 riastrad #define SCDC_READ_REQUEST_ENABLE (1 << 0) 53 1.1 riastrad 54 1.1 riastrad #define SCDC_STATUS_FLAGS_0 0x40 55 1.1 riastrad #define SCDC_CH2_LOCK (1 << 3) 56 1.1 riastrad #define SCDC_CH1_LOCK (1 << 2) 57 1.1 riastrad #define SCDC_CH0_LOCK (1 << 1) 58 1.1 riastrad #define SCDC_CH_LOCK_MASK (SCDC_CH2_LOCK | SCDC_CH1_LOCK | SCDC_CH0_LOCK) 59 1.1 riastrad #define SCDC_CLOCK_DETECT (1 << 0) 60 1.1 riastrad 61 1.1 riastrad #define SCDC_STATUS_FLAGS_1 0x41 62 1.1 riastrad 63 1.1 riastrad #define SCDC_ERR_DET_0_L 0x50 64 1.1 riastrad #define SCDC_ERR_DET_0_H 0x51 65 1.1 riastrad #define SCDC_ERR_DET_1_L 0x52 66 1.1 riastrad #define SCDC_ERR_DET_1_H 0x53 67 1.1 riastrad #define SCDC_ERR_DET_2_L 0x54 68 1.1 riastrad #define SCDC_ERR_DET_2_H 0x55 69 1.1 riastrad #define SCDC_CHANNEL_VALID (1 << 7) 70 1.1 riastrad 71 1.1 riastrad #define SCDC_ERR_DET_CHECKSUM 0x56 72 1.1 riastrad 73 1.1 riastrad #define SCDC_TEST_CONFIG_0 0xc0 74 1.1 riastrad #define SCDC_TEST_READ_REQUEST (1 << 7) 75 1.1 riastrad #define SCDC_TEST_READ_REQUEST_DELAY(x) ((x) & 0x7f) 76 1.1 riastrad 77 1.1 riastrad #define SCDC_MANUFACTURER_IEEE_OUI 0xd0 78 1.1 riastrad #define SCDC_MANUFACTURER_IEEE_OUI_SIZE 3 79 1.1 riastrad 80 1.1 riastrad #define SCDC_DEVICE_ID 0xd3 81 1.1 riastrad #define SCDC_DEVICE_ID_SIZE 8 82 1.1 riastrad 83 1.1 riastrad #define SCDC_DEVICE_HARDWARE_REVISION 0xdb 84 1.1 riastrad #define SCDC_GET_DEVICE_HARDWARE_REVISION_MAJOR(x) (((x) >> 4) & 0xf) 85 1.1 riastrad #define SCDC_GET_DEVICE_HARDWARE_REVISION_MINOR(x) (((x) >> 0) & 0xf) 86 1.1 riastrad 87 1.1 riastrad #define SCDC_DEVICE_SOFTWARE_MAJOR_REVISION 0xdc 88 1.1 riastrad #define SCDC_DEVICE_SOFTWARE_MINOR_REVISION 0xdd 89 1.1 riastrad 90 1.1 riastrad #define SCDC_MANUFACTURER_SPECIFIC 0xde 91 1.1 riastrad #define SCDC_MANUFACTURER_SPECIFIC_SIZE 34 92 1.1 riastrad 93 1.1 riastrad ssize_t drm_scdc_read(struct i2c_adapter *adapter, u8 offset, void *buffer, 94 1.1 riastrad size_t size); 95 1.1 riastrad ssize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset, 96 1.1 riastrad const void *buffer, size_t size); 97 1.1 riastrad 98 1.1 riastrad /** 99 1.1 riastrad * drm_scdc_readb - read a single byte from SCDC 100 1.1 riastrad * @adapter: I2C adapter 101 1.1 riastrad * @offset: offset of register to read 102 1.1 riastrad * @value: return location for the register value 103 1.1 riastrad * 104 1.1 riastrad * Reads a single byte from SCDC. This is a convenience wrapper around the 105 1.1 riastrad * drm_scdc_read() function. 106 1.1 riastrad * 107 1.1 riastrad * Returns: 108 1.1 riastrad * 0 on success or a negative error code on failure. 109 1.1 riastrad */ 110 1.1 riastrad static inline int drm_scdc_readb(struct i2c_adapter *adapter, u8 offset, 111 1.1 riastrad u8 *value) 112 1.1 riastrad { 113 1.1 riastrad return drm_scdc_read(adapter, offset, value, sizeof(*value)); 114 1.1 riastrad } 115 1.1 riastrad 116 1.1 riastrad /** 117 1.1 riastrad * drm_scdc_writeb - write a single byte to SCDC 118 1.1 riastrad * @adapter: I2C adapter 119 1.1 riastrad * @offset: offset of register to read 120 1.1 riastrad * @value: return location for the register value 121 1.1 riastrad * 122 1.1 riastrad * Writes a single byte to SCDC. This is a convenience wrapper around the 123 1.1 riastrad * drm_scdc_write() function. 124 1.1 riastrad * 125 1.1 riastrad * Returns: 126 1.1 riastrad * 0 on success or a negative error code on failure. 127 1.1 riastrad */ 128 1.1 riastrad static inline int drm_scdc_writeb(struct i2c_adapter *adapter, u8 offset, 129 1.1 riastrad u8 value) 130 1.1 riastrad { 131 1.1 riastrad return drm_scdc_write(adapter, offset, &value, sizeof(value)); 132 1.1 riastrad } 133 1.1 riastrad 134 1.1 riastrad bool drm_scdc_get_scrambling_status(struct i2c_adapter *adapter); 135 1.1 riastrad 136 1.1 riastrad bool drm_scdc_set_scrambling(struct i2c_adapter *adapter, bool enable); 137 1.1 riastrad bool drm_scdc_set_high_tmds_clock_ratio(struct i2c_adapter *adapter, bool set); 138 1.1 riastrad #endif 139