rkfb:add display lut set/read interface
[firefly-linux-kernel-4.4.55.git] / include / linux / rk_fb.h
1 /* drivers/video/rk_fb.h
2  *
3  * Copyright (C) 2010 ROCKCHIP, Inc.
4  *
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.
8  *
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.
13  *
14  */
15
16 #ifndef __ARCH_ARM_MACH_RK30_FB_H
17 #define __ARCH_ARM_MACH_RK30_FB_H
18
19 #include <linux/fb.h>
20 #include<linux/completion.h>
21 #include<linux/spinlock.h>
22 #include<asm/atomic.h>
23 #include <mach/board.h>
24
25
26 #define RK30_MAX_LCDC_SUPPORT   4
27 #define RK30_MAX_LAYER_SUPPORT  4
28 #define RK_MAX_FB_SUPPORT       8
29
30
31
32 #define FB0_IOCTL_STOP_TIMER_FLUSH              0x6001
33 #define FB0_IOCTL_SET_PANEL                             0x6002
34
35 #ifdef CONFIG_FB_WIMO
36 #define FB_WIMO_FLAG
37 #endif
38 #ifdef FB_WIMO_FLAG
39 #define FB0_IOCTL_SET_BUF                               0x6017
40 #define FB0_IOCTL_COPY_CURBUF                           0x6018
41 #define FB0_IOCTL_CLOSE_BUF                             0x6019
42 #endif
43
44 #define FBIOGET_PANEL_SIZE              0x5001
45 #define FBIOSET_YUV_ADDR                0x5002
46 //#define FB1_TOCTL_SET_MCU_DIR                 0x5003
47 #define FBIOSET_ROTATE                  0x5003
48 #define FB_IOCTL_SET_I2P_ODD_ADDR       0x5005
49 #define FB_IOCTL_SET_I2P_EVEN_ADDR      0x5006
50 #define FBIOSET_OVERLAY_STATE           0x5018
51 #define FBIOSET_ENABLE                  0x5019  
52 #define FBIOGET_ENABLE                  0x5020
53
54 /********************************************************************
55 **              display output interface supported by rk lcdc                       *
56 ********************************************************************/
57 /* */
58 #define OUT_P888            0
59 #define OUT_P666            1    //
60 #define OUT_P565            2    //
61 #define OUT_S888x           4
62 #define OUT_CCIR656         6
63 #define OUT_S888            8
64 #define OUT_S888DUMY        12
65 #define OUT_P16BPP4         24  //
66 #define OUT_D888_P666       0x21  //
67 #define OUT_D888_P565       0x22  //
68
69
70 /**
71  * pixel format definitions,this is copy from android/system/core/include/system/graphics.h
72  */
73
74 enum {
75     HAL_PIXEL_FORMAT_RGBA_8888          = 1,
76     HAL_PIXEL_FORMAT_RGBX_8888          = 2,
77     HAL_PIXEL_FORMAT_RGB_888            = 3,
78     HAL_PIXEL_FORMAT_RGB_565            = 4,
79     HAL_PIXEL_FORMAT_BGRA_8888          = 5,
80     HAL_PIXEL_FORMAT_RGBA_5551          = 6,
81     HAL_PIXEL_FORMAT_RGBA_4444          = 7,
82
83     /* 0x8 - 0xFF range unavailable */
84
85     /*
86      * 0x100 - 0x1FF
87      *
88      * This range is reserved for pixel formats that are specific to the HAL
89      * implementation.  Implementations can use any value in this range to
90      * communicate video pixel formats between their HAL modules.  These formats
91      * must not have an alpha channel.  Additionally, an EGLimage created from a
92      * gralloc buffer of one of these formats must be supported for use with the
93      * GL_OES_EGL_image_external OpenGL ES extension.
94      */
95
96     /*
97      * Android YUV format:
98      *
99      * This format is exposed outside of the HAL to software decoders and
100      * applications.  EGLImageKHR must support it in conjunction with the
101      * OES_EGL_image_external extension.
102      *
103      * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
104      * by (W/2) x (H/2) Cr and Cb planes.
105      *
106      * This format assumes
107      * - an even width
108      * - an even height
109      * - a horizontal stride multiple of 16 pixels
110      * - a vertical stride equal to the height
111      *
112      *   y_size = stride * height
113      *   c_size = ALIGN(stride/2, 16) * height/2
114      *   size = y_size + c_size * 2
115      *   cr_offset = y_size
116      *   cb_offset = y_size + c_size
117      *
118      */
119     HAL_PIXEL_FORMAT_YV12   = 0x32315659, // YCrCb 4:2:0 Planar
120
121
122
123     /* Legacy formats (deprecated), used by ImageFormat.java */
124     HAL_PIXEL_FORMAT_YCbCr_422_SP       = 0x10, // NV16
125     HAL_PIXEL_FORMAT_YCrCb_420_SP       = 0x11, // NV21
126     HAL_PIXEL_FORMAT_YCbCr_422_I        = 0x14, // YUY2
127     HAL_PIXEL_FORMAT_YCrCb_NV12         = 0x20, // YUY2
128     HAL_PIXEL_FORMAT_YCrCb_NV12_VIDEO   = 0x21, // YUY2
129     HAL_PIXEL_FORMAT_YCrCb_444          = 0x22, //yuv444
130
131
132 };
133
134
135 //display data format
136 enum data_format{
137         ARGB888 = 0,
138         RGB888,
139         RGB565,
140         YUV420 = 4,
141         YUV422,
142         YUV444,
143 };
144
145 enum fb_win_map_order{
146         FB_DEFAULT_ORDER           = 0,
147         FB0_WIN2_FB1_WIN1_FB2_WIN0 = 012,
148         FB0_WIN1_FB1_WIN2_FB2_WIN0 = 021, 
149         FB0_WIN2_FB1_WIN0_FB2_WIN1 = 102,
150         FB0_WIN0_FB1_WIN2_FB2_WIN1 = 120,
151         FB0_WIN0_FB1_WIN1_FB2_WIN2 = 210,
152         FB0_WIN1_FB1_WIN0_FB2_WIN2 = 201,       
153 };
154
155 struct rk_fb_rgb {
156         struct fb_bitfield      red;
157         struct fb_bitfield      green;
158         struct fb_bitfield      blue;
159         struct fb_bitfield      transp;
160 };
161
162 typedef enum _TRSP_MODE
163 {
164     TRSP_CLOSE = 0,
165     TRSP_FMREG,
166     TRSP_FMREGEX,
167     TRSP_FMRAM,
168     TRSP_FMRAMEX,
169     TRSP_MASK,
170     TRSP_INVAL
171 } TRSP_MODE;
172
173 struct layer_par {
174     char name[5];
175     int id;
176     bool state;         //on or off
177     u32 pseudo_pal[16];
178     u32 y_offset;       //yuv/rgb offset  -->LCDC_WINx_YRGB_MSTx
179     u32 c_offset;     //cb cr offset--->LCDC_WINx_CBR_MSTx
180     u32 xpos;         //start point in panel  --->LCDC_WINx_DSP_ST
181     u32 ypos;
182     u16 xsize;        // display window width/height  -->LCDC_WINx_DSP_INFO
183     u16 ysize;          
184     u16 xact;        //origin display window size -->LCDC_WINx_ACT_INFO
185     u16 yact;
186     u16 xvir;       //virtual width/height     -->LCDC_WINx_VIR
187     u16 yvir;
188     unsigned long smem_start;
189     unsigned long cbr_start;  // Cbr memory start address
190     enum data_format format;
191         
192     bool support_3d;
193     
194 };
195
196 struct rk_lcdc_device_driver{
197         char name[6];
198         int id;
199         struct device  *dev;
200         
201         struct layer_par *layer_par[RK_MAX_FB_SUPPORT];
202         struct layer_par *def_layer_par;
203         int num_layer;
204         int num_buf;                            //the num_of buffer
205         int fb_index_base;                     //the first fb index of the lcdc device
206         rk_screen *screen;
207         u32 pixclock;
208
209         
210         char fb0_win_id;
211         char fb1_win_id;
212         char fb2_win_id;
213         struct mutex fb_win_id_mutex;
214         
215         struct completion  frame_done;            //sync for pan_display,whe we set a new frame address to lcdc register,we must make sure the frame begain to display
216         spinlock_t  cpl_lock;                    //lock for completion  frame done
217         int first_frame ;
218
219         struct rk29fb_info *screen_ctr_info;
220         int (*open)(struct rk_lcdc_device_driver *dev_drv,int layer_id,bool open);
221         int (*init_lcdc)(struct rk_lcdc_device_driver *dev_drv);
222         int (*ioctl)(struct rk_lcdc_device_driver *dev_drv, unsigned int cmd,unsigned long arg,int layer_id);
223         int (*suspend)(struct rk_lcdc_device_driver *dev_drv);
224         int (*resume)(struct rk_lcdc_device_driver *dev_drv);
225         int (*blank)(struct rk_lcdc_device_driver *dev_drv,int layer_id,int blank_mode);
226         int (*set_par)(struct rk_lcdc_device_driver *dev_drv,int layer_id);
227         int (*pan_display)(struct rk_lcdc_device_driver *dev_drv,int layer_id);
228         int (*get_disp_info)(struct rk_lcdc_device_driver *dev_drv,int layer_id);
229         int (*load_screen)(struct rk_lcdc_device_driver *dev_drv, bool initscreen);
230         int (*get_layer_state)(struct rk_lcdc_device_driver *dev_drv,int layer_id);
231         int (*ovl_mgr)(struct rk_lcdc_device_driver *dev_drv,int swap,bool set);  //overlay manager
232         int (*fps_mgr)(struct rk_lcdc_device_driver *dev_drv,int fps,bool set);
233         int (*fb_get_layer)(struct rk_lcdc_device_driver *dev_drv,const char *id);                                      //find layer for fb
234         int (*fb_layer_remap)(struct rk_lcdc_device_driver *dev_drv,enum fb_win_map_order order);
235         int (*set_dsp_lut)(struct rk_lcdc_device_driver *dev_drv,int *lut);
236         int (*read_dsp_lut)(struct rk_lcdc_device_driver *dev_drv,int *lut);
237         
238 };
239
240 struct rk_fb_inf {
241         struct rk29fb_info * mach_info;     //lcd io control info
242         struct fb_info *fb[RK_MAX_FB_SUPPORT];
243         int num_fb;
244
245         struct rk_lcdc_device_driver *lcdc_dev_drv[RK30_MAX_LCDC_SUPPORT];
246         int num_lcdc;
247
248         int video_mode;  //when play video set it to 1
249         struct workqueue_struct *workqueue;
250         struct delayed_work delay_work;
251 };
252 extern int rk_fb_register(struct rk_lcdc_device_driver *dev_drv,
253         struct rk_lcdc_device_driver *def_drv,int id);
254 extern int rk_fb_unregister(struct rk_lcdc_device_driver *dev_drv);
255 extern int get_fb_layer_id(struct fb_fix_screeninfo *fix);
256 extern struct rk_lcdc_device_driver * rk_get_lcdc_drv(char *name);
257 extern int rk_fb_switch_screen(rk_screen *screen ,int enable ,int lcdc_id);
258 extern int rk_fb_disp_scale(u8 scale_x, u8 scale_y,u8 lcdc_id);
259 extern int rkfb_create_sysfs(struct fb_info *fbi);
260 #endif