1 /* drivers/video/rk_fb.h
3 * Copyright (C) 2010 ROCKCHIP, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #ifndef __ARCH_ARM_MACH_RK30_FB_H
17 #define __ARCH_ARM_MACH_RK30_FB_H
20 #include <linux/platform_device.h>
21 #include <linux/completion.h>
22 #include <linux/spinlock.h>
23 #include <asm/atomic.h>
24 #include <linux/rk_screen.h>
25 #if defined(CONFIG_OF)
26 #include <dt-bindings/rkfb/rk_fb.h>
28 #include "../../drivers/staging/android/sw_sync.h"
29 #include <linux/file.h>
30 #include <linux/kthread.h>
33 #define RK30_MAX_LCDC_SUPPORT 4
34 #define RK30_MAX_LAYER_SUPPORT 4
35 #define RK_MAX_FB_SUPPORT 4
36 #define RK_WIN_MAX_AREA 4
37 #define RK_MAX_BUF_NUM 10
39 #define FB0_IOCTL_STOP_TIMER_FLUSH 0x6001
40 #define FB0_IOCTL_SET_PANEL 0x6002
46 #define FB0_IOCTL_SET_BUF 0x6017
47 #define FB0_IOCTL_COPY_CURBUF 0x6018
48 #define FB0_IOCTL_CLOSE_BUF 0x6019
51 #define RK_FBIOGET_PANEL_SIZE 0x5001
52 #define RK_FBIOSET_YUV_ADDR 0x5002
53 #define RK_FBIOGET_SCREEN_STATE 0X4620
54 #define RK_FBIOGET_16OR32 0X4621
55 #define RK_FBIOGET_IDLEFBUff_16OR32 0X4622
56 #define RK_FBIOSET_COMPOSE_LAYER_COUNTS 0X4623
58 #define RK_FBIOGET_DMABUF_FD 0x5003
59 #define RK_FBIOSET_DMABUF_FD 0x5004
60 #define RK_FB_IOCTL_SET_I2P_ODD_ADDR 0x5005
61 #define RK_FB_IOCTL_SET_I2P_EVEN_ADDR 0x5006
62 #define RK_FBIOSET_OVERLAY_STA 0x5018
63 #define RK_FBIOGET_OVERLAY_STA 0X4619
64 #define RK_FBIOSET_ENABLE 0x5019
65 #define RK_FBIOGET_ENABLE 0x5020
66 #define RK_FBIOSET_CONFIG_DONE 0x4628
67 #define RK_FBIOSET_VSYNC_ENABLE 0x4629
68 #define RK_FBIOPUT_NUM_BUFFERS 0x4625
69 #define RK_FBIOPUT_COLOR_KEY_CFG 0x4626
70 #define RK_FBIOGET_DSP_ADDR 0x4630
71 #define RK_FBIOGET_LIST_STA 0X4631
72 #define RK_FBIOGET_IOMMU_STA 0x4632
73 #define RK_FBIOSET_CLEAR_FB 0x4633
77 #define RK_LF_STATUS_FC 0xef
78 #define RK_LF_STATUS_FR 0xee
79 #define RK_LF_STATUS_NC 0xfe
80 #define RK_LF_MAX_TIMEOUT (1600000UL << 6) //>0.64s
83 /* x y mirror or rotate mode */
85 #define X_MIRROR 1 /* up-down flip*/
86 #define Y_MIRROR 2 /* left-right flip */
87 #define X_Y_MIRROR 3 /* the same as rotate 180 degrees */
88 #define ROTATE_90 4 /* clockwise rotate 90 degrees */
89 #define ROTATE_180 8 /* rotate 180 degrees
90 * It is recommended to use X_Y_MIRROR
91 * rather than ROTATE_180
93 #define ROTATE_270 12 /* clockwise rotate 270 degrees */
97 * pixel align value for gpu,align as 64 bytes in an odd number of times
99 #define ALIGN_PIXEL_64BYTE_RGB565 32 /* 64/2*/
100 #define ALIGN_PIXEL_64BYTE_RGB8888 16 /* 64/4*/
101 #define ALIGN_N_TIMES(x, align) (((x) % (align) == 0) ? (x) : (((x) + ((align) - 1)) & (~((align) - 1))))
102 #define ALIGN_ODD_TIMES(x, align) (((x) % ((align) * 2) == 0) ? ((x) + (align)) : (x))
103 #define ALIGN_64BYTE_ODD_TIMES(x, align) ALIGN_ODD_TIMES(ALIGN_N_TIMES(x, align), align)
106 //#define USE_ION_MMU 1
107 #if defined(CONFIG_ION_ROCKCHIP)
108 extern struct ion_client *rockchip_ion_client_create(const char *name);
111 extern int rk_fb_poll_prmry_screen_vblank(void);
112 extern u32 rk_fb_get_prmry_screen_ft(void);
113 extern u32 rk_fb_get_prmry_screen_vbt(void);
114 extern u64 rk_fb_get_prmry_screen_framedone_t(void);
115 extern int rk_fb_set_prmry_screen_status(int status);
116 extern bool rk_fb_poll_wait_frame_complete(void);
118 /********************************************************************
119 ** display output interface supported by rockchip lcdc *
120 ********************************************************************/
122 #define OUT_P888 0 //24bit screen,connect to lcdc D0~D23
123 #define OUT_P666 1 //18bit screen,connect to lcdc D0~D17
126 #define OUT_CCIR656 6
128 #define OUT_S888DUMY 12
129 #define OUT_RGB_AAA 15
130 #define OUT_P16BPP4 24
131 #define OUT_D888_P666 0x21 //18bit screen,connect to lcdc D2~D7, D10~D15, D18~D23
132 #define OUT_D888_P565 0x22
135 * pixel format definitions,this is copy from android/system/core/include/system/graphics.h
139 HAL_PIXEL_FORMAT_RGBA_8888 = 1,
140 HAL_PIXEL_FORMAT_RGBX_8888 = 2,
141 HAL_PIXEL_FORMAT_RGB_888 = 3,
142 HAL_PIXEL_FORMAT_RGB_565 = 4,
143 HAL_PIXEL_FORMAT_BGRA_8888 = 5,
144 HAL_PIXEL_FORMAT_RGBA_5551 = 6,
145 HAL_PIXEL_FORMAT_RGBA_4444 = 7,
147 /* 0x8 - 0xFF range unavailable */
152 * This range is reserved for pixel formats that are specific to the HAL
153 * implementation. Implementations can use any value in this range to
154 * communicate video pixel formats between their HAL modules. These formats
155 * must not have an alpha channel. Additionally, an EGLimage created from a
156 * gralloc buffer of one of these formats must be supported for use with the
157 * GL_OES_EGL_image_external OpenGL ES extension.
161 * Android YUV format:
163 * This format is exposed outside of the HAL to software decoders and
164 * applications. EGLImageKHR must support it in conjunction with the
165 * OES_EGL_image_external extension.
167 * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
168 * by (W/2) x (H/2) Cr and Cb planes.
170 * This format assumes
173 * - a horizontal stride multiple of 16 pixels
174 * - a vertical stride equal to the height
176 * y_size = stride * height
177 * c_size = ALIGN(stride/2, 16) * height/2
178 * size = y_size + c_size * 2
180 * cb_offset = y_size + c_size
183 HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar
185 /* Legacy formats (deprecated), used by ImageFormat.java */
186 HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10, // NV16
187 HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11, // NV21
188 HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14, // YUY2
189 HAL_PIXEL_FORMAT_YCrCb_NV12 = 0x20, // YUY2
190 HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO = 0x21, // YUY2
192 HAL_PIXEL_FORMAT_YCrCb_NV12_10 = 0x22, // YUV420_1obit
193 HAL_PIXEL_FORMAT_YCbCr_422_SP_10 = 0x23, // YUV422_1obit
194 HAL_PIXEL_FORMAT_YCrCb_420_SP_10 = 0x24, //YUV444_1obit
196 HAL_PIXEL_FORMAT_YCrCb_444 = 0x25, //yuv444
201 //display data format
236 SCREEN_PREPARE_DDR_CHANGE = 0x0,
237 SCREEN_UNPREPARE_DDR_CHANGE,
241 struct fb_bitfield red;
242 struct fb_bitfield green;
243 struct fb_bitfield blue;
244 struct fb_bitfield transp;
247 struct rk_fb_frame_time {
248 u64 last_framedone_t;
254 wait_queue_head_t wait;
259 struct mutex irq_lock;
260 struct task_struct *thread;
263 struct color_key_cfg {
264 u32 win0_color_key_cfg;
265 u32 win1_color_key_cfg;
266 u32 win2_color_key_cfg;
280 struct rk_disp_pwr_ctr_list {
281 struct list_head list;
282 struct pwr_ctr pwr_ctr;
285 typedef enum _TRSP_MODE {
295 struct rk_lcdc_post_cfg{
302 struct rk_lcdc_bcsh {
311 struct rk_lcdc_win_area{
313 u32 y_offset; /*yuv/rgb offset -->LCDC_WINx_YRGB_MSTx*/
314 u32 c_offset; /*cb cr offset--->LCDC_WINx_CBR_MSTx*/
315 u32 xpos; /*start point in panel --->LCDC_WINx_DSP_ST*/
317 u16 xsize; /* display window width/height -->LCDC_WINx_DSP_INFO*/
319 u16 xact; /*origin display window size -->LCDC_WINx_ACT_INFO*/
321 u16 xvir; /*virtual width/height -->LCDC_WINx_VIR*/
323 unsigned long smem_start;
324 unsigned long cbr_start; /*Cbr memory start address*/
325 #if defined(CONFIG_ION_ROCKCHIP)
326 struct ion_handle *ion_hdl;
328 struct dma_buf *dma_buf;
344 bool state; /*on or off*/
345 bool last_state; /*on or off*/
347 enum data_format format;
348 int z_order; /*win sel layer*/
363 u8 yrgb_hor_scl_mode;//h 01:scale up ;10:down
364 u8 yrgb_ver_scl_mode;//v 01:scale up ;10:down
365 u8 yrgb_hsd_mode;//h scale down mode
366 u8 yrgb_vsu_mode;//v scale up mode
367 u8 yrgb_vsd_mode;//v scale down mode
384 struct rk_lcdc_win_area area[RK_WIN_MAX_AREA];
385 struct rk_lcdc_post_cfg post_cfg;
388 struct rk_lcdc_driver;
390 struct rk_fb_trsm_ops {
392 int (*disable)(void);
393 int (*dsp_pwr_on) (void);
394 int (*dsp_pwr_off) (void);
397 struct rk_lcdc_drv_ops {
398 int (*open) (struct rk_lcdc_driver *dev_drv, int layer_id, bool open);
399 int (*win_direct_en)(struct rk_lcdc_driver *dev_drv, int win_id, int en);
400 int (*init_lcdc) (struct rk_lcdc_driver *dev_drv);
401 int (*ioctl) (struct rk_lcdc_driver *dev_drv, unsigned int cmd,
402 unsigned long arg, int layer_id);
403 int (*suspend) (struct rk_lcdc_driver *dev_drv);
404 int (*resume) (struct rk_lcdc_driver *dev_drv);
405 int (*blank) (struct rk_lcdc_driver *dev_drv, int layer_id,
407 int (*set_par) (struct rk_lcdc_driver *dev_drv, int layer_id);
408 int (*pan_display) (struct rk_lcdc_driver *dev_drv, int layer_id);
409 int (*direct_set_addr)(struct rk_lcdc_driver *drv, int win_id, u32 addr);
410 int (*lcdc_reg_update) (struct rk_lcdc_driver *dev_drv);
411 ssize_t(*get_disp_info) (struct rk_lcdc_driver *dev_drv, char *buf,
413 int (*load_screen) (struct rk_lcdc_driver *dev_drv, bool initscreen);
414 int (*get_win_state) (struct rk_lcdc_driver *dev_drv, int layer_id);
415 int (*ovl_mgr) (struct rk_lcdc_driver *dev_drv, int swap, bool set); /*overlay manager*/
416 int (*fps_mgr) (struct rk_lcdc_driver *dev_drv, int fps, bool set);
417 int (*fb_get_win_id) (struct rk_lcdc_driver *dev_drv, const char *id); /*find layer for fb*/
418 int (*fb_win_remap) (struct rk_lcdc_driver *dev_drv,
419 u16 fb_win_map_order);
420 int (*set_dsp_lut) (struct rk_lcdc_driver *dev_drv, int *lut);
421 int (*set_hwc_lut) (struct rk_lcdc_driver *dev_drv, int *hwc_lut, int mode);
422 int (*read_dsp_lut) (struct rk_lcdc_driver *dev_drv, int *lut);
423 int (*lcdc_hdmi_process) (struct rk_lcdc_driver *dev_drv, int mode); /*some lcdc need to some process in hdmi mode*/
424 int (*set_irq_to_cpu)(struct rk_lcdc_driver *dev_drv,int enable);
425 int (*poll_vblank) (struct rk_lcdc_driver *dev_drv);
426 int (*lcdc_rst) (struct rk_lcdc_driver *dev_drv);
427 int (*dpi_open) (struct rk_lcdc_driver *dev_drv, bool open);
428 int (*dpi_win_sel) (struct rk_lcdc_driver *dev_drv, int layer_id);
429 int (*dpi_status) (struct rk_lcdc_driver *dev_drv);
430 int (*get_dsp_addr)(struct rk_lcdc_driver *dev_drv,unsigned int *dsp_addr);
431 int (*set_dsp_cabc) (struct rk_lcdc_driver *dev_drv, int mode);
432 int (*set_dsp_bcsh_hue) (struct rk_lcdc_driver *dev_drv,int sin_hue, int cos_hue);
433 int (*set_dsp_bcsh_bcs)(struct rk_lcdc_driver *dev_drv,bcsh_bcs_mode mode,int value);
434 int (*get_dsp_bcsh_hue) (struct rk_lcdc_driver *dev_drv,bcsh_hue_mode mode);
435 int (*get_dsp_bcsh_bcs)(struct rk_lcdc_driver *dev_drv,bcsh_bcs_mode mode);
436 int (*open_bcsh)(struct rk_lcdc_driver *dev_drv, bool open);
437 int (*set_screen_scaler) (struct rk_lcdc_driver *dev_drv, struct rk_screen *screen, bool enable);
438 int (*dump_reg) (struct rk_lcdc_driver *dev_drv);
439 int (*mmu_en) (struct rk_lcdc_driver *dev_drv);
440 int (*cfg_done) (struct rk_lcdc_driver *dev_drv);
441 int (*set_overscan) (struct rk_lcdc_driver *dev_drv,
442 struct overscan *overscan);
445 struct rk_fb_area_par {
447 unsigned long phy_addr;
451 u32 xpos; /*start point in panel --->LCDC_WINx_DSP_ST*/
453 u32 xsize; /* display window width/height -->LCDC_WINx_DSP_INFO*/
455 u32 xact; /*origin display window size -->LCDC_WINx_ACT_INFO*/
457 u32 xvir; /*virtual width/height -->LCDC_WINx_VIR*/
462 struct rk_fb_win_par {
463 u8 data_format; /*layer data fmt*/
465 u8 z_order; /*win sel layer*/
466 struct rk_fb_area_par area_par[RK_WIN_MAX_AREA];
471 struct rk_fb_win_cfg_data {
473 int rel_fence_fd[RK_MAX_BUF_NUM];
474 struct rk_fb_win_par win_par[RK30_MAX_LAYER_SUPPORT];
475 struct rk_lcdc_post_cfg post_cfg;
480 struct rk_fb_reg_area_data {
481 struct sync_fence *acq_fence;
482 u8 index_buf; /*judge if the buffer is index*/
483 u32 y_offset; /*yuv/rgb offset -->LCDC_WINx_YRGB_MSTx*/
484 u32 c_offset; /*cb cr offset--->LCDC_WINx_CBR_MSTx*/
487 u32 xpos; /*start point in panel --->LCDC_WINx_DSP_ST*/
489 u16 xsize; /* display window width/height -->LCDC_WINx_DSP_INFO*/
491 u16 xact; /*origin display window size -->LCDC_WINx_ACT_INFO*/
493 u16 xvir; /*virtual width/height -->LCDC_WINx_VIR*/
495 unsigned long smem_start;
496 unsigned long cbr_start; /*Cbr memory start address*/
498 struct ion_handle *ion_handle;
500 struct dma_buf *dma_buf;
501 struct dma_buf_attachment *attachment;
502 struct sg_table *sg_table;
507 struct rk_fb_reg_win_data {
508 u8 data_format; /*layer data fmt*/
510 u8 z_order; /*win sel layer*/
511 u32 area_num; /*maybe two region have the same dma buff,*/
512 u32 area_buf_num; /*so area_num maybe not equal to area_buf_num*/
518 struct rk_fb_reg_area_data reg_area_data[RK_WIN_MAX_AREA];
521 struct rk_fb_reg_data {
522 struct list_head list;
526 struct rk_fb_reg_win_data reg_win_data[RK30_MAX_LAYER_SUPPORT];
527 struct rk_lcdc_post_cfg post_cfg;
528 //struct sync_fence *acq_fence[RK_MAX_BUF_NUM];
529 //int fence_wait_begin;
532 struct rk_lcdc_driver {
538 struct rk_lcdc_win *win[RK_MAX_FB_SUPPORT];
540 int num_buf; //the num_of buffer
542 int fb_index_base; //the first fb index of the lcdc device
543 struct rk_screen *screen0; //some platform have only one lcdc,but extend
544 struct rk_screen *screen1; //two display devices for dual display,such as rk2918,rk2928
545 struct rk_screen *cur_screen; //screen0 is primary screen ,like lcd panel,screen1 is extend screen,like hdmi
558 char mmu_dts_name[40];
559 struct device *mmu_dev;
562 struct rk_fb_reg_area_data reg_area_data;
563 struct mutex fb_win_id_mutex;
565 struct completion frame_done; /*sync for pan_display,whe we set a new
566 frame address to lcdc register,we must
567 make sure the frame begain to display*/
568 spinlock_t cpl_lock; /*lock for completion frame done */
570 struct rk_fb_vsync vsync_info;
571 struct rk_fb_frame_time frame_time;
572 int wait_fs; /*wait for new frame start in kernel */
573 struct sw_sync_timeline *timeline;
576 struct list_head update_regs_list;
577 struct mutex update_regs_list_lock;
578 struct kthread_worker update_regs_worker;
579 struct task_struct *update_regs_thread;
580 struct kthread_work update_regs_work;
581 wait_queue_head_t update_regs_wait;
583 struct mutex output_lock;
584 struct rk29fb_info *screen_ctr_info;
585 struct list_head pwrlist_head;
586 struct rk_lcdc_drv_ops *ops;
587 struct rk_fb_trsm_ops *trsm_ops;
588 #ifdef CONFIG_DRM_ROCKCHIP
589 void (*irq_call_back)(struct rk_lcdc_driver *driver);
591 struct overscan overscan;
592 struct rk_lcdc_bcsh bcsh;
596 /*disp_mode: dual display mode
597 * NO_DUAL,no dual display,
598 ONE_DUAL,use one lcdc + rk61x for dual display
599 DUAL,use 2 lcdcs for dual display
600 num_fb: the total number of fb
601 num_lcdc: the total number of lcdc
606 struct rk29fb_info *mach_info;
607 struct fb_info *fb[RK_MAX_FB_SUPPORT*2];
610 struct rk_lcdc_driver *lcdc_dev_drv[RK30_MAX_LCDC_SUPPORT];
613 #if defined(CONFIG_ION_ROCKCHIP)
614 struct ion_client *ion_client;
620 extern int rk_fb_trsm_ops_register(struct rk_fb_trsm_ops *ops, int type);
621 extern struct rk_fb_trsm_ops *rk_fb_trsm_ops_get(int type);
622 extern int rk_fb_register(struct rk_lcdc_driver *dev_drv,
623 struct rk_lcdc_win *win, int id);
624 extern int rk_fb_unregister(struct rk_lcdc_driver *dev_drv);
625 extern struct rk_lcdc_driver *rk_get_lcdc_drv(char *name);
626 extern int rk_fb_get_prmry_screen( struct rk_screen *screen);
627 extern int rk_fb_set_prmry_screen(struct rk_screen *screen);
628 extern u32 rk_fb_get_prmry_screen_pixclock(void);
629 extern int rk_disp_pwr_ctr_parse_dt(struct rk_lcdc_driver *dev_drv);
630 extern int rk_disp_pwr_enable(struct rk_lcdc_driver *dev_drv);
631 extern int rk_disp_pwr_disable(struct rk_lcdc_driver *dev_drv);
632 extern bool is_prmry_rk_lcdc_registered(void);
633 extern int rk_fb_prase_timing_dt(struct device_node *np,
634 struct rk_screen *screen);
635 extern int rk_disp_prase_timing_dt(struct rk_lcdc_driver *dev_drv);
637 extern int rk_fb_dpi_open(bool open);
638 extern int rk_fb_dpi_layer_sel(int layer_id);
639 extern int rk_fb_dpi_status(void);
641 extern int rk_fb_switch_screen(struct rk_screen *screen, int enable, int lcdc_id);
642 extern int rk_fb_disp_scale(u8 scale_x, u8 scale_y, u8 lcdc_id);
643 extern int rkfb_create_sysfs(struct fb_info *fbi);
644 extern char *get_format_string(enum data_format, char *fmt);
645 extern int support_uboot_display(void);
646 extern int rk_fb_calc_fps(struct rk_screen *screen, u32 pixclock);
647 extern int rk_get_real_fps(int time);
648 extern struct device *rk_fb_get_sysmmu_device_by_compatible(const char *compt);
649 extern void rk_fb_platform_set_sysmmu(struct device *sysmmu,