2 * Copyright (C) 2012 Spreadtrum Communications Inc.
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.
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.
17 #ifdef CONFIG_HAS_EARLYSUSPEND
18 #include <linux/earlysuspend.h>
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>
27 #include <linux/time.h>
28 #include <linux/notifier.h>
29 #ifdef CONFIG_DRM_SPRD
30 #include <drm/sprd_drm.h>
33 #ifdef CONFIG_SPRDFB_MDNIE_LITE_TUNING
34 #include "mdnie/mdnie_lite.h"
37 #if ((!defined(CONFIG_FB_SCX35)) && (!defined(CONFIG_FB_SCX15)))
38 #define FB_CHECK_ESD_IN_VFP
40 //#define FB_CHECK_ESD_BY_TE_SUPPORT
41 #define BIT_PER_PIXEL_SURPPORT
43 #if defined(CONFIG_FB_LCD_OVERLAY_SUPPORT)
44 #define SPRDFB_OVERLAY_DEBUG
48 SPRDFB_PANEL_IF_DBI = 0,
56 SPRDFB_DYNAMIC_PCLK = 0x1,
58 SPRDFB_DYNAMIC_MIPI_CLK,
64 MCU_LCD_REGISTER_TIMING = 0,
66 MCU_LCD_TIMING_KIND_MAX
72 RGB_LCD_TIMING_KIND_MAX
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*/
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,
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
103 SPRD_OVERLAY_STATUS_OFF = 0,
104 SPRD_OVERLAY_STATUS_ON,
105 SPRD_OVERLAY_STATUS_STARTED,
106 SPRD_OVERLAY_STATUS_MAX
110 SPRD_OVERLAY_DISPLAY_ASYNC = 0,
111 SPRD_OVERLAY_DISPLAY_SYNC,
112 SPRD_OVERLAY_DISPLAY_MAX
116 SPRD_DISPLAY_UPDATE_NONE = 0,
117 SPRD_DISPLAY_UPDATE_PAN,
118 SPRD_DISPLAY_UPDATE_OVERLAY,
119 SPRD_DISPLAY_UPDATE_MAX
122 typedef struct overlay_rect {
129 typedef struct overlay_info {
139 #if defined (CONFIG_DRM_SPRD) && defined (CONFIG_SPRDFB_USE_GEM_INDEX)
140 typedef struct overlay_handle {
146 typedef struct overlay_display {
148 #ifdef CONFIG_DRM_SPRD
149 #ifdef CONFIG_SPRDFB_USE_GEM_INDEX
150 struct overlay_handle osd_handle;
151 struct overlay_handle img_handle;
157 unsigned char *osd_buffer;
158 unsigned char *img_buffer;
163 #ifdef SPRDFB_OVERLAY_DEBUG
168 unsigned char *osd_buffer;
169 unsigned char *img_buffer;
175 typedef struct overlay_info32{
182 compat_caddr_t buffer;
188 MIPI_PLL_TYPE_NONE = 0,
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*/
199 #ifdef CONFIG_DRM_SPRD
206 enum sprdfb_notifier {
211 struct sprdfb_nb_event {
220 struct timespec timestamp_last;
221 u32 frame_counter_last;
224 int fps_checking_mode; /*pan or overlay*/
227 struct sprdfb_device {
229 struct panel_spec *panel;
230 struct display_ctrl *ctrl;
231 void *logo_buffer_addr_v;
235 struct device *of_dev;
239 uint16_t dev_id; /*main_lcd, sub_lcd*/
241 uint32_t bpp; /*input bit per pixel*/
243 uint16_t panel_ready; /*panel has been inited by uboot*/
244 uint16_t panel_if_type; /*panel IF*/
246 #ifdef CONFIG_FB_LOW_RES_SIMU
247 uint32_t display_width;
248 uint32_t display_height;
252 uint32_t mcu_timing[MCU_LCD_TIMING_KIND_MAX];
253 uint32_t rgb_timing[RGB_LCD_TIMING_KIND_MAX];
256 struct fb_capability capability;
258 struct semaphore refresh_lock;
259 uint64_t frame_count;
261 #ifdef CONFIG_FB_ESD_SUPPORT
262 struct delayed_work ESD_work;
263 // struct semaphore ESD_lock;
264 uint32_t ESD_timeout_val;
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;
277 uint32_t logo_buffer_size;
279 #ifdef CONFIG_DRM_DPMS_IOCTL
280 struct notifier_block nb_ctrl;
282 #ifdef CONFIG_HAS_EARLYSUSPEND
283 struct early_suspend early_suspend;
285 /*For Special features*/
286 struct ion_client *fb_ion_client;
288 #ifdef SPRDFB_OVERLAY_DEBUG
289 struct ov_info overlay_data;
291 #if defined(CONFIG_LCD_CLASS_DEVICE)
292 struct lcd_device *ld;
295 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE)
296 struct backlight_device *bd;
298 #ifdef CONFIG_SLEEP_MONITOR
303 struct display_ctrl {
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);
310 int32_t (*refresh) (struct sprdfb_device *dev);
311 void (*logo_proc) (struct sprdfb_device *dev);
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);
317 #ifdef CONFIG_FB_ESD_SUPPORT
318 int32_t (*ESD_check) (struct sprdfb_device *dev);
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);
327 #ifdef CONFIG_FB_VSYNC_SUPPORT
328 int32_t (*wait_for_vsync) (struct sprdfb_device *dev);
331 #ifdef CONFIG_FB_MMAP_CACHED
332 void (*set_vma)(struct vm_area_struct *vma);
334 int32_t (*is_refresh_done) (struct sprdfb_device *dev);
339 #define ROUND(a, b) (((a) + (b) / 2) / (b))
342 /* function declaration begin */
343 int sprdfb_create_sysfs(struct sprdfb_device *fb_dev);
344 void sprdfb_remove_sysfs(struct sprdfb_device *fb_dev);
346 #ifdef CONFIG_FB_DYNAMIC_FREQ_SCALING
347 int sprdfb_dispc_chg_clk(struct sprdfb_device *fb_dev,
348 int type, u32 new_val);
350 #define sprdfb_dispc_chg_clk(fb_dev, type, new_val) ( \
353 pr_err("dynamical clock feature hasn't been enabled yet\n"); \
359 #if !defined(CONFIG_FB_SCX15)
360 int sprdfb_dsi_chg_dphy_freq(struct sprdfb_device *fb_dev,
362 int32_t dsi_dpi_init(struct sprdfb_device *dev);
364 #define sprdfb_dsi_chg_dphy_freq(fb_dev, dphy_freq) ( \
367 pr_err("this chip doesn't support for mipi dsi\n"); \
372 #define dsi_dpi_init(fb_dev) ( \
375 pr_err("this chip doesn't support for mipi dsi\n"); \
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);
387 /* Function declare end */
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);