1 /* 2 * (C) Copyright 2008-2017 Fuzhou Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #ifndef _ROCKCHIP_DISPLAY_H 8 #define _ROCKCHIP_DISPLAY_H 9 10 #include <bmp_layout.h> 11 #include <drm_modes.h> 12 #include <edid.h> 13 #include <dm/ofnode.h> 14 #include <drm/drm_dsc.h> 15 16 /* 17 * major: IP major version, used for IP structure 18 * minor: big feature change under same structure 19 * build: RTL current SVN number 20 */ 21 #define VOP_VERSION(major, minor) ((major) << 8 | (minor)) 22 #define VOP_MAJOR(version) ((version) >> 8) 23 #define VOP_MINOR(version) ((version) & 0xff) 24 25 #define VOP2_VERSION(major, minor, build) ((major) << 24 | (minor) << 16 | (build)) 26 #define VOP2_MAJOR(version) (((version) >> 24) & 0xff) 27 #define VOP2_MINOR(version) (((version) >> 16) & 0xff) 28 #define VOP2_BUILD(version) ((version) & 0xffff) 29 30 #define VOP_VERSION_RK3528 VOP2_VERSION(0x50, 0x17, 0x1263) 31 #define VOP_VERSION_RK3562 VOP2_VERSION(0x50, 0x17, 0x4350) 32 #define VOP_VERSION_RK3568 VOP2_VERSION(0x40, 0x15, 0x8023) 33 #define VOP_VERSION_RK3588 VOP2_VERSION(0x40, 0x17, 0x6786) 34 35 #define ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE BIT(0) 36 #define ROCKCHIP_OUTPUT_DUAL_CHANNEL_ODD_EVEN_MODE BIT(1) 37 #define ROCKCHIP_OUTPUT_DATA_SWAP BIT(2) 38 #define ROCKCHIP_OUTPUT_MIPI_DS_MODE BIT(3) 39 40 #define ROCKCHIP_DSC_PPS_SIZE_BYTE 88 41 42 enum data_format { 43 ROCKCHIP_FMT_ARGB8888 = 0, 44 ROCKCHIP_FMT_RGB888, 45 ROCKCHIP_FMT_RGB565, 46 ROCKCHIP_FMT_YUV420SP = 4, 47 ROCKCHIP_FMT_YUV422SP, 48 ROCKCHIP_FMT_YUV444SP, 49 }; 50 51 enum display_mode { 52 ROCKCHIP_DISPLAY_FULLSCREEN, 53 ROCKCHIP_DISPLAY_CENTER, 54 }; 55 56 enum rockchip_cmd_type { 57 CMD_TYPE_DEFAULT, 58 CMD_TYPE_SPI, 59 CMD_TYPE_MCU 60 }; 61 62 enum rockchip_mcu_cmd { 63 MCU_WRCMD = 0, 64 MCU_WRDATA, 65 MCU_SETBYPASS, 66 }; 67 68 /* 69 * display output interface supported by rockchip lcdc 70 */ 71 #define ROCKCHIP_OUT_MODE_P888 0 72 #define ROCKCHIP_OUT_MODE_BT1120 0 73 #define ROCKCHIP_OUT_MODE_P666 1 74 #define ROCKCHIP_OUT_MODE_P565 2 75 #define ROCKCHIP_OUT_MODE_BT656 5 76 #define ROCKCHIP_OUT_MODE_S888 8 77 #define ROCKCHIP_OUT_MODE_S888_DUMMY 12 78 #define ROCKCHIP_OUT_MODE_YUV420 14 79 /* for use special outface */ 80 #define ROCKCHIP_OUT_MODE_AAAA 15 81 82 #define VOP_OUTPUT_IF_RGB BIT(0) 83 #define VOP_OUTPUT_IF_BT1120 BIT(1) 84 #define VOP_OUTPUT_IF_BT656 BIT(2) 85 #define VOP_OUTPUT_IF_LVDS0 BIT(3) 86 #define VOP_OUTPUT_IF_LVDS1 BIT(4) 87 #define VOP_OUTPUT_IF_MIPI0 BIT(5) 88 #define VOP_OUTPUT_IF_MIPI1 BIT(6) 89 #define VOP_OUTPUT_IF_eDP0 BIT(7) 90 #define VOP_OUTPUT_IF_eDP1 BIT(8) 91 #define VOP_OUTPUT_IF_DP0 BIT(9) 92 #define VOP_OUTPUT_IF_DP1 BIT(10) 93 #define VOP_OUTPUT_IF_HDMI0 BIT(11) 94 #define VOP_OUTPUT_IF_HDMI1 BIT(12) 95 96 struct rockchip_mcu_timing { 97 int mcu_pix_total; 98 int mcu_cs_pst; 99 int mcu_cs_pend; 100 int mcu_rw_pst; 101 int mcu_rw_pend; 102 int mcu_hold_mode; 103 }; 104 105 struct vop_rect { 106 int width; 107 int height; 108 }; 109 110 struct rockchip_dsc_sink_cap { 111 /** 112 * @slice_width: the number of pixel columns that comprise the slice width 113 * @slice_height: the number of pixel rows that comprise the slice height 114 * @block_pred: Does block prediction 115 * @native_420: Does sink support DSC with 4:2:0 compression 116 * @bpc_supported: compressed bpc supported by sink : 10, 12 or 16 bpc 117 * @version_major: DSC major version 118 * @version_minor: DSC minor version 119 * @target_bits_per_pixel_x16: bits num after compress and multiply 16 120 */ 121 u16 slice_width; 122 u16 slice_height; 123 bool block_pred; 124 bool native_420; 125 u8 bpc_supported; 126 u8 version_major; 127 u8 version_minor; 128 u16 target_bits_per_pixel_x16; 129 }; 130 131 struct display_rect { 132 int x; 133 int y; 134 int w; 135 int h; 136 }; 137 138 struct bcsh_state { 139 int brightness; 140 int contrast; 141 int saturation; 142 int sin_hue; 143 int cos_hue; 144 }; 145 146 struct crtc_state { 147 struct udevice *dev; 148 struct rockchip_crtc *crtc; 149 void *private; 150 ofnode node; 151 struct device_node *ports_node; /* if (ports_node) it's vop2; */ 152 int crtc_id; 153 154 int format; 155 u32 dma_addr; 156 int ymirror; 157 int rb_swap; 158 int xvir; 159 int post_csc_mode; 160 int dclk_core_div; 161 int dclk_out_div; 162 struct display_rect src_rect; 163 struct display_rect crtc_rect; 164 struct display_rect right_src_rect; 165 struct display_rect right_crtc_rect; 166 bool yuv_overlay; 167 bool post_r2y_en; 168 bool post_y2r_en; 169 bool bcsh_en; 170 bool splice_mode; 171 u8 splice_crtc_id; 172 u8 dsc_id; 173 u8 dsc_enable; 174 u8 dsc_slice_num; 175 u8 dsc_pixel_num; 176 struct rockchip_mcu_timing mcu_timing; 177 u32 dual_channel_swap; 178 u32 feature; 179 struct vop_rect max_output; 180 181 u64 dsc_txp_clk_rate; 182 u64 dsc_pxl_clk_rate; 183 u64 dsc_cds_clk_rate; 184 struct drm_dsc_picture_parameter_set pps; 185 struct rockchip_dsc_sink_cap dsc_sink_cap; 186 }; 187 188 struct panel_state { 189 struct rockchip_panel *panel; 190 191 ofnode dsp_lut_node; 192 }; 193 194 struct overscan { 195 int left_margin; 196 int right_margin; 197 int top_margin; 198 int bottom_margin; 199 }; 200 201 struct connector_state { 202 struct rockchip_connector *connector; 203 struct rockchip_connector *secondary; 204 205 struct drm_display_mode mode; 206 struct overscan overscan; 207 u8 edid[EDID_SIZE * 4]; 208 int bus_format; 209 int output_mode; 210 int type; 211 int output_if; 212 int output_flags; 213 int color_space; 214 unsigned int bpc; 215 216 /** 217 * @hold_mode: enabled when it's: 218 * (1) mcu hold mode 219 * (2) mipi dsi cmd mode 220 * (3) edp psr mode 221 */ 222 bool hold_mode; 223 224 struct base2_disp_info *disp_info; /* disp_info from baseparameter 2.0 */ 225 226 u8 dsc_id; 227 u8 dsc_slice_num; 228 u8 dsc_pixel_num; 229 u64 dsc_txp_clk; 230 u64 dsc_pxl_clk; 231 u64 dsc_cds_clk; 232 struct rockchip_dsc_sink_cap dsc_sink_cap; 233 struct drm_dsc_picture_parameter_set pps; 234 235 struct { 236 u32 *lut; 237 int size; 238 } gamma; 239 }; 240 241 struct logo_info { 242 int mode; 243 char *mem; 244 bool ymirror; 245 u32 offset; 246 u32 width; 247 int height; 248 u32 bpp; 249 }; 250 251 struct rockchip_logo_cache { 252 struct list_head head; 253 char name[20]; 254 struct logo_info logo; 255 }; 256 257 struct display_state { 258 struct list_head head; 259 260 const void *blob; 261 ofnode node; 262 263 struct crtc_state crtc_state; 264 struct connector_state conn_state; 265 struct panel_state panel_state; 266 267 char ulogo_name[30]; 268 char klogo_name[30]; 269 270 struct logo_info logo; 271 int logo_mode; 272 int charge_logo_mode; 273 void *mem_base; 274 int mem_size; 275 276 int enable; 277 int is_init; 278 int is_enable; 279 bool is_klogo_valid; 280 bool force_output; 281 struct drm_display_mode force_mode; 282 u32 force_bus_format; 283 }; 284 285 int drm_mode_vrefresh(const struct drm_display_mode *mode); 286 int display_send_mcu_cmd(struct display_state *state, u32 type, u32 val); 287 bool drm_mode_is_420(const struct drm_display_info *display, 288 struct drm_display_mode *mode); 289 struct base2_disp_info *rockchip_get_disp_info(int type, int id); 290 291 void drm_mode_max_resolution_filter(struct hdmi_edid_data *edid_data, 292 struct vop_rect *max_output); 293 unsigned long get_cubic_lut_buffer(int crtc_id); 294 int rockchip_ofnode_get_display_mode(ofnode node, struct drm_display_mode *mode); 295 296 int display_rect_calc_hscale(struct display_rect *src, struct display_rect *dst, 297 int min_hscale, int max_hscale); 298 int display_rect_calc_vscale(struct display_rect *src, struct display_rect *dst, 299 int min_vscale, int max_vscale); 300 const struct device_node * 301 rockchip_of_graph_get_endpoint_by_regs(ofnode node, int port, int endpoint); 302 303 #endif 304