1 /* 2 * include/include.h 3 * 4 * Copyright (c) 2007-2019 Allwinnertech Co., Ltd. 5 * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com> 6 * 7 * This software is licensed under the terms of the GNU General Public 8 * License version 2, as published by the Free Software Foundation, and 9 * may be copied, distributed, and modified under those terms. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 */ 17 #ifndef _INCLUDE_H 18 #define _INCLUDE_H 19 20 #define __LINUX_PLAT__ 21 #include "asm-generic/int-ll64.h" 22 #include "linux/semaphore.h" 23 #include <asm/barrier.h> 24 #include <asm/div64.h> 25 #include <asm/memory.h> 26 #include <asm/unistd.h> 27 #include <linux/cdev.h> 28 #include <linux/clk-provider.h> 29 #include <linux/clk.h> 30 #include <linux/compat.h> 31 #include <linux/delay.h> 32 #include <linux/delay.h> 33 #include <linux/dma-buf.h> 34 #include <linux/dma-mapping.h> 35 #include <linux/dma-mapping.h> 36 #include <linux/dma-mapping.h> 37 #include <linux/err.h> /* IS_ERR()??PTR_ERR() */ 38 #include <linux/errno.h> 39 #include <linux/fb.h> 40 #include <linux/fs.h> 41 #include <linux/gpio.h> 42 #include <linux/init.h> 43 #include <linux/interrupt.h> 44 #include <linux/kernel.h> 45 #include <linux/kthread.h> /* kthread_create()??kthread_run() */ 46 #include <linux/mm.h> 47 #include <linux/module.h> 48 #include <linux/of_address.h> 49 #include <linux/of_device.h> 50 #include <linux/of_gpio.h> 51 #include <linux/of_iommu.h> 52 #include <linux/of_irq.h> 53 #include <linux/of_platform.h> 54 #include <linux/platform_device.h> 55 #include <linux/platform_device.h> 56 #include <linux/pwm.h> 57 #include <linux/regulator/consumer.h> 58 #include <linux/sched.h> /* wake_up_process() */ 59 #include <linux/slab.h> 60 #include <linux/timer.h> 61 #include <linux/types.h> 62 #include <linux/uaccess.h> 63 #include <linux/vmalloc.h> 64 #include <sunxi-clk.h> 65 #include <linux/sunxi-gpio.h> 66 #include <linux/pinctrl/consumer.h> 67 #include <linux/clk-provider.h> 68 #include <linux/spi/spidev.h> 69 #include <linux/spi/spi.h> 70 #include "../../../../spi/spi-sunxi.h" 71 #include "lcd_fb_feature.h" 72 73 #define LCD_GAMMA_TABLE_SIZE (256 * sizeof(unsigned int)) 74 #define LCD_FB_DEBUG_LEVEL 0 75 #define LCD_FB_MAX 2 /*TODO:auto detect*/ 76 77 #if LCD_FB_DEBUG_LEVEL == 1 78 #define lcd_fb_inf(msg...) do { \ 79 pr_warn("[LCD_FB] %s,line:%d:", __func__, __LINE__); \ 80 pr_warn(msg); \ 81 } while (0) 82 #define lcd_fb_msg(msg...) do { \ 83 pr_warn("[LCD_FB] %s,line:%d:", __func__, __LINE__); \ 84 pr_warn(msg); \ 85 } while (0) 86 #define lcd_fb_here 87 #define lcd_fb_dbg(msg...) 88 #elif LCD_FB_DEBUG_LEVEL == 2 89 #define lcd_fb_inf(msg...) do { \ 90 pr_warn("[LCD_FB] %s,line:%d:", __func__, __LINE__); \ 91 pr_warn(msg); \ 92 } while (0) 93 #define lcd_fb_here do { \ 94 pr_warn("[LCD_FB] %s,line:%d\n", __func__, __LINE__);\ 95 } while (0) 96 #define lcd_fb_dbg(msg...) do { \ 97 pr_warn("[LCD_FB] %s,line:%d:", __func__, __LINE__); \ 98 pr_warn(msg); \ 99 } while (0) 100 #else 101 #define lcd_fb_inf(msg...) 102 #define lcd_fb_msg(msg...) 103 #define lcd_fb_here 104 #define lcd_fb_dbg(msg...) 105 #endif 106 107 #define lcd_fb_wrn(msg...) do { \ 108 pr_warn("[LCD_FB] %s,line:%d:", __func__, __LINE__); \ 109 pr_warn(msg); \ 110 } while (0) 111 112 113 typedef void (*LCD_FUNC) (unsigned int sel); 114 struct disp_lcd_function { 115 LCD_FUNC func; 116 unsigned int delay; 117 }; 118 119 #define LCD_MAX_SEQUENCES 7 120 struct disp_lcd_flow { 121 struct disp_lcd_function func[LCD_MAX_SEQUENCES]; 122 unsigned int func_num; 123 unsigned int cur_step; 124 }; 125 126 struct panel_extend_para { 127 unsigned int lcd_gamma_en; 128 unsigned int lcd_gamma_tbl[256]; 129 unsigned int lcd_cmap_en; 130 unsigned int lcd_cmap_tbl[2][3][4]; 131 unsigned int lcd_bright_curve_tbl[256]; 132 }; 133 134 struct disp_rect { 135 int x; 136 int y; 137 unsigned int width; 138 unsigned int height; 139 }; 140 141 142 struct disp_lcd_panel_fun { 143 void (*cfg_panel_info)(struct panel_extend_para *info); 144 int (*cfg_open_flow)(unsigned int sel); 145 int (*cfg_close_flow)(unsigned int sel); 146 int (*lcd_user_defined_func)(unsigned int sel, unsigned int para1, 147 unsigned int para2, unsigned int para3); 148 int (*set_bright)(unsigned int sel, unsigned int bright); 149 int (*blank)(unsigned int sel, unsigned int en); 150 int (*set_var)(unsigned int sel, struct fb_info *info); 151 int (*set_addr_win)(unsigned int sel, int x, int y, int width, int height); 152 }; 153 154 155 struct disp_video_timings { 156 unsigned int vic; /* video information code */ 157 unsigned int tv_mode; 158 unsigned int pixel_clk; 159 unsigned int pixel_repeat; /* pixel repeat (pixel_repeat+1) times */ 160 unsigned int x_res; 161 unsigned int y_res; 162 unsigned int hor_total_time; 163 unsigned int hor_back_porch; 164 unsigned int hor_front_porch; 165 unsigned int hor_sync_time; 166 unsigned int ver_total_time; 167 unsigned int ver_back_porch; 168 unsigned int ver_front_porch; 169 unsigned int ver_sync_time; 170 unsigned int hor_sync_polarity; /* 0: negative, 1: positive */ 171 unsigned int ver_sync_polarity; /* 0: negative, 1: positive */ 172 bool b_interlace; 173 unsigned int vactive_space; 174 unsigned int trd_mode; 175 unsigned long dclk_rate_set; /*unit: hz */ 176 unsigned long long frame_period; /* unit: ns */ 177 int start_delay; /* unit: line */ 178 }; 179 180 enum disp_fb_mode { 181 FB_MODE_SCREEN0 = 0, 182 FB_MODE_SCREEN1 = 1, 183 FB_MODE_SCREEN2 = 2, 184 FB_MODE_DUAL_SAME_SCREEN_TB = 3,/* two screen, top buffer for screen0, bottom buffer for screen1 */ 185 FB_MODE_DUAL_DIFF_SCREEN_SAME_CONTENTS = 4,/* two screen, they have same contents; */ 186 }; 187 188 struct disp_fb_create_info { 189 enum disp_fb_mode fb_mode; 190 unsigned int buffer_num; 191 unsigned int width; 192 unsigned int height; 193 194 unsigned int output_width; /* used when scaler mode */ 195 unsigned int output_height; /* used when scaler mode */ 196 }; 197 198 199 enum disp_lcd_if { 200 LCD_FB_IF_SPI = 0, 201 LCD_FB_IF_DBI = 1, 202 }; 203 204 enum lcd_fb_dbi_if { 205 LCD_FB_L3I1 = 0x0, 206 LCD_FB_L3I2 = 0x1, 207 LCD_FB_L4I1 = 0x2, 208 LCD_FB_L4I2 = 0x3, 209 LCD_FB_D2LI = 0x4, 210 }; 211 212 enum lcdfb_pixel_format { 213 LCDFB_FORMAT_ARGB_8888 = 0x00, /* MSB A-R-G-B LSB */ 214 LCDFB_FORMAT_ABGR_8888 = 0x01, 215 LCDFB_FORMAT_RGBA_8888 = 0x02, 216 LCDFB_FORMAT_BGRA_8888 = 0x03, 217 LCDFB_FORMAT_XRGB_8888 = 0x04, 218 LCDFB_FORMAT_XBGR_8888 = 0x05, 219 LCDFB_FORMAT_RGBX_8888 = 0x06, 220 LCDFB_FORMAT_BGRX_8888 = 0x07, 221 LCDFB_FORMAT_RGB_888 = 0x08, 222 LCDFB_FORMAT_BGR_888 = 0x09, 223 LCDFB_FORMAT_RGB_565 = 0x0a, 224 LCDFB_FORMAT_BGR_565 = 0x0b, 225 LCDFB_FORMAT_ARGB_4444 = 0x0c, 226 LCDFB_FORMAT_ABGR_4444 = 0x0d, 227 LCDFB_FORMAT_RGBA_4444 = 0x0e, 228 LCDFB_FORMAT_BGRA_4444 = 0x0f, 229 LCDFB_FORMAT_ARGB_1555 = 0x10, 230 LCDFB_FORMAT_ABGR_1555 = 0x11, 231 LCDFB_FORMAT_RGBA_5551 = 0x12, 232 LCDFB_FORMAT_BGRA_5551 = 0x13, 233 }; 234 235 enum lcdfb_dbi_fmt { 236 LCDFB_DBI_RGB111 = 0x0, 237 LCDFB_DBI_RGB444 = 0x1, 238 LCDFB_DBI_RGB565 = 0x2, 239 LCDFB_DBI_RGB666 = 0x3, 240 LCDFB_DBI_RGB888 = 0x4, 241 }; 242 243 struct disp_panel_para { 244 enum disp_lcd_if lcd_if; 245 enum lcd_fb_dbi_if dbi_if; 246 unsigned int lcd_spi_bus_num; 247 248 unsigned int lcd_data_speed; 249 unsigned int lcd_x; /* horizontal resolution */ 250 unsigned int lcd_y; /* vertical resolution */ 251 unsigned int lcd_width; /* width of lcd in mm */ 252 unsigned int lcd_height; /* height of lcd in mm */ 253 254 unsigned int lcd_pwm_used; 255 unsigned int lcd_pwm_ch; 256 unsigned int lcd_pwm_freq; 257 unsigned int lcd_pwm_pol; 258 enum lcdfb_pixel_format lcd_pixel_fmt; 259 enum lcdfb_dbi_fmt lcd_dbi_fmt; 260 unsigned int lcd_dbi_clk_mode; 261 unsigned int lcd_dbi_te; 262 unsigned int fb_buffer_num; 263 264 enum dbi_src_seq lcd_rgb_order; 265 unsigned int lcd_fps; 266 267 unsigned int lcd_frm; 268 unsigned int lcd_gamma_en; 269 unsigned int lcd_bright_curve_en; 270 unsigned int lines_per_transfer; 271 272 char lcd_size[8]; /* e.g. 7.9, 9.7 */ 273 char lcd_model_name[32]; 274 275 }; 276 277 278 279 struct lcd_fb_device { 280 struct list_head list; 281 struct device *dev; 282 char name[32]; 283 u32 disp; 284 285 void *priv_data; 286 struct spi_device *spi_device; 287 288 struct disp_video_timings timings; 289 s32 (*init)(struct lcd_fb_device *p_lcd); 290 s32 (*exit)(struct lcd_fb_device *p_lcd); 291 s32 (*enable)(struct lcd_fb_device *p_lcd); 292 s32 (*fake_enable)(struct lcd_fb_device *p_lcd); 293 s32 (*disable)(struct lcd_fb_device *p_lcd); 294 s32 (*is_enabled)(struct lcd_fb_device *p_lcd); 295 s32 (*get_resolution)(struct lcd_fb_device *p_lcd, u32 *xres, 296 u32 *yres); 297 s32 (*get_dimensions)(struct lcd_fb_device *dispdev, u32 *width, 298 u32 *height); 299 s32 (*set_color_temperature)(struct lcd_fb_device *dispdev, s32 color_temperature); 300 s32 (*get_color_temperature)(struct lcd_fb_device *dispdev); 301 s32 (*suspend)(struct lcd_fb_device *p_lcd); 302 s32 (*resume)(struct lcd_fb_device *p_lcd); 303 s32 (*set_bright)(struct lcd_fb_device *p_lcd, u32 bright); 304 s32 (*get_bright)(struct lcd_fb_device *p_lcd); 305 s32 (*backlight_enable)(struct lcd_fb_device *p_lcd); 306 s32 (*backlight_disable)(struct lcd_fb_device *p_lcd); 307 s32 (*pwm_enable)(struct lcd_fb_device *p_lcd); 308 s32 (*pwm_disable)(struct lcd_fb_device *p_lcd); 309 s32 (*power_enable)(struct lcd_fb_device *p_lcd, u32 power_id); 310 s32 (*power_disable)(struct lcd_fb_device *p_lcd, u32 power_id); 311 s32 (*pin_cfg)(struct lcd_fb_device *p_lcd, u32 bon); 312 s32 (*set_gamma_tbl)(struct lcd_fb_device *p_lcd, u32 *tbl, 313 u32 size); 314 s32 (*set_bright_dimming)(struct lcd_fb_device *dispdev, u32 dimming); 315 s32 (*enable_gamma)(struct lcd_fb_device *p_lcd); 316 s32 (*disable_gamma)(struct lcd_fb_device *p_lcd); 317 s32 (*set_panel_func)(struct lcd_fb_device *lcd, char *name, 318 struct disp_lcd_panel_fun *lcd_cfg); 319 s32 (*set_open_func)(struct lcd_fb_device *lcd, LCD_FUNC func, 320 u32 delay); 321 s32 (*set_close_func)(struct lcd_fb_device *lcd, LCD_FUNC func, 322 u32 delay); 323 int (*gpio_set_value)(struct lcd_fb_device *p_lcd, 324 unsigned int io_index, u32 value); 325 int (*gpio_set_direction)(struct lcd_fb_device *p_lcd, 326 unsigned int io_index, u32 direction); 327 int (*get_panel_info)(struct lcd_fb_device *p_lcd, 328 struct disp_panel_para *info); 329 int (*set_layer)(struct lcd_fb_device *p_lcd, struct fb_info *p_info); 330 int (*set_var)(struct lcd_fb_device *p_lcd, struct fb_info *p_info); 331 int (*blank)(struct lcd_fb_device *p_lcd, unsigned int en); 332 int (*cmd_write)(struct lcd_fb_device *p_lcd, unsigned char cmd); 333 int (*para_write)(struct lcd_fb_device *p_lcd, unsigned char para); 334 int (*cmd_read)(struct lcd_fb_device *p_lcd, unsigned char cmd, 335 unsigned char *rx_buf, unsigned char len); 336 int (*wait_for_vsync)(struct lcd_fb_device *p_lcd); 337 }; 338 339 struct sunxi_disp_source_ops { 340 int (*sunxi_lcd_delay_ms)(unsigned int ms); 341 int (*sunxi_lcd_delay_us)(unsigned int us); 342 int (*sunxi_lcd_backlight_enable)(unsigned int screen_id); 343 int (*sunxi_lcd_backlight_disable)(unsigned int screen_id); 344 int (*sunxi_lcd_pwm_enable)(unsigned int screen_id); 345 int (*sunxi_lcd_pwm_disable)(unsigned int screen_id); 346 int (*sunxi_lcd_power_enable)(unsigned int screen_id, 347 unsigned int pwr_id); 348 int (*sunxi_lcd_power_disable)(unsigned int screen_id, 349 unsigned int pwr_id); 350 int (*sunxi_lcd_set_panel_funs)(char *drv_name, 351 struct disp_lcd_panel_fun *lcd_cfg); 352 int (*sunxi_lcd_pin_cfg)(unsigned int screen_id, unsigned int bon); 353 int (*sunxi_lcd_gpio_set_value)(unsigned int screen_id, 354 unsigned int io_index, u32 value); 355 int (*sunxi_lcd_gpio_set_direction)(unsigned int screen_id, 356 unsigned int io_index, 357 u32 direction); 358 int (*sunxi_lcd_cmd_write)(unsigned int screen_id, 359 unsigned char cmd); 360 int (*sunxi_lcd_para_write)(unsigned int screen_id, 361 unsigned char para); 362 int (*sunxi_lcd_cmd_read)(unsigned int screen_id, 363 unsigned char cmd, unsigned char *rx_buf, unsigned char len); 364 }; 365 366 enum disp_return_value { 367 DIS_SUCCESS = 0, 368 DIS_FAIL = -1, 369 DIS_PARA_FAILED = -2, 370 DIS_PRIO_ERROR = -3, 371 DIS_OBJ_NOT_INITED = -4, 372 DIS_NOT_SUPPORT = -5, 373 DIS_NO_RES = -6, 374 DIS_OBJ_COLLISION = -7, 375 DIS_DEV_NOT_INITED = -8, 376 DIS_DEV_SRAM_COLLISION = -9, 377 DIS_TASK_ERROR = -10, 378 DIS_PRIO_COLLSION = -11 379 }; 380 381 382 #endif /*End of file*/ 383