59e642ca1cc4574b2ecabb1741d9521628e3fedf
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / video / sprdfb / sprdfb.h
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #ifndef _SPRDFB_H_
15 #define _SPRDFB_H_
16
17 #ifdef CONFIG_HAS_EARLYSUSPEND
18 #include <linux/earlysuspend.h>
19 #endif
20 #include <linux/compat.h>
21 #include <linux/workqueue.h>
22 #include <linux/semaphore.h>
23 #include <linux/wait.h>
24 #ifdef CONFIG_FB_MMAP_CACHED
25 #include <linux/mm_types.h>
26 #endif
27 #include <linux/time.h>
28 #include <linux/notifier.h>
29 #ifdef CONFIG_DRM_SPRD
30 #include <drm/sprd_drm.h>
31 #endif
32
33 #ifdef CONFIG_SPRDFB_MDNIE_LITE_TUNING
34 #include "mdnie/mdnie_lite.h"
35 #endif
36
37 #if ((!defined(CONFIG_FB_SCX35)) && (!defined(CONFIG_FB_SCX15)))
38 #define FB_CHECK_ESD_IN_VFP
39 #endif
40 //#define FB_CHECK_ESD_BY_TE_SUPPORT
41 #define BIT_PER_PIXEL_SURPPORT
42
43 #if defined(CONFIG_FB_LCD_OVERLAY_SUPPORT)
44 #define SPRDFB_OVERLAY_DEBUG
45 #endif
46
47 enum{
48         SPRDFB_PANEL_IF_DBI = 0,
49         SPRDFB_PANEL_IF_DPI,
50         SPRDFB_PANEL_IF_EDPI,
51         SPRDFB_PANEL_IF_LIMIT
52 };
53
54 enum {
55         SPRDFB_UNKNOWN = 0,
56         SPRDFB_DYNAMIC_PCLK = 0x1,
57         SPRDFB_DYNAMIC_FPS,
58         SPRDFB_DYNAMIC_MIPI_CLK,
59         SPRDFB_FORCE_FPS,
60         SPRDFB_FORCE_PCLK,
61 };
62
63 enum{
64         MCU_LCD_REGISTER_TIMING = 0,
65         MCU_LCD_GRAM_TIMING,
66         MCU_LCD_TIMING_KIND_MAX
67 };
68
69 enum{
70         RGB_LCD_H_TIMING = 0,
71         RGB_LCD_V_TIMING,
72         RGB_LCD_TIMING_KIND_MAX
73 };
74
75
76 #ifdef CONFIG_FB_LCD_OVERLAY_SUPPORT
77 #define SPRD_LAYER_IMG (0x01)   /*support YUV & RGB*/
78 #define SPRD_LAYER_OSD (0x02)   /*support RGB only*/
79 #define SPRD_LAYER_BOTH (0x03)  /*support RGB only*/
80
81 enum {
82         SPRD_DATA_TYPE_YUV422 = 0,
83         SPRD_DATA_TYPE_YUV420,
84         SPRD_DATA_TYPE_YUV400,
85         SPRD_DATA_TYPE_RGB888,
86         SPRD_DATA_TYPE_RGB666,
87         SPRD_DATA_TYPE_RGB565,
88         SPRD_DATA_TYPE_RGB555,
89         SPRD_DATA_TYPE_YUV422_3P = 8,
90         SPRD_DATA_TYPE_YUV420_3P,
91         SPRD_DATA_TYPE_LIMIT
92 };
93
94 enum{
95         SPRD_IMG_DATA_ENDIAN_B0B1B2B3 = 0,
96         SPRD_IMG_DATA_ENDIAN_B3B2B1B0,
97         SPRD_IMG_DATA_ENDIAN_B2B3B0B1,
98         SPRD_IMG_DATA_ENDIAN_B1B0B3B2,
99         SPRD_IMG_DATA_ENDIAN_LIMIT
100 };
101
102 enum{
103         SPRD_OVERLAY_STATUS_OFF = 0,
104         SPRD_OVERLAY_STATUS_ON,
105         SPRD_OVERLAY_STATUS_STARTED,
106         SPRD_OVERLAY_STATUS_MAX
107 };
108
109 enum{
110         SPRD_OVERLAY_DISPLAY_ASYNC = 0,
111         SPRD_OVERLAY_DISPLAY_SYNC,
112         SPRD_OVERLAY_DISPLAY_MAX
113 };
114
115 enum {
116         SPRD_DISPLAY_UPDATE_NONE = 0,
117         SPRD_DISPLAY_UPDATE_PAN,
118         SPRD_DISPLAY_UPDATE_OVERLAY,
119         SPRD_DISPLAY_UPDATE_MAX
120 };
121
122 typedef struct overlay_rect {
123         uint16_t x;
124         uint16_t y;
125         uint16_t w;
126         uint16_t h;
127 } overlay_rect;
128
129 typedef struct overlay_info {
130         int layer_index;
131         int data_type;
132         int y_endian;
133         int uv_endian;
134         bool rb_switch;
135         overlay_rect rect;
136         int v_endian;
137 } overlay_info;
138
139 #if defined (CONFIG_DRM_SPRD) && defined (CONFIG_SPRDFB_USE_GEM_INDEX)
140 typedef struct overlay_handle {
141         int handle;
142         int index;
143 } overlay_handle;
144 #endif
145
146 typedef struct overlay_display {
147         int layer_index;
148 #ifdef CONFIG_DRM_SPRD
149 #ifdef CONFIG_SPRDFB_USE_GEM_INDEX
150         struct overlay_handle osd_handle;
151         struct overlay_handle img_handle;
152 #else
153         int osd_handle;
154         int img_handle;
155 #endif
156 #else
157         unsigned char *osd_buffer;
158         unsigned char *img_buffer;
159 #endif
160         int display_mode;
161 } overlay_display;
162
163 #ifdef SPRDFB_OVERLAY_DEBUG
164 struct ov_info {
165         int y_endian;
166         int uv_endian;
167         int layer_index;
168         unsigned char *osd_buffer;
169         unsigned char *img_buffer;
170         overlay_rect rect;
171 };
172 #endif
173
174 #ifdef CONFIG_COMPAT
175 typedef struct overlay_info32{
176         int layer_index;
177         int data_type;
178         int y_endian;
179         int uv_endian;
180         bool rb_switch;
181         overlay_rect rect;
182         compat_caddr_t buffer;
183 }overlay_info32;
184 #endif
185 #endif
186
187 enum{
188         MIPI_PLL_TYPE_NONE = 0,
189         MIPI_PLL_TYPE_1,
190         MIPI_PLL_TYPE_2,
191         MIPI_PLL_TYPE_LIMIT
192 };
193
194 typedef struct fb_capability {
195         uint16_t need_light_sleep;      /* enable light_sleep in fb driver*/
196         uint16_t mipi_pll_type;         /* 0:none       1:for pike/pikel        2:for sharkl64/sharklT8*/
197 }fb_capability;
198
199 #ifdef CONFIG_DRM_SPRD
200 enum sprdfb_dpms {
201         SPRDFB_DPMS_ON = 0,
202         SPRDFB_DPMS_OFF = 3,
203         SPRDFB_DPMS_MAX,
204 };
205
206 enum sprdfb_notifier {
207         SPRDFB_SET_DPMS,
208         SPRDFB_MAX_NOTI,
209 };
210
211 struct sprdfb_nb_event {
212         int index;
213         void *data;
214 };
215 #endif
216
217 struct fps_info {
218         u32 enable_dmesg;
219         u32 interval_ms;
220         struct timespec timestamp_last;
221         u32 frame_counter_last;
222         u32 frame_counter;
223         u32 fpks;
224         int fps_checking_mode;  /*pan or overlay*/
225 };
226
227 struct sprdfb_device {
228         struct fb_info  *fb;
229         struct panel_spec       *panel;
230         struct display_ctrl     *ctrl;
231         void *logo_buffer_addr_v;
232         void *priv1;
233
234 #ifdef CONFIG_OF
235         struct device *of_dev;
236 #endif
237
238         uint16_t                enable;
239         uint16_t                dev_id; /*main_lcd, sub_lcd*/
240
241         uint32_t                bpp;  /*input bit per pixel*/
242
243         uint16_t                panel_ready; /*panel has been inited by uboot*/
244         uint16_t                panel_if_type; /*panel IF*/
245
246 #ifdef CONFIG_FB_LOW_RES_SIMU
247         uint32_t display_width;
248         uint32_t display_height;
249 #endif
250
251         union{
252                 uint32_t        mcu_timing[MCU_LCD_TIMING_KIND_MAX];
253                 uint32_t        rgb_timing[RGB_LCD_TIMING_KIND_MAX];
254         }panel_timing;
255
256         struct fb_capability capability;
257         uint32_t dpi_clock;
258         struct semaphore   refresh_lock;
259         uint64_t frame_count;
260
261 #ifdef CONFIG_FB_ESD_SUPPORT
262         struct delayed_work ESD_work;
263 //      struct semaphore   ESD_lock;
264         uint32_t ESD_timeout_val;
265         bool ESD_work_start;
266         /*for debug only*/
267         uint32_t check_esd_time;
268         uint32_t panel_reset_time;
269         uint32_t reset_dsi_time;
270 #ifdef FB_CHECK_ESD_BY_TE_SUPPORT
271         uint32_t esd_te_waiter;
272         wait_queue_head_t  esd_te_queue;
273         uint32_t esd_te_done;
274 #endif
275 #endif
276         unsigned int irq;
277         uint32_t logo_buffer_size;
278         struct fps_info fps;
279 #ifdef CONFIG_DRM_DPMS_IOCTL
280         struct notifier_block   nb_ctrl;
281 #endif
282 #ifdef CONFIG_HAS_EARLYSUSPEND
283         struct early_suspend    early_suspend;
284 #endif
285         /*For Special features*/
286         struct ion_client *fb_ion_client;
287         uint32_t dbg_cnt;
288 #ifdef SPRDFB_OVERLAY_DEBUG
289         struct ov_info overlay_data;
290 #endif
291 #if defined(CONFIG_LCD_CLASS_DEVICE)
292         struct lcd_device *ld;
293         uint16_t power;
294 #endif
295 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE)
296         struct backlight_device *bd;
297 #endif
298 #ifdef CONFIG_SLEEP_MONITOR
299         uint32_t act_cnt;
300 #endif
301 };
302
303 struct display_ctrl {
304         const char      *name;
305
306         int32_t (*early_init)     (struct sprdfb_device *dev);
307         int32_t (*init)           (struct sprdfb_device *dev);
308         int32_t (*uninit)                 (struct sprdfb_device *dev);
309
310         int32_t         (*refresh)        (struct sprdfb_device *dev);
311         void    (*logo_proc)      (struct sprdfb_device *dev);
312
313         int32_t (*suspend)        (struct sprdfb_device *dev);
314         int32_t         (*resume)         (struct sprdfb_device *dev);
315         int32_t (*update_clk) (struct sprdfb_device *dev);
316
317 #ifdef CONFIG_FB_ESD_SUPPORT
318         int32_t (*ESD_check)      (struct sprdfb_device *dev);
319 #endif
320
321 #ifdef  CONFIG_FB_LCD_OVERLAY_SUPPORT
322         int32_t         (*enable_overlay)       (struct sprdfb_device *dev, struct overlay_info* info, int enable);
323         int32_t (*display_overlay)      (struct sprdfb_device *dev, struct overlay_display* setting);
324         int32_t         (*disable_overlay)      (struct sprdfb_device *dev, int layer_index);
325 #endif
326
327 #ifdef CONFIG_FB_VSYNC_SUPPORT
328         int32_t         (*wait_for_vsync)       (struct sprdfb_device *dev);
329 #endif
330
331 #ifdef CONFIG_FB_MMAP_CACHED
332         void (*set_vma)(struct vm_area_struct *vma);
333 #endif
334         int32_t (*is_refresh_done)      (struct sprdfb_device *dev);
335
336 };
337
338 #ifndef ROUND
339 #define ROUND(a, b) (((a) + (b) / 2) / (b))
340 #endif
341
342 /* function declaration begin */
343 int sprdfb_create_sysfs(struct sprdfb_device *fb_dev);
344 void sprdfb_remove_sysfs(struct sprdfb_device *fb_dev);
345
346 #ifdef CONFIG_FB_DYNAMIC_FREQ_SCALING
347 int sprdfb_dispc_chg_clk(struct sprdfb_device *fb_dev,
348                                 int type, u32 new_val);
349 #else
350 #define sprdfb_dispc_chg_clk(fb_dev, type, new_val) ( \
351 { \
352         int _ret = -ENXIO; \
353         pr_err("dynamical clock feature hasn't been enabled yet\n"); \
354         _ret; \
355 } \
356 )
357 #endif
358
359 #if !defined(CONFIG_FB_SCX15)
360 int sprdfb_dsi_chg_dphy_freq(struct sprdfb_device *fb_dev,
361                 u32 dphy_freq);
362 int32_t dsi_dpi_init(struct sprdfb_device *dev);
363 #else
364 #define sprdfb_dsi_chg_dphy_freq(fb_dev, dphy_freq) ( \
365 { \
366         int _ret = -ENXIO; \
367         pr_err("this chip doesn't support for mipi dsi\n"); \
368         _ret; \
369 } \
370 )
371
372 #define dsi_dpi_init(fb_dev) ( \
373 { \
374         int _ret = -ENXIO; \
375         pr_err("this chip doesn't support for mipi dsi\n"); \
376         _ret; \
377 } \
378 )
379 #endif
380
381 int sprdfb_chg_clk_intf(struct sprdfb_device *fb_dev,
382                         int type, u32 new_val);
383 /* Function declare begin */
384 #ifdef CONFIG_SC_FPGA
385 int sprdchip_lvds_init(void);
386 #endif
387 /* Function declare end */
388
389 #ifdef CONFIG_DRM_SPRD
390 int sprdfb_nb_register(struct notifier_block *nb);
391 int sprdfb_nb_unregister(struct notifier_block *nb);
392 int sprdfb_nb_send_event(unsigned long val, void *v);
393 #endif
394
395 #endif