From 7d1848446e55d3fdce4ca4717dede8474a017424 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Mon, 16 Aug 2021 13:26:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=B4=E6=98=8E=EF=BC=9A1.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=8F=82=E6=95=B0=E4=BE=8B=E8=A1=8C?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=92=8C=E5=BF=85=E8=A6=81=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E3=80=81log=EF=BC=9B2.=E5=A2=9E=E5=8A=A0=E4=BA=86mipi?= =?UTF-8?q?=5Fdsi=5Fdefine.h=E6=96=87=E4=BB=B6=EF=BC=8C=E6=9D=A5=E6=BA=90?= =?UTF-8?q?=E5=8E=9F=E6=9D=A5mipi=5Ftx=5Fdev.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: YOUR_NAME --- platform/mipi_dsi/Makefile | 1 + platform/mipi_dsi/mipi_dsi_adapter.c | 129 ----- platform/mipi_dsi/mipi_dsi_adapter.h | 4 - platform/mipi_dsi/mipi_dsi_define.h | 93 ++++ platform/mipi_dsi/mipi_tx_dev.c | 725 +++++++++++++++++---------- platform/mipi_dsi/mipi_tx_dev.h | 103 +--- platform/mipi_dsi/mipi_tx_hi35xx.c | 500 +++++++++++++----- platform/mipi_dsi/mipi_tx_hi35xx.h | 10 - 8 files changed, 926 insertions(+), 639 deletions(-) create mode 100755 platform/mipi_dsi/mipi_dsi_define.h diff --git a/platform/mipi_dsi/Makefile b/platform/mipi_dsi/Makefile index e99d0b8..82728cc 100644 --- a/platform/mipi_dsi/Makefile +++ b/platform/mipi_dsi/Makefile @@ -15,6 +15,7 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mipi_dsi_core.o \ + $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mipi_dsi_if.o \ mipi_dsi_adapter.o obj-y += mipi_tx_dev.o \ diff --git a/platform/mipi_dsi/mipi_dsi_adapter.c b/platform/mipi_dsi/mipi_dsi_adapter.c index 8fdb7ed..1cc0e55 100644 --- a/platform/mipi_dsi/mipi_dsi_adapter.c +++ b/platform/mipi_dsi/mipi_dsi_adapter.c @@ -16,134 +16,5 @@ * */ -#include "hdf_base.h" -#include "osal_mem.h" -#include "mipi_dsi_core.h" #include "mipi_dsi_adapter.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "securec.h" - -#define NAME_LEN 20 - -static struct miscdevice *g_mipiDsiMiscdev[MAX_CNTLR_CNT]; - -int MipiDsiRegisterDevice(const char *name, uint32_t id, unsigned short mode, struct file_operations *ops) -{ - int error; - struct miscdevice *dev = NULL; - - if (name == NULL || ops == NULL || id >= MAX_CNTLR_CNT) { - return -1; - } - dev = OsalMemCalloc(sizeof(struct miscdevice)); - if (dev == NULL) { - return -1; - } - dev->fops = ops; - dev->name = OsalMemCalloc(NAME_LEN + 1); - if (dev->name == NULL) { - OsalMemFree(dev); - return -1; - } - if (id != 0) { /* 0 : id */ - if (snprintf_s((char *)dev->name, NAME_LEN + 1, NAME_LEN, "%s%u", name, id) < 0) { - OsalMemFree((char *)dev->name); - OsalMemFree(dev); - return -1; - } - } else { - if (memcpy_s((char *)dev->name, NAME_LEN, name, strlen(name)) != EOK) { - OsalMemFree((char *)dev->name); - OsalMemFree(dev); - return -1; - } - } - ops->owner = THIS_MODULE; - dev->minor = MISC_DYNAMIC_MINOR; - dev->mode = mode; - error = misc_register(dev); - if (error < 0) { - printk("%s: id %u cannot register miscdev on minor=%d (err=%d)", - __func__, id, MISC_DYNAMIC_MINOR, error); - OsalMemFree((char *)dev->name); - OsalMemFree(dev); - return error; - } - g_mipiDsiMiscdev[id] = dev; - printk("mipi_dsi:create inode ok %s %d", dev->name, dev->minor); - return 0; -} - -int MipiDsiProcRegister(const char *name, uint32_t id, unsigned short mode, const struct file_operations *ops) -{ - char procName[NAME_LEN + 1]; - struct proc_dir_entry* err = NULL; - int ret; - - if (name == NULL || ops == NULL || id >= MAX_CNTLR_CNT) { - return -1; - } - if (memset_s(procName, NAME_LEN + 1, 0, NAME_LEN + 1) != EOK) { - return -1; - } - if (id != 0) { - ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s%u", name, id); - } else { - ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s", name); - } - if (ret < 0) { - printk(KERN_ERR "%s: procName %s snprintf_s fail", __func__, procName); - return -1; - } - err = proc_create(procName, mode, NULL, ops); - if (err == NULL) { - printk(KERN_ERR "%s: proc_create name %s fail", __func__, procName); - return -1; - } - return 0; -} - -void MipiDsiUnregisterDevice(uint32_t id) -{ - if (id >= MAX_CNTLR_CNT) { - return; - } - misc_deregister(g_mipiDsiMiscdev[id]); - OsalMemFree((void *)g_mipiDsiMiscdev[id]->name); - g_mipiDsiMiscdev[id]->name = NULL; - OsalMemFree(g_mipiDsiMiscdev[id]); - g_mipiDsiMiscdev[id] = NULL; -} - -void MipiDsiProcUnregister(const char *name, uint32_t id) -{ - char procName[NAME_LEN + 1]; - int ret; - - if (id >= MAX_CNTLR_CNT) { - return; - } - if (memset_s(procName, NAME_LEN + 1, 0, NAME_LEN + 1) != EOK) { - return; - } - if (id != 0) { - ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s%u", name, id); - } else { - ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s", name); - } - if (ret < 0) { - printk(KERN_ERR "%s: procName format fail", __func__); - return; - } - remove_proc_entry(procName, NULL); -} diff --git a/platform/mipi_dsi/mipi_dsi_adapter.h b/platform/mipi_dsi/mipi_dsi_adapter.h index eb1e969..f9fb21e 100644 --- a/platform/mipi_dsi/mipi_dsi_adapter.h +++ b/platform/mipi_dsi/mipi_dsi_adapter.h @@ -21,8 +21,4 @@ #include -int MipiDsiRegisterDevice(const char *name, uint32_t id, unsigned short mode, struct file_operations *ops); -void MipiDsiUnregisterDevice(uint32_t id); -int MipiDsiProcRegister(const char *name, uint32_t id, unsigned short mode, const struct file_operations *ops); -void MipiDsiProcUnregister(const char *name, uint32_t id); #endif /* MIPI_DSI_ADAPTER_H */ diff --git a/platform/mipi_dsi/mipi_dsi_define.h b/platform/mipi_dsi/mipi_dsi_define.h new file mode 100755 index 0000000..5409efa --- /dev/null +++ b/platform/mipi_dsi/mipi_dsi_define.h @@ -0,0 +1,93 @@ +/* + * mipi_dsi_define.h + * + * hi35xx mipi_tx driver implement. + * + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef MIPI_DSI_DEFINE_H +#define MIPI_DSI_DEFINE_H + +#define CMD_MAX_NUM 4 +#define LANE_MAX_NUM 4 +#define MIPI_TX_DISABLE_LANE_ID (-1) +#define MIPI_TX_SET_DATA_SIZE 800 +#define MIPI_TX_GET_DATA_SIZE 160 + +typedef enum { + OUTPUT_MODE_CSI = 0x0, /* csi mode */ + OUTPUT_MODE_DSI_VIDEO = 0x1, /* dsi video mode */ + OUTPUT_MODE_DSI_CMD = 0x2, /* dsi command mode */ + + OUTPUT_MODE_BUTT +} OutPutModeTag; + +typedef enum { + BURST_MODE = 0x0, + NON_BURST_MODE_SYNC_PULSES = 0x1, + NON_BURST_MODE_SYNC_EVENTS = 0x2, + + VIDEO_DATA_MODE_BUTT +} VideoModeTag; + +typedef enum { + OUT_FORMAT_RGB_16_BIT = 0x0, + OUT_FORMAT_RGB_18_BIT = 0x1, + OUT_FORMAT_RGB_24_BIT = 0x2, + OUT_FORMAT_YUV420_8_BIT_NORMAL = 0x3, + OUT_FORMAT_YUV420_8_BIT_LEGACY = 0x4, + OUT_FORMAT_YUV422_8_BIT = 0x5, + + OUT_FORMAT_BUTT +} OutputFormatTag; + +typedef struct { + unsigned short vidPktSize; + unsigned short vidHsaPixels; + unsigned short vidHbpPixels; + unsigned short vidHlinePixels; + unsigned short vidVsaLines; + unsigned short vidVbpLines; + unsigned short vidVfpLines; + unsigned short vidActiveLines; + unsigned short edpiCmdSize; +} SyncInfoTag; + +typedef struct { + unsigned int devno; /* device number */ + short laneId[LANE_MAX_NUM]; /* lane_id: -1 - disable */ + OutPutModeTag outputMode; /* output mode: CSI/DSI_VIDEO/DSI_CMD */ + VideoModeTag videoMode; + OutputFormatTag outputFormat; + SyncInfoTag syncInfo; + unsigned int phyDataRate; /* mbps */ + unsigned int pixelClk; /* KHz */ +} ComboDevCfgTag; + +typedef struct { + unsigned int devno; /* device number */ + unsigned short dataType; + unsigned short cmdSize; + unsigned char *cmd; +} CmdInfoTag; + +typedef struct { + unsigned int devno; /* device number */ + unsigned short dataType; /* DSI data type */ + unsigned short dataParam; /* data param,low 8 bit:1st param.high 8 bit:2nt param, set 0 if not use */ + unsigned short getDataSize; /* read data size */ + unsigned char *getData; /* read data memory address, should malloc by user */ +} GetCmdInfoTag; + +#endif /* MIPI_DSI_DEFINE_H */ diff --git a/platform/mipi_dsi/mipi_tx_dev.c b/platform/mipi_dsi/mipi_tx_dev.c index cd0e4ea..336ae33 100644 --- a/platform/mipi_dsi/mipi_tx_dev.c +++ b/platform/mipi_dsi/mipi_tx_dev.c @@ -16,18 +16,28 @@ * */ +#include "mipi_tx_dev.h" #include #include #include +#include +#include +#include +#include +#include +#include +#include #include "hdf_base.h" #include "hdf_log.h" -#include "mipi_dsi_adapter.h" -#include "mipi_tx_dev.h" -#include "mipi_tx_hi35xx.h" -#include "mipi_tx_reg.h" +#include "securec.h" #include "osal_io.h" #include "osal_mem.h" -#include "securec.h" +#include "osal_uaccess.h" +#include +#include +#include "mipi_dsi_adapter.h" +#include "mipi_dsi_core.h" +#include "mipi_tx_reg.h" #ifdef __cplusplus #if __cplusplus @@ -38,281 +48,501 @@ extern "C"{ /**************************************************************************** * macro definition * ****************************************************************************/ +#define HDF_LOG_TAG mipi_tx_dev #define MIPI_TX_DEV_NAME "hi_mipi_tx" #define MIPI_TX_PROC_NAME "mipi_tx" +#define NAME_LEN 20 + +struct MipiDsiVfsPara { + struct MipiDsiCntlr *cntlr; + struct miscdevice *miscdev; + struct semaphore sem; + void *priv; +}; -struct semaphore g_mipiTxSem; -static int32_t MipiTxSemaInit(struct semaphore *sem, uint16_t val) +static struct MipiDsiVfsPara g_vfsPara[MAX_CNTLR_CNT]; +static uint8_t g_curId = 0; +static int32_t RegisterDevice(const char *name, uint8_t id, unsigned short mode, struct file_operations *ops) { - if (sem == NULL) { - return -1; + int32_t error; + struct miscdevice *dev = NULL; + + if ((name == NULL) || (ops == NULL) || (id >= MAX_CNTLR_CNT)) { + HDF_LOGE("%s: name, ops or id is error.", __func__); + return HDF_FAILURE; + } + dev = OsalMemCalloc(sizeof(struct miscdevice)); + if (dev == NULL) { + HDF_LOGE("%s: [OsalMemCalloc] failed.", __func__); + return HDF_FAILURE; + } + dev->fops = ops; + dev->name = OsalMemCalloc(NAME_LEN + 1); + if (dev->name == NULL) { + OsalMemFree(dev); + HDF_LOGE("%s: [OsalMemCalloc] failed.", __func__); + return HDF_FAILURE; + } + if (id != 0) { /* 0 : id */ + if (snprintf_s((char *)dev->name, NAME_LEN + 1, NAME_LEN, "%s%u", name, id) < 0) { + OsalMemFree((char *)dev->name); + OsalMemFree(dev); + HDF_LOGE("%s: [snprintf_s] failed.", __func__); + return HDF_FAILURE; + } + } else { + if (memcpy_s((char *)dev->name, NAME_LEN, name, strlen(name)) != EOK) { + OsalMemFree((char *)dev->name); + OsalMemFree(dev); + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + return HDF_FAILURE; + } + } + ops->owner = THIS_MODULE; + dev->minor = MISC_DYNAMIC_MINOR; + dev->mode = mode; + error = misc_register(dev); + if (error < 0) { + printk("%s: id %u cannot register miscdev on minor=%d (err=%d)", + __func__, id, MISC_DYNAMIC_MINOR, error); + OsalMemFree((char *)dev->name); + OsalMemFree(dev); + return error; } - sema_init(sem, val); - return 0; -} -static void MipiTxSemaDestroy(const struct semaphore *sem) -{ - (void *)sem; - return; + g_vfsPara[id].miscdev = dev; + g_curId = id; + printk("mipi_dsi:create inode ok %s %d", dev->name, dev->minor); + HDF_LOGI("%s: success.", __func__); + + return HDF_SUCCESS; } -static int32_t MipiTxSemaDownInterruptable(const struct semaphore *sem) +static int32_t ProcRegister(const char *name, uint8_t id, unsigned short mode, const struct file_operations *ops) { - return down_interruptible((struct semaphore *)sem); + char procName[NAME_LEN + 1]; + struct proc_dir_entry* entry = NULL; + int32_t ret; + + if ((name == NULL) || (ops == NULL) || (id >= MAX_CNTLR_CNT)) { + HDF_LOGE("%s: name, ops or id is error.", __func__); + return HDF_FAILURE; + } + if (memset_s(procName, NAME_LEN + 1, 0, NAME_LEN + 1) != EOK) { + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + return HDF_FAILURE; + } + if (id != 0) { + ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s%u", name, id); + } else { + ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s", name); + } + if (ret < 0) { + printk(KERN_ERR "%s: procName %s snprintf_s fail", __func__, procName); + return HDF_FAILURE; + } + entry = proc_create(procName, mode, NULL, ops); + if (entry == NULL) { + printk(KERN_ERR "%s: proc_create name %s fail", __func__, procName); + return HDF_FAILURE; + } + HDF_LOGI("%s: success.", __func__); + return HDF_SUCCESS; } -static void MipiTxUp(const struct semaphore *sem) +static void UnregisterDevice(uint8_t id) { - up((struct semaphore *)sem); -} + if (id >= MAX_CNTLR_CNT) { + HDF_LOGE("%s: id error.", __func__); + return; + } + struct miscdevice *dev = g_vfsPara[id].miscdev; + if (dev == NULL) { + HDF_LOGE("%s: dev is NULL.", __func__); + return; + } -static int g_enDev; -static int g_enDevCfg; -MipiTxDevCtxTag g_mipiTxDevCtx; + misc_deregister(dev); + OsalMemFree((void *)dev->name); + dev->name = NULL; + OsalMemFree(dev); + dev = NULL; + g_curId = 0; + HDF_LOGI("%s: success.", __func__); +} -static int MipiTxCheckCombDevCfg(const ComboDevCfgTag *devCfg) +static void ProcUnregister(const char *name, uint8_t id) { - int i; - int validLaneId[LANE_MAX_NUM] = {0, 1, 2, 3}; + char procName[NAME_LEN + 1]; + int32_t ret; - if (g_enDev == TRUE) { - HDF_LOGE("mipi_tx dev has enable!\n"); - return -1; + if (id >= MAX_CNTLR_CNT) { + HDF_LOGE("%s: id error.", __func__); + return; } - if (devCfg->devno != 0) { - HDF_LOGE("mipi_tx dev devno err!\n"); - return -1; + if (memset_s(procName, NAME_LEN + 1, 0, NAME_LEN + 1) != EOK) { + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + return; } - for (i = 0; i < LANE_MAX_NUM; i++) { - if ((devCfg->laneId[i] != validLaneId[i]) && (devCfg->laneId[i] != MIPI_TX_DISABLE_LANE_ID)) { - HDF_LOGE("mipi_tx dev laneId %d err!\n", devCfg->laneId[i]); - return -1; - } + if (id != 0) { + ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s%u", name, id); + } else { + ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s", name); } - if ((devCfg->outputMode != OUTPUT_MODE_CSI) && (devCfg->outputMode != OUTPUT_MODE_DSI_VIDEO) && - (devCfg->outputMode != OUTPUT_MODE_DSI_CMD)) { - HDF_LOGE("mipi_tx dev outputMode %d err!\n", devCfg->outputMode); - return -1; + if (ret < 0) { + printk(KERN_ERR "%s: procName format fail", __func__); + return; } - if ((devCfg->videoMode != BURST_MODE) && (devCfg->videoMode != NON_BURST_MODE_SYNC_PULSES) && - (devCfg->videoMode != NON_BURST_MODE_SYNC_EVENTS)) { - HDF_LOGE("mipi_tx dev videoMode %d err!\n", devCfg->videoMode); - return -1; + remove_proc_entry(procName, NULL); + HDF_LOGI("%s: success.", __func__); +} + +static int32_t SemaInit(struct semaphore *sem, uint16_t val) +{ + if (sem == NULL) { + HDF_LOGE("%s: sem is NULL", __func__); + return HDF_FAILURE; } - if ((devCfg->outputFormat != OUT_FORMAT_RGB_16_BIT) && (devCfg->outputFormat != OUT_FORMAT_RGB_18_BIT) && - (devCfg->outputFormat != OUT_FORMAT_RGB_24_BIT) && (devCfg->outputFormat != - OUT_FORMAT_YUV420_8_BIT_NORMAL) && (devCfg->outputFormat != OUT_FORMAT_YUV420_8_BIT_LEGACY) && - (devCfg->outputFormat != OUT_FORMAT_YUV422_8_BIT)) { - HDF_LOGE("mipi_tx dev outputFormat %d err!\n", devCfg->outputFormat); - return -1; + sema_init(sem, val); + return HDF_SUCCESS; +} + +static void SemaDestroy(struct semaphore *sem) +{ + // don't support sema_destory(sem)! + (void *)sem; + return; +} + +static int32_t SemaDownInterruptable(struct semaphore *sem) +{ + return down_interruptible(sem); +} + +static void SemaUp(struct semaphore *sem) +{ + up(sem); +} + +static uint8_t GetId() +{ + if (g_curId >= MAX_CNTLR_CNT) { + HDF_LOGE("%s: failed g_curId = %u.", __func__, g_curId); + return 0; } - return 0; + + HDF_LOGI("%s: success.", __func__); + return g_curId; } -int MipiTxSetComboDevCfg(const ComboDevCfgTag *devCfg) +static uint8_t GetIdFromFilep(struct file *filep) { - int ret; + uint8_t id; + if (filep == NULL) { + HDF_LOGE("%s: filep is invalid.", __func__); + return 0; + } - ret = MipiTxCheckCombDevCfg(devCfg); - if (ret < 0) { - HDF_LOGE("mipi_tx check combo_dev config failed!\n"); - return ret; + if (filep->private_data == NULL) { + HDF_LOGE("%s: private_data is NULL.", __func__); + return 0; } - /* set controller config */ - MipiTxDrvSetControllerCfg(devCfg); - /* set phy config */ - MipiTxDrvSetPhyCfg(devCfg); - ret = memcpy_s(&g_mipiTxDevCtx.devCfg, sizeof(ComboDevCfgTag), devCfg, sizeof(ComboDevCfgTag)); - if (ret != EOK) { - return ret; + + id = (uint8_t)(filep->private_data); + if (id >= MAX_CNTLR_CNT) { + HDF_LOGE("%s: id error.", __func__); + return 0; } - g_enDevCfg = TRUE; - return ret; + + return id; } -static int MipiTxCheckSetCmdInfo(const CmdInfoTag *cmdInfo) +static struct MipiDsiCntlr *GetCntlrFromFilep(struct file *filep) { - if (g_enDev == TRUE) { - HDF_LOGE("mipi_tx dev has enable!\n"); - return -1; - } - if (g_enDevCfg != TRUE) { - HDF_LOGE("mipi_tx dev has not config!\n"); - return -1; - } - if (cmdInfo->devno != 0) { - HDF_LOGE("mipi_tx devno %d err!\n", cmdInfo->devno); - return -1; - } - /* When cmd is not NULL, cmd_size means the length of cmd or it means cmd and addr */ - if (cmdInfo->cmd != NULL) { - if (cmdInfo->cmdSize > MIPI_TX_SET_DATA_SIZE) { - HDF_LOGE("mipi_tx dev cmd_size %d err!\n", cmdInfo->cmdSize); - return -1; - } + uint8_t id; + if (filep == NULL) { + HDF_LOGE("%s: filep is invalid.", __func__); + return NULL; } - return 0; + id = GetId(); + + return g_vfsPara[id].cntlr; } -int MipiTxSetCmd(const CmdInfoTag *cmdInfo) +static struct semaphore *GetSemaFromFilep(struct file *filep) { - int ret; - - ret = MipiTxCheckSetCmdInfo(cmdInfo); - if (ret < 0) { - HDF_LOGE("mipi_tx check combo_dev config failed!\n"); - return ret; + uint8_t id; + if (filep == NULL) { + HDF_LOGE("%s: filep is invalid.", __func__); + return NULL; } - return MipiTxDrvSetCmdInfo(cmdInfo); + id = GetId(); + + return &g_vfsPara[id].sem; } -static int MipiTxCheckGetCmdInfo(const GetCmdInfoTag *getCmdInfo) +static struct MipiCfg *GetCfgFromFilep(struct file *filep) { - if (g_enDev == TRUE) { - HDF_LOGE("mipi_tx dev has enable!\n"); - return -1; + uint8_t id; + if (filep == NULL) { + HDF_LOGE("%s: filep is invalid.", __func__); + return NULL; } - if (g_enDevCfg != TRUE) { - HDF_LOGE("mipi_tx dev has not config!\n"); - return -1; + id = GetId(); + if (g_vfsPara[id].cntlr == NULL) { + HDF_LOGE("%s: g_vfsPara[id].cntlr is NULL.", __func__); + return NULL; } - if (getCmdInfo->devno != 0) { - HDF_LOGE("mipi_tx dev devno %d err!\n", getCmdInfo->devno); - return -1; + + return &(g_vfsPara[id].cntlr->cfg); +} + +static int32_t MipiDsiDevSetCfg(struct MipiDsiCntlr *cntlr, struct MipiCfg *arg) +{ + int32_t ret; + struct MipiCfg *temp = NULL; + + if (arg == NULL) { + HDF_LOGE("%s: arg is invalid.", __func__); + return HDF_ERR_INVALID_PARAM; } - if ((getCmdInfo->getDataSize == 0) || (getCmdInfo->getDataSize > MIPI_TX_GET_DATA_SIZE)) { - HDF_LOGE("mipi_tx dev getDataSize %d err!\n", getCmdInfo->getDataSize); - return -1; + + if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL.", __func__); + return HDF_ERR_INVALID_PARAM; } - if (getCmdInfo->getData == NULL) { - HDF_LOGE("mipi_tx dev getData is null!\n"); - return -1; + + uint32_t size = sizeof(struct MipiCfg); + temp = (struct MipiCfg *)OsalMemCalloc(size); + if (temp == NULL) { + HDF_LOGE("%s: OsalMemCalloc error.", __func__); + return HDF_ERR_MALLOC_FAIL; } - return 0; + + if (access_ok(VERIFY_READ, arg, size)) { /* user space */ + if (CopyFromUser(temp, arg, size) != 0) { + OsalMemFree(temp); + temp = NULL; + HDF_LOGE("%s: [CopyFromUser] failed.", __func__); + return HDF_FAILURE; + } + } else { /* kernel space */ + if (memcpy_s(temp, size, arg, size) != EOK) { + OsalMemFree(temp); + temp = NULL; + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + return HDF_FAILURE; + } + } + + ret = MipiDsiCntlrSetCfg(cntlr, temp); + g_curId = cntlr->devNo; + OsalMemFree(temp); + HDF_LOGI("%s: success.", __func__); + + return ret; } -int MipiTxGetCmd(GetCmdInfoTag *getCmdInfo) +int32_t MipiDsiDevSetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *arg) { - int ret; + int32_t ret; + struct DsiCmdDesc *temp = NULL; - ret = MipiTxCheckGetCmdInfo(getCmdInfo); - if (ret < 0) { - HDF_LOGE("mipi_tx check combo_dev config failed!\n"); - return ret; + if (arg == NULL) { + HDF_LOGE("%s: arg is invalid.", __func__); + return HDF_ERR_INVALID_PARAM; } - return MipiTxDrvGetCmdInfo(getCmdInfo); -} -static void MipiTxEnable(void) -{ - OutPutModeTag mode; + if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL.", __func__); + return HDF_ERR_INVALID_PARAM; + } - mode = g_mipiTxDevCtx.devCfg.outputMode; - MipiTxDrvEnableInput(mode); - g_enDev = TRUE; + uint32_t size = sizeof(struct DsiCmdDesc); + temp = (struct DsiCmdDesc *)OsalMemCalloc(size); + if (temp == NULL) { + HDF_LOGE("%s: [OsalMemCalloc] error.", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + if (access_ok(VERIFY_READ, arg, size)) { /* user space */ + if (CopyFromUser(temp, arg, size) != 0) { + OsalMemFree(temp); + temp = NULL; + HDF_LOGE("%s: [CopyFromUser] failed.", __func__); + return HDF_FAILURE; + } + } else { /* kernel space */ + if (memcpy_s(temp, size, arg, size) != EOK) { + OsalMemFree(temp); + temp = NULL; + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + return HDF_FAILURE; + } + } + + ret = MipiDsiCntlrTx(cntlr, temp); + OsalMemFree(temp); + HDF_LOGI("%s: success.", __func__); + + return ret; } -static void MipiTxDisable(void) +int32_t MipiDsiDevGetCmd(struct MipiDsiCntlr *cntlr, GetDsiCmdDescTag *arg) { - MipiTxDrvDisableInput(); - g_enDev = FALSE; - g_enDevCfg = FALSE; + int32_t ret; + GetDsiCmdDescTag *temp = NULL; + if ((cntlr == NULL) || (arg == NULL)) { + HDF_LOGE("%s: cntlr or arg is NULL.", __func__); + return HDF_ERR_INVALID_PARAM; + } + + uint32_t size = sizeof(GetDsiCmdDescTag); + temp = (GetDsiCmdDescTag *)OsalMemCalloc(size); + if (temp == NULL) { + HDF_LOGE("%s: [OsalMemCalloc] error.", __func__); + return HDF_ERR_MALLOC_FAIL; + } + if (access_ok(VERIFY_READ, arg, size)) { /* user space */ + if (CopyFromUser(temp, arg, size) != 0) { + HDF_LOGE("%s: [CopyFromUser] failed.", __func__); + goto fail0; + } + } else { /* kernel space */ + if (memcpy_s(temp, size, arg, size) != EOK) { + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + goto fail0; + } + } + ret = MipiDsiCntlrRx(cntlr, &temp->readCmd, temp->readLen, temp->out); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiDsiCntlrRx] failed.", __func__); + goto fail0; + } + if (access_ok(VERIFY_WRITE, arg, size)) { /* user space */ + if (CopyToUser(arg, temp, size) != 0) { + HDF_LOGE("%s: [CopyToUser] failed.", __func__); + goto fail0; + } + } else { /* kernel space */ + if (memcpy_s(arg, size, temp, size) != EOK) { + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + goto fail0; + } + } + OsalMemFree(temp); + temp = NULL; + HDF_LOGI("%s: success.", __func__); + return HDF_SUCCESS; +fail0: + OsalMemFree(temp); + temp = NULL; + return HDF_FAILURE; } -static long MipiTxIoctl(struct file *filep, unsigned int cmd, unsigned long arg) +static long MipiDsiDevIoctl(struct file *filep, unsigned int cmd, unsigned long arg) { - int ret = 0; + int32_t ret = HDF_SUCCESS; void *pArg = (void *)arg; if (filep == NULL || pArg == NULL) { - HDF_LOGE("invalid input param"); - return -1; + HDF_LOGE("%s: filep or pArg is NULL.", __func__); + return HDF_FAILURE; } - if (MipiTxSemaDownInterruptable(&g_mipiTxSem)) { - return -1; + struct MipiDsiCntlr *cntlr = GetCntlrFromFilep(filep); + if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL.", __func__); + return HDF_FAILURE; } + + struct semaphore *sem = GetSemaFromFilep(filep); + if (sem == NULL) { + HDF_LOGE("%s: sem is NULL.", __func__); + return HDF_FAILURE; + } + + (void)SemaDownInterruptable(sem); switch (cmd) { case HI_MIPI_TX_SET_DEV_CFG: - ret = MipiTxSetComboDevCfg((ComboDevCfgTag *)pArg); - if (ret < 0) { - HDF_LOGE("mipi_tx set combo_dev config failed!\n"); - } + ret = MipiDsiDevSetCfg(cntlr, (struct MipiCfg *)pArg); break; case HI_MIPI_TX_SET_CMD: - ret = MipiTxSetCmd((CmdInfoTag *)pArg); - if (ret < 0) { - HDF_LOGE("mipi_tx set cmd failed!\n"); - } + ret = MipiDsiDevSetCmd(cntlr, (struct DsiCmdDesc *)pArg); break; case HI_MIPI_TX_GET_CMD: - ret = MipiTxGetCmd((GetCmdInfoTag *)pArg); - if (ret < 0) { - HDF_LOGE("mipi_tx get cmd failed!\n"); - } + ret = MipiDsiDevGetCmd(cntlr, (GetDsiCmdDescTag *)pArg); break; case HI_MIPI_TX_ENABLE: - MipiTxEnable(); + MipiDsiCntlrSetHsMode(cntlr); + HDF_LOGI("%s: [MipiDsiCntlrSetHsMode] do.", __func__); break; case HI_MIPI_TX_DISABLE: - MipiTxDisable(); + MipiDsiCntlrSetLpMode(cntlr); + HDF_LOGI("%s: [MipiDsiCntlrSetLpMode] do.", __func__); break; default: - HDF_LOGE("invalid mipi_tx ioctl cmd"); + HDF_LOGE("%s: [default] failed.", __func__); ret = -1; break; } - MipiTxUp(&g_mipiTxSem); - return ret; -} - -static int MipiTxInit(int smooth) -{ - return MipiTxDrvInit(smooth); -} + SemaUp(sem); -static void MipiTxExit(void) -{ - MipiTxDrvExit(); + return ret; } -static int MipiTxOpen(struct inode *inode, struct file *filep) +static int MipiDsiDevOpen(struct inode *inode, struct file *filep) { + uint8_t id; (void)inode; (void)filep; + + id = GetId(); + g_vfsPara[id].cntlr = MipiDsiCntlrOpen(id); + HDF_LOGI("%s: success.", __func__); + return 0; } -static int MipiTxRelease(struct inode *inode, struct file *filep) +static int MipiDsiDevRelease(struct inode *inode, struct file *filep) { + uint8_t id; (void)inode; (void)filep; + + id = GetId(); + if (g_vfsPara[id].cntlr != NULL) { + MipiDsiCntlrClose(g_vfsPara[id].cntlr); + } + HDF_LOGI("%s: success.", __func__); return 0; } -static void MipiTxProcDevShow(struct seq_file *s) +static void MipiDsiDevProcDevShow(struct seq_file *s) { - ComboDevCfgTag *devCfg = NULL; - SyncInfoTag *syncInfo = NULL; - devCfg = (ComboDevCfgTag *)&g_mipiTxDevCtx.devCfg; - syncInfo = (SyncInfoTag *)&g_mipiTxDevCtx.devCfg.syncInfo; + struct MipiCfg *cfg = NULL; + struct DsiTimingInfo *t = NULL; + uint8_t id; + + id = GetId(); + if (g_vfsPara[id].cntlr == NULL) { + HDF_LOGE("%s: g_vfsPara[id].cntlr is NULL", __func__); + return; + } + cfg = &(g_vfsPara[id].cntlr->cfg); + t = &(cfg->timing); /* mipi tx device config */ seq_printf(s, "----------MIPI_Tx DEV CONFIG---------------------------\n"); - seq_printf(s, "%8s%8s%8s%8s%8s%15s%15s%15s%15s%15s\n", - "devno", "lane0", "lane1", "lane2", "lane3", "output_mode", "phy_data_rate", "pixel_clk(KHz)", + seq_printf(s, "%8s%15s%15s%15s%15s%15s\n", + "lane", "output_mode", "phy_data_rate", "pixel_clk(KHz)", "video_mode", "output_fmt"); - seq_printf(s, "%8d%8d%8d%8d%8d%15d%15d%15d%15d%15d\n", - devCfg->devno, - devCfg->laneId[0], - devCfg->laneId[1], - devCfg->laneId[2], /* lina id 2 */ - devCfg->laneId[3], /* lina id 3 */ - devCfg->outputMode, - devCfg->phyDataRate, - devCfg->pixelClk, - devCfg->videoMode, - devCfg->outputFormat); + seq_printf(s, "%8d%15d%15d%15d%15d%15d\n", + cfg->lane, + cfg->mode, + cfg->phyDataRate, + cfg->pixelClk, + cfg->burstMode, + cfg->format); seq_printf(s, "\r\n"); /* mipi tx device sync config */ seq_printf(s, "----------MIPI_Tx SYNC CONFIG---------------------------\n"); @@ -320,124 +550,81 @@ static void MipiTxProcDevShow(struct seq_file *s) "pkt_size", "hsa_pixels", "hbp_pixels", "hline_pixels", "vsa_lines", "vbp_lines", "vfp_lines", "active_lines", "edpi_cmd_size"); seq_printf(s, "%14d%14d%14d%14d%14d%14d%14d%14d%14d\n", - syncInfo->vidPktSize, - syncInfo->vidHsaPixels, - syncInfo->vidHbpPixels, - syncInfo->vidHlinePixels, - syncInfo->vidVsaLines, - syncInfo->vidVbpLines, - syncInfo->vidVfpLines, - syncInfo->vidActiveLines, - syncInfo->edpiCmdSize); - seq_printf(s, "\r\n"); -} - -static void MipiTxProcDevStatusShow(struct seq_file *s) -{ - MipiTxDevPhyTag phyCtx; - - MipiTxDrvGetDevStatus(&phyCtx); - /* mipi tx phy status */ - seq_printf(s, "----------MIPI_Tx DEV STATUS---------------------------\n"); - seq_printf(s, "%8s%8s%8s%8s%8s%8s%8s\n", - "width", "height", "HoriAll", "VertAll", "hbp", "hsa", "vsa"); - seq_printf(s, "%8u%8u%8u%8u%8u%8u%8u\n", - phyCtx.hactDet, - phyCtx.vactDet, - phyCtx.hallDet, - phyCtx.vallDet, - phyCtx.hbpDet, - phyCtx.hsaDet, - phyCtx.vsaDet); + t->xPixels, + t->hsaPixels, + t->hbpPixels, + t->hlinePixels, + t->vsaLines, + t->vbpLines, + t->vfpLines, + t->ylines, + t->edpiCmdSize); seq_printf(s, "\r\n"); + HDF_LOGI("%s: success.", __func__); } -static int MipiTxProcShow(struct seq_file *m, void *v) +static int MipiDsiDevProcShow(struct seq_file *m, void *v) { seq_printf(m, "\nModule: [MIPI_TX], Build Time["__DATE__", "__TIME__"]\n"); - MipiTxProcDevShow(m); - MipiTxProcDevStatusShow(m); + MipiDsiDevProcDevShow(m); HDF_LOGI("%s: v %p", __func__, v); + HDF_LOGI("%s: success.", __func__); return 0; } -static int MipiTxProcOpen(struct inode *inode, struct file *file) +static int MipiDsiDevProcOpen(struct inode *inode, struct file *file) { - return single_open(file, MipiTxProcShow, NULL); + (void)inode; + HDF_LOGE("%s: enter.", __func__); + return single_open(file, MipiDsiDevProcShow, NULL); } -static const struct file_operations g_procMipiTxOps = { - .open = MipiTxProcOpen, +static const struct file_operations g_procMipiDsiDevOps = { + .open = MipiDsiDevProcOpen, .read = seq_read, }; static const struct file_operations g_mipiTxfOps = { - .open = MipiTxOpen, - .release = MipiTxRelease, - .unlocked_ioctl = MipiTxIoctl, + .open = MipiDsiDevOpen, + .release = MipiDsiDevRelease, + .unlocked_ioctl = MipiDsiDevIoctl, }; -static int MipiVfsInit(int smooth) +int32_t MipiDsiDevModuleInit(uint8_t id) { - int ret; + int32_t ret; - (void)smooth; /* 0660 : node mode */ - ret = MipiDsiRegisterDevice(MIPI_TX_DEV_NAME, 0, 0660, (struct file_operations *)&g_mipiTxfOps); + ret = RegisterDevice(MIPI_TX_DEV_NAME, id, 0660, (struct file_operations *)&g_mipiTxfOps); if (ret < 0) { - HDF_LOGE("%s: mipi dsi reg dev fail:%d", __func__, ret); + HDF_LOGE("%s: [RegisterDevice] fail: %d.", __func__, ret); return ret; } - ret = MipiDsiProcRegister(MIPI_TX_PROC_NAME, 0, 0440, &g_procMipiTxOps); /* 0440 : proc file mode */ + ret = ProcRegister(MIPI_TX_PROC_NAME, id, 0440, &g_procMipiDsiDevOps); /* 0440 : proc file mode */ if (ret < 0) { - MipiDsiUnregisterDevice(0); - HDF_LOGE("%s: mipi dsi reg proc fail:%d", __func__, ret); + UnregisterDevice(id); + HDF_LOGE("%s: [ProcRegister] fail: %d.", __func__, ret); return ret; } - return 0; -} - -static void MipiVfsRemove(void) -{ - MipiDsiUnregisterDevice(0); - MipiDsiProcUnregister(MIPI_TX_PROC_NAME, 0); -} - -int MipiTxModuleInit(int smooth) -{ - int ret; - - (void)MipiVfsInit; - - ret = MipiTxInit(smooth); - if (ret != 0) { - HDF_LOGE("hi_mipi_init failed!\n"); - goto fail1; + ret = SemaInit(&g_vfsPara[id].sem, 1); + if (ret != HDF_SUCCESS) { + UnregisterDevice(id); + ProcUnregister(MIPI_TX_PROC_NAME, id); + HDF_LOGE("%s: [SemaInit] failed.", __func__); + return HDF_FAILURE; } - ret = MipiTxSemaInit(&g_mipiTxSem, 1); - if (ret != 0) { - HDF_LOGE("init sema error!\n"); - goto fail2; - } - HDF_LOGE("load mipi_tx driver successful!\n"); - return 0; - -fail2: - MipiTxExit(); -fail1: - (void)MipiVfsRemove; - - HDF_LOGE("load mipi_tx driver failed!\n"); - return ret; + HDF_LOGI("%s: success!", __func__); + return HDF_SUCCESS; } -void MipiTxModuleExit(void) +void MipiDsiDevModuleExit(uint8_t id) { - MipiTxSemaDestroy(&g_mipiTxSem); - MipiTxExit(); - (void)MipiVfsRemove; - HDF_LOGI("unload mipi_tx driver ok!\n"); + SemaDestroy(&g_vfsPara[id].sem); + UnregisterDevice(id); + ProcUnregister(MIPI_TX_PROC_NAME, id); + + HDF_LOGI("%s: success!", __func__); } #ifdef __cplusplus diff --git a/platform/mipi_dsi/mipi_tx_dev.h b/platform/mipi_dsi/mipi_tx_dev.h index 1816531..612383e 100644 --- a/platform/mipi_dsi/mipi_tx_dev.h +++ b/platform/mipi_dsi/mipi_tx_dev.h @@ -18,103 +18,24 @@ #ifndef MIPI_TX_DEV_H #define MIPI_TX_DEV_H - -#define CMD_MAX_NUM 4 -#define LANE_MAX_NUM 4 - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif - -#define CMD_MAX_NUM 4 -#define LANE_MAX_NUM 4 -#define MIPI_TX_DISABLE_LANE_ID (-1) -#define MIPI_TX_SET_DATA_SIZE 800 -#define MIPI_TX_GET_DATA_SIZE 160 - -typedef enum { - OUTPUT_MODE_CSI = 0x0, /* csi mode */ - OUTPUT_MODE_DSI_VIDEO = 0x1, /* dsi video mode */ - OUTPUT_MODE_DSI_CMD = 0x2, /* dsi command mode */ - - OUTPUT_MODE_BUTT -} OutPutModeTag; - -typedef enum { - BURST_MODE = 0x0, - NON_BURST_MODE_SYNC_PULSES = 0x1, - NON_BURST_MODE_SYNC_EVENTS = 0x2, - - VIDEO_DATA_MODE_BUTT -} VideoModeTag; - -typedef enum { - OUT_FORMAT_RGB_16_BIT = 0x0, - OUT_FORMAT_RGB_18_BIT = 0x1, - OUT_FORMAT_RGB_24_BIT = 0x2, - OUT_FORMAT_YUV420_8_BIT_NORMAL = 0x3, - OUT_FORMAT_YUV420_8_BIT_LEGACY = 0x4, - OUT_FORMAT_YUV422_8_BIT = 0x5, - - OUT_FORMAT_BUTT -} OutputFormatTag; +#include "hdf_base.h" +#include "mipi_dsi_if.h" typedef struct { - unsigned short vidPktSize; - unsigned short vidHsaPixels; - unsigned short vidHbpPixels; - unsigned short vidHlinePixels; - unsigned short vidVsaLines; - unsigned short vidVbpLines; - unsigned short vidVfpLines; - unsigned short vidActiveLines; - unsigned short edpiCmdSize; -} SyncInfoTag; - -typedef struct { - unsigned int devno; /* device number */ - short laneId[LANE_MAX_NUM]; /* lane_id: -1 - disable */ - OutPutModeTag outputMode; /* output mode: CSI/DSI_VIDEO/DSI_CMD */ - VideoModeTag videoMode; - OutputFormatTag outputFormat; - SyncInfoTag syncInfo; - unsigned int phyDataRate; /* mbps */ - unsigned int pixelClk; /* KHz */ -} ComboDevCfgTag; - -typedef struct { - unsigned int devno; /* device number */ - unsigned short dataType; - unsigned short cmdSize; - unsigned char *cmd; -} CmdInfoTag; - -typedef struct { - unsigned int devno; /* device number */ - unsigned short dataType; /* DSI data type */ - unsigned short dataParam; /* data param,low 8 bit:1st param.high 8 bit:2nt param, set 0 if not use */ - unsigned short getDataSize; /* read data size */ - unsigned char *getData; /* read data memory address, should malloc by user */ -} GetCmdInfoTag; - -typedef struct { - ComboDevCfgTag devCfg; -} MipiTxDevCtxTag; + struct DsiCmdDesc readCmd; + uint32_t readLen; + uint8_t *out; +} GetDsiCmdDescTag; #define HI_MIPI_TX_IOC_MAGIC 't' -#define HI_MIPI_TX_SET_DEV_CFG _IOW(HI_MIPI_TX_IOC_MAGIC, 0x01, ComboDevCfgTag) -#define HI_MIPI_TX_SET_CMD _IOW(HI_MIPI_TX_IOC_MAGIC, 0x02, CmdInfoTag) +#define HI_MIPI_TX_SET_DEV_CFG _IOW(HI_MIPI_TX_IOC_MAGIC, 0x01, struct MipiCfg) +#define HI_MIPI_TX_SET_CMD _IOW(HI_MIPI_TX_IOC_MAGIC, 0x02, struct DsiCmdDesc) #define HI_MIPI_TX_ENABLE _IO(HI_MIPI_TX_IOC_MAGIC, 0x03) -#define HI_MIPI_TX_GET_CMD _IOWR(HI_MIPI_TX_IOC_MAGIC, 0x04, GetCmdInfoTag) +#define HI_MIPI_TX_GET_CMD _IOWR(HI_MIPI_TX_IOC_MAGIC, 0x04, GetDsiCmdDescTag) #define HI_MIPI_TX_DISABLE _IO(HI_MIPI_TX_IOC_MAGIC, 0x05) -int MipiTxSetCmd(const CmdInfoTag *cmdInfo); -int MipiTxGetCmd(GetCmdInfoTag *getCmdInfo); -int MipiTxSetComboDevCfg(const ComboDevCfgTag *devCfg); -int MipiTxModuleInit(int smooth); -void MipiTxModuleExit(void); +int32_t MipiDsiDevModuleInit(uint8_t id); +void MipiDsiDevModuleExit(uint8_t id); + #endif /* MIPI_TX_DEV_H */ diff --git a/platform/mipi_dsi/mipi_tx_hi35xx.c b/platform/mipi_dsi/mipi_tx_hi35xx.c index 39832be..fc5b109 100644 --- a/platform/mipi_dsi/mipi_tx_hi35xx.c +++ b/platform/mipi_dsi/mipi_tx_hi35xx.c @@ -16,17 +16,18 @@ * */ +#include "mipi_tx_hi35xx.h" #include #include #include "hdf_log.h" -#include "mipi_dsi_core.h" -#include "mipi_tx_dev.h" -#include "mipi_tx_hi35xx.h" -#include "mipi_tx_reg.h" +#include "securec.h" +#include "osal_time.h" #include "osal_io.h" #include "osal_mem.h" -#include "osal_time.h" -#include "securec.h" +#include "mipi_dsi_define.h" +#include "mipi_dsi_core.h" +#include "mipi_tx_reg.h" +#include "mipi_tx_dev.h" #ifdef __cplusplus #if __cplusplus @@ -34,10 +35,14 @@ extern "C" { #endif #endif /* End of #ifdef __cplusplus */ +#define HDF_LOG_TAG mipi_tx_hi35xx + volatile MipiTxRegsTypeTag *g_mipiTxRegsVa = NULL; unsigned int g_mipiTxIrqNum = MIPI_TX_IRQ; unsigned int g_actualPhyDataRate; static unsigned int g_regMapFlag; +static bool g_enCfg = false; +static bool g_enDev = false; static void WriteReg32(unsigned long addr, unsigned int value, unsigned int mask) { @@ -88,7 +93,6 @@ static void SetPhyReg(unsigned int addr, unsigned char value) HdfIsbDsbDmb(); } - static unsigned char MipiTxDrvGetPhyPllSet0(unsigned int phyDataRate) { unsigned char pllSet0; @@ -173,7 +177,7 @@ static void MipiTxDrvSetPhyPllSetX(unsigned int phyDataRate) SetPhyReg(PLL_SET5, pllSet5); #ifdef MIPI_TX_DEBUG - HDF_LOGI("\n==========phy pll info======="); + HDF_LOGI("%s: \n==========phy pll info=======", __func__); HDF_LOGI("pllSet0(0x14): 0x%x", pllSet0); HDF_LOGI("pllSet1(0x15): 0x%x", pllSet1); HDF_LOGI("pllSet2(0x16): 0x%x", pllSet2); @@ -195,10 +199,10 @@ static void MipiTxDrvGetPhyClkPrepare(unsigned char *clkPrepare) ((((g_actualPhyDataRate * TCLK_PREPARE + ROUNDUP_VALUE) / INNER_PEROID + ((g_actualPhyDataRate * PREPARE_COMPENSATE + ROUNDUP_VALUE) / INNER_PEROID)) * INNER_PEROID - PREPARE_COMPENSATE * g_actualPhyDataRate - TCLK_PREPARE * g_actualPhyDataRate) / INNER_PEROID)); - if (temp0 > 0) { /* 0 is the minimum */ + if (temp0 > 0) { /* 0 is the minimum */ temp1 = temp0; } else { - temp1 = 0; /* 0 is the minimum */ + temp1 = 0; /* 0 is the minimum */ } if (((temp1 + 1) * INNER_PEROID - PREPARE_COMPENSATE * g_actualPhyDataRate) /* temp + 1 is next level period */ @@ -207,13 +211,13 @@ static void MipiTxDrvGetPhyClkPrepare(unsigned char *clkPrepare) *clkPrepare = temp0 - 1; } else { *clkPrepare = 255; /* set 255 will easy to found mistake */ - HDF_LOGE("err when calc phy timing"); + HDF_LOGE("%s: err when calc phy timing.", __func__); } } else { - if (temp0 > 0) { /* 0 is the minimum */ + if (temp0 > 0) { /* 0 is the minimum */ *clkPrepare = temp0; } else { - *clkPrepare = 0; /* 0 is the minimum */ + *clkPrepare = 0; /* 0 is the minimum */ } } } @@ -242,7 +246,7 @@ static void MipiTxDrvGetPhyDataPrepare(unsigned char *dataPrepare) *dataPrepare = temp0 - 1; } else { *dataPrepare = 255; /* set 255 will easy to found mistake */ - HDF_LOGE("err when calc phy timing"); + HDF_LOGE("%s: err when calc phy timing.", __func__); } } else { if (temp0 > 0) { @@ -327,7 +331,7 @@ static void MipiTxDrvSetPhyTimingParam(const MipiTxPhyTimingParamTag *tp) SetPhyReg(DATA3_THS_TRAIL, tp->dataThsTrail); #ifdef MIPI_TX_DEBUG - HDF_LOGI("\n==========phy timing parameters======="); + HDF_LOGI("%s:\n==========phy timing parameters=======", __func__); HDF_LOGI("data_tpre_delay(0x30/40/50/60): 0x%x", tp->dataTpreDelay); HDF_LOGI("clk_tlpx(0x22): 0x%x", tp->clkTlpx); HDF_LOGI("clk_tclk_prepare(0x23): 0x%x", tp->clkTclkPrepare); @@ -355,14 +359,15 @@ static void MipiTxDrvSetPhyHsLpSwitchTime(const MipiTxPhyTimingParamTag *tp) g_mipiTxRegsVa->PHY_TMR_LPCLK_CFG.u32 = ((31 + tp->dataThsTrail) << 16) + /* 31 from algorithm, 16 set register */ tp->clkTlpx + tp->clkTclkPrepare + tp->clkTclkZero + 6; /* 6 from algorithm */ #ifdef MIPI_TX_DEBUG - HDF_LOGI("PHY_TMR_CFG(0x9C): 0x%x", g_mipiTxRegsVa->PHY_TMR_CFG.u32); - HDF_LOGI("PHY_TMR_LPCLK_CFG(0x98): 0x%x", g_mipiTxRegsVa->PHY_TMR_LPCLK_CFG.u32); + HDF_LOGI("%s: PHY_TMR_CFG(0x9C): 0x%x", __func__, g_mipiTxRegsVa->PHY_TMR_CFG.u32); + HDF_LOGI("%s: PHY_TMR_LPCLK_CFG(0x98): 0x%x", __func__, g_mipiTxRegsVa->PHY_TMR_LPCLK_CFG.u32); #endif } -void MipiTxDrvSetPhyCfg(const ComboDevCfgTag *cfg) +static void MipiTxDrvSetPhyCfg(const ComboDevCfgTag *cfg) { if (cfg == NULL) { + HDF_LOGE("%s: cfg is NULL!", __func__); return; } MipiTxPhyTimingParamTag tp = {0}; @@ -407,6 +412,7 @@ void MipiTxDrvSetPhyCfg(const ComboDevCfgTag *cfg) void MipiTxDrvGetDevStatus(MipiTxDevPhyTag *phyCtx) { if (phyCtx == NULL) { + HDF_LOGE("%s: phyCtx is NULL!", __func__); return; } phyCtx->hactDet = g_mipiTxRegsVa->HORI0_DET.bits.hact_det; @@ -439,7 +445,7 @@ static void SetOutputFormat(const ComboDevCfgTag *cfg) } g_mipiTxRegsVa->COLOR_CODING.u32 = colorCoding; #ifdef MIPI_TX_DEBUG - HDF_LOGI("SetOutputFormat: 0x%x", colorCoding); + HDF_LOGI("%s: SetOutputFormat: 0x%x", __func__, colorCoding); #endif } @@ -467,7 +473,7 @@ static void SetTimingConfig(const ComboDevCfgTag *cfg) unsigned int hline; if (cfg->pixelClk == 0) { - HDF_LOGE("cfg->pixelClk is 0, illegal."); + HDF_LOGE("%s: cfg->pixelClk is 0, illegal.", __func__); return; } /* 125 from algorithm */ @@ -484,17 +490,19 @@ static void SetTimingConfig(const ComboDevCfgTag *cfg) g_mipiTxRegsVa->VID_VFP_LINES.u32 = cfg->syncInfo.vidVfpLines; g_mipiTxRegsVa->VID_VACTIVE_LINES.u32 = cfg->syncInfo.vidActiveLines; #ifdef MIPI_TX_DEBUG + HDF_LOGI("%s:\n==========Set Timing Config=======", __func__); HDF_LOGI("VID_HSA_TIME(0x48): 0x%x", hsa); HDF_LOGI("VID_HBP_TIME(0x4c): 0x%x", hbp); HDF_LOGI("VID_HLINE_TIME(0x50): 0x%x", hline); HDF_LOGI("VID_VSA_LINES(0x54): 0x%x", cfg->syncInfo.vidVsaLines); HDF_LOGI("VID_VBP_LINES(0x58): 0x%x", cfg->syncInfo.vidVbpLines); HDF_LOGI("VID_VFP_LINES(0x5c): 0x%x", cfg->syncInfo.vidVfpLines); - HDF_LOGI("VID_VACTIVE_LINES(0x60): 0x%x\n", cfg->syncInfo.vidActiveLines); + HDF_LOGI("VID_VACTIVE_LINES(0x60): 0x%x", cfg->syncInfo.vidActiveLines); + HDF_LOGI("=========================\n"); #endif } -void SetLaneConfig(const short laneId[], int len) +static void SetLaneConfig(const short laneId[], int len) { int num = 0; int i; @@ -507,7 +515,7 @@ void SetLaneConfig(const short laneId[], int len) g_mipiTxRegsVa->PHY_IF_CFG.u32 = num - 1; } -void MipiTxDrvSetClkMgrCfg(void) +static void MipiTxDrvSetClkMgrCfg(void) { if (g_actualPhyDataRate / 160 < 2) { /* 160 cal div, should not smaller than 2 */ g_mipiTxRegsVa->CLKMGR_CFG.u32 = 0x102; @@ -516,9 +524,10 @@ void MipiTxDrvSetClkMgrCfg(void) } } -void MipiTxDrvSetControllerCfg(const ComboDevCfgTag *cfg) +static void MipiTxDrvSetControllerCfg(const ComboDevCfgTag *cfg) { if (cfg == NULL) { + HDF_LOGE("%s: cfg is NULL!", __func__); return; } /* disable input */ @@ -581,11 +590,11 @@ static int MipiTxWaitCmdFifoEmpty(void) waitCnt++; OsalUDelay(1); if (waitCnt > MIPI_TX_READ_TIMEOUT_CNT) { - HDF_LOGW("timeout when send cmd buffer"); - return -1; + HDF_LOGW("%s: timeout when send cmd buffer.", __func__); + return HDF_FAILURE; } } while (cmdPktStatus.bits.gen_cmd_empty == 0); - return 0; + return HDF_SUCCESS; } static int MipiTxWaitWriteFifoEmpty(void) @@ -599,11 +608,11 @@ static int MipiTxWaitWriteFifoEmpty(void) waitCnt++; OsalUDelay(1); if (waitCnt > MIPI_TX_READ_TIMEOUT_CNT) { - HDF_LOGW("timeout when send data buffer"); - return -1; + HDF_LOGW("%s: timeout when send data buffer.", __func__); + return HDF_FAILURE; } } while (cmdPktStatus.bits.gen_pld_w_empty == 0); - return 0; + return HDF_SUCCESS; } static int MipiTxWaitWriteFifoNotFull(void) @@ -616,15 +625,15 @@ static int MipiTxWaitWriteFifoNotFull(void) cmdPktStatus.u32 = g_mipiTxRegsVa->CMD_PKT_STATUS.u32; if (waitCnt > 0) { OsalUDelay(1); - HDF_LOGW("write fifo full happened wait count = %u", waitCnt); + HDF_LOGW("%s: write fifo full happened wait count = %u.", __func__, waitCnt); } if (waitCnt > MIPI_TX_READ_TIMEOUT_CNT) { - HDF_LOGW("timeout when wait write fifo not full buffer"); - return -1; + HDF_LOGW("%s: timeout when wait write fifo not full buffer.", __func__); + return HDF_FAILURE; } waitCnt++; } while (cmdPktStatus.bits.gen_pld_w_full == 1); - return 0; + return HDF_SUCCESS; } /* @@ -633,6 +642,7 @@ static int MipiTxWaitWriteFifoNotFull(void) */ static void MipiTxDrvSetPayloadData(const unsigned char *cmd, unsigned short cmdSize) { + int32_t ret; U_GEN_PLD_DATA genPldData; int i, j; @@ -643,7 +653,11 @@ static void MipiTxDrvSetPayloadData(const unsigned char *cmd, unsigned short cmd genPldData.bits.gen_pld_b2 = cmd[i * 4 + 1]; /* 1 in 4 */ genPldData.bits.gen_pld_b3 = cmd[i * 4 + 2]; /* 2 in 4 */ genPldData.bits.gen_pld_b4 = cmd[i * 4 + 3]; /* 3 in 4 */ - MipiTxWaitWriteFifoNotFull(); + ret = MipiTxWaitWriteFifoNotFull(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiTxWaitWriteFifoNotFull] failed.", __func__); + return; + } g_mipiTxRegsVa->GEN_PLD_DATA.u32 = genPldData.u32; } j = cmdSize % 4; /* remainder of 4 */ @@ -657,67 +671,88 @@ static void MipiTxDrvSetPayloadData(const unsigned char *cmd, unsigned short cmd if (j > 2) { /* bigger than 2 */ genPldData.bits.gen_pld_b3 = cmd[i * 4 + 2]; /* 2 in 4 */ } - MipiTxWaitWriteFifoNotFull(); + ret = MipiTxWaitWriteFifoNotFull(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiTxWaitWriteFifoNotFull] failed.", __func__); + return; + } g_mipiTxRegsVa->GEN_PLD_DATA.u32 = genPldData.u32; } #ifdef MIPI_TX_DEBUG - HDF_LOGI("\n=====set cmd======="); - HDF_LOGI("GEN_PLD_DATA(0x70): 0x%x\n", genPldData); + HDF_LOGI("%s: \n=====set cmd=======", __func__); + HDF_LOGI("GEN_PLD_DATA(0x70): 0x%x", genPldData); #endif } -int MipiTxDrvSetCmdInfo(const CmdInfoTag *cmdInfo) +static int32_t LinuxCopyToKernel(void *dest, uint32_t max, const void *src, uint32_t count) { + int32_t ret; + + if (access_ok(VERIFY_READ, src, count)) { /* user space */ + ret = (copy_from_user(dest, src, count) != 0) ? HDF_FAILURE : HDF_SUCCESS; + if (ret == HDF_FAILURE) { + HDF_LOGE("%s: [copy_from_user] failed.", __func__); + } + } else { /* kernel space */ + ret = (memcpy_s(dest, max, src, count) != EOK) ? HDF_FAILURE : HDF_SUCCESS; + if (ret == HDF_FAILURE) { + HDF_LOGE("%s: [memcpy_s] failed.", __func__); + } + } + HDF_LOGI("%s: success.", __func__); + + return ret; +} + +static int MipiTxDrvSetCmdInfo(const CmdInfoTag *cmdInfo) +{ + int32_t ret; U_GEN_HDR genHdr; unsigned char *cmd = NULL; if (cmdInfo == NULL) { - return -1; + HDF_LOGE("%s: cmdInfo is NULL.", __func__); + return HDF_FAILURE; } genHdr.u32 = g_mipiTxRegsVa->GEN_HDR.u32; if (cmdInfo->cmd != NULL) { if (cmdInfo->cmdSize > 200 || cmdInfo->cmdSize == 0) { /* 200 is max cmd size */ - HDF_LOGE("set cmd size illegal, size =%u", cmdInfo->cmdSize); - return -1; + HDF_LOGE("%s: set cmd size illegal, size =%u.", __func__, cmdInfo->cmdSize); + return HDF_FAILURE; } cmd = (unsigned char *)OsalMemCalloc(cmdInfo->cmdSize); if (cmd == NULL) { - HDF_LOGE("kmalloc fail,please check,need %u bytes", cmdInfo->cmdSize); - return -1; + HDF_LOGE("%s: OsalMemCalloc fail,please check,need %u bytes.", __func__, cmdInfo->cmdSize); + return HDF_FAILURE; } - if (access_ok(VERIFY_READ, cmdInfo->cmd, cmdInfo->cmdSize)) { /* user space */ - if (copy_from_user(cmd, cmdInfo->cmd, cmdInfo->cmdSize) != 0) { - OsalMemFree(cmd); - cmd = NULL; - HDF_LOGE("%s: copy_from_user fail", __func__); - return -1; - } - } else { /* kernel space */ - if (memcpy_s(cmd, cmdInfo->cmdSize, cmdInfo->cmd, cmdInfo->cmdSize) != EOK) { - OsalMemFree(cmd); - cmd = NULL; - HDF_LOGE("%s: memcpy_s fail", __func__); - return -1; - } + ret = LinuxCopyToKernel(cmd, cmdInfo->cmdSize, cmdInfo->cmd, cmdInfo->cmdSize); + if (ret == HDF_SUCCESS) { + MipiTxDrvSetPayloadData(cmd, cmdInfo->cmdSize); } - MipiTxDrvSetPayloadData(cmd, cmdInfo->cmdSize); OsalMemFree(cmd); cmd = NULL; + if (ret == HDF_FAILURE) { + HDF_LOGE("%s: [LinuxCopyToKernel] failed.", __func__); + return HDF_FAILURE; + } } genHdr.bits.gen_dt = cmdInfo->dataType; genHdr.bits.gen_wc_lsbyte = cmdInfo->cmdSize & 0xff; genHdr.bits.gen_wc_msbyte = (cmdInfo->cmdSize & 0xff00) >> 8; /* height 8 bits */ g_mipiTxRegsVa->GEN_HDR.u32 = genHdr.u32; OsalUDelay(350); /* wait 350 us transfer end */ - MipiTxWaitCmdFifoEmpty(); - MipiTxWaitWriteFifoEmpty(); -#ifdef MIPI_TX_DEBUG - HDF_LOGI("\n=====set cmd======="); - HDF_LOGI("cmdInfo->cmdSize: 0x%x", cmdInfo->cmdSize); - HDF_LOGI("cmdInfo->dataType: 0x%x", cmdInfo->dataType); - HDF_LOGI("GEN_HDR(0x6C): 0x%x\n", genHdr); -#endif - return 0; + ret = MipiTxWaitCmdFifoEmpty(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiTxWaitCmdFifoEmpty] failed.", __func__); + return HDF_FAILURE; + } + ret = MipiTxWaitWriteFifoEmpty(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiTxWaitWriteFifoEmpty] failed.", __func__); + return HDF_FAILURE; + } + HDF_LOGI("%s: cmdSize = 0x%x, dataType = 0x%x", __func__, cmdInfo->cmdSize, cmdInfo->dataType); + return HDF_SUCCESS; } static int MipiTxWaitReadFifoNotEmpty(void) @@ -732,18 +767,19 @@ static int MipiTxWaitReadFifoNotEmpty(void) intSt1.u32 = g_mipiTxRegsVa->INT_ST1.u32; intSt0.u32 = g_mipiTxRegsVa->INT_ST0.u32; if ((intSt1.u32 & 0x3e) != 0) { - HDF_LOGE("err happened when read data, int_st1 = 0x%x,int_st0 = %x", intSt1.u32, intSt0.u32); - return -1; + HDF_LOGE("%s: err happened when read data, int_st1 = 0x%x,int_st0 = %x.", + __func__, intSt1.u32, intSt0.u32); + return HDF_FAILURE; } if (waitCnt > MIPI_TX_READ_TIMEOUT_CNT) { - HDF_LOGW("timeout when read data"); - return -1; + HDF_LOGW("%s: timeout when read data.", __func__); + return HDF_FAILURE; } waitCnt++; OsalUDelay(1); cmdPktStatus.u32 = g_mipiTxRegsVa->CMD_PKT_STATUS.u32; } while (cmdPktStatus.bits.gen_pld_r_empty == 0x1); - return 0; + return HDF_SUCCESS; } static int MipiTxWaitReadFifoEmpty(void) @@ -761,11 +797,11 @@ static int MipiTxWaitReadFifoEmpty(void) waitCnt++; OsalUDelay(1); if (waitCnt > MIPI_TX_READ_TIMEOUT_CNT) { - HDF_LOGW("timeout when clear data buffer, the last read data is 0x%x", pldData.u32); - return -1; + HDF_LOGW("%s: timeout when clear data buffer, the last read data is 0x%x.", __func__, pldData.u32); + return HDF_FAILURE; } } while ((intSt1.bits.gen_pld_rd_err) == 0x0); - return 0; + return HDF_SUCCESS; } static int MipiTxSendShortPacket(unsigned char virtualChannel, @@ -779,9 +815,10 @@ static int MipiTxSendShortPacket(unsigned char virtualChannel, genHdr.bits.gen_wc_msbyte = (dataParam & 0xff00) >> 8; /* height 8 bits */ g_mipiTxRegsVa->GEN_HDR.u32 = genHdr.u32; if (MipiTxWaitCmdFifoEmpty() != 0) { - return -1; + HDF_LOGE("%s: [MipiTxWaitCmdFifoEmpty] failed!", __func__); + return HDF_FAILURE; } - return 0; + return HDF_SUCCESS; } static int MipiTxGetReadFifoData(unsigned int getDataSize, unsigned char *dataBuf) @@ -791,7 +828,8 @@ static int MipiTxGetReadFifoData(unsigned int getDataSize, unsigned char *dataBu for (i = 0; i < getDataSize / 4; i++) { /* 4byte once */ if (MipiTxWaitReadFifoNotEmpty() != 0) { - return -1; + HDF_LOGE("%s: [MipiTxWaitReadFifoNotEmpty] failed at first!", __func__); + return HDF_FAILURE; } pldData.u32 = g_mipiTxRegsVa->GEN_PLD_DATA.u32; dataBuf[i * 4] = pldData.bits.gen_pld_b1; /* 0 in 4 */ @@ -804,7 +842,8 @@ static int MipiTxGetReadFifoData(unsigned int getDataSize, unsigned char *dataBu if (j != 0) { if (MipiTxWaitReadFifoNotEmpty() != 0) { - return -1; + HDF_LOGE("%s: [MipiTxWaitReadFifoNotEmpty] failed at second!", __func__); + return HDF_FAILURE; } pldData.u32 = g_mipiTxRegsVa->GEN_PLD_DATA.u32; if (j > 0) { @@ -817,10 +856,10 @@ static int MipiTxGetReadFifoData(unsigned int getDataSize, unsigned char *dataBu dataBuf[i * 4 + 2] = pldData.bits.gen_pld_b3; /* 2 in 4 */ } } - return 0; + return HDF_SUCCESS; } -void MipiTxReset(void) +static void MipiTxReset(void) { g_mipiTxRegsVa->PWR_UP.u32 = 0x0; g_mipiTxRegsVa->PHY_RSTZ.u32 = 0xd; @@ -831,45 +870,53 @@ void MipiTxReset(void) return; } -int MipiTxDrvGetCmdInfo(GetCmdInfoTag *getCmdInfo) +static int MipiTxDrvGetCmdInfo(GetCmdInfoTag *getCmdInfo) { unsigned char *dataBuf = NULL; + HDF_LOGI("%s: enter!", __func__); dataBuf = (unsigned char*)OsalMemAlloc(getCmdInfo->getDataSize); if (dataBuf == NULL) { - return -1; + HDF_LOGE("%s: dataBuf is NULL!", __func__); + return HDF_FAILURE; } if (MipiTxWaitReadFifoEmpty() != 0) { + HDF_LOGE("%s: [MipiTxWaitReadFifoEmpty] failed!", __func__); goto fail0; } if (MipiTxSendShortPacket(0, getCmdInfo->dataType, getCmdInfo->dataParam) != 0) { + HDF_LOGE("%s: [MipiTxSendShortPacket] failed!", __func__); goto fail0; } if (MipiTxGetReadFifoData(getCmdInfo->getDataSize, dataBuf) != 0) { - /* fail will block mipi data lane, so need reset */ + /* fail will block mipi data lane, so need reset */ MipiTxReset(); + HDF_LOGE("%s: [MipiTxGetReadFifoData] failed!", __func__); goto fail0; } if (access_ok(VERIFY_WRITE, getCmdInfo->getData, getCmdInfo->getDataSize)) { /* user space */ if (copy_to_user(getCmdInfo->getData, dataBuf, getCmdInfo->getDataSize) != 0) { - HDF_LOGE("copy_to_user fail"); + HDF_LOGE("%s: copy_to_user fail", __func__); + goto fail0; } } else { /* kernel space */ if (memcpy_s(getCmdInfo->getData, getCmdInfo->getDataSize, dataBuf, getCmdInfo->getDataSize) != EOK) { - HDF_LOGE("memcpy_s fail"); + HDF_LOGE("%s: memcpy_s fail", __func__); + goto fail0; } } OsalMemFree(dataBuf); dataBuf = NULL; - return 0; + HDF_LOGI("%s: success!", __func__); + return HDF_SUCCESS; fail0: OsalMemFree(dataBuf); dataBuf = NULL; - return -1; + return HDF_FAILURE; } -void MipiTxDrvEnableInput(const OutPutModeTag outputMode) +static void MipiTxDrvEnableInput(const OutPutModeTag outputMode) { if ((outputMode == OUTPUT_MODE_DSI_VIDEO) || (outputMode == OUTPUT_MODE_CSI)) { g_mipiTxRegsVa->MODE_CFG.u32 = 0x0; @@ -881,9 +928,10 @@ void MipiTxDrvEnableInput(const OutPutModeTag outputMode) g_mipiTxRegsVa->OPERATION_MODE.u32 = 0x80150000; g_mipiTxRegsVa->LPCLK_CTRL.u32 = 0x1; MipiTxReset(); + g_enDev = true; } -void MipiTxDrvDisableInput(void) +static void MipiTxDrvDisableInput(void) { /* disable input */ g_mipiTxRegsVa->OPERATION_MODE.u32 = 0x0; @@ -892,6 +940,8 @@ void MipiTxDrvDisableInput(void) g_mipiTxRegsVa->MODE_CFG.u32 = 0x1; g_mipiTxRegsVa->LPCLK_CTRL.u32 = 0x0; MipiTxReset(); + g_enDev = false; + g_enCfg = false; } static int MipiTxDrvRegInit(void) @@ -899,13 +949,13 @@ static int MipiTxDrvRegInit(void) if (!g_mipiTxRegsVa) { g_mipiTxRegsVa = (MipiTxRegsTypeTag *)OsalIoRemap(MIPI_TX_REGS_ADDR, (unsigned int)MIPI_TX_REGS_SIZE); if (g_mipiTxRegsVa == NULL) { - HDF_LOGE("remap mipi_tx reg addr fail"); - return -1; + HDF_LOGE("%s: remap mipi_tx reg addr fail.", __func__); + return HDF_FAILURE; } g_regMapFlag = 1; } - return 0; + return HDF_SUCCESS; } static void MipiTxDrvRegExit(void) @@ -927,7 +977,7 @@ static void MipiTxDrvHwInit(int smooth) /* mipi_tx gate clk enable */ WriteReg32(mipiTxCrgAddr, 1, 0x1); /* reset */ - if (smooth == FALSE) { + if (smooth == 0) { WriteReg32(mipiTxCrgAddr, 1 << 1, 0x1 << 1); } /* unreset */ @@ -937,72 +987,173 @@ static void MipiTxDrvHwInit(int smooth) OsalIoUnmap((void *)mipiTxCrgAddr); } -int MipiTxDrvInit(int smooth) +static int MipiTxDrvInit(int smooth) { - int ret; + int32_t ret; ret = MipiTxDrvRegInit(); if (ret < 0) { - HDF_LOGE("MipiTxDrvRegInit fail!"); - return -1; + HDF_LOGE("%s: MipiTxDrvRegInit fail!", __func__); + return HDF_FAILURE; } MipiTxDrvHwInit(smooth); - return 0; + return HDF_SUCCESS; } -void MipiTxDrvExit(void) +static void MipiTxDrvExit(void) { MipiTxDrvRegExit(); } -ComboDevCfgTag *GetDevCfg(struct MipiDsiCntlr *cntlr) +static ComboDevCfgTag *GetDevCfg(struct MipiDsiCntlr *cntlr) { static ComboDevCfgTag dev; int i; if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL!", __func__); return NULL; } dev.devno = cntlr->devNo; - dev.outputMode = (OutPutModeTag)cntlr->mode; - dev.videoMode = (VideoModeTag)cntlr->burstMode; - dev.outputFormat = (OutputFormatTag)cntlr->format; - dev.syncInfo.vidPktSize = cntlr->timing.xPixels; - dev.syncInfo.vidHsaPixels = cntlr->timing.hsaPixels; - dev.syncInfo.vidHbpPixels = cntlr->timing.hbpPixels; - dev.syncInfo.vidHlinePixels = cntlr->timing.hlinePixels; - dev.syncInfo.vidVsaLines = cntlr->timing.vsaLines; - dev.syncInfo.vidVbpLines = cntlr->timing.vbpLines; - dev.syncInfo.vidVfpLines = cntlr->timing.vfpLines; - dev.syncInfo.vidActiveLines = cntlr->timing.ylines; - dev.syncInfo.edpiCmdSize = cntlr->timing.edpiCmdSize; - dev.phyDataRate = cntlr->phyDataRate; - dev.pixelClk = cntlr->pixelClk; + dev.outputMode = (OutPutModeTag)cntlr->cfg.mode; + dev.videoMode = (VideoModeTag)cntlr->cfg.burstMode; + dev.outputFormat = (OutputFormatTag)cntlr->cfg.format; + dev.syncInfo.vidPktSize = cntlr->cfg.timing.xPixels; + dev.syncInfo.vidHsaPixels = cntlr->cfg.timing.hsaPixels; + dev.syncInfo.vidHbpPixels = cntlr->cfg.timing.hbpPixels; + dev.syncInfo.vidHlinePixels = cntlr->cfg.timing.hlinePixels; + dev.syncInfo.vidVsaLines = cntlr->cfg.timing.vsaLines; + dev.syncInfo.vidVbpLines = cntlr->cfg.timing.vbpLines; + dev.syncInfo.vidVfpLines = cntlr->cfg.timing.vfpLines; + dev.syncInfo.vidActiveLines = cntlr->cfg.timing.ylines; + dev.syncInfo.edpiCmdSize = cntlr->cfg.timing.edpiCmdSize; + dev.phyDataRate = cntlr->cfg.phyDataRate; + dev.pixelClk = cntlr->cfg.pixelClk; for (i = 0; i < LANE_MAX_NUM; i++) { dev.laneId[i] = -1; /* -1 : not use */ } - for (i = 0; i < cntlr->lane; i++) { + for (i = 0; i < cntlr->cfg.lane; i++) { dev.laneId[i] = i; } return &dev; } -int32_t Hi35xxSetCntlrCfg(struct MipiDsiCntlr *cntlr) +static int MipiTxCheckCombDevCfg(const ComboDevCfgTag *devCfg) +{ + int i; + int validLaneId[LANE_MAX_NUM] = {0, 1, 2, 3}; + + if (g_enDev) { + HDF_LOGE("%s: mipi_tx dev has enable!", __func__); + return HDF_FAILURE; + } + if (devCfg->devno != 0) { + HDF_LOGE("%s: mipi_tx dev devno err!", __func__); + return HDF_FAILURE; + } + for (i = 0; i < LANE_MAX_NUM; i++) { + if ((devCfg->laneId[i] != validLaneId[i]) && (devCfg->laneId[i] != MIPI_TX_DISABLE_LANE_ID)) { + HDF_LOGE("%s: mipi_tx dev laneId %d err!", __func__, devCfg->laneId[i]); + return HDF_FAILURE; + } + } + if ((devCfg->outputMode != OUTPUT_MODE_CSI) && (devCfg->outputMode != OUTPUT_MODE_DSI_VIDEO) && + (devCfg->outputMode != OUTPUT_MODE_DSI_CMD)) { + HDF_LOGE("%s: mipi_tx dev outputMode %d err!", __func__, devCfg->outputMode); + return HDF_FAILURE; + } + if ((devCfg->videoMode != BURST_MODE) && (devCfg->videoMode != NON_BURST_MODE_SYNC_PULSES) && + (devCfg->videoMode != NON_BURST_MODE_SYNC_EVENTS)) { + HDF_LOGE("%s: mipi_tx dev videoMode %d err!", __func__, devCfg->videoMode); + return HDF_FAILURE; + } + if ((devCfg->outputFormat != OUT_FORMAT_RGB_16_BIT) && (devCfg->outputFormat != OUT_FORMAT_RGB_18_BIT) && + (devCfg->outputFormat != OUT_FORMAT_RGB_24_BIT) && (devCfg->outputFormat != + OUT_FORMAT_YUV420_8_BIT_NORMAL) && (devCfg->outputFormat != OUT_FORMAT_YUV420_8_BIT_LEGACY) && + (devCfg->outputFormat != OUT_FORMAT_YUV422_8_BIT)) { + HDF_LOGE("%s: mipi_tx dev outputFormat %d err!", __func__, devCfg->outputFormat); + return HDF_FAILURE; + } + + HDF_LOGI("%s: success!", __func__); + return HDF_SUCCESS; +} + +static int MipiTxSetComboDevCfg(const ComboDevCfgTag *devCfg) +{ + int32_t ret; + + ret = MipiTxCheckCombDevCfg(devCfg); + if (ret < 0) { + HDF_LOGE("%s: mipi_tx check combo_dev config failed!", __func__); + return ret; + } + /* set controler config */ + MipiTxDrvSetControllerCfg(devCfg); + /* set phy config */ + MipiTxDrvSetPhyCfg(devCfg); + g_enCfg = true; + return ret; +} + +static int32_t Hi35xxSetCntlrCfg(struct MipiDsiCntlr *cntlr) { ComboDevCfgTag *dev = GetDevCfg(cntlr); if (dev == NULL) { - return -1; + HDF_LOGE("%s: dev is NULL!", __func__); + return HDF_FAILURE; } return MipiTxSetComboDevCfg(dev); } -int32_t Hi35xxSetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd) +static int MipiTxCheckSetCmdInfo(const CmdInfoTag *cmdInfo) +{ + if (g_enDev) { + HDF_LOGE("%s: mipi_tx dev has enable!", __func__); + return HDF_FAILURE; + } + + if (!g_enCfg) { + HDF_LOGE("%s: mipi_tx dev has not config!", __func__); + return HDF_FAILURE; + } + if (cmdInfo->devno != 0) { + HDF_LOGE("%s: mipi_tx devno %d err!", __func__, cmdInfo->devno); + return HDF_FAILURE; + } + /* When cmd is not NULL, cmd_size means the length of cmd or it means cmd and addr */ + if (cmdInfo->cmd != NULL) { + if (cmdInfo->cmdSize > MIPI_TX_SET_DATA_SIZE) { + HDF_LOGE("%s: mipi_tx dev cmd_size %d err!", __func__, cmdInfo->cmdSize); + return HDF_FAILURE; + } + } + return HDF_SUCCESS; +} + +static int MipiTxSetCmd(const CmdInfoTag *cmdInfo) +{ + int32_t ret; + if (cmdInfo == NULL) { + HDF_LOGE("%s: cmdInfo is NULL!", __func__); + return HDF_FAILURE; + } + ret = MipiTxCheckSetCmdInfo(cmdInfo); + if (ret < 0) { + HDF_LOGE("%s: mipi_tx check combo_dev config failed!", __func__); + return ret; + } + return MipiTxDrvSetCmdInfo(cmdInfo); +} + +static int32_t Hi35xxSetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd) { CmdInfoTag cmdInfo; (void)cntlr; if (cmd == NULL) { + HDF_LOGE("%s: cmd is NULL!", __func__); return HDF_FAILURE; } cmdInfo.devno = 0; @@ -1011,30 +1162,70 @@ int32_t Hi35xxSetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd) cmdInfo.dataType = cmd->dataType; /* 0x29: long data type */ cmdInfo.cmd = cmd->payload; } else if (cmd->dataLen == 2) { /* 2: use short data type */ - uint16_t tmp = cmd->payload[1]; /* 3: payload */ - tmp = (tmp & 0x00ff) << 8; /* 0x00ff , 8: payload to high */ + uint16_t tmp = cmd->payload[1]; /* 3: payload */ + tmp = (tmp & 0x00ff) << 8; /* 0x00ff , 8: payload to high */ tmp = 0xff00 & tmp; - tmp = tmp | cmd->payload[0]; /* 2: reg addr */ + tmp = tmp | cmd->payload[0]; /* 2: reg addr */ cmdInfo.cmdSize = tmp; cmdInfo.dataType = cmd->dataType; /* 0x23: short data type */ cmdInfo.cmd = NULL; } else if (cmd->dataLen == 1) { - cmdInfo.cmdSize = cmd->payload[0]; /* 2: reg addr */ + cmdInfo.cmdSize = cmd->payload[0]; /* 2: reg addr */ cmdInfo.dataType = cmd->dataType; /* 0x05: short data type */ cmdInfo.cmd = NULL; } else { - // error + HDF_LOGE("%s: dataLen error!", __func__); return HDF_FAILURE; } return MipiTxSetCmd(&cmdInfo); } -int32_t Hi35xxGetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd, uint32_t readLen, uint8_t *out) +static int MipiTxCheckGetCmdInfo(const GetCmdInfoTag *getCmdInfo) +{ + if (g_enDev) { + HDF_LOGE("%s: mipi_tx dev has enable!", __func__); + return HDF_FAILURE; + } + + if (!g_enCfg) { + HDF_LOGE("%s: mipi_tx dev has not config!", __func__); + return HDF_FAILURE; + } + if (getCmdInfo->devno != 0) { + HDF_LOGE("%s: mipi_tx dev devno %d err!", __func__, getCmdInfo->devno); + return HDF_FAILURE; + } + if ((getCmdInfo->getDataSize == 0) || (getCmdInfo->getDataSize > MIPI_TX_GET_DATA_SIZE)) { + HDF_LOGE("%s: mipi_tx dev getDataSize %d err!", __func__, getCmdInfo->getDataSize); + return HDF_FAILURE; + } + if (getCmdInfo->getData == NULL) { + HDF_LOGE("%s: mipi_tx dev getData is null!", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int MipiTxGetCmd(GetCmdInfoTag *getCmdInfo) +{ + int32_t ret; + + ret = MipiTxCheckGetCmdInfo(getCmdInfo); + if (ret < 0) { + HDF_LOGE("%s: [MipiTxCheckGetCmdInfo] failed!", __func__); + return ret; + } + return MipiTxDrvGetCmdInfo(getCmdInfo); +} + +static int32_t Hi35xxGetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd, uint32_t readLen, uint8_t *out) { GetCmdInfoTag cmdInfo; + HDF_LOGI("%s: enter!", __func__); (void)cntlr; if (cmd == NULL || out == NULL) { + HDF_LOGE("%s: cmd or out is NULL!", __func__); return HDF_FAILURE; } cmdInfo.devno = 0; @@ -1045,48 +1236,84 @@ int32_t Hi35xxGetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd, uint32_ return MipiTxGetCmd(&cmdInfo); } -void Hi35xxToLp(struct MipiDsiCntlr *cntlr) +static void Hi35xxToLp(struct MipiDsiCntlr *cntlr) { (void)cntlr; MipiTxDrvDisableInput(); } -void Hi35xxToHs(struct MipiDsiCntlr *cntlr) +static void Hi35xxToHs(struct MipiDsiCntlr *cntlr) { ComboDevCfgTag *dev = GetDevCfg(cntlr); if (dev == NULL) { + HDF_LOGE("%s: dev is NULL.", __func__); return; } MipiTxDrvEnableInput(dev->outputMode); } static struct MipiDsiCntlr g_mipiTx = { - .devNo = 0, + .devNo = 0 +}; + +static struct MipiDsiCntlrMethod g_method = { .setCntlrCfg = Hi35xxSetCntlrCfg, .setCmd = Hi35xxSetCmd, .getCmd = Hi35xxGetCmd, .toHs = Hi35xxToHs, - .toLp = Hi35xxToLp, + .toLp = Hi35xxToLp }; static int32_t Hi35xxMipiTxInit(struct HdfDeviceObject *device) { int32_t ret; - (void)device; - ret = MipiDsiRegisterCntlr(&g_mipiTx); + HDF_LOGI("%s: enter!", __func__); + + g_mipiTx.priv = NULL; + g_mipiTx.ops = &g_method; + ret = MipiDsiRegisterCntlr(&g_mipiTx, device); if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiDsiRegisterCntlr] failed!", __func__); return ret; } - HDF_LOGI("load mipi_tx driver 1212!"); - return MipiTxModuleInit(0); + + ret = MipiTxDrvInit(0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiTxDrvInit] failed.", __func__); + return ret; + } + ret = MipiDsiDevModuleInit(g_mipiTx.devNo); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [MipiDsiDevModuleInit] failed!", __func__); + return ret; + } + HDF_LOGI("%s: load mipi_tx driver 1212!", __func__); + + return ret; } static void Hi35xxMipiTxRelease(struct HdfDeviceObject *device) { - (void)device; - return MipiTxModuleExit(); + struct MipiDsiCntlr *cntlr = NULL; + + if (device == NULL) { + HDF_LOGE("%s: device is NULL.", __func__); + return; + } + cntlr = MipiDsiCntlrFromDevice(device); + if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL.", __func__); + return; + } + + MipiTxDrvExit(); + MipiDsiDevModuleExit(cntlr->devNo); + MipiDsiUnregisterCntlr(&g_mipiTx); + g_mipiTx.priv = NULL; + HDF_LOGI("%s: unload mipi_tx driver 1212!", __func__); } + struct HdfDriverEntry g_mipiTxDriverEntry = { .moduleVersion = 1, .Init = Hi35xxMipiTxInit, @@ -1094,6 +1321,7 @@ struct HdfDriverEntry g_mipiTxDriverEntry = { .moduleName = "HDF_MIPI_TX", }; HDF_INIT(g_mipiTxDriverEntry); + #ifdef __cplusplus #if __cplusplus } diff --git a/platform/mipi_dsi/mipi_tx_hi35xx.h b/platform/mipi_dsi/mipi_tx_hi35xx.h index 2611af1..1cdcdd3 100644 --- a/platform/mipi_dsi/mipi_tx_hi35xx.h +++ b/platform/mipi_dsi/mipi_tx_hi35xx.h @@ -19,7 +19,6 @@ #ifndef MIPI_TX_HI35XX_H #define MIPI_TX_HI35XX_H -#include "mipi_tx_dev.h" /**************************************************************************** * macro definition * ****************************************************************************/ @@ -106,14 +105,5 @@ typedef struct { unsigned int vsaDet; } MipiTxDevPhyTag; -void MipiTxDrvSetPhyCfg(const ComboDevCfgTag *cfg); void MipiTxDrvGetDevStatus(MipiTxDevPhyTag *phyCtx); -void MipiTxDrvSetControllerCfg(const ComboDevCfgTag *cfg); -int MipiTxDrvSetCmdInfo(const CmdInfoTag *cmdInfo); -int MipiTxDrvGetCmdInfo(GetCmdInfoTag *getCmdInfo); -void MipiTxDrvEnableInput(const OutPutModeTag outputMode); -void MipiTxDrvDisableInput(void); -int MipiTxDrvInit(int smooth); -void MipiTxDrvExit(void); - #endif /* MIPI_TX_HI35XX_H */ -- Gitee