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