Rishabh Bhatnagar | e9a05bb | 2018-12-10 11:09:45 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 2 | /* |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 3 | * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _DP_PANEL_H_ |
| 7 | #define _DP_PANEL_H_ |
| 8 | |
| 9 | #include <drm/msm_drm.h> |
| 10 | |
| 11 | #include "dp_aux.h" |
| 12 | #include "dp_link.h" |
| 13 | #include "dp_usbpd.h" |
| 14 | #include "sde_edid_parser.h" |
| 15 | #include "sde_connector.h" |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 16 | #include "msm_drv.h" |
| 17 | |
| 18 | #define DP_RECEIVER_DSC_CAP_SIZE 15 |
| 19 | #define DP_RECEIVER_FEC_STATUS_SIZE 3 |
| 20 | |
| 21 | /* |
| 22 | * A source initiated power down flag is set |
| 23 | * when the DP is powered off while physical |
| 24 | * DP cable is still connected i.e. without |
| 25 | * HPD or not initiated by sink like HPD_IRQ. |
| 26 | * This can happen if framework reboots or |
| 27 | * device suspends. |
| 28 | */ |
| 29 | #define DP_PANEL_SRC_INITIATED_POWER_DOWN BIT(0) |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 30 | |
| 31 | enum dp_lane_count { |
| 32 | DP_LANE_COUNT_1 = 1, |
| 33 | DP_LANE_COUNT_2 = 2, |
| 34 | DP_LANE_COUNT_4 = 4, |
| 35 | }; |
| 36 | |
| 37 | #define DP_MAX_DOWNSTREAM_PORTS 0x10 |
| 38 | |
| 39 | struct dp_panel_info { |
| 40 | u32 h_active; |
| 41 | u32 v_active; |
| 42 | u32 h_back_porch; |
| 43 | u32 h_front_porch; |
| 44 | u32 h_sync_width; |
| 45 | u32 h_active_low; |
| 46 | u32 v_back_porch; |
| 47 | u32 v_front_porch; |
| 48 | u32 v_sync_width; |
| 49 | u32 v_active_low; |
| 50 | u32 h_skew; |
| 51 | u32 refresh_rate; |
| 52 | u32 pixel_clk_khz; |
| 53 | u32 bpp; |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 54 | bool widebus_en; |
| 55 | struct msm_compression_info comp_info; |
| 56 | s64 dsc_overhead_fp; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct dp_display_mode { |
| 60 | struct dp_panel_info timing; |
| 61 | u32 capabilities; |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 62 | s64 fec_overhead_fp; |
| 63 | s64 dsc_overhead_fp; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct dp_panel; |
| 67 | |
| 68 | struct dp_panel_in { |
| 69 | struct device *dev; |
| 70 | struct dp_aux *aux; |
| 71 | struct dp_link *link; |
| 72 | struct dp_catalog_panel *catalog; |
| 73 | struct drm_connector *connector; |
| 74 | struct dp_panel *base_panel; |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 75 | struct dp_parser *parser; |
| 76 | }; |
| 77 | |
| 78 | struct dp_dsc_caps { |
| 79 | bool dsc_capable; |
| 80 | u8 version; |
| 81 | bool block_pred_en; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct dp_audio; |
| 85 | |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 86 | #define DP_PANEL_CAPS_DSC BIT(0) |
| 87 | |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 88 | struct dp_panel { |
| 89 | /* dpcd raw data */ |
| 90 | u8 dpcd[DP_RECEIVER_CAP_SIZE + 1]; |
| 91 | u8 ds_ports[DP_MAX_DOWNSTREAM_PORTS]; |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 92 | u8 dsc_dpcd[DP_RECEIVER_DSC_CAP_SIZE + 1]; |
| 93 | u8 fec_dpcd; |
| 94 | u8 fec_sts_dpcd[DP_RECEIVER_FEC_STATUS_SIZE + 1]; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 95 | |
| 96 | struct drm_dp_link link_info; |
| 97 | struct sde_edid_ctrl *edid_ctrl; |
| 98 | struct dp_panel_info pinfo; |
| 99 | bool video_test; |
| 100 | bool spd_enabled; |
| 101 | |
| 102 | u32 vic; |
| 103 | u32 max_pclk_khz; |
Steve Cohen | 3ad0888 | 2019-02-01 19:05:41 -0500 | [diff] [blame] | 104 | s64 mst_target_sc; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 105 | |
| 106 | /* debug */ |
| 107 | u32 max_bw_code; |
| 108 | |
| 109 | /* By default, stream_id is assigned to DP_INVALID_STREAM. |
| 110 | * Client sets the stream id value using set_stream_id interface. |
| 111 | */ |
| 112 | enum dp_stream_id stream_id; |
Govinda Rajulu Chenna | 32a2488 | 2019-01-09 23:51:37 -0500 | [diff] [blame] | 113 | int vcpi; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 114 | |
| 115 | u32 channel_start_slot; |
| 116 | u32 channel_total_slots; |
| 117 | u32 pbn; |
| 118 | |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 119 | u32 tot_dsc_blks_in_use; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 120 | /* DRM connector assosiated with this panel */ |
| 121 | struct drm_connector *connector; |
| 122 | |
| 123 | struct dp_audio *audio; |
| 124 | bool audio_supported; |
| 125 | |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 126 | struct dp_dsc_caps sink_dsc_caps; |
| 127 | bool dsc_feature_enable; |
| 128 | bool fec_feature_enable; |
| 129 | bool dsc_en; |
| 130 | bool fec_en; |
| 131 | bool widebus_en; |
| 132 | bool mst_state; |
| 133 | |
| 134 | s64 fec_overhead_fp; |
| 135 | |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 136 | int (*init)(struct dp_panel *dp_panel); |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 137 | int (*deinit)(struct dp_panel *dp_panel, u32 flags); |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 138 | int (*hw_cfg)(struct dp_panel *dp_panel, bool enable); |
| 139 | int (*read_sink_caps)(struct dp_panel *dp_panel, |
| 140 | struct drm_connector *connector, bool multi_func); |
| 141 | u32 (*get_min_req_link_rate)(struct dp_panel *dp_panel); |
| 142 | u32 (*get_mode_bpp)(struct dp_panel *dp_panel, u32 mode_max_bpp, |
| 143 | u32 mode_pclk_khz); |
| 144 | int (*get_modes)(struct dp_panel *dp_panel, |
| 145 | struct drm_connector *connector, struct dp_display_mode *mode); |
| 146 | void (*handle_sink_request)(struct dp_panel *dp_panel); |
| 147 | int (*set_edid)(struct dp_panel *dp_panel, u8 *edid); |
| 148 | int (*set_dpcd)(struct dp_panel *dp_panel, u8 *dpcd); |
| 149 | int (*setup_hdr)(struct dp_panel *dp_panel, |
Steve Cohen | 3ad0888 | 2019-02-01 19:05:41 -0500 | [diff] [blame] | 150 | struct drm_msm_ext_hdr_metadata *hdr_meta, |
| 151 | bool dhdr_update, u64 core_clk_rate); |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 152 | void (*tpg_config)(struct dp_panel *dp_panel, bool enable); |
| 153 | int (*spd_config)(struct dp_panel *dp_panel); |
| 154 | bool (*hdr_supported)(struct dp_panel *dp_panel); |
| 155 | |
| 156 | int (*set_stream_info)(struct dp_panel *dp_panel, |
| 157 | enum dp_stream_id stream_id, u32 ch_start_slot, |
Govinda Rajulu Chenna | 32a2488 | 2019-01-09 23:51:37 -0500 | [diff] [blame] | 158 | u32 ch_tot_slots, u32 pbn, int vcpi); |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 159 | |
| 160 | int (*read_sink_status)(struct dp_panel *dp_panel, u8 *sts, u32 size); |
| 161 | int (*update_edid)(struct dp_panel *dp_panel, struct edid *edid); |
| 162 | bool (*read_mst_cap)(struct dp_panel *dp_panel); |
| 163 | void (*convert_to_dp_mode)(struct dp_panel *dp_panel, |
| 164 | const struct drm_display_mode *drm_mode, |
| 165 | struct dp_display_mode *dp_mode); |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 166 | void (*update_pps)(struct dp_panel *dp_panel, char *pps_cmd); |
| 167 | }; |
| 168 | |
| 169 | struct dp_tu_calc_input { |
| 170 | u64 lclk; /* 162, 270, 540 and 810 */ |
| 171 | u64 pclk_khz; /* in KHz */ |
| 172 | u64 hactive; /* active h-width */ |
| 173 | u64 hporch; /* bp + fp + pulse */ |
| 174 | int nlanes; /* no.of.lanes */ |
| 175 | int bpp; /* bits */ |
| 176 | int pixel_enc; /* 444, 420, 422 */ |
| 177 | int dsc_en; /* dsc on/off */ |
| 178 | int async_en; /* async mode */ |
| 179 | int fec_en; /* fec */ |
| 180 | int compress_ratio; /* 2:1 = 200, 3:1 = 300, 3.75:1 = 375 */ |
| 181 | int num_of_dsc_slices; /* number of slices per line */ |
| 182 | }; |
| 183 | |
| 184 | struct dp_vc_tu_mapping_table { |
| 185 | u32 vic; |
| 186 | u8 lanes; |
| 187 | u8 lrate; /* DP_LINK_RATE -> 162(6), 270(10), 540(20), 810 (30) */ |
| 188 | u8 bpp; |
| 189 | u32 valid_boundary_link; |
| 190 | u32 delay_start_link; |
| 191 | bool boundary_moderation_en; |
| 192 | u32 valid_lower_boundary_link; |
| 193 | u32 upper_boundary_count; |
| 194 | u32 lower_boundary_count; |
| 195 | u32 tu_size_minus1; |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | /** |
| 199 | * is_link_rate_valid() - validates the link rate |
| 200 | * @lane_rate: link rate requested by the sink |
| 201 | * |
| 202 | * Returns true if the requested link rate is supported. |
| 203 | */ |
| 204 | static inline bool is_link_rate_valid(u32 bw_code) |
| 205 | { |
| 206 | return ((bw_code == DP_LINK_BW_1_62) || |
| 207 | (bw_code == DP_LINK_BW_2_7) || |
| 208 | (bw_code == DP_LINK_BW_5_4) || |
| 209 | (bw_code == DP_LINK_BW_8_1)); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * dp_link_is_lane_count_valid() - validates the lane count |
| 214 | * @lane_count: lane count requested by the sink |
| 215 | * |
| 216 | * Returns true if the requested lane count is supported. |
| 217 | */ |
| 218 | static inline bool is_lane_count_valid(u32 lane_count) |
| 219 | { |
| 220 | return (lane_count == DP_LANE_COUNT_1) || |
| 221 | (lane_count == DP_LANE_COUNT_2) || |
| 222 | (lane_count == DP_LANE_COUNT_4); |
| 223 | } |
| 224 | |
| 225 | struct dp_panel *dp_panel_get(struct dp_panel_in *in); |
| 226 | void dp_panel_put(struct dp_panel *dp_panel); |
Satya Rama Aditya Pinapala | 10ffbfa | 2019-01-21 11:02:56 -0800 | [diff] [blame] | 227 | void dp_panel_calc_tu_test(struct dp_tu_calc_input *in, |
| 228 | struct dp_vc_tu_mapping_table *tu_table); |
Samantha Tran | 1eae18f | 2018-10-15 14:04:01 -0700 | [diff] [blame] | 229 | #endif /* _DP_PANEL_H_ */ |