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