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_device_desc.h" 14 #include "hdf_log.h" 15 #include "hdf_sbuf.h" 16 #include "hdf_workqueue.h" 17 #include "mipi_dsi_if.h" 18 #include "osal_mem.h" 19 #include "osal_mutex.h" 20 #include "osal_timer.h" 21 22 #ifdef HDF_LOG_TAG 23 #undef HDF_LOG_TAG 24 #endif 25 #define HDF_LOG_TAG HDF_DISP 26 #define ESD_DEFAULT_INTERVAL 5000 27 #define ESD_MAX_RECOVERY 10 28 /* support max panel number */ 29 #define PANEL_MAX 2 30 31 enum LcdIntfType { 32 MIPI_DSI, 33 LCD_6BIT, 34 LCD_8BIT, 35 LCD_16BIT, 36 LCD_18BIT, 37 LCD_24BIT, 38 }; 39 40 enum BacklightType { 41 BLK_PWM, 42 BLK_MIPI, 43 }; 44 45 struct MipiDsiDesc { 46 enum DsiLane lane; 47 enum DsiMode mode; /* output mode: DSI_VIDEO/DSI_CMD */ 48 enum DsiBurstMode burstMode; 49 enum DsiOutFormat format; 50 }; 51 52 enum PowerStatus { 53 POWER_STATUS_ON, /* The power status is on */ 54 POWER_STATUS_STANDBY, /* The power status is standby */ 55 POWER_STATUS_SUSPEND, /* The power status is suspend */ 56 POWER_STATUS_OFF, /* The power status is off */ 57 POWER_STATUS_BUTT 58 }; 59 60 struct BlkDesc { 61 uint32_t type; 62 uint32_t minLevel; 63 uint32_t maxLevel; 64 uint32_t defLevel; 65 }; 66 67 struct PwmCfg { 68 uint32_t dev; 69 uint32_t period; 70 }; 71 72 struct PanelInfo { 73 uint32_t width; 74 uint32_t height; 75 uint32_t hbp; 76 uint32_t hfp; 77 uint32_t hsw; 78 uint32_t vbp; 79 uint32_t vfp; 80 uint32_t vsw; 81 uint32_t frameRate; 82 uint32_t clockFreq; 83 uint32_t pWidth; 84 uint32_t pHeight; 85 int32_t connectorType; 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 int32_t (*prepare)(struct PanelData *panel); 110 int32_t (*unprepare)(struct PanelData *panel); 111 struct PanelInfo *info; 112 enum PowerStatus powerStatus; 113 struct PanelEsd *esd; 114 struct BacklightDev *blDev; 115 void *priv; 116 }; 117 118 struct PanelManager { 119 struct PanelData *panel[PANEL_MAX]; 120 uint32_t panelNum; 121 }; 122 123 typedef int32_t (*DispCmdHandle)(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData); 124 125 struct DispInfo { 126 uint32_t width; 127 uint32_t hbp; 128 uint32_t hfp; 129 uint32_t hsw; 130 uint32_t height; 131 uint32_t vbp; 132 uint32_t vfp; 133 uint32_t vsw; 134 uint32_t frameRate; 135 uint32_t intfType; 136 uint32_t intfSync; 137 uint32_t minLevel; 138 uint32_t maxLevel; 139 uint32_t defLevel; 140 }; 141 142 struct DispOperations { 143 int32_t (*init)(uint32_t devId); 144 int32_t (*on)(uint32_t devId); 145 int32_t (*off)(uint32_t devId); 146 int32_t (*setBacklight)(uint32_t devId, uint32_t level); 147 int32_t (*getDispInfo)(uint32_t devId, struct DispInfo *info); 148 }; 149 150 enum EsdState { 151 ESD_READY = 1, 152 ESD_RUNNING, 153 }; 154 155 struct DispEsd { 156 struct PanelEsd **panelEsd; 157 HdfWork **work; 158 bool *workInit; 159 OsalTimer **timer; 160 uint32_t panelNum; 161 }; 162 163 struct DispManager { 164 struct PanelManager *panelManager; 165 struct OsalMutex dispMutex; 166 HdfWorkQueue dispWorkQueue; 167 bool initialzed; 168 struct DispEsd *esd; 169 }; 170 171 int32_t RegisterPanel(struct PanelData *panel); 172 struct PanelManager *GetPanelManager(void); 173 struct DispManager *GetDispManager(void); 174 175 #endif /* HDF_DISP_H */ 176