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 int dclk_core_div; 153 int dclk_out_div; 154 struct display_rect src_rect; 155 struct display_rect crtc_rect; 156 struct display_rect right_src_rect; 157 struct display_rect right_crtc_rect; 158 bool yuv_overlay; 159 bool post_r2y_en; 160 bool post_y2r_en; 161 bool bcsh_en; 162 bool splice_mode; 163 u8 splice_crtc_id; 164 u8 dsc_id; 165 u8 dsc_enable; 166 u8 dsc_slice_num; 167 u8 dsc_pixel_num; 168 struct rockchip_mcu_timing mcu_timing; 169 u32 dual_channel_swap; 170 u32 feature; 171 struct vop_rect max_output; 172 173 u64 dsc_txp_clk_rate; 174 u64 dsc_pxl_clk_rate; 175 u64 dsc_cds_clk_rate; 176 struct drm_dsc_picture_parameter_set pps; 177 struct rockchip_dsc_sink_cap dsc_sink_cap; 178 }; 179 180 struct panel_state { 181 struct rockchip_panel *panel; 182 183 ofnode dsp_lut_node; 184 }; 185 186 struct overscan { 187 int left_margin; 188 int right_margin; 189 int top_margin; 190 int bottom_margin; 191 }; 192 193 struct connector_state { 194 struct udevice *dev; 195 const struct rockchip_connector *connector; 196 struct rockchip_bridge *bridge; 197 struct rockchip_phy *phy; 198 ofnode node; 199 200 void *private; 201 202 struct drm_display_mode mode; 203 struct overscan overscan; 204 u8 edid[EDID_SIZE * 4]; 205 int bus_format; 206 int output_mode; 207 int type; 208 int output_if; 209 int output_flags; 210 int color_space; 211 unsigned int bpc; 212 213 /** 214 * @hold_mode: enabled when it's: 215 * (1) mcu hold mode 216 * (2) mipi dsi cmd mode 217 * (3) edp psr mode 218 */ 219 bool hold_mode; 220 221 struct base2_disp_info *disp_info; /* disp_info from baseparameter 2.0 */ 222 223 u8 dsc_id; 224 u8 dsc_slice_num; 225 u8 dsc_pixel_num; 226 u64 dsc_txp_clk; 227 u64 dsc_pxl_clk; 228 u64 dsc_cds_clk; 229 struct rockchip_dsc_sink_cap dsc_sink_cap; 230 struct drm_dsc_picture_parameter_set pps; 231 232 struct { 233 u32 *lut; 234 int size; 235 } gamma; 236 }; 237 238 struct logo_info { 239 int mode; 240 char *mem; 241 bool ymirror; 242 u32 offset; 243 u32 width; 244 int height; 245 u32 bpp; 246 }; 247 248 struct rockchip_logo_cache { 249 struct list_head head; 250 char name[20]; 251 struct logo_info logo; 252 }; 253 254 struct display_state { 255 struct list_head head; 256 257 const void *blob; 258 ofnode node; 259 260 struct crtc_state crtc_state; 261 struct connector_state conn_state; 262 struct panel_state panel_state; 263 264 char ulogo_name[30]; 265 char klogo_name[30]; 266 267 struct logo_info logo; 268 int logo_mode; 269 int charge_logo_mode; 270 void *mem_base; 271 int mem_size; 272 273 int enable; 274 int is_init; 275 int is_enable; 276 bool force_output; 277 struct drm_display_mode force_mode; 278 u32 force_bus_format; 279 }; 280 281 static inline struct rockchip_panel *state_get_panel(struct display_state *s) 282 { 283 struct panel_state *panel_state = &s->panel_state; 284 285 return panel_state->panel; 286 } 287 288 int drm_mode_vrefresh(const struct drm_display_mode *mode); 289 int display_send_mcu_cmd(struct display_state *state, u32 type, u32 val); 290 bool drm_mode_is_420(const struct drm_display_info *display, 291 struct drm_display_mode *mode); 292 struct base2_disp_info *rockchip_get_disp_info(int type, int id); 293 294 void drm_mode_max_resolution_filter(struct hdmi_edid_data *edid_data, 295 struct vop_rect *max_output); 296 unsigned long get_cubic_lut_buffer(int crtc_id); 297 int rockchip_ofnode_get_display_mode(ofnode node, struct drm_display_mode *mode); 298 299 #endif 300