From 663b503074b3ce82cbe8e7babf6261e6e6b436bd Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Fri, 30 Jul 2021 06:34:51 +0000 Subject: [PATCH] add hdf drm panel driver for display Signed-off-by: YOUR_NAME --- .../driver/{ => adapter_soc}/hi35xx_disp.c | 280 ++--------- .../hi35xx_disp.h} | 114 +---- model/display/driver/hdf_disp.c | 152 +++--- model/display/driver/hdf_disp.h | 122 ++++- model/display/driver/hdf_drm_panel.c | 257 ++++++++++ model/display/driver/hdf_drm_panel.h | 25 + model/display/driver/hi35xx_disp.h | 29 -- model/display/driver/lcd_abs_if.c | 57 --- model/display/driver/lcdkit/lite_lcdkit.c | 2 +- model/display/driver/lcdkit/lite_lcdkit.h | 1 - model/display/driver/panel/ili9881c_boe.c | 340 +++++++++++++ model/display/driver/panel/ili9881c_boe.h | 446 ++++++++++++++++++ model/display/driver/panel/mipi_icn9700.c | 5 +- model/display/driver/panel/ssp_st7789.c | 9 +- 14 files changed, 1332 insertions(+), 507 deletions(-) rename model/display/driver/{ => adapter_soc}/hi35xx_disp.c (57%) rename model/display/driver/{lcd_abs_if.h => adapter_soc/hi35xx_disp.h} (59%) create mode 100644 model/display/driver/hdf_drm_panel.c create mode 100644 model/display/driver/hdf_drm_panel.h delete mode 100644 model/display/driver/hi35xx_disp.h delete mode 100644 model/display/driver/lcd_abs_if.c create mode 100644 model/display/driver/panel/ili9881c_boe.c create mode 100644 model/display/driver/panel/ili9881c_boe.h diff --git a/model/display/driver/hi35xx_disp.c b/model/display/driver/adapter_soc/hi35xx_disp.c similarity index 57% rename from model/display/driver/hi35xx_disp.c rename to model/display/driver/adapter_soc/hi35xx_disp.c index 98ddc0e3e..febf1ef92 100644 --- a/model/display/driver/hi35xx_disp.c +++ b/model/display/driver/adapter_soc/hi35xx_disp.c @@ -12,20 +12,12 @@ #include "hdf_device_desc.h" #include "hdf_disp.h" #include "hdf_log.h" -#include "lcd_abs_if.h" #include "osal_io.h" -#include "osal_mem.h" #include "pwm_if.h" #define TRANSFORM_KILO 1000 #define TRANSFORM_MILL 1000000 -struct Hi35xxDispCtrl { - struct DispControl ctrl; - unsigned long mipiCfgBase; - unsigned long pwmCfgBase; -}; - static void MipiMuxCfg(unsigned long ioCfgBase) { /* config dsi data lane0 */ @@ -107,11 +99,11 @@ void Lcd24BitMuxCfg(unsigned long ioCfgBase) OSAL_WRITEL(0x532, ioCfgBase + 0x0030); } -static void LcdPinMuxCfg(const struct Hi35xxDispCtrl *hi35xxCtrl, uint32_t intf) +static void LcdPinMuxCfg(uint32_t intf) { unsigned long ioCfgBase; - ioCfgBase = hi35xxCtrl->mipiCfgBase; + ioCfgBase = (unsigned long)OsalIoRemap(IO_CFG2_BASE, IO_CFG_SIZE); if (intf == MIPI_DSI) { MipiMuxCfg(ioCfgBase); } else if (intf == LCD_6BIT) { @@ -125,12 +117,11 @@ static void LcdPinMuxCfg(const struct Hi35xxDispCtrl *hi35xxCtrl, uint32_t intf) } } -static void PwmPinMuxCfg(const struct Hi35xxDispCtrl *hi35xxCtrl, uint32_t dev) +static void PwmPinMuxCfg(uint32_t dev) { /* pwm pin config */ unsigned long ioCfgBase; - - ioCfgBase = hi35xxCtrl->pwmCfgBase; + ioCfgBase = (unsigned long)OsalIoRemap(IO_CFG1_BASE, IO_CFG_SIZE); switch (dev) { case PWM_DEV0: OSAL_WRITEL(0x601, ioCfgBase + 0x0024); @@ -206,7 +197,7 @@ static uint32_t CalcDataRate(struct PanelInfo *info) static int32_t MipiDsiInit(struct PanelInfo *info) { int32_t ret; - struct DevHandle *mipiHandle = NULL; + DevHandle mipiHandle = NULL; struct MipiCfg cfg; mipiHandle = MipiDsiOpen(0); @@ -240,18 +231,19 @@ static int32_t MipiDsiInit(struct PanelInfo *info) return ret; } -static int32_t PwmInit(struct Hi35xxDispCtrl *hi35xxCtrl, struct PanelInfo *info) +static int32_t PwmInit(struct PanelInfo *info) { int32_t ret; /* pwm pin config */ - PwmPinMuxCfg(hi35xxCtrl, info->pwm.dev); + PwmPinMuxCfg(info->pwm.dev); /* pwm config */ - struct DevHandle *pwmHandle = PwmOpen(info->pwm.dev); + DevHandle pwmHandle = PwmOpen(info->pwm.dev); if (pwmHandle == NULL) { HDF_LOGE("%s: PwmOpen failed", __func__); return HDF_FAILURE; } + struct PwmConfig config; (void)memset_s(&config, sizeof(struct PwmConfig), 0, sizeof(struct PwmConfig)); config.duty = 1; @@ -267,59 +259,6 @@ static int32_t PwmInit(struct Hi35xxDispCtrl *hi35xxCtrl, struct PanelInfo *info return HDF_SUCCESS; } -static int32_t Hi35xxHardwareInit(struct Hi35xxDispCtrl *hi35xxCtrl) -{ - int32_t i; - int32_t panelNum; - int32_t ret = HDF_FAILURE; - struct PanelData **panel = NULL; - struct PanelInfo *info = NULL; - - if (hi35xxCtrl->ctrl.panelManager == NULL) { - HDF_LOGE("%s: panelManager is null", __func__); - return HDF_FAILURE; - } - if (hi35xxCtrl->ctrl.panelManager->panelNum <= 0) { - HDF_LOGE("%s: none of panels registered", __func__); - return HDF_FAILURE; - } - panelNum = hi35xxCtrl->ctrl.panelManager->panelNum; - panel = hi35xxCtrl->ctrl.panelManager->panel; - for (i = 0; i < panelNum; i++) { - info = panel[i]->info; - if (info == NULL) { - HDF_LOGE("%s:get info failed", __func__); - return HDF_FAILURE; - } - if (info->blk.type == BLK_PWM) { - ret = PwmInit(hi35xxCtrl, info); - if (ret) { - HDF_LOGE("%s:PwmInit failed", __func__); - return HDF_FAILURE; - } - } - /* lcd pin mux config */ - LcdPinMuxCfg(hi35xxCtrl, info->intfType); - if (info->intfType == MIPI_DSI) { - /* mipi dsi init */ - ret = MipiDsiInit(info); - if (ret) { - HDF_LOGE("%s:MipiDsiInit failed", __func__); - return HDF_FAILURE; - } - } - if (panel[i]->init != NULL) { - /* panel driver init */ - ret = panel[i]->init(panel[i]); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: panelData->init failed", __func__); - return HDF_FAILURE; - } - } - } - return ret; -} - static int32_t GetLcdIntfType(enum LcdIntfType type, uint32_t *out) { int32_t ret = HDF_SUCCESS; @@ -351,187 +290,64 @@ static int32_t GetLcdIntfType(enum LcdIntfType type, uint32_t *out) return ret; } -static int32_t Hi35xxGetDispInfo(struct DispControl *dispCtrl, uint32_t devId) -{ - struct PanelInfo *panelInfo = NULL; - struct DispInfo *info = NULL; - struct PanelData *panel = NULL; - - if (dispCtrl == NULL) { - HDF_LOGE("%s:dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s:panel is null", __func__); - return HDF_FAILURE; - } - panelInfo = panel->info; - if (panelInfo == NULL) { - HDF_LOGE("%s:get info failed", __func__); - return HDF_FAILURE; - } - info = dispCtrl->info; - if (info == NULL) { - HDF_LOGE("%s:info is null", __func__); - return HDF_FAILURE; - } - info->width = panelInfo->width; - info->height = panelInfo->height; - info->hbp = panelInfo->hbp; - info->hfp = panelInfo->hfp; - info->hsw = panelInfo->hsw; - info->vbp = panelInfo->vbp; - info->vfp = panelInfo->vfp; - info->vsw = panelInfo->vsw; - if (GetLcdIntfType(panelInfo->intfType, &info->intfType) != HDF_SUCCESS) { - HDF_LOGE("%s:GetLcdIntfType failed", __func__); - return HDF_FAILURE; - } - info->intfSync = panelInfo->intfSync; - info->frameRate = panelInfo->frameRate; - info->minLevel = panelInfo->blk.minLevel; - info->maxLevel = panelInfo->blk.maxLevel; - info->defLevel = panelInfo->blk.defLevel; - HDF_LOGI("info->width = %d, info->height = %d", info->width, info->height); - HDF_LOGI("info->hbp = %d, info->hfp = %d", info->hbp, info->hfp); - HDF_LOGI("info->frameRate = %d, info->intfSync = %d", info->frameRate, info->intfSync); - return HDF_SUCCESS; -} - -static int32_t Hi35xxOn(struct DispControl *dispCtrl, uint32_t devId) +static int32_t Hi35xxHardWareInit(void) { - int32_t ret = HDF_FAILURE; + int32_t i; + int32_t ret; + struct PanelManager *panelManager = NULL; struct PanelData *panel = NULL; + struct PanelInfo *info = NULL; - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s: panel is null", __func__); + panelManager = GetPanelManager(); + if (panelManager == NULL) { + HDF_LOGE("%s: panelManager is null", __func__); return HDF_FAILURE; } - if (panel->on != NULL) { - /* panel driver on */ - ret = panel->on(panel); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: panel->on failed", __func__); + for (i = 0; i < panelManager->panelNum; i++) { + panel = panelManager->panel[i]; + info = panel->info; + if (info == NULL) { + HDF_LOGE("%s:GetPanelInfo failed", __func__); return HDF_FAILURE; } - } - return ret; -} - -static int32_t Hi35xxOff(struct DispControl *dispCtrl, uint32_t devId) -{ - int32_t ret = HDF_FAILURE; - struct PanelData *panel = NULL; - - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s: panel is null", __func__); - return HDF_FAILURE; - } - if (panel->off != NULL) { - /* panel driver off */ - ret = panel->off(panel); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: panel->off failed", __func__); - return HDF_FAILURE; + if (info->blk.type == BLK_PWM) { + ret = PwmInit(info); + if (ret) { + HDF_LOGE("%s:PwmInit failed", __func__); + return HDF_FAILURE; + } } - } - return ret; -} - -static int32_t Hi35xxSetBacklight(struct DispControl *dispCtrl, uint32_t devId, uint32_t level) -{ - int32_t ret = HDF_FAILURE; - struct PanelData *panel = NULL; - - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); - return HDF_FAILURE; - } - if (dispCtrl->panelManager == NULL || (devId >= dispCtrl->panelManager->panelNum)) { - HDF_LOGE("%s: get panel fail", __func__); - return HDF_FAILURE; - } - panel = dispCtrl->panelManager->panel[devId]; - if (panel == NULL) { - HDF_LOGE("%s: panel is null", __func__); - return HDF_FAILURE; - } - if (panel->setBacklight != NULL) { - /* panel driver set backlight */ - ret = panel->setBacklight(panel, level); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: setBacklight failed", __func__); + /* lcd pin mux config */ + LcdPinMuxCfg(info->intfType); + if (info->intfType == MIPI_DSI) { + /* mipi dsi init */ + ret = MipiDsiInit(info); + if (ret) { + HDF_LOGE("%s:MipiDsiInit failed", __func__); + return HDF_FAILURE; + } + } + if (GetLcdIntfType(info->intfType, &info->intfType) != HDF_SUCCESS) { + HDF_LOGE("%s:GetLcdIntfType failed", __func__); return HDF_FAILURE; } + if (panel->init != NULL) { + if ((panel->init(panel)) != HDF_SUCCESS) { + HDF_LOGE("%s:panel[%d] init failed", __func__, i); + return HDF_FAILURE; + } + } } - return ret; -} - -static int32_t Hi35xxResInit(struct Hi35xxDispCtrl *hi35xxCtrl, struct PanelManager *panelManager) -{ - hi35xxCtrl->ctrl.ops.on = Hi35xxOn; - hi35xxCtrl->ctrl.ops.off = Hi35xxOff; - hi35xxCtrl->ctrl.ops.setBacklight = Hi35xxSetBacklight; - hi35xxCtrl->ctrl.ops.getDispInfo = Hi35xxGetDispInfo; - hi35xxCtrl->ctrl.panelManager = panelManager; - hi35xxCtrl->mipiCfgBase = (unsigned long)OsalIoRemap(IO_CFG2_BASE, IO_CFG_SIZE); - hi35xxCtrl->pwmCfgBase = (unsigned long)OsalIoRemap(IO_CFG1_BASE, IO_CFG_SIZE); return HDF_SUCCESS; } static int32_t Hi35xxEntryInit(struct HdfDeviceObject *object) { - struct PanelManager *panelManager = NULL; - struct Hi35xxDispCtrl *hi35xxCtrl = NULL; - if (object == NULL) { - HDF_LOGE("%s: object is null!", __func__); - return HDF_FAILURE; - } - hi35xxCtrl = (struct Hi35xxDispCtrl *)OsalMemCalloc(sizeof(struct Hi35xxDispCtrl)); - if (hi35xxCtrl == NULL) { - HDF_LOGE("%s hi35xxCtrl malloc fail", __func__); - return HDF_FAILURE; - } - panelManager = GetPanelManager(); - if (panelManager == NULL) { - HDF_LOGE("%s: panelManager is null", __func__); - return HDF_FAILURE; - } - if (Hi35xxResInit(hi35xxCtrl, panelManager) == HDF_FAILURE) { - HDF_LOGE("%s Hi35xxResInit fail", __func__); - return HDF_FAILURE; - } - if (Hi35xxHardwareInit(hi35xxCtrl) == HDF_FAILURE) { - HDF_LOGE("%s Hi35xxHardwareInit fail", __func__); + HDF_LOGE("%s: object is null", __func__); return HDF_FAILURE; } - hi35xxCtrl->ctrl.object = object; - hi35xxCtrl->ctrl.object->priv = hi35xxCtrl; - return RegisterDispCtrl(&hi35xxCtrl->ctrl); + return Hi35xxHardWareInit(); } struct HdfDriverEntry g_hi35xxDevEntry = { diff --git a/model/display/driver/lcd_abs_if.h b/model/display/driver/adapter_soc/hi35xx_disp.h similarity index 59% rename from model/display/driver/lcd_abs_if.h rename to model/display/driver/adapter_soc/hi35xx_disp.h index aa20f497f..682546b93 100644 --- a/model/display/driver/lcd_abs_if.h +++ b/model/display/driver/adapter_soc/hi35xx_disp.h @@ -6,29 +6,24 @@ * See the LICENSE file in the root of this repository for complete details. */ -#ifndef LCD_ABS_IF_H -#define LCD_ABS_IF_H +#ifndef HI35XX_DISP_H +#define HI35XX_DISP_H #include "hdf_base.h" -#include "hdf_device_desc.h" -#include "hdf_log.h" -#include "mipi_dsi_if.h" -/* support max panel number */ -#define PANEL_MAX 2 +#define IO_CFG1_BASE 0x111F0000 +#define IO_CFG2_BASE 0x112F0000 +#define IO_CFG_SIZE 0x10000 -enum LcdIntfType { - MIPI_DSI, - LCD_6BIT, - LCD_8BIT, - LCD_16BIT, - LCD_18BIT, - LCD_24BIT, -}; +#define PWM_DEV0 0 +#define PWM_DEV1 1 -enum BacklightType { - BLK_PWM, - BLK_MIPI, -}; +/* output interface type */ +#define INTF_LCD_6BIT (0x01L << 9) +#define INTF_LCD_8BIT (0x01L << 10) +#define INTF_LCD_16BIT (0x01L << 11) +#define INTF_LCD_18BIT (0x01L << 12) +#define INTF_LCD_24BIT (0x01L << 13) +#define INTF_MIPI (0x01L << 14) /* output timing */ enum IntfSync { @@ -82,83 +77,4 @@ enum IntfSync { OUTPUT_7680X4320_30, /* For HDMI2.1 at 30 Hz */ }; -struct MipiDsiDesc { - enum DsiLane lane; - enum DsiMode mode; /* output mode: DSI_VIDEO/DSI_CMD */ - enum DsiBurstMode burstMode; - enum DsiOutFormat format; -}; - -enum PowerStatus { - POWER_STATUS_ON, /* The power status is on */ - POWER_STATUS_STANDBY, /* The power status is standby */ - POWER_STATUS_SUSPEND, /* The power status is suspend */ - POWER_STATUS_OFF, /* The power status is off */ - POWER_STATUS_BUTT -}; - -struct BlkDesc { - uint32_t type; - uint32_t minLevel; - uint32_t maxLevel; - uint32_t defLevel; -}; - -struct PwmCfg { - uint32_t dev; - uint32_t period; -}; - -struct PanelInfo { - uint32_t width; - uint32_t height; - uint32_t hbp; - uint32_t hfp; - uint32_t hsw; - uint32_t vbp; - uint32_t vfp; - uint32_t vsw; - uint32_t frameRate; - enum LcdIntfType intfType; - enum IntfSync intfSync; - struct MipiDsiDesc mipi; - struct BlkDesc blk; - struct PwmCfg pwm; -}; - -struct PanelStatus { - enum PowerStatus powerStatus; - uint32_t currLevel; -}; - -struct PanelData; -struct PanelEsd { - bool support; - uint32_t interval; - uint32_t state; - uint32_t recoveryNum; - uint32_t cmpMode; - int32_t (*checkFunc)(struct PanelData *panel); - void *expect_data; -}; - -struct PanelData { - struct HdfDeviceObject *object; - int32_t (*init)(struct PanelData *panel); - int32_t (*on)(struct PanelData *panel); - int32_t (*off)(struct PanelData *panel); - int32_t (*setBacklight)(struct PanelData *panel, uint32_t level); - struct PanelInfo *info; - struct PanelStatus status; - struct PanelEsd *esd; -}; - -struct PanelManager { - struct PanelData *panel[PANEL_MAX]; - uint32_t panelNum; -}; - -int32_t RegisterPanel(struct PanelData *data); -struct PanelManager *GetPanelManager(void); -struct PanelData *GetPanel(int32_t index); -#endif /* LCD_ABS_IF_H */ +#endif /* HI35XX_DISP_H */ diff --git a/model/display/driver/hdf_disp.c b/model/display/driver/hdf_disp.c index 77b80cb54..dbbf41a3c 100644 --- a/model/display/driver/hdf_disp.c +++ b/model/display/driver/hdf_disp.c @@ -14,27 +14,40 @@ #define OFFSET_TWO_BYTE 16 static struct DispManager *g_dispManager = NULL; - -int32_t RegisterDispCtrl(struct DispControl *dispCtrl) +static struct PanelManager g_panelManager; +int32_t RegisterPanel(struct PanelData *data) { - if (dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); + int32_t panelNum; + + if (data == NULL) { + HDF_LOGE("%s: panel data is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (data->info == NULL) { + HDF_LOGE("%s panel info is null", __func__); return HDF_FAILURE; } - if (g_dispManager == NULL) { - g_dispManager = (struct DispManager *)OsalMemCalloc(sizeof(struct DispManager)); - if (g_dispManager == NULL) { - HDF_LOGE("%s g_dispManager malloc fail", __func__); - return HDF_FAILURE; - } - g_dispManager->dispCtrl = dispCtrl; - g_dispManager->panelManager = dispCtrl->panelManager; + panelNum = g_panelManager.panelNum; + if (panelNum >= PANEL_MAX) { + HDF_LOGE("%s registered panel up PANEL_MAX", __func__); + return HDF_FAILURE; } - HDF_LOGI("%s: success", __func__); + g_panelManager.panel[panelNum] = data; + g_panelManager.panelNum++; + HDF_LOGI("%s: register success", __func__); return HDF_SUCCESS; } -static struct DispManager *GetDispManager(void) +struct PanelManager *GetPanelManager(void) +{ + if (g_panelManager.panelNum == 0) { + return NULL; + } else { + return &g_panelManager; + } +} + +struct DispManager *GetDispManager(void) { if (g_dispManager != NULL && g_dispManager->initialzed) { return g_dispManager; @@ -87,7 +100,6 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) int32_t ret = HDF_FAILURE; struct DispManager *disp = NULL; struct PanelInfo *info = NULL; - struct DispControlOps *ops = NULL; struct PanelData *panel = NULL; disp = GetDispManager(); @@ -104,10 +116,6 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) } else if (level < info->blk.minLevel && level != 0) { level = info->blk.minLevel; } - if (disp->dispCtrl == NULL) { - HDF_LOGE("%s:dispCtrl is null", __func__); - return HDF_FAILURE; - } OsalMutexLock(&disp->dispMutex); if (panel->status.powerStatus != POWER_STATUS_ON) { HDF_LOGE("%s:devId[%d] not in power on mode", __func__, devId); @@ -119,9 +127,8 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) OsalMutexUnlock(&disp->dispMutex); return HDF_SUCCESS; } - ops = &disp->dispCtrl->ops; - if (ops->setBacklight) { - ret = ops->setBacklight(disp->dispCtrl, devId, level); + if (panel->setBacklight) { + ret = panel->setBacklight(panel, level); if (ret != HDF_SUCCESS) { HDF_LOGE("%s:setBacklight failed", __func__); OsalMutexUnlock(&disp->dispMutex); @@ -135,9 +142,8 @@ static int32_t SetDispBacklight(uint32_t devId, uint32_t level) static int32_t GetDispInfo(uint32_t devId, struct DispInfo *info) { - int32_t ret = HDF_FAILURE; - struct DispControlOps *ops = NULL; struct DispManager *disp = NULL; + struct PanelData *panel = NULL; if (info == NULL) { HDF_LOGE("%s:info is null", __func__); @@ -148,32 +154,37 @@ static int32_t GetDispInfo(uint32_t devId, struct DispInfo *info) HDF_LOGE("%s: disp is null", __func__); return HDF_FAILURE; } - if (disp->dispCtrl == NULL) { - HDF_LOGE("%s: dispCtrl is null", __func__); + if (devId >= disp->panelManager->panelNum) { + HDF_LOGE("%s: devId exceed registered panelNum", __func__); return HDF_FAILURE; } - disp->dispCtrl->info = info; - ops = &disp->dispCtrl->ops; - if (ops->getDispInfo != NULL) { - ret = ops->getDispInfo(disp->dispCtrl, devId); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: getDispInfo failed", __func__); - return HDF_FAILURE; - } - } - return ret; + panel = disp->panelManager->panel[devId]; + info->width = panel->info->width; + info->height = panel->info->height; + info->hbp = panel->info->hbp; + info->hfp = panel->info->hfp; + info->hsw = panel->info->hsw; + info->vbp = panel->info->vbp; + info->vfp = panel->info->vfp; + info->vsw = panel->info->vsw; + info->intfType = panel->info->intfType; + info->intfSync = panel->info->intfSync; + info->frameRate = panel->info->frameRate; + info->minLevel = panel->info->blk.minLevel; + info->maxLevel = panel->info->blk.maxLevel; + info->defLevel = panel->info->blk.defLevel; + return HDF_SUCCESS; } static int32_t SetDispPower(uint32_t devId, uint32_t powerStatus) { int32_t ret = HDF_FAILURE; - struct DispControlOps *ops = NULL; struct DispManager *disp = NULL; struct PanelData *panel = NULL; disp = GetDispManager(); - if (disp == NULL || disp->dispCtrl == NULL) { - HDF_LOGE("%s:disp or dispCtrl is null", __func__); + if (disp == NULL) { + HDF_LOGE("%s:disp is null", __func__); return HDF_FAILURE; } if (devId >= disp->panelManager->panelNum) { @@ -187,19 +198,18 @@ static int32_t SetDispPower(uint32_t devId, uint32_t powerStatus) HDF_LOGE("%s:devId[%d] already in mode = %d", __func__, devId, powerStatus); return HDF_SUCCESS; } - ops = &disp->dispCtrl->ops; switch (powerStatus) { case POWER_STATUS_ON: - if (ops->on) { - ret = ops->on(disp->dispCtrl, devId); + if (panel->on) { + ret = panel->on(panel); } if (ret == HDF_SUCCESS) { EsdCheckStartUp(disp->esd, devId); } break; case POWER_STATUS_OFF: - if (ops->off) { - ret = ops->off(disp->dispCtrl, devId); + if (panel->off) { + ret = panel->off(panel); } if (ret == HDF_SUCCESS) { EsdCheckEnd(disp->esd, devId); @@ -388,18 +398,15 @@ static int HdfDispBind(struct HdfDeviceObject *dev) return HDF_SUCCESS; } -static void PanelRecovery(struct DispControl *dispCtrl, uint32_t devId) +static void PanelRecovery(struct PanelData *panel) { - struct DispControlOps *ops = NULL; - HDF_LOGI("%s enter", __func__); - ops = &dispCtrl->ops; - if (ops->off) { - ops->off(dispCtrl, devId); + if (panel->off) { + panel->off(panel); } OsalMSleep(150); // delay 150ms - if (ops->on) { - ops->on(dispCtrl, devId); + if (panel->on) { + panel->on(panel); } } @@ -425,7 +432,7 @@ static void EsdWorkHandler(void *arg) struct DispManager *disp = NULL; disp = GetDispManager(); - if ((disp->dispCtrl == NULL) || (devId >= disp->panelManager->panelNum)) { + if (devId >= disp->panelManager->panelNum) { HDF_LOGE("%s: dispCtrl is null or panel is null", __func__); return; } @@ -436,7 +443,7 @@ static void EsdWorkHandler(void *arg) if (ret != HDF_SUCCESS) { OsalMutexLock(&disp->dispMutex); if (panel->esd->state == ESD_RUNNING) { - PanelRecovery(disp->dispCtrl, devId); + PanelRecovery(panel); } else { HDF_LOGI("%s: esd check has disabled", __func__); OsalMutexUnlock(&disp->dispMutex); @@ -445,7 +452,7 @@ static void EsdWorkHandler(void *arg) OsalMutexUnlock(&disp->dispMutex); panel->esd->recoveryNum++; } - HDF_LOGD("%s devId[%d] recoveryNum = %d",__func__, devId, panel->esd->recoveryNum); + HDF_LOGD("%s devId[%d] recoveryNum = %d", __func__, devId, panel->esd->recoveryNum); if (panel->esd->recoveryNum >= ESD_MAX_RECOVERY) { panel->esd->recoveryNum = 0; OsalMutexLock(&disp->dispMutex); @@ -475,7 +482,7 @@ static void EsdCheckStartUp(struct DispEsd *esd, uint32_t devId) EsdTimerHandler, (uintptr_t)devId); OsalTimerStartLoop(esd->timer[devId]); esd->panelEsd[devId]->state = ESD_RUNNING; - HDF_LOGI("%s , devId[%d] enable esd check", __func__, devId); + HDF_LOGI("%s devId[%d] enable esd check", __func__, devId); } } } @@ -633,18 +640,16 @@ static int32_t EsdCheckInit(struct DispManager *disp) return HDF_SUCCESS; } -static int32_t HdfDispEntryInit(struct HdfDeviceObject *object) +static int32_t DispManagerInit(struct PanelManager *panelManager) { int32_t ret; - if (object == NULL) { - HDF_LOGE("%s: object is null!", __func__); - return HDF_FAILURE; - } + g_dispManager = (struct DispManager *)OsalMemCalloc(sizeof(struct DispManager)); if (g_dispManager == NULL) { - HDF_LOGE("%s: g_dispManager is null", __func__); + HDF_LOGE("%s g_dispManager malloc fail", __func__); return HDF_FAILURE; } + g_dispManager->panelManager = panelManager; ret = HdfWorkQueueInit(&g_dispManager->dispWorkQueue, "dispWQ"); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: HdfWorkQueueInit fail", __func__); @@ -661,6 +666,29 @@ static int32_t HdfDispEntryInit(struct HdfDeviceObject *object) return HDF_SUCCESS; } +static int32_t HdfDispEntryInit(struct HdfDeviceObject *object) +{ + int32_t ret; + struct PanelManager *panelManager = NULL; + + if (object == NULL) { + HDF_LOGE("%s: object is null!", __func__); + return HDF_FAILURE; + } + panelManager = GetPanelManager(); + if (panelManager == NULL) { + HDF_LOGE("%s: panelManager is null!", __func__); + return HDF_FAILURE; + } + ret = DispManagerInit(panelManager); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: DispManagerInit fail", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s success", __func__); + return HDF_SUCCESS; +} + struct HdfDriverEntry g_dispDevEntry = { .moduleVersion = 1, .moduleName = "HDF_DISP", diff --git a/model/display/driver/hdf_disp.h b/model/display/driver/hdf_disp.h index 4c9f2e852..6d7bb13ea 100644 --- a/model/display/driver/hdf_disp.h +++ b/model/display/driver/hdf_disp.h @@ -10,9 +10,10 @@ #define HDF_DISP_H #include "hdf_base.h" #include "hdf_device_desc.h" +#include "hdf_log.h" #include "hdf_sbuf.h" #include "hdf_workqueue.h" -#include "lcd_abs_if.h" +#include "mipi_dsi_if.h" #include "osal_mem.h" #include "osal_mutex.h" #include "osal_timer.h" @@ -23,6 +24,102 @@ #define HDF_LOG_TAG HDF_DISP #define ESD_DEFAULT_INTERVAL 5000 #define ESD_MAX_RECOVERY 10 +/* support max panel number */ +#define PANEL_MAX 2 + +enum LcdIntfType { + MIPI_DSI, + LCD_6BIT, + LCD_8BIT, + LCD_16BIT, + LCD_18BIT, + LCD_24BIT, +}; + +enum BacklightType { + BLK_PWM, + BLK_MIPI, +}; + +struct MipiDsiDesc { + enum DsiLane lane; + enum DsiMode mode; /* output mode: DSI_VIDEO/DSI_CMD */ + enum DsiBurstMode burstMode; + enum DsiOutFormat format; +}; + +enum PowerStatus { + POWER_STATUS_ON, /* The power status is on */ + POWER_STATUS_STANDBY, /* The power status is standby */ + POWER_STATUS_SUSPEND, /* The power status is suspend */ + POWER_STATUS_OFF, /* The power status is off */ + POWER_STATUS_BUTT +}; + +struct BlkDesc { + uint32_t type; + uint32_t minLevel; + uint32_t maxLevel; + uint32_t defLevel; +}; + +struct PwmCfg { + uint32_t dev; + uint32_t period; +}; + +struct PanelInfo { + uint32_t width; + uint32_t height; + uint32_t hbp; + uint32_t hfp; + uint32_t hsw; + uint32_t vbp; + uint32_t vfp; + uint32_t vsw; + uint32_t frameRate; + uint32_t clockFreq; + uint32_t pWidth; + uint32_t pHeight; + enum LcdIntfType intfType; + uint32_t intfSync; + struct MipiDsiDesc mipi; + struct BlkDesc blk; + struct PwmCfg pwm; +}; + +struct PanelStatus { + enum PowerStatus powerStatus; + uint32_t currLevel; +}; + +struct PanelData; +struct PanelEsd { + bool support; + uint32_t interval; + uint32_t state; + uint32_t recoveryNum; + uint32_t cmpMode; + int32_t (*checkFunc)(struct PanelData *panel); + void *expect_data; +}; + +struct PanelData { + struct HdfDeviceObject *object; + int32_t (*init)(struct PanelData *panel); + int32_t (*on)(struct PanelData *panel); + int32_t (*off)(struct PanelData *panel); + int32_t (*setBacklight)(struct PanelData *panel, uint32_t level); + struct PanelInfo *info; + struct PanelStatus status; + struct PanelEsd *esd; + void *priv; +}; + +struct PanelManager { + struct PanelData *panel[PANEL_MAX]; + uint32_t panelNum; +}; typedef int32_t (*DispCmdHandle)(struct HdfDeviceObject *device, struct HdfSBuf *reqData, struct HdfSBuf *rspData); @@ -37,7 +134,7 @@ struct DispInfo { uint32_t vsw; uint32_t frameRate; uint32_t intfType; - enum IntfSync intfSync; + uint32_t intfSync; uint32_t minLevel; uint32_t maxLevel; uint32_t defLevel; @@ -64,23 +161,7 @@ struct DispEsd { int32_t panelNum; }; -struct DispControl; -struct DispControlOps { - int32_t (*on)(struct DispControl *dispCtrl, uint32_t devId); - int32_t (*off)(struct DispControl *dispCtrl, uint32_t devId); - int32_t (*setBacklight)(struct DispControl *dispCtrl, uint32_t devId, uint32_t level); - int32_t (*getDispInfo)(struct DispControl *dispCtrl, uint32_t devId); -}; - -struct DispControl { - struct HdfDeviceObject *object; - struct PanelManager *panelManager; - struct DispInfo *info; - struct DispControlOps ops; -}; - struct DispManager { - struct DispControl *dispCtrl; struct PanelManager *panelManager; struct OsalMutex dispMutex; HdfWorkQueue dispWorkQueue; @@ -88,5 +169,8 @@ struct DispManager { struct DispEsd *esd; }; -int32_t RegisterDispCtrl(struct DispControl *dispCtrl); +int32_t RegisterPanel(struct PanelData *data); +struct PanelManager *GetPanelManager(void); +struct DispManager *GetDispManager(void); + #endif /* HDF_DISP_H */ diff --git a/model/display/driver/hdf_drm_panel.c b/model/display/driver/hdf_drm_panel.c new file mode 100644 index 000000000..f6a3b8391 --- /dev/null +++ b/model/display/driver/hdf_drm_panel.c @@ -0,0 +1,257 @@ + +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "hdf_drm_panel.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include