1 /* 2 * Allwinner SoCs display driver. 3 * 4 * Copyright (C) 2016 Allwinner. 5 * 6 * This file is licensed under the terms of the GNU General Public 7 * License version 2. This program is licensed "as is" without any 8 * warranty of any kind, whether express or implied. 9 */ 10 11 #ifndef __DEV_DISP_H__ 12 #define __DEV_DISP_H__ 13 14 #include <linux/poll.h> 15 #include "dev_disp_debugfs.h" 16 #include "de/bsp_display.h" 17 #include "de/disp_display.h" 18 #include "de/disp_manager.h" 19 #include "de/lcd_debug.h" 20 #ifdef CONFIG_HAS_EARLYSUSPEND 21 #include <linux/earlysuspend.h> 22 #endif 23 #include <linux/version.h> 24 25 #ifdef CONFIG_DMABUF_HEAPS 26 #define FB_RESERVED_MEM 27 #endif 28 29 enum disp_standby_flags { 30 DISPLAY_NORMAL = 0, 31 DISPLAY_LIGHT_SLEEP = 1, 32 DISPLAY_DEEP_SLEEP = 2, 33 DISPLAY_BLANK = 4, 34 }; 35 36 struct info_mm { 37 void *info_base; /* Virtual address */ 38 uintptr_t mem_start; /* Start of frame buffer mem */ 39 /* (physical address) */ 40 u32 mem_len; /* Length of frame buffer mem */ 41 struct disp_ion_mem *p_ion_mem; 42 }; 43 44 struct proc_list { 45 void (*proc)(u32 screen_id); 46 struct list_head list; 47 }; 48 49 struct ioctl_list { 50 unsigned int cmd; 51 int (*func)(unsigned int cmd, unsigned long arg); 52 struct list_head list; 53 }; 54 55 struct standby_cb_list { 56 int (*suspend)(void); 57 int (*resume)(void); 58 struct list_head list; 59 }; 60 61 struct disp_init_para { 62 bool b_init; 63 enum disp_init_mode disp_mode; 64 65 /* for screen0/1/2 */ 66 enum disp_output_type output_type[8]; 67 unsigned int output_mode[8]; 68 enum disp_csc_type output_format[DISP_SCREEN_NUM]; 69 enum disp_data_bits output_bits[DISP_SCREEN_NUM]; 70 enum disp_eotf output_eotf[DISP_SCREEN_NUM]; 71 enum disp_color_space output_cs[DISP_SCREEN_NUM]; 72 enum disp_dvi_hdmi output_dvi_hdmi[DISP_SCREEN_NUM]; 73 enum disp_color_range output_range[DISP_SCREEN_NUM]; 74 enum disp_scan_info output_scan[DISP_SCREEN_NUM]; 75 unsigned int output_aspect_ratio[DISP_SCREEN_NUM]; 76 bool using_device_config[DISP_SCREEN_NUM]; 77 unsigned int reserve1; 78 unsigned int reserve2; 79 80 /* for fb0/1/2 */ 81 unsigned int buffer_num[DISP_SCREEN_NUM]; 82 enum disp_pixel_format format[DISP_SCREEN_NUM]; 83 unsigned int fb_width[DISP_SCREEN_NUM]; 84 unsigned int fb_height[DISP_SCREEN_NUM]; 85 86 unsigned int chn_cfg_mode; 87 }; 88 89 struct disp_ion_mgr { 90 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0) 91 struct ion_client *client; 92 #endif 93 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) 94 struct ion_handle *handle; 95 #else 96 struct dma_buf *dma_buf; 97 #endif 98 struct mutex mlock; 99 struct list_head ion_list; 100 }; 101 102 103 struct disp_ion_mem { 104 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0) 105 struct ion_handle *handle; 106 #endif 107 void *vaddr; 108 size_t size; 109 struct dmabuf_item *p_item; 110 111 }; 112 113 struct disp_ion_list_node { 114 struct list_head node; 115 struct disp_ion_mem mem; 116 }; 117 118 #define VSYNC_NUM 4 119 struct disp_vsync { 120 struct task_struct *vsync_task[3]; 121 spinlock_t slock[DISP_SCREEN_NUM]; 122 int vsync_cur_line[DISP_SCREEN_NUM][VSYNC_NUM]; 123 ktime_t vsync_timestamp[DISP_SCREEN_NUM][VSYNC_NUM]; 124 u32 vsync_timestamp_head[DISP_SCREEN_NUM]; 125 u32 vsync_timestamp_tail[DISP_SCREEN_NUM]; 126 wait_queue_head_t vsync_waitq; 127 bool vsync_read[DISP_SCREEN_NUM]; 128 }; 129 struct disp_drv_info { 130 struct device *dev; 131 struct device_node *node; 132 uintptr_t reg_base[DISP_MOD_NUM]; 133 u32 irq_no[DISP_MOD_NUM]; 134 135 136 struct clk *clk_de[DE_NUM]; 137 struct clk *clk_bus_de[DE_NUM]; 138 #if defined(HAVE_DEVICE_COMMON_MODULE) 139 struct clk *clk_bus_extra; 140 #endif 141 struct clk *clk_bus_dpss_top[DISP_DEVICE_NUM]; 142 struct clk *clk_tcon[DISP_DEVICE_NUM]; 143 struct clk *clk_bus_tcon[DISP_DEVICE_NUM]; 144 145 struct reset_control *rst_bus_de[DE_NUM]; 146 #if defined(HAVE_DEVICE_COMMON_MODULE) 147 struct reset_control *rst_bus_extra; 148 #endif 149 struct reset_control *rst_bus_dpss_top[DISP_DEVICE_NUM]; 150 struct reset_control *rst_bus_tcon[DISP_DEVICE_NUM]; 151 struct reset_control *rst_bus_lvds[DEVICE_LVDS_NUM]; 152 #if defined(SUPPORT_DSI) 153 struct clk *clk_mipi_dsi[CLK_DSI_NUM]; 154 struct clk *clk_bus_mipi_dsi[CLK_DSI_NUM]; 155 struct reset_control *rst_bus_mipi_dsi[DEVICE_DSI_NUM]; 156 #endif 157 158 struct disp_vsync disp_vsync; 159 struct disp_init_para disp_init; 160 struct disp_manager *mgr[DISP_SCREEN_NUM]; 161 struct disp_eink_manager *eink_manager[1]; 162 struct proc_list sync_proc_list; 163 struct proc_list sync_finish_proc_list; 164 struct ioctl_list ioctl_extend_list; 165 struct ioctl_list compat_ioctl_extend_list; 166 struct standby_cb_list stb_cb_list; 167 struct mutex mlock; 168 struct work_struct resume_work[DISP_SCREEN_NUM]; 169 struct work_struct start_work; 170 171 u32 exit_mode; /* 0:clean all 1:disable interrupt */ 172 bool b_lcd_enabled[DISP_SCREEN_NUM]; 173 bool inited; /* indicate driver if init */ 174 struct disp_bsp_init_para para; 175 #if defined(CONFIG_DMABUF_HEAPS) 176 struct disp_ion_mgr ion_mgr; 177 #endif 178 }; 179 180 struct sunxi_disp_mod { 181 enum disp_mod_id id; 182 char name[32]; 183 }; 184 185 struct __fb_addr_para { 186 uintptr_t fb_paddr; 187 int fb_size; 188 }; 189 190 #define DISP_RESOURCE(res_name, res_start, res_end, res_flags) \ 191 {\ 192 .start = (int __force)res_start, \ 193 .end = (int __force)res_end, \ 194 .flags = res_flags, \ 195 .name = #res_name \ 196 }, 197 198 struct bmp_color_table_entry { 199 u8 blue; 200 u8 green; 201 u8 red; 202 u8 reserved; 203 } __packed; 204 205 struct lzma_header { 206 char signature[4]; 207 u32 file_size; 208 u32 original_file_size; 209 }; 210 211 struct bmp_header { 212 /* Header */ 213 char signature[2]; 214 u32 file_size; 215 u32 reserved; 216 u32 data_offset; 217 /* InfoHeader */ 218 u32 size; 219 u32 width; 220 u32 height; 221 u16 planes; 222 u16 bit_count; 223 u32 compression; 224 u32 image_size; 225 u32 x_pixels_per_m; 226 u32 y_pixels_per_m; 227 u32 colors_used; 228 u32 colors_important; 229 /* ColorTable */ 230 } __packed; 231 232 struct bmp_pad_header { 233 char data[2]; /* pading 2 byte */ 234 char signature[2]; 235 u32 file_size; 236 u32 reserved; 237 u32 data_offset; 238 /* InfoHeader */ 239 u32 size; 240 u32 width; 241 u32 height; 242 u16 planes; 243 u16 bit_count; 244 u32 compression; 245 u32 image_size; 246 u32 x_pixels_per_m; 247 u32 y_pixels_per_m; 248 u32 colors_used; 249 u32 colors_important; 250 } __packed; 251 252 struct bmp_image { 253 struct bmp_header header; 254 /* 255 * We use a zero sized array just as a placeholder for variable 256 * sized array 257 */ 258 struct bmp_color_table_entry color_table[0]; 259 }; 260 261 struct sunxi_bmp_store { 262 int x; 263 int y; 264 int bit; 265 void *buffer; 266 }; 267 268 int disp_draw_colorbar(u32 disp, u8 zorder); 269 270 void disp_set_suspend_output_type(u8 disp, u8 output_type); 271 272 int disp_open(struct inode *inode, struct file *file); 273 int disp_release(struct inode *inode, struct file *file); 274 ssize_t disp_read(struct file *file, char __user *buf, size_t count, 275 loff_t *ppos); 276 ssize_t disp_write(struct file *file, const char __user *buf, size_t count, 277 loff_t *ppos); 278 int disp_mmap(struct file *file, struct vm_area_struct *vma); 279 long disp_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 280 281 int disp_suspend(struct device *dev); 282 int disp_resume(struct device *dev); 283 s32 disp_create_heap(u32 pHeapHead, u32 pHeapHeadPhy, u32 nHeapSize); 284 void *disp_malloc(u32 num_bytes, void *phy_addr); 285 void disp_free(void *virt_addr, void *phy_addr, u32 num_bytes); 286 287 extern s32 disp_register_sync_proc(void (*proc) (u32)); 288 extern s32 disp_unregister_sync_proc(void (*proc) (u32)); 289 extern s32 disp_register_sync_finish_proc(void (*proc) (u32)); 290 extern s32 disp_unregister_sync_finish_proc(void (*proc) (u32)); 291 extern s32 disp_register_ioctl_func(unsigned int cmd, 292 int (*proc)(unsigned int cmd, 293 unsigned long arg)); 294 extern s32 disp_unregister_ioctl_func(unsigned int cmd); 295 extern s32 disp_register_compat_ioctl_func(unsigned int cmd, 296 int (*proc)(unsigned int cmd, 297 unsigned long arg)); 298 extern s32 disp_unregister_compat_ioctl_func(unsigned int cmd); 299 extern s32 disp_register_standby_func(int (*suspend) (void), 300 int (*resume)(void)); 301 extern s32 disp_unregister_standby_func(int (*suspend) (void), 302 int (*resume)(void)); 303 extern s32 composer_init(struct disp_drv_info *psg_disp_drv); 304 extern unsigned int composer_dump(char *buf); 305 extern s32 disp_tv_register(struct disp_tv_func *func); 306 extern s32 disp_set_hdmi_detect(bool hpd); 307 s32 disp_set_edp_func(struct disp_tv_func *func); 308 unsigned int vsync_poll(struct file *file, poll_table *wait); 309 int bsp_disp_get_vsync_timestamp(int disp, int64_t *timestamp); 310 311 extern struct disp_drv_info g_disp_drv; 312 313 extern int sunxi_disp_get_source_ops(struct sunxi_disp_source_ops *src_ops); 314 extern s32 disp_lcd_open(u32 sel); 315 extern s32 disp_lcd_close(u32 sel); 316 extern s32 fb_init(struct platform_device *pdev); 317 extern s32 fb_exit(void); 318 extern unsigned long fb_get_address_info(u32 fb_id, u32 phy_virt_flag); 319 extern s32 fb_exit(void); 320 extern int lcd_init(void); 321 322 s32 disp_set_hdmi_func(struct disp_device_func *func); 323 s32 disp_set_vdpo_func(struct disp_tv_func *func); 324 s32 sunxi_get_fb_addr_para(struct __fb_addr_para *fb_addr_para); 325 s32 fb_draw_gray_pictures(char *base, u32 width, u32 height, 326 struct fb_var_screeninfo *var); 327 s32 drv_disp_vsync_event(u32 sel); 328 void DRV_disp_int_process(u32 sel); 329 s32 Display_set_fb_timming(u32 sel); 330 unsigned int disp_boot_para_parse(const char *name); 331 const char *disp_boot_para_parse_str(const char *name); 332 int disp_get_parameter_for_cmdlind(char *cmdline, char *name, char *value); 333 extern s32 bsp_disp_shadow_protect(u32 disp, bool protect); 334 extern int disp_attr_node_init(void); 335 extern int capture_module_init(void); 336 extern void capture_module_exit(void); 337 338 #if defined(SUPPORT_VDPO) 339 extern s32 disp_vdpo_set_config(struct disp_device *p_vdpo, 340 struct disp_vdpo_config *p_cfg); 341 #endif /*endif SUPPORT_VDPO */ 342 343 struct disp_ion_mem *disp_ion_malloc(u32 num_bytes, void *phys_addr); 344 void disp_ion_free(void *virt_addr, void *phys_addr, u32 num_bytes); 345 void disp_ion_flush_cache(void *startAddr, int size); 346 int disp_get_ion_fd(struct disp_ion_mem *mem); 347 void *disp_get_phy_addr(struct disp_ion_mem *mem); 348 #endif 349