Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef _DP_CATALOG_H_ |
| 16 | #define _DP_CATALOG_H_ |
| 17 | |
Ajay Singh Parmar | 9c842d4 | 2017-09-21 13:02:05 -0700 | [diff] [blame] | 18 | #include <drm/msm_drm.h> |
| 19 | |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 20 | #include "dp_parser.h" |
| 21 | |
| 22 | /* interrupts */ |
| 23 | #define DP_INTR_HPD BIT(0) |
| 24 | #define DP_INTR_AUX_I2C_DONE BIT(3) |
| 25 | #define DP_INTR_WRONG_ADDR BIT(6) |
| 26 | #define DP_INTR_TIMEOUT BIT(9) |
| 27 | #define DP_INTR_NACK_DEFER BIT(12) |
| 28 | #define DP_INTR_WRONG_DATA_CNT BIT(15) |
| 29 | #define DP_INTR_I2C_NACK BIT(18) |
| 30 | #define DP_INTR_I2C_DEFER BIT(21) |
| 31 | #define DP_INTR_PLL_UNLOCKED BIT(24) |
| 32 | #define DP_INTR_AUX_ERROR BIT(27) |
| 33 | |
| 34 | #define DP_INTR_READY_FOR_VIDEO BIT(0) |
| 35 | #define DP_INTR_IDLE_PATTERN_SENT BIT(3) |
| 36 | #define DP_INTR_FRAME_END BIT(6) |
| 37 | #define DP_INTR_CRC_UPDATED BIT(9) |
| 38 | |
Ajay Singh Parmar | 059d0e0 | 2017-09-13 11:37:40 -0700 | [diff] [blame] | 39 | struct dp_catalog_hdr_data { |
Ajay Singh Parmar | 7e72436 | 2017-11-05 00:06:30 -0700 | [diff] [blame] | 40 | u32 ext_header_byte0; |
| 41 | u32 ext_header_byte1; |
| 42 | u32 ext_header_byte2; |
| 43 | u32 ext_header_byte3; |
| 44 | |
Ajay Singh Parmar | 9c842d4 | 2017-09-21 13:02:05 -0700 | [diff] [blame] | 45 | u32 vsc_header_byte0; |
| 46 | u32 vsc_header_byte1; |
| 47 | u32 vsc_header_byte2; |
| 48 | u32 vsc_header_byte3; |
| 49 | |
| 50 | u32 vscext_header_byte0; |
| 51 | u32 vscext_header_byte1; |
| 52 | u32 vscext_header_byte2; |
| 53 | u32 vscext_header_byte3; |
Ajay Singh Parmar | 059d0e0 | 2017-09-13 11:37:40 -0700 | [diff] [blame] | 54 | |
| 55 | u32 bpc; |
| 56 | |
| 57 | u32 version; |
| 58 | u32 length; |
Ajay Singh Parmar | 9c842d4 | 2017-09-21 13:02:05 -0700 | [diff] [blame] | 59 | u32 pixel_encoding; |
| 60 | u32 colorimetry; |
| 61 | u32 dynamic_range; |
| 62 | u32 content_type; |
Ajay Singh Parmar | 059d0e0 | 2017-09-13 11:37:40 -0700 | [diff] [blame] | 63 | |
Ajay Singh Parmar | 9c842d4 | 2017-09-21 13:02:05 -0700 | [diff] [blame] | 64 | struct drm_msm_ext_hdr_metadata hdr_meta; |
Ajay Singh Parmar | 059d0e0 | 2017-09-13 11:37:40 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 67 | struct dp_catalog_aux { |
| 68 | u32 data; |
Padmanabhan Komanduru | 15e757d | 2017-05-24 04:07:31 -0700 | [diff] [blame] | 69 | u32 isr; |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 70 | |
| 71 | u32 (*read_data)(struct dp_catalog_aux *aux); |
| 72 | int (*write_data)(struct dp_catalog_aux *aux); |
| 73 | int (*write_trans)(struct dp_catalog_aux *aux); |
Tatenda Chipeperekwa | 1a43e70 | 2017-09-15 15:45:16 -0700 | [diff] [blame] | 74 | int (*clear_trans)(struct dp_catalog_aux *aux, bool read); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 75 | void (*reset)(struct dp_catalog_aux *aux); |
| 76 | void (*enable)(struct dp_catalog_aux *aux, bool enable); |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 77 | void (*update_aux_cfg)(struct dp_catalog_aux *aux, |
| 78 | struct dp_aux_cfg *cfg, enum dp_phy_aux_config_type type); |
Padmanabhan Komanduru | 20a21db | 2017-07-10 16:58:59 +0530 | [diff] [blame] | 79 | void (*setup)(struct dp_catalog_aux *aux, |
| 80 | struct dp_aux_cfg *aux_cfg); |
Padmanabhan Komanduru | 15e757d | 2017-05-24 04:07:31 -0700 | [diff] [blame] | 81 | void (*get_irq)(struct dp_catalog_aux *aux, bool cmd_busy); |
Padmanabhan Komanduru | f69e357 | 2017-09-27 20:39:32 +0530 | [diff] [blame] | 82 | void (*clear_hw_interrupts)(struct dp_catalog_aux *aux); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | struct dp_catalog_ctrl { |
| 86 | u32 dp_tu; |
| 87 | u32 valid_boundary; |
| 88 | u32 valid_boundary2; |
Padmanabhan Komanduru | 15e757d | 2017-05-24 04:07:31 -0700 | [diff] [blame] | 89 | u32 isr; |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 90 | |
| 91 | void (*state_ctrl)(struct dp_catalog_ctrl *ctrl, u32 state); |
| 92 | void (*config_ctrl)(struct dp_catalog_ctrl *ctrl, u32 config); |
| 93 | void (*lane_mapping)(struct dp_catalog_ctrl *ctrl); |
| 94 | void (*mainlink_ctrl)(struct dp_catalog_ctrl *ctrl, bool enable); |
| 95 | void (*config_misc)(struct dp_catalog_ctrl *ctrl, u32 cc, u32 tb); |
Aravind Venkateswaran | 7599a99 | 2017-08-10 14:17:57 -0700 | [diff] [blame] | 96 | void (*config_msa)(struct dp_catalog_ctrl *ctrl, u32 rate, |
| 97 | u32 stream_rate_khz, bool fixed_nvid); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 98 | void (*set_pattern)(struct dp_catalog_ctrl *ctrl, u32 pattern); |
| 99 | void (*reset)(struct dp_catalog_ctrl *ctrl); |
Padmanabhan Komanduru | b6117bd | 2017-05-11 20:18:40 -0700 | [diff] [blame] | 100 | void (*usb_reset)(struct dp_catalog_ctrl *ctrl, bool flip); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 101 | bool (*mainlink_ready)(struct dp_catalog_ctrl *ctrl); |
| 102 | void (*enable_irq)(struct dp_catalog_ctrl *ctrl, bool enable); |
| 103 | void (*hpd_config)(struct dp_catalog_ctrl *ctrl, bool enable); |
| 104 | void (*phy_reset)(struct dp_catalog_ctrl *ctrl); |
| 105 | void (*phy_lane_cfg)(struct dp_catalog_ctrl *ctrl, bool flipped, |
| 106 | u8 lane_cnt); |
| 107 | void (*update_vx_px)(struct dp_catalog_ctrl *ctrl, u8 v_level, |
| 108 | u8 p_level); |
Padmanabhan Komanduru | 15e757d | 2017-05-24 04:07:31 -0700 | [diff] [blame] | 109 | void (*get_interrupt)(struct dp_catalog_ctrl *ctrl); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 110 | void (*update_transfer_unit)(struct dp_catalog_ctrl *ctrl); |
Tatenda Chipeperekwa | 3954736 | 2017-07-07 17:44:09 -0700 | [diff] [blame] | 111 | u32 (*read_hdcp_status)(struct dp_catalog_ctrl *ctrl); |
Tatenda Chipeperekwa | 8ce1d5f | 2017-08-07 18:44:21 -0700 | [diff] [blame] | 112 | void (*send_phy_pattern)(struct dp_catalog_ctrl *ctrl, |
| 113 | u32 pattern); |
| 114 | u32 (*read_phy_pattern)(struct dp_catalog_ctrl *ctrl); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Padmanabhan Komanduru | 62a01d0 | 2017-11-03 19:44:13 +0530 | [diff] [blame] | 117 | #define HEADER_BYTE_2_BIT 0 |
| 118 | #define PARITY_BYTE_2_BIT 8 |
| 119 | #define HEADER_BYTE_1_BIT 16 |
| 120 | #define PARITY_BYTE_1_BIT 24 |
| 121 | #define HEADER_BYTE_3_BIT 16 |
| 122 | #define PARITY_BYTE_3_BIT 24 |
| 123 | |
Tatenda Chipeperekwa | 758dea0 | 2017-04-28 12:26:31 -0700 | [diff] [blame] | 124 | enum dp_catalog_audio_sdp_type { |
| 125 | DP_AUDIO_SDP_STREAM, |
| 126 | DP_AUDIO_SDP_TIMESTAMP, |
| 127 | DP_AUDIO_SDP_INFOFRAME, |
| 128 | DP_AUDIO_SDP_COPYMANAGEMENT, |
| 129 | DP_AUDIO_SDP_ISRC, |
| 130 | DP_AUDIO_SDP_MAX, |
| 131 | }; |
| 132 | |
| 133 | enum dp_catalog_audio_header_type { |
| 134 | DP_AUDIO_SDP_HEADER_1, |
| 135 | DP_AUDIO_SDP_HEADER_2, |
| 136 | DP_AUDIO_SDP_HEADER_3, |
| 137 | DP_AUDIO_SDP_HEADER_MAX, |
| 138 | }; |
| 139 | |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 140 | struct dp_catalog_audio { |
Tatenda Chipeperekwa | 758dea0 | 2017-04-28 12:26:31 -0700 | [diff] [blame] | 141 | enum dp_catalog_audio_sdp_type sdp_type; |
| 142 | enum dp_catalog_audio_header_type sdp_header; |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 143 | u32 data; |
| 144 | |
Tatenda Chipeperekwa | 758dea0 | 2017-04-28 12:26:31 -0700 | [diff] [blame] | 145 | void (*init)(struct dp_catalog_audio *audio); |
| 146 | void (*enable)(struct dp_catalog_audio *audio); |
| 147 | void (*config_acr)(struct dp_catalog_audio *audio); |
| 148 | void (*config_sdp)(struct dp_catalog_audio *audio); |
| 149 | void (*set_header)(struct dp_catalog_audio *audio); |
| 150 | void (*get_header)(struct dp_catalog_audio *audio); |
| 151 | void (*safe_to_exit_level)(struct dp_catalog_audio *audio); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct dp_catalog_panel { |
| 155 | u32 total; |
| 156 | u32 sync_start; |
| 157 | u32 width_blanking; |
| 158 | u32 dp_active; |
Padmanabhan Komanduru | 62a01d0 | 2017-11-03 19:44:13 +0530 | [diff] [blame] | 159 | u8 *spd_vendor_name; |
| 160 | u8 *spd_product_description; |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 161 | |
Ajay Singh Parmar | 9c842d4 | 2017-09-21 13:02:05 -0700 | [diff] [blame] | 162 | struct dp_catalog_hdr_data hdr_data; |
| 163 | |
Padmanabhan Komanduru | 04aa2a7 | 2017-11-06 17:59:24 +0530 | [diff] [blame] | 164 | /* TPG */ |
| 165 | u32 hsync_period; |
| 166 | u32 vsync_period; |
| 167 | u32 display_v_start; |
| 168 | u32 display_v_end; |
| 169 | u32 v_sync_width; |
| 170 | u32 hsync_ctl; |
| 171 | u32 display_hctl; |
| 172 | |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 173 | int (*timing_cfg)(struct dp_catalog_panel *panel); |
Ajay Singh Parmar | 973cab1 | 2017-11-15 15:33:33 -0800 | [diff] [blame] | 174 | void (*config_hdr)(struct dp_catalog_panel *panel, bool en); |
Padmanabhan Komanduru | 04aa2a7 | 2017-11-06 17:59:24 +0530 | [diff] [blame] | 175 | void (*tpg_config)(struct dp_catalog_panel *panel, bool enable); |
Padmanabhan Komanduru | 62a01d0 | 2017-11-03 19:44:13 +0530 | [diff] [blame] | 176 | void (*config_spd)(struct dp_catalog_panel *panel); |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | struct dp_catalog { |
| 180 | struct dp_catalog_aux aux; |
| 181 | struct dp_catalog_ctrl ctrl; |
| 182 | struct dp_catalog_audio audio; |
| 183 | struct dp_catalog_panel panel; |
| 184 | }; |
| 185 | |
Padmanabhan Komanduru | 62a01d0 | 2017-11-03 19:44:13 +0530 | [diff] [blame] | 186 | static inline u8 dp_ecc_get_g0_value(u8 data) |
| 187 | { |
| 188 | u8 c[4]; |
| 189 | u8 g[4]; |
| 190 | u8 ret_data = 0; |
| 191 | u8 i; |
| 192 | |
| 193 | for (i = 0; i < 4; i++) |
| 194 | c[i] = (data >> i) & 0x01; |
| 195 | |
| 196 | g[0] = c[3]; |
| 197 | g[1] = c[0] ^ c[3]; |
| 198 | g[2] = c[1]; |
| 199 | g[3] = c[2]; |
| 200 | |
| 201 | for (i = 0; i < 4; i++) |
| 202 | ret_data = ((g[i] & 0x01) << i) | ret_data; |
| 203 | |
| 204 | return ret_data; |
| 205 | } |
| 206 | |
| 207 | static inline u8 dp_ecc_get_g1_value(u8 data) |
| 208 | { |
| 209 | u8 c[4]; |
| 210 | u8 g[4]; |
| 211 | u8 ret_data = 0; |
| 212 | u8 i; |
| 213 | |
| 214 | for (i = 0; i < 4; i++) |
| 215 | c[i] = (data >> i) & 0x01; |
| 216 | |
| 217 | g[0] = c[0] ^ c[3]; |
| 218 | g[1] = c[0] ^ c[1] ^ c[3]; |
| 219 | g[2] = c[1] ^ c[2]; |
| 220 | g[3] = c[2] ^ c[3]; |
| 221 | |
| 222 | for (i = 0; i < 4; i++) |
| 223 | ret_data = ((g[i] & 0x01) << i) | ret_data; |
| 224 | |
| 225 | return ret_data; |
| 226 | } |
| 227 | |
| 228 | static inline u8 dp_header_get_parity(u32 data) |
| 229 | { |
| 230 | u8 x0 = 0; |
| 231 | u8 x1 = 0; |
| 232 | u8 ci = 0; |
| 233 | u8 iData = 0; |
| 234 | u8 i = 0; |
| 235 | u8 parity_byte; |
| 236 | u8 num_byte = (data & 0xFF00) > 0 ? 8 : 2; |
| 237 | |
| 238 | for (i = 0; i < num_byte; i++) { |
| 239 | iData = (data >> i*4) & 0xF; |
| 240 | |
| 241 | ci = iData ^ x1; |
| 242 | x1 = x0 ^ dp_ecc_get_g1_value(ci); |
| 243 | x0 = dp_ecc_get_g0_value(ci); |
| 244 | } |
| 245 | |
| 246 | parity_byte = x1 | (x0 << 4); |
| 247 | |
| 248 | return parity_byte; |
| 249 | } |
| 250 | |
Ajay Singh Parmar | bd3097f | 2017-03-29 15:04:13 -0700 | [diff] [blame] | 251 | struct dp_catalog *dp_catalog_get(struct device *dev, struct dp_io *io); |
| 252 | void dp_catalog_put(struct dp_catalog *catalog); |
| 253 | |
| 254 | #endif /* _DP_CATALOG_H_ */ |