1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef HDF_DISP_H 10 #define HDF_DISP_H 11 12 #include "hdf_base.h" 13 #include "hdf_bl.h" 14 #include "hdf_device_desc.h" 15 #include "hdf_log.h" 16 #include "hdf_sbuf.h" 17 #include "hdf_workqueue.h" 18 #include "mipi_dsi_if.h" 19 #include "osal_mem.h" 20 #include "osal_mutex.h" 21 #include "osal_timer.h" 22 23 #ifdef HDF_LOG_TAG 24 #undef HDF_LOG_TAG 25 #endif 26 #define HDF_LOG_TAG HDF_DISP 27 #define ESD_DEFAULT_INTERVAL 5000 28 #define ESD_MAX_RECOVERY 10 29 /* support max panel number */ 30 #define PANEL_MAX 2 31 32 enum LcdIntfType { 33 MIPI_DSI, 34 LCD_6BIT, 35 LCD_8BIT, 36 LCD_16BIT, 37 LCD_18BIT, 38 LCD_24BIT, 39 }; 40 41 enum BacklightType { 42 BLK_PWM, 43 BLK_MIPI, 44 }; 45 46 struct MipiDsiDesc { 47 enum DsiLane lane; 48 enum DsiMode mode; /* output mode: DSI_VIDEO/DSI_CMD */ 49 enum DsiBurstMode burstMode; 50 enum DsiOutFormat format; 51 }; 52 53 enum PowerStatus { 54 POWER_STATUS_ON, /* The power status is on */ 55 POWER_STATUS_STANDBY, /* The power status is standby */ 56 POWER_STATUS_SUSPEND, /* The power status is suspend */ 57 POWER_STATUS_OFF, /* The power status is off */ 58 POWER_STATUS_BUTT 59 }; 60 61 struct BlkDesc { 62 uint32_t type; 63 uint32_t minLevel; 64 uint32_t maxLevel; 65 uint32_t defLevel; 66 }; 67 68 struct PwmCfg { 69 uint32_t dev; 70 uint32_t period; 71 }; 72 73 struct PanelInfo { 74 uint32_t width; 75 uint32_t height; 76 uint32_t hbp; 77 uint32_t hfp; 78 uint32_t hsw; 79 uint32_t vbp; 80 uint32_t vfp; 81 uint32_t vsw; 82 uint32_t frameRate; 83 uint32_t clockFreq; 84 uint32_t pWidth; 85 uint32_t pHeight; 86 enum LcdIntfType intfType; 87 uint32_t intfSync; 88 struct MipiDsiDesc mipi; 89 struct BlkDesc blk; 90 struct PwmCfg pwm; 91 }; 92 93 struct PanelData; 94 struct PanelEsd { 95 bool support; 96 uint32_t interval; 97 uint32_t state; 98 uint32_t recoveryNum; 99 uint32_t cmpMode; 100 int32_t (*checkFunc)(struct PanelData *panel); 101 void *expect_data; 102 }; 103 104 struct PanelData { 105 struct HdfDeviceObject *object; 106 int32_t (*init)(struct PanelData *panel); 107 int32_t (*on)(struct PanelData *panel); 108 int32_t (*off)(struct PanelData *panel); 109 struct PanelInfo *info; 110 enum PowerStatus powerStatus; 111 struct PanelEsd *esd; 112 struct BacklightDev *blDev; 113 void *priv; 114 }; 115 116 struct PanelManager { 117 struct PanelData *panel[PANEL_MAX]; 118 uint32_t panelNum; 119 }; 120 121 typedef int32_t (*DispCmdHandle)(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData); 122 123 struct DispInfo { 124 uint32_t width; 125 uint32_t hbp; 126 uint32_t hfp; 127 uint32_t hsw; 128 uint32_t height; 129 uint32_t vbp; 130 uint32_t vfp; 131 uint32_t vsw; 132 uint32_t frameRate; 133 uint32_t intfType; 134 uint32_t intfSync; 135 uint32_t minLevel; 136 uint32_t maxLevel; 137 uint32_t defLevel; 138 }; 139 140 struct DispOperations { 141 int32_t (*init)(uint32_t devId); 142 int32_t (*on)(uint32_t devId); 143 int32_t (*off)(uint32_t devId); 144 int32_t (*setBacklight)(uint32_t devId, uint32_t level); 145 int32_t (*getDispInfo)(uint32_t devId, struct DispInfo *info); 146 }; 147 148 enum EsdState { 149 ESD_READY = 1, 150 ESD_RUNNING, 151 }; 152 153 struct DispEsd { 154 struct PanelEsd **panelEsd; 155 HdfWork **work; 156 bool *workInit; 157 OsalTimer **timer; 158 int32_t panelNum; 159 }; 160 161 struct DispManager { 162 struct PanelManager *panelManager; 163 struct OsalMutex dispMutex; 164 HdfWorkQueue dispWorkQueue; 165 bool initialzed; 166 struct DispEsd *esd; 167 }; 168 169 int32_t RegisterPanel(struct PanelData *data); 170 struct PanelManager *GetPanelManager(void); 171 struct DispManager *GetDispManager(void); 172 173 #endif /* HDF_DISP_H */ 174