From b9852853e9e0d3baed46bfa776891b12602cde98 Mon Sep 17 00:00:00 2001 From: zhaoxc0502 Date: Tue, 28 Dec 2021 19:20:37 +0800 Subject: [PATCH 1/9] merge vim3l content Signed-off-by: zhaoxc0502 --- Kconfig | 4 +- Makefile | 4 + model/audio/Makefile | 49 ++- model/input/Makefile | 2 + model/usb/device/Kconfig | 2 +- model/usb/device/f_generic.c | 1 + network/src/Makefile | 1 + osal/src/osal_mem.c | 17 +- osal/src/osal_mutex.c | 13 + osal/src/osal_thread.c | 2 +- platform/emmc/Makefile | 8 +- platform/emmc/meson_emmc_adapter.c | 189 +++++++++ platform/mipi_dsi/Makefile | 8 +- platform/mipi_dsi/mipi_tx_dev.c | 8 +- platform/mipi_dsi/mipi_tx_hi35xx.c | 4 +- platform/pwm/Makefile | 5 +- platform/pwm/pwm_vim3l.h | 112 +++++ platform/pwm/pwm_vim3l_adapter.c | 153 +++++++ platform/pwm/pwm_vim3l_linux.c | 189 +++++++++ platform/rtc/rtc_adapter.c | 2 +- platform/sdio/Makefile | 9 +- platform/sdio/meson_sdio_adapter.c | 599 +++++++++++++++++++++++++++ platform/spi/Makefile | 9 +- platform/spi/vim3l_spi_adapter.c | 395 ++++++++++++++++++ platform/uart/uart_adapter.c | 2 +- platform/watchdog/watchdog_adapter.c | 2 +- 26 files changed, 1760 insertions(+), 29 deletions(-) create mode 100644 platform/emmc/meson_emmc_adapter.c create mode 100644 platform/pwm/pwm_vim3l.h create mode 100644 platform/pwm/pwm_vim3l_adapter.c create mode 100644 platform/pwm/pwm_vim3l_linux.c create mode 100644 platform/sdio/meson_sdio_adapter.c create mode 100644 platform/spi/vim3l_spi_adapter.c diff --git a/Kconfig b/Kconfig index 037b190..c646dec 100644 --- a/Kconfig +++ b/Kconfig @@ -25,4 +25,6 @@ source "drivers/hdf/khdf/model/usb/host/Kconfig" source "drivers/hdf/khdf/model/usb/device/Kconfig" source "drivers/hdf/khdf/model/audio/Kconfig" source "drivers/hdf/khdf/model/misc/vibrator/Kconfig" -source "drivers/hdf/khdf/model/misc/dsoftbus/Kconfig" \ No newline at end of file +source "drivers/hdf/khdf/model/misc/dsoftbus/Kconfig" +source "../../../../../device/amlogic/drivers/ethernet/adapter/Kconfig" +source "drivers/hdf/framework/model/input/driver/touchscreen/Kconfig" diff --git a/Makefile b/Makefile index 33c8c23..ece323f 100644 --- a/Makefile +++ b/Makefile @@ -51,3 +51,7 @@ obj-$(CONFIG_DRIVERS_HDF_BT) += model/network/bluetooth/ obj-$(CONFIG_DRIVERS_HDF_VIBRATOR) += model/misc/vibrator/ obj-$(CONFIG_DRIVERS_HDF_AUDIO) += model/audio/ obj-$(CONFIG_DRIVERS_HDF_DSOFTBUS) += model/misc/dsoftbus/ +obj-y += network/ +obj-$(CONFIG_DRIVERS_HDF_VIM3L_ETHERNET) += ../../../../device/amlogic/drivers/ethernet/adapter/ +ccflags-$(CONFIG_DRIVERS_HDF_VIM3L_ETHERNET) += -Idrivers/net/ethernet/stmicro/stmmac/ +obj-$(CONFIG_DRIVERS_HDF_WIFI) += ../../../../device/amlogic/drivers/wifi/ap6212/ diff --git a/model/audio/Makefile b/model/audio/Makefile index f6eeeb8..c21d521 100755 --- a/model/audio/Makefile +++ b/model/audio/Makefile @@ -40,6 +40,48 @@ obj-y += \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_ops.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_adapter.o +obj-$(CONFIG_VIM3L_AUDIO) += \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/amlogic_dai_driver.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/amlogic_platform_driver.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/audio_controller.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/audio_io.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/audio_clks.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/axg,clocks.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/g12a,clocks.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/tl1,clocks.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/sm1,clocks.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/tm2,clocks.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/card_utils.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/tdm_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/spdif.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/spdif_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/iomap.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/pdm.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/pdm_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/ddr_mngr.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/loopback.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/loopback_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/audio_utils.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/locker.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/locker_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/resample.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/resample_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/effects.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/effects_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/effects_v2.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/effects_hw_v2.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/pwrdet.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/pwrdet_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/sharebuffer.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/extn.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/frhdmirx_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/vad.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/vad_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/vad_dev.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/earc.o \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/earc_hw.o \ + $(KHDF_AUDIO_CODEC_DIR)/dummy_codec/dummy_codec_adapter.o + obj-$(CONFIG_ARCH_HI3516DV300) += \ $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.o \ $(KHDF_AUDIO_ROOT_DIR)/core/src/audio_host.o \ @@ -61,7 +103,7 @@ obj-$(CONFIG_ARCH_HI3516DV300) += \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_ops.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_adapter.o -ccflags-y += -lm -lc -lgcc -std=gnu99 -Werror \ +ccflags-y += -lm -lc -lgcc -std=gnu99 \ -Iinclude/$(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/framework/include/platform \ -Iinclude/$(KHDF_AUDIO_BASE_ROOT_DIR)/utils/native/base/include \ -Iinclude/$(KHDF_AUDIO_KHDF_ROOT_DIR)/osal/include \ @@ -87,5 +129,8 @@ ccflags-y += -lm -lc -lgcc -std=gnu99 -Werror \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/include \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/include \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/include \ + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/include \ + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/include \ + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter \ -Iinclude/$(KHDF_AUDIO_PERIPHERAL_ROOT_DIR)/audio/interfaces/include \ - -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/include + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/include diff --git a/model/input/Makefile b/model/input/Makefile index 024bc5e..f34a9ac 100644 --- a/model/input/Makefile +++ b/model/input/Makefile @@ -25,6 +25,8 @@ obj-$(CONFIG_DRIVERS_HDF_INPUT) += \ obj-$(CONFIG_DRIVERS_HDF_TP_5P5_GT911) += \ $(INPUT_ROOT_DIR)/touchscreen/touch_gt911.o +obj-$(CONFIG_ARCH_VIM3L_TOUCH) += \ + $(INPUT_ROOT_DIR)/touchscreen/touch_ft5336.o obj-$(CONFIG_DRIVERS_HDF_TP_2P35_FT6236) += \ $(INPUT_ROOT_DIR)/touchscreen/touch_ft6336.o diff --git a/model/usb/device/Kconfig b/model/usb/device/Kconfig index 54d4cc7..eb473b3 100644 --- a/model/usb/device/Kconfig +++ b/model/usb/device/Kconfig @@ -1,6 +1,6 @@ config DRIVERS_HDF_USB_F_GENERIC bool "Enable F_GENERIC driver" - default y + default n depends on DRIVERS_HDF help Answer Y to choice HDF USB F_GENERIC driver. diff --git a/model/usb/device/f_generic.c b/model/usb/device/f_generic.c index 6878c95..1d9bde5 100644 --- a/model/usb/device/f_generic.c +++ b/model/usb/device/f_generic.c @@ -28,6 +28,7 @@ #include "u_f.h" #include "u_os_desc.h" #include "configfs.h" +#include "linux/swait.h" #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ diff --git a/network/src/Makefile b/network/src/Makefile index 34d25ae..2b4c378 100755 --- a/network/src/Makefile +++ b/network/src/Makefile @@ -23,3 +23,4 @@ ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += \ -Iinclude/hdf/utils \ -Iinclude/hdf/osal \ -I$(PROJECT_ROOT)/third_party/bounds_checking_function/include +ccflags-$(CONFIG_DRIVERS_HDF_VIM3L_ETHERNET) += -Idrivers/net/ethernet/stmicro/stmmac/ \ No newline at end of file diff --git a/osal/src/osal_mem.c b/osal/src/osal_mem.c index 22024ab..b3c3495 100644 --- a/osal/src/osal_mem.c +++ b/osal/src/osal_mem.c @@ -54,11 +54,18 @@ static void *osal_mem_alloc(size_t size, uint32_t *type) if (size > (KMALLOC_SIZE - mng_size)) { base = (char *)vmalloc(size + mng_size); - *type = TYPE_VMALLOC; - } else { - base = (char *)kmalloc(size + mng_size, GFP_KERNEL); - *type = TYPE_KMALLOC; - } + *type = TYPE_VMALLOC; + } else { + base = (char *)kmalloc(size + mng_size, GFP_NOWAIT); + if (base == NULL) { + HDF_LOGE("cannot allocate memory by no wait!\n"); + base = (char *)kmalloc(size + mng_size, GFP_ATOMIC); + if (base == NULL) { + HDF_LOGE("cannot allocate memory by atomic!\n"); + } + } + *type = TYPE_KMALLOC; + } return base; } diff --git a/osal/src/osal_mutex.c b/osal/src/osal_mutex.c index 1809540..1025720 100644 --- a/osal/src/osal_mutex.c +++ b/osal/src/osal_mutex.c @@ -73,6 +73,19 @@ int32_t OsalMutexLock(struct OsalMutex *mutex) } EXPORT_SYMBOL(OsalMutexLock); +int32_t OsalMutexTryLock(struct OsalMutex *mutex) +{ + int32_t retVal = 0; + if (mutex == NULL || mutex->realMutex == NULL) { + HDF_LOGE("%s invalid param", __func__); + return HDF_ERR_INVALID_PARAM; + } + + retVal = mutex_trylock((struct mutex *)mutex->realMutex); + return HDF_SUCCESS; +} +EXPORT_SYMBOL(OsalMutexTryLock); + int32_t OsalMutexTimedLock(struct OsalMutex *mutex, uint32_t mSec) { if (mutex == NULL || mutex->realMutex == NULL) { diff --git a/osal/src/osal_thread.c b/osal/src/osal_thread.c index b2fb28d..343a8e4 100644 --- a/osal/src/osal_thread.c +++ b/osal/src/osal_thread.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "hdf_log.h" #include "osal_mem.h" #include "securec.h" diff --git a/platform/emmc/Makefile b/platform/emmc/Makefile index 7cc5ea0..c22fa97 100644 --- a/platform/emmc/Makefile +++ b/platform/emmc/Makefile @@ -14,5 +14,9 @@ include drivers/hdf/khdf/platform/platform.mk -obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/emmc_if.o \ - ./emmc_adapter.o +obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/emmc_if.o +#ifdef $(CONFIG_EMMC_IMX8MM) +obj-y += ./meson_emmc_adapter.o +#else +obj-y += ./emmc_adapter.o +#endif diff --git a/platform/emmc/meson_emmc_adapter.c b/platform/emmc/meson_emmc_adapter.c new file mode 100644 index 0000000..7c4799a --- /dev/null +++ b/platform/emmc/meson_emmc_adapter.c @@ -0,0 +1,189 @@ +/* + * emmc_adapter.c + * + * linux emmc 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. + * + */ + +#include +#include +#include +#include "mmc_corex.h" +#include "mmc_emmc.h" +#include "device_resource_if.h" +#include "emmc_if.h" +#include "hdf_log.h" + +#define HDF_LOG_TAG emmc_adapter_c + +struct mmc_host *meson_get_mmc_host(int slot); + +int32_t LinuxEmmcGetCid(struct EmmcDevice *dev, uint8_t *cid, uint32_t size) +{ + struct mmc_host *mmcHost = NULL; + struct MmcCntlr *cntlr = NULL; + + if (dev == NULL || dev->mmc.cntlr == NULL) { + HDF_LOGE("LinuxEmmcGetCid: dev or cntlr is null."); + return HDF_ERR_INVALID_OBJECT; + } + if (cid == NULL || size < EMMC_CID_LEN) { + HDF_LOGE("LinuxEmmcGetCid: cid is null or size is invalid."); + return HDF_ERR_INVALID_PARAM; + } + + cntlr = dev->mmc.cntlr; + mmcHost = (struct mmc_host *)cntlr->priv; + if (mmcHost == NULL) { + HDF_LOGE("LinuxEmmcGetCid: mmcHost is NULL!"); + return HDF_ERR_NOT_SUPPORT; + } + if (mmcHost->card == NULL) { + HDF_LOGE("LinuxEmmcGetCid: card is null."); + return HDF_ERR_NOT_SUPPORT; + } + if (memcpy_s(cid, sizeof(uint8_t) * size, (uint8_t *)(mmcHost->card->raw_cid), + sizeof(mmcHost->card->raw_cid)) != EOK) { + HDF_LOGE("LinuxEmmcGetCid: memcpy_s fail!"); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static struct EmmcDeviceOps g_emmcMethod = { + .getCid = LinuxEmmcGetCid, +}; + +static void LinuxEmmcDeleteCntlr(struct MmcCntlr *cntlr) +{ + if (cntlr == NULL) { + return; + } + + if (cntlr->curDev != NULL) { + MmcDeviceRemove(cntlr->curDev); + OsalMemFree(cntlr->curDev); + } + MmcCntlrRemove(cntlr); + OsalMemFree(cntlr); +} + +static int32_t LinuxEmmcCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) +{ + const struct DeviceResourceNode *node = NULL; + struct DeviceResourceIface *drsOps = NULL; + int32_t ret; + + if (obj == NULL || cntlr == NULL) { + HDF_LOGE("LinuxEmmcCntlrParse: input para is NULL."); + return HDF_FAILURE; + } + + node = obj->property; + if (node == NULL) { + HDF_LOGE("LinuxEmmcCntlrParse: drs node is NULL."); + return HDF_FAILURE; + } + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) { + HDF_LOGE("LinuxEmmcCntlrParse: invalid drs ops fail!"); + return HDF_FAILURE; + } + + ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxEmmcCntlrParse: read hostIndex fail!"); + return ret; + } + ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxEmmcCntlrParse: read devType fail!"); + return ret; + } + return HDF_SUCCESS; +} + +static int32_t LinuxEmmcBind(struct HdfDeviceObject *obj) +{ + struct MmcCntlr *cntlr = NULL; + int32_t ret; + + HDF_LOGE("LinuxEmmcBind: entry!"); + if (obj == NULL) { + HDF_LOGE("LinuxEmmcBind: Fail, obj is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr)); + if (cntlr == NULL) { + HDF_LOGE("LinuxEmmcBind: no mem for MmcCntlr."); + return HDF_ERR_MALLOC_FAIL; + } + + cntlr->ops = NULL; + cntlr->hdfDevObj = obj; + obj->service = &cntlr->service; + ret = LinuxEmmcCntlrParse(cntlr, obj); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxEmmcBind: cntlr parse fail."); + LinuxEmmcDeleteCntlr(cntlr); + HDF_LOGE("LinuxEmmcBind: Fail!"); + return HDF_FAILURE; + } + cntlr->priv = (void *)meson_get_mmc_host((int32_t)cntlr->index); + + ret = MmcCntlrAdd(cntlr); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxEmmcBind: cntlr add fail."); + LinuxEmmcDeleteCntlr(cntlr); + HDF_LOGE("LinuxEmmcBind: Fail!"); + return HDF_FAILURE; + } + + ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxEmmcBind: alloc dev fail."); + LinuxEmmcDeleteCntlr(cntlr); + HDF_LOGE("LinuxEmmcBind: Fail!"); + return HDF_FAILURE; + } + MmcDeviceAddOps(cntlr->curDev, &g_emmcMethod); + HDF_LOGD("LinuxEmmcBind: Success!"); + return HDF_SUCCESS; +} + +static int32_t LinuxEmmcInit(struct HdfDeviceObject *obj) +{ + (void)obj; + + HDF_LOGD("LinuxEmmcInit: Success!"); + return HDF_SUCCESS; +} + +static void LinuxEmmcRelease(struct HdfDeviceObject *obj) +{ + if (obj == NULL) { + return; + } + LinuxEmmcDeleteCntlr((struct MmcCntlr *)obj->service); +} + +struct HdfDriverEntry g_emmcdriverentry = { + .moduleVersion = 1, + .Bind = LinuxEmmcBind, + .Init = LinuxEmmcInit, + .Release = LinuxEmmcRelease, + .moduleName = "HDF_PLATFORM_EMMC", +}; +HDF_INIT(g_emmcdriverentry); diff --git a/platform/mipi_dsi/Makefile b/platform/mipi_dsi/Makefile index 82728cc..fb57977 100644 --- a/platform/mipi_dsi/Makefile +++ b/platform/mipi_dsi/Makefile @@ -18,7 +18,11 @@ 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 \ - mipi_tx_hi35xx.o +#ifdef $(CONFIG_MIPI_VIM3L) +obj-y += mipi_tx_dev.o +#else +obj-y += mipi_tx_dev.o +obj-y += mipi_tx_hi35xx.o +#endif EXTRA_CFLAGS += -Wno-error=date-time diff --git a/platform/mipi_dsi/mipi_tx_dev.c b/platform/mipi_dsi/mipi_tx_dev.c index ce49737..a7e6503 100644 --- a/platform/mipi_dsi/mipi_tx_dev.c +++ b/platform/mipi_dsi/mipi_tx_dev.c @@ -328,7 +328,7 @@ static int32_t MipiDsiDevSetCfg(struct MipiDsiCntlr *cntlr, struct MipiCfg *arg) } if (access_ok( -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) VERIFY_READ, #endif arg, size)) { /* user space */ @@ -378,7 +378,7 @@ int32_t MipiDsiDevSetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *arg) } if (access_ok( -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) VERIFY_READ, #endif arg, size)) { /* user space */ @@ -420,7 +420,7 @@ int32_t MipiDsiDevGetCmd(struct MipiDsiCntlr *cntlr, GetDsiCmdDescTag *arg) return HDF_ERR_MALLOC_FAIL; } if (access_ok( -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) VERIFY_READ, #endif arg, size)) { /* user space */ @@ -440,7 +440,7 @@ int32_t MipiDsiDevGetCmd(struct MipiDsiCntlr *cntlr, GetDsiCmdDescTag *arg) goto fail0; } if (access_ok( -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) VERIFY_WRITE, #endif arg, size)) { /* user space */ diff --git a/platform/mipi_dsi/mipi_tx_hi35xx.c b/platform/mipi_dsi/mipi_tx_hi35xx.c index 0c43806..f322745 100644 --- a/platform/mipi_dsi/mipi_tx_hi35xx.c +++ b/platform/mipi_dsi/mipi_tx_hi35xx.c @@ -690,7 +690,7 @@ static int32_t LinuxCopyToKernel(void *dest, uint32_t max, const void *src, uint int32_t ret; if (access_ok( -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) VERIFY_READ, #endif src, count)) { /* user space */ @@ -897,7 +897,7 @@ static int MipiTxDrvGetCmdInfo(GetCmdInfoTag *getCmdInfo) goto fail0; } if (access_ok( -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) VERIFY_WRITE, #endif getCmdInfo->getData, getCmdInfo->getDataSize)) { /* user space */ diff --git a/platform/pwm/Makefile b/platform/pwm/Makefile index a09cbc0..364638f 100644 --- a/platform/pwm/Makefile +++ b/platform/pwm/Makefile @@ -13,6 +13,7 @@ # include drivers/hdf/khdf/platform/platform.mk -obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o \ - pwm_adapter.o +obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o +obj-$(CONFIG_PWM_HI35XX) += pwm_adapter.o obj-$(CONFIG_PWM_HI35XX) += pwm_hi35xx_linux.o +obj-$(CONFIG_DRIVERS_HDF_PLATFORM_IMX8MM_PWM) += pwm_vim3l_adapter.o diff --git a/platform/pwm/pwm_vim3l.h b/platform/pwm/pwm_vim3l.h new file mode 100644 index 0000000..ecdb5a7 --- /dev/null +++ b/platform/pwm/pwm_vim3l.h @@ -0,0 +1,112 @@ +/* + * pwm_hi35xx.h + * + * hi35xx pwm 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 PWM_HI35XX_H +#define PWM_HI35XX_H + +#include "hdf_base.h" + +#define PWM_CLK_HZ 3000000 // 3MHz +#define PWM_CLK_PERIOD 333 // 333ns + +#define PWM_MAX_HZ 1500000 // 1.5MHz +#define PWM_MIN_PERIOD 666 // 666ns + +#define PWM_MIN_HZ 0.045 // 0.045Hz +#define PWM_MAX_PERIOD 22222222222 // 22222222222ns > 4294967295ns (UINT32_MAX) + +#define PWM_ENABLE 1 +#define PWM_DISABLE 0 + +#define PWM_INV_OFFSET 1 +#define PWM_KEEP_OFFSET 2 + +#define PWM_DEFAULT_PERIOD 0x018F +#define PWM_DEFAULT_POLARITY 0 +#define PWM_DEFAULT_DUTY_CYCLE 0x00C7 + +struct HiPwmRegs { + volatile uint32_t cfg0; + volatile uint32_t cfg1; + volatile uint32_t cfg2; + volatile uint32_t ctrl; + volatile uint32_t state0; + volatile uint32_t state1; + volatile uint32_t state2; +}; + +static inline void HiPwmDisable(struct HiPwmRegs *reg) +{ + if (reg == NULL) { + return; + } + reg->ctrl = PWM_DISABLE; +} + +static inline void HiPwmAlwaysOutput(struct HiPwmRegs *reg) +{ + if (reg == NULL) { + return; + } + /* keep the pwm always output */ + reg->ctrl |= ((1 << PWM_KEEP_OFFSET) | PWM_ENABLE); +} + +static inline void HiPwmOutputNumberSquareWaves(struct HiPwmRegs *reg, uint32_t number) +{ + uint32_t mask; + + if (reg == NULL) { + return; + } + /* pwm output number square waves */ + reg->cfg2 = number; + mask = ~(1 << PWM_KEEP_OFFSET); + reg->ctrl &= mask; + reg->ctrl |= PWM_ENABLE; +} + +static inline void HiPwmSetPolarity(struct HiPwmRegs *reg, uint8_t polarity) +{ + uint32_t mask; + + if (reg == NULL) { + return; + } + mask = ~(1 << PWM_INV_OFFSET); + reg->ctrl &= mask; + reg->ctrl |= (polarity << PWM_INV_OFFSET); +} + +static inline void HiPwmSetPeriod(struct HiPwmRegs *reg, uint32_t period) +{ + if (reg == NULL) { + return; + } + reg->cfg0 = period / PWM_CLK_PERIOD; +} + +static inline void HiPwmSetDuty(struct HiPwmRegs *reg, uint32_t duty) +{ + if (reg == NULL) { + return; + } + reg->cfg1 = duty / PWM_CLK_PERIOD; +} + +#endif /* PWM_HI35XX_H */ diff --git a/platform/pwm/pwm_vim3l_adapter.c b/platform/pwm/pwm_vim3l_adapter.c new file mode 100644 index 0000000..e94cb71 --- /dev/null +++ b/platform/pwm/pwm_vim3l_adapter.c @@ -0,0 +1,153 @@ +/* + * pwm_adapter.c + * + * pwm driver adapter of linux + * + * 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. + * + */ + +#include +#include "device_resource_if.h" +#include "hdf_base.h" +#include "hdf_log.h" +#include "osal_io.h" +#include "osal_mem.h" +#include "pwm_core.h" +#include "pwm_if.h" + +#define HDF_LOG_TAG HDF_PWM_LINUX_ADAPTER + +int32_t HdfPwmOpen(struct PwmDev *pwm) +{ + struct pwm_device *device = NULL; + + if (pwm == NULL) { + HDF_LOGE("%s: pwm is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + device = pwm_request(pwm->num, NULL); + if (IS_ERR(device)) { + HDF_LOGE("%s: pwm_request pwm%d fail", __func__, pwm->num); + return HDF_FAILURE; + } + pwm->cfg.period = device->state.period; + pwm->cfg.duty = device->state.duty_cycle; + pwm->cfg.polarity = device->state.polarity; + pwm->cfg.status = device->state.enabled ? PWM_ENABLE_STATUS : PWM_DISABLE_STATUS; + pwm->priv = device; + return HDF_SUCCESS; +} + +int32_t HdfPwmClose(struct PwmDev *pwm) +{ + if (pwm == NULL) { + HDF_LOGE("%s: pwm is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + pwm_free((struct pwm_device *)pwm->priv); + return HDF_SUCCESS; +} + +int32_t HdfPwmSetConfig(struct PwmDev *pwm, struct PwmConfig *config) +{ + struct pwm_state state; + + if (pwm == NULL || pwm->priv == NULL || config == NULL) { + HDF_LOGE("%s: hp reg or config is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + + state.duty_cycle = config->duty; + state.enabled = (config->status == PWM_ENABLE_STATUS) ? true : false; + state.period = config->period; + state.polarity = config->polarity; + return pwm_apply_state(pwm->priv, &state); +} + +struct PwmMethod g_pwmOps = { + .setConfig = HdfPwmSetConfig, + .open = HdfPwmOpen, + .close = HdfPwmClose, +}; + +static int32_t HdfPwmBind(struct HdfDeviceObject *obj) +{ + (void)obj; + return HDF_SUCCESS; +} + +static int32_t HdfPwmInit(struct HdfDeviceObject *obj) +{ + int32_t ret; + uint32_t num; + struct PwmDev *pwm = NULL; + struct DeviceResourceIface *iface = NULL; + + HDF_LOGI("%s: entry", __func__); + if (obj == NULL) { + HDF_LOGE("%s: obj is null", __func__); + return HDF_ERR_INVALID_OBJECT; + } + iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (iface == NULL || iface->GetUint32 == NULL) { + HDF_LOGE("%s: face is invalid", __func__); + return HDF_FAILURE; + } + if (iface->GetUint32(obj->property, "num", &num, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read num fail", __func__); + return HDF_FAILURE; + } + pwm = (struct PwmDev *)OsalMemCalloc(sizeof(*pwm)); + if (pwm == NULL) { + HDF_LOGE("%s: OsalMemCalloc pwm error", __func__); + return HDF_ERR_MALLOC_FAIL; + } + pwm->cfg.number = 0; + pwm->num = num; + pwm->method = &g_pwmOps; + pwm->busy = false; + ret = PwmDeviceAdd(obj, pwm); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: error probe, ret is %d", __func__, ret); + OsalMemFree(pwm); + } + return ret; +} + +static void HdfPwmRelease(struct HdfDeviceObject *obj) +{ + struct PwmDev *pwm = NULL; + + HDF_LOGI("%s: entry", __func__); + if (obj == NULL) { + HDF_LOGE("%s: obj is null", __func__); + return; + } + pwm = (struct PwmDev *)obj->service; + if (pwm == NULL) { + HDF_LOGE("%s: pwm is null", __func__); + return; + } + PwmDeviceRemove(obj, pwm); + OsalMemFree(pwm); +} + +struct HdfDriverEntry g_hdfPwm = { + .moduleVersion = 1, + .moduleName = "HDF_PLATFORM_PWM", + .Bind = HdfPwmBind, + .Init = HdfPwmInit, + .Release = HdfPwmRelease, +}; + +HDF_INIT(g_hdfPwm); diff --git a/platform/pwm/pwm_vim3l_linux.c b/platform/pwm/pwm_vim3l_linux.c new file mode 100644 index 0000000..38c411d --- /dev/null +++ b/platform/pwm/pwm_vim3l_linux.c @@ -0,0 +1,189 @@ +/* + * pwm_hi35xx_linux.c + * + * pwm driver of hi35xx + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pwm_hi35xx.h" + +#define PWM_ENABLE_MASK 0x1 +#define PWM_HI35XX_N_CELLS 2 + +struct Hi35xxPwmChip { + struct pwm_chip chip; + struct HiPwmRegs *reg; + void __iomem *base; + struct clk *clk; +}; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) +static int Hi35xxPwmApply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) +#else +static int Hi35xxPwmApply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) +#endif +{ + struct HiPwmRegs *reg = NULL; + struct Hi35xxPwmChip *hi35xxChip = (struct Hi35xxPwmChip *)chip; + + if (hi35xxChip == NULL || pwm == NULL || state == NULL) { + pr_err("%s: parameter is null\n", __func__); + return -EINVAL; + } + reg = (struct HiPwmRegs *)hi35xxChip->base; + if (state->polarity != PWM_POLARITY_NORMAL && state->polarity != PWM_POLARITY_INVERSED) { + pr_err("%s: polarity %u is invalid", __func__, state->polarity); + return -EINVAL; + } + + if (state->period < PWM_MIN_PERIOD) { + pr_err("%s: period %u is not support, min period %u", __func__, state->period, PWM_MIN_PERIOD); + return -EINVAL; + } + if (state->duty_cycle < 1 || state->duty_cycle > state->period) { + pr_err("%s: duty_cycle %u is not support, min duty_cycle 1 max duty_cycle %u", + __func__, state->duty_cycle , state->period); + return -EINVAL; + } + + HiPwmDisable(reg); + if (pwm->state.polarity != state->polarity) { + HiPwmSetPolarity(reg, state->polarity); + } + if (pwm->state.period != state->period) { + HiPwmSetPeriod(reg, state->period); + } + if (pwm->state.duty_cycle != state->duty_cycle) { + HiPwmSetDuty(reg, state->duty_cycle); + } + if (state->enabled) { + HiPwmAlwaysOutput(reg); + } + return 0; +} + + +static void Hi35xxGetState(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) +{ + struct HiPwmRegs *reg = NULL; + struct Hi35xxPwmChip *hi35xxChip = (struct Hi35xxPwmChip *)chip; + + if (hi35xxChip == NULL || pwm == NULL || state == NULL) { + pr_err("%s: parameter is null\n", __func__); + return; + } + reg = (struct HiPwmRegs *)hi35xxChip->base; + state->period = reg->cfg0; + state->duty_cycle = reg->cfg1; + state->enabled = reg->ctrl & PWM_ENABLE_MASK; +} + +static struct pwm_ops Hi35xxPwmOps = { + .apply = Hi35xxPwmApply, + .get_state = Hi35xxGetState, + .owner = THIS_MODULE, +}; + +static int PwmProbe(struct platform_device *pdev) +{ + int ret; + struct resource *r = NULL; + struct Hi35xxPwmChip *chip = NULL; + struct device_node *np = pdev->dev.of_node; + + if (!np) { + dev_err(&pdev->dev, "invalid devicetree node\n"); + return -EINVAL; + } + + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); + if (chip == NULL) { + return -ENOMEM; + } + chip->chip.dev = &pdev->dev; + chip->chip.ops = &Hi35xxPwmOps; + chip->chip.of_xlate = NULL; + chip->chip.of_pwm_n_cells = PWM_HI35XX_N_CELLS; + chip->chip.base = -1; + chip->chip.npwm = 1; + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + chip->base = devm_ioremap_resource(&pdev->dev, r); + if (IS_ERR(chip->base)) { + return PTR_ERR(chip->base); + } + chip->reg = (struct HiPwmRegs *)chip->base; + chip->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(chip->clk)) { + dev_err(&pdev->dev, "failed to get clock\n"); + return PTR_ERR(chip->clk); + } + ret = clk_prepare_enable(chip->clk); + if (ret < 0) { + dev_err(&pdev->dev, "failed to enable clock\n"); + return ret; + } + ret = pwmchip_add(&chip->chip); + if (ret < 0) { + dev_err(&pdev->dev, "failed to add PWM chip\n"); + return ret; + } + + platform_set_drvdata(pdev, chip); + return ret; +} + +static int PwmRemove(struct platform_device *pdev) +{ + int ret; + struct Hi35xxPwmChip *chip = NULL; + + chip = platform_get_drvdata(pdev); + if (chip == NULL) { + return -ENODEV; + } + ret = pwmchip_remove(&chip->chip); + if (ret < 0) { + return ret; + } + clk_disable_unprepare(chip->clk); + return 0; +} + +static const struct of_device_id g_pwmMatch[] = { + { .compatible = "hisilicon,pwm" }, + {}, +}; + +static struct platform_driver g_pwmDriver = { + .probe = PwmProbe, + .remove = PwmRemove, + .driver = { + .name = "pwm", + .of_match_table = g_pwmMatch, + } +}; +module_platform_driver(g_pwmDriver); +MODULE_LICENSE("GPL"); diff --git a/platform/rtc/rtc_adapter.c b/platform/rtc/rtc_adapter.c index 41262fd..031b529 100644 --- a/platform/rtc/rtc_adapter.c +++ b/platform/rtc/rtc_adapter.c @@ -51,7 +51,7 @@ static inline void LinuxTimeToHdfTime(struct RtcTime *hdfTime, const struct rtc_ static inline struct rtc_device *HdfGetRtcDevice(void) { - struct rtc_device *dev = rtc_class_open(CONFIG_RTC_SYSTOHC_DEVICE); + struct rtc_device *dev = rtc_class_open("rtc0"); if (dev == NULL) { HDF_LOGE("%s: failed to get rtc device", __func__); diff --git a/platform/sdio/Makefile b/platform/sdio/Makefile index 2c0d97e..02358fc 100644 --- a/platform/sdio/Makefile +++ b/platform/sdio/Makefile @@ -14,5 +14,10 @@ include drivers/hdf/khdf/platform/platform.mk -obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/sdio_if.o \ - ./sdio_adapter.o +obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/sdio_if.o +#ifdef $(CONFIG_SDIO_VIM3L) +obj-$(CONFIG_SDIO_VIM3L) += ./meson_sdio_adapter.o +#else +obj-y += ./sdio_adapter.o +#endif + diff --git a/platform/sdio/meson_sdio_adapter.c b/platform/sdio/meson_sdio_adapter.c new file mode 100644 index 0000000..3af6b88 --- /dev/null +++ b/platform/sdio/meson_sdio_adapter.c @@ -0,0 +1,599 @@ +/* + * sdio_adapter.c + * + * linux sdio 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. + * + */ + +#include +#include +#include +#include +#include "plat_log.h" +#include "device_resource_if.h" +#include "mmc_corex.h" +#include "mmc_sdio.h" + +#define HDF_LOG_TAG sdio_adapter_c + +#define DATA_LEN_ONE_BYTE 1 +#define DATA_LEN_TWO_BYTES 2 +#define DATA_LEN_FOUR_BYTES 4 +#define MMC_SLOT_NUM 3 +#define SDIO_RESCAN_WAIT_TIME 40 + +struct mmc_host *meson_get_mmc_host(int slot); +void meson_mmc_sdio_rescan(int slot); + +static struct sdio_func *LinuxSdioGetFunc(struct SdioDevice *dev) +{ + if (dev == NULL) { + HDF_LOGE("LinuxSdioGetFunc: dev is null."); + return NULL; + } + return (struct sdio_func *)dev->sd.mmc.priv; +} + +static int32_t LinuxSdioIncrAddrReadBytes(struct SdioDevice *dev, + uint8_t *data, uint32_t addr, uint32_t size) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + int32_t ret = HDF_SUCCESS; + uint16_t *output16 = NULL; + uint32_t *output32 = NULL; + + if (func == NULL) { + HDF_LOGE("LinuxSdioIncrAddrReadBytes: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if ((data == NULL) || (size == 0)) { + HDF_LOGE("LinuxSdioIncrAddrReadBytes: data or size is invalid."); + return HDF_ERR_INVALID_PARAM; + } + + if (size == DATA_LEN_ONE_BYTE) { + *data = sdio_readb(func, addr, &ret); + return ret; + } + if (size == DATA_LEN_TWO_BYTES) { + output16 = (uint16_t *)data; + *output16 = sdio_readw(func, addr, &ret); + return ret; + } + if (size == DATA_LEN_FOUR_BYTES) { + output32 = (uint32_t *)data; + *output32 = sdio_readl(func, addr, &ret); + return ret; + } + return sdio_memcpy_fromio(func, data, addr, size); +} + +static int32_t LinuxSdioIncrAddrWriteBytes(struct SdioDevice *dev, + uint8_t *data, uint32_t addr, uint32_t size) +{ + int32_t ret = HDF_SUCCESS; + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioIncrAddrWriteBytes: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if ((data == NULL) || (size == 0)) { + HDF_LOGE("LinuxSdioIncrAddrWriteBytes: data or size is invalid."); + return HDF_ERR_INVALID_PARAM; + } + + if (size == DATA_LEN_ONE_BYTE) { + sdio_writeb(func, *data, addr, &ret); + return ret; + } + if (size == DATA_LEN_TWO_BYTES) { + sdio_writew(func, *(uint16_t *)data, addr, &ret); + return ret; + } + if (size == DATA_LEN_FOUR_BYTES) { + sdio_writel(func, *(uint32_t *)data, addr, &ret); + return ret; + } + return sdio_memcpy_toio(func, addr, data, size); +} + +static int32_t LinuxSdioFixedAddrReadBytes(struct SdioDevice *dev, + uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioFixedAddrReadBytes: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if ((data == NULL) || (size == 0)) { + HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid."); + return HDF_ERR_INVALID_PARAM; + } + + if (scatterLen > 0) { + HDF_LOGE("LinuxSdioFixedAddrReadBytes: not support!"); + return HDF_ERR_NOT_SUPPORT; + } + return sdio_readsb(func, data, addr, size); +} + +static int32_t LinuxSdioFixedAddrWriteBytes(struct SdioDevice *dev, + uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioFixedAddrWriteBytes: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if ((data == NULL) || (size == 0)) { + HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid."); + return HDF_ERR_INVALID_PARAM; + } + + if (scatterLen > 0) { + HDF_LOGE("LinuxSdioFixedAddrWriteBytes: not support!"); + return HDF_ERR_NOT_SUPPORT; + } + return sdio_writesb(func, addr, data, size); +} + +static int32_t LinuxSdioFunc0ReadBytes(struct SdioDevice *dev, + uint8_t *data, uint32_t addr, uint32_t size) +{ + int32_t ret = HDF_SUCCESS; + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioFunc0ReadBytes: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if ((data == NULL) || (size == 0)) { + HDF_LOGE("LinuxSdioFunc0ReadBytes: data or size is invalid."); + return HDF_ERR_INVALID_PARAM; + } + + *data = sdio_f0_readb(func, addr, &ret); + return ret; +} + +static int32_t LinuxSdioFunc0WriteBytes(struct SdioDevice *dev, + uint8_t *data, uint32_t addr, uint32_t size) +{ + int32_t ret = HDF_SUCCESS; + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioFunc0WriteBytes: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if ((data == NULL) || (size == 0)) { + HDF_LOGE("LinuxSdioFunc0WriteBytes: data or size is invalid."); + return HDF_ERR_INVALID_PARAM; + } + + sdio_f0_writeb(func, *data, addr, &ret); + return ret; +} + +static int32_t LinuxSdioSetBlockSize(struct SdioDevice *dev, uint32_t blockSize) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioSetBlockSize, func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + return sdio_set_block_size(func, blockSize); +} + +static int32_t LinuxSdioGetCommonInfo(struct SdioDevice *dev, + SdioCommonInfo *info, uint32_t infoType) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioGetCommonInfo: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if (info == NULL) { + HDF_LOGE("LinuxSdioGetCommonInfo: info is null."); + return HDF_ERR_INVALID_PARAM; + } + if (infoType != SDIO_FUNC_INFO) { + HDF_LOGE("LinuxSdioGetCommonInfo: cur type %d is not support.", infoType); + return HDF_ERR_NOT_SUPPORT; + } + + if (func->card == NULL) { + HDF_LOGE("LinuxSdioGetCommonInfo fail, card is null."); + return HDF_ERR_INVALID_PARAM; + } + if (func->card->host == NULL) { + HDF_LOGE("LinuxSdioGetCommonInfo fail, host is null."); + return HDF_ERR_INVALID_PARAM; + } + info->funcInfo.enTimeout = func->enable_timeout; + info->funcInfo.maxBlockNum = func->card->host->max_blk_count; + info->funcInfo.maxBlockSize = func->card->host->max_blk_size; + info->funcInfo.maxRequestSize = func->card->host->max_req_size; + info->funcInfo.funcNum = func->num; + info->funcInfo.irqCap = func->card->host->caps & MMC_CAP_SDIO_IRQ; + info->funcInfo.data = func; + return HDF_SUCCESS; +} + +static int32_t LinuxSdioSetCommonInfo(struct SdioDevice *dev, + SdioCommonInfo *info, uint32_t infoType) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioSetCommonInfo: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if (info == NULL) { + HDF_LOGE("LinuxSdioSetCommonInfo: info is null."); + return HDF_ERR_INVALID_PARAM; + } + if (infoType != SDIO_FUNC_INFO) { + HDF_LOGE("LinuxSdioSetCommonInfo: cur type %d is not support.", infoType); + return HDF_ERR_NOT_SUPPORT; + } + + if (func->card == NULL) { + HDF_LOGE("LinuxSdioSetCommonInfo fail, card is null."); + return HDF_ERR_INVALID_PARAM; + } + if (func->card->host == NULL) { + HDF_LOGE("LinuxSdioSetCommonInfo fail, host is null."); + return HDF_ERR_INVALID_PARAM; + } + func->enable_timeout = info->funcInfo.enTimeout; + func->card->host->max_blk_count = info->funcInfo.maxBlockNum; + func->card->host->max_blk_size = info->funcInfo.maxBlockSize; + func->card->host->max_req_size = info->funcInfo.maxRequestSize; + func->num = info->funcInfo.funcNum; + return HDF_SUCCESS; +} + +static int32_t LinuxSdioFlushData(struct SdioDevice *dev) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioFlushData: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if (func->card == NULL) { + HDF_LOGE("LinuxSdioFlushData: card is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + return mmc_hw_reset(func->card->host); +} + +static int32_t LinuxSdioClaimHost(struct SdioDevice *dev) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioClaimHost: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + sdio_claim_host(func); + return HDF_SUCCESS; +} + +static int32_t LinuxSdioReleaseHost(struct SdioDevice *dev) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioReleaseHost: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + sdio_release_host(func); + return HDF_SUCCESS; +} + +static int32_t LinuxSdioEnableFunc(struct SdioDevice *dev) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioEnableFunc: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + return sdio_enable_func(func); +} + +static int32_t LinuxSdioDisableFunc(struct SdioDevice *dev) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioDisableFunc: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + return sdio_disable_func(func); +} + +static int32_t LinuxSdioClaimIrq(struct SdioDevice *dev, SdioIrqHandler *handler) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioClaimIrq: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if (handler == NULL) { + HDF_LOGE("LinuxSdioClaimIrq: handler is null."); + return HDF_ERR_INVALID_PARAM; + } + return sdio_claim_irq(func, (sdio_irq_handler_t *)handler); +} + +static int32_t LinuxSdioReleaseIrq(struct SdioDevice *dev) +{ + struct sdio_func *func = LinuxSdioGetFunc(dev); + + if (func == NULL) { + HDF_LOGE("LinuxSdioReleaseIrq: func is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + return sdio_release_irq(func); +} + +static struct sdio_func *LinuxSdioSearchFunc(uint32_t funcNum, uint16_t vendorId, uint16_t deviceId) +{ + struct mmc_card *card = NULL; + struct mmc_host *host = NULL; + struct sdio_func *func = NULL; + uint32_t i, j; + + for (i = 0; i < MMC_SLOT_NUM; i++) { + host = meson_get_mmc_host(i); + if (host == NULL) { + continue; + } + card = host->card; + if (card == NULL) { + continue; + } + for (j = 0; j <= card->sdio_funcs; j++) { + func = card->sdio_func[j]; + if ((func != NULL) && + (func->num == funcNum) && + (func->vendor == vendorId) && + (func->device == deviceId)) { + HDF_LOGD("LinuxSdioSearchFunc: find func!"); + return func; + } + } + } + + HDF_LOGE("LinuxSdioSearchFunc: get sdio func fail!"); + return NULL; +} + +static int32_t LinuxSdioFindFunc(struct SdioDevice *dev, struct SdioFunctionConfig *configData) +{ + if (dev == NULL || configData == NULL) { + HDF_LOGE("LinuxSdioFindFunc: dev or configData is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + dev->sd.mmc.priv = LinuxSdioSearchFunc(configData->funcNr, configData->vendorId, configData->deviceId); + if (dev->sd.mmc.priv == NULL) { + HDF_LOGE("LinuxSdioFindFunc: LinuxSdioSearchFunc fail."); + return HDF_ERR_NOT_SUPPORT; + } + return HDF_SUCCESS; +} + +static struct SdioDeviceOps g_sdioDeviceOps = { + .incrAddrReadBytes = LinuxSdioIncrAddrReadBytes, + .incrAddrWriteBytes = LinuxSdioIncrAddrWriteBytes, + .fixedAddrReadBytes = LinuxSdioFixedAddrReadBytes, + .fixedAddrWriteBytes = LinuxSdioFixedAddrWriteBytes, + .func0ReadBytes = LinuxSdioFunc0ReadBytes, + .func0WriteBytes = LinuxSdioFunc0WriteBytes, + .setBlockSize = LinuxSdioSetBlockSize, + .getCommonInfo = LinuxSdioGetCommonInfo, + .setCommonInfo = LinuxSdioSetCommonInfo, + .flushData = LinuxSdioFlushData, + .enableFunc = LinuxSdioEnableFunc, + .disableFunc = LinuxSdioDisableFunc, + .claimIrq = LinuxSdioClaimIrq, + .releaseIrq = LinuxSdioReleaseIrq, + .findFunc = LinuxSdioFindFunc, + .claimHost = LinuxSdioClaimHost, + .releaseHost = LinuxSdioReleaseHost, +}; + +static bool LinuxSdioRescanFinish(struct MmcCntlr *cntlr) +{ + struct mmc_host *host = NULL; + struct mmc_card *card = NULL; + + host = meson_get_mmc_host(cntlr->index); + if (host == NULL) { + return false; + } + + card = host->card; + if (card == NULL) { + return false; + } + if (card->sdio_funcs > 0) { + return true; + } + return false; +} + +static int32_t LinuxSdioRescan(struct MmcCntlr *cntlr) +{ + bool rescanFinish = false; + uint32_t count = 0; + + if (cntlr == NULL) { + HDF_LOGE("LinuxSdioRescan: cntlr is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + meson_mmc_sdio_rescan(cntlr->index); + while (rescanFinish == false && count < SDIO_RESCAN_WAIT_TIME) { + OsalMSleep(50); + count++; + rescanFinish = LinuxSdioRescanFinish(cntlr); + } + + if (rescanFinish == false) { + HDF_LOGE("LinuxSdioRescan: fail!"); + return HDF_FAILURE; + } + + OsalMSleep(10); + return HDF_SUCCESS; +} + +struct MmcCntlrOps g_sdiodntlrops = { + // .rescanSdioDev = LinuxSdioRescan, +}; + +static void LinuxSdioDeleteCntlr(struct MmcCntlr *cntlr) +{ + if (cntlr == NULL) { + return; + } + + if (cntlr->curDev != NULL) { + MmcDeviceRemove(cntlr->curDev); + OsalMemFree(cntlr->curDev); + } + MmcCntlrRemove(cntlr); + OsalMemFree(cntlr); +} + +static int32_t LinuxSdioCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) +{ + const struct DeviceResourceNode *node = NULL; + struct DeviceResourceIface *drsOps = NULL; + int32_t ret; + + if (obj == NULL || cntlr == NULL) { + HDF_LOGE("LinuxSdioCntlrParse: input para is NULL."); + return HDF_FAILURE; + } + + node = obj->property; + if (node == NULL) { + HDF_LOGE("LinuxSdioCntlrParse: drs node is NULL."); + return HDF_FAILURE; + } + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) { + HDF_LOGE("LinuxSdioCntlrParse: invalid drs ops fail!"); + return HDF_FAILURE; + } + + ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxSdioCntlrParse: read hostIndex fail!"); + return ret; + } + ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxSdioCntlrParse: read devType fail!"); + return ret; + } + HDF_LOGD("LinuxSdioCntlrParse: hostIndex = %d, devType = %d.", cntlr->index, cntlr->devType); + return HDF_SUCCESS; +} + +static int32_t LinuxSdioBind(struct HdfDeviceObject *obj) +{ + struct MmcCntlr *cntlr = NULL; + int32_t ret; + + HDF_LOGE("LinuxSdioBind: entry!"); + if (obj == NULL) { + HDF_LOGE("LinuxSdioBind: Fail, obj is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + + cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr)); + if (cntlr == NULL) { + HDF_LOGE("LinuxSdioBind: no mem for MmcCntlr."); + return HDF_ERR_MALLOC_FAIL; + } + + cntlr->ops = &g_sdiodntlrops; + cntlr->hdfDevObj = obj; + obj->service = &cntlr->service; + /* init cntlr. */ + ret = LinuxSdioCntlrParse(cntlr, obj); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxSdioBind: cntlr parse fail."); + LinuxSdioDeleteCntlr(cntlr); + HDF_LOGE("LinuxSdioBind: Fail!"); + return HDF_FAILURE; + } + + ret = MmcCntlrAdd(cntlr); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxSdioBind: cntlr add fail."); + LinuxSdioDeleteCntlr(cntlr); + HDF_LOGE("LinuxSdioBind: Fail!"); + return HDF_FAILURE; + } + + ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType); + if (ret != HDF_SUCCESS) { + HDF_LOGE("LinuxSdioBind: alloc dev fail."); + LinuxSdioDeleteCntlr(cntlr); + HDF_LOGE("LinuxSdioBind: Fail!"); + return HDF_FAILURE; + } + MmcDeviceAddOps(cntlr->curDev, &g_sdioDeviceOps); + HDF_LOGD("LinuxSdioBind: Success!"); + return HDF_SUCCESS; +} + +static int32_t LinuxSdioInit(struct HdfDeviceObject *obj) +{ + (void)obj; + HDF_LOGD("LinuxSdioInit: Success!"); + return HDF_SUCCESS; +} + +static void LinuxSdioRelease(struct HdfDeviceObject *obj) +{ + if (obj == NULL) { + return; + } + LinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service); +} + +struct HdfDriverEntry g_sdiodriverentry = { + .moduleVersion = 1, + .Bind = LinuxSdioBind, + .Init = LinuxSdioInit, + .Release = LinuxSdioRelease, + .moduleName = "HDF_PLATFORM_SDIO", +}; +HDF_INIT(g_sdiodriverentry); diff --git a/platform/spi/Makefile b/platform/spi/Makefile index d049969..acf6116 100644 --- a/platform/spi/Makefile +++ b/platform/spi/Makefile @@ -15,6 +15,11 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_core.o \ - $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_if.o \ - hi35xx_spi_adapter.o + $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_if.o + +#ifdef $(CONFIG_SPI_VIM3L) +obj-y += vim3l_spi_adapter.o +#else +obj-y += hi35xx_spi_adapter.o +#endif diff --git a/platform/spi/vim3l_spi_adapter.c b/platform/spi/vim3l_spi_adapter.c new file mode 100644 index 0000000..4f60cb5 --- /dev/null +++ b/platform/spi/vim3l_spi_adapter.c @@ -0,0 +1,395 @@ +/* + * spi_adapter.c + * + * spi driver adapter of linux + * + * 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. + * + */ + +#include +#include "device_resource_if.h" +#include "hdf_base.h" +#include "hdf_dlist.h" +#include "hdf_log.h" +#include "osal_io.h" +#include "osal_mem.h" +#include "osal_time.h" +#include "spi_core.h" +#include "spi_if.h" + +#define HDF_LOG_TAG HDF_SPI_LINUX_ADAPTER +#define SPI_DEV_NEED_FIND_NEXT 0 +#define SPI_DEV_CREAT_FAILURE 1 +#define SPI_DEV_FIND_SUCCESS 2 + +static uint16_t HdfSpiModeToLinuxMode(uint16_t mode) +{ + return ((!!(mode & SPI_CLK_PHASE) ? SPI_CPHA : 0) | + (!!(mode & SPI_CLK_POLARITY) ? SPI_CPOL : 0) | + (!!(mode & SPI_MODE_CS_HIGH) ? SPI_CS_HIGH : 0) | + (!!(mode & SPI_MODE_LSBFE) ? SPI_LSB_FIRST : 0) | + (!!(mode & SPI_MODE_3WIRE) ? SPI_3WIRE : 0) | + (!!(mode & SPI_MODE_LOOP) ? SPI_LOOP : 0) | + (!!(mode & SPI_MODE_NOCS) ? SPI_NO_CS : 0) | + (!!(mode & SPI_MODE_READY) ? SPI_READY : 0)); +} + +static uint16_t LinuxSpiModeToHdfMode(uint16_t mode) +{ + return ((!!(mode & SPI_CPHA) ? SPI_CLK_PHASE : 0) | + (!!(mode & SPI_CPOL) ? SPI_CLK_POLARITY : 0) | + (!!(mode & SPI_CS_HIGH) ? SPI_MODE_CS_HIGH : 0) | + (!!(mode & SPI_LSB_FIRST) ? SPI_MODE_LSBFE : 0) | + (!!(mode & SPI_3WIRE) ? SPI_MODE_3WIRE : 0) | + (!!(mode & SPI_LOOP) ? SPI_MODE_LOOP : 0) | + (!!(mode & SPI_NO_CS) ? SPI_MODE_NOCS : 0) | + (!!(mode & SPI_READY) ? SPI_MODE_READY : 0)); +} + +static struct SpiDev *SpiFindDeviceByCsNum(const struct SpiCntlr *cntlr, uint32_t cs) +{ + struct SpiDev *dev = NULL; + struct SpiDev *tmpDev = NULL; + + if (cntlr->numCs <= cs) { + HDF_LOGE("%s: invalid cs %u", __func__, cs); + return NULL; + } + DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(cntlr->list), struct SpiDev, list) { + if (dev->csNum == cs) { + return dev; + } + } + return NULL; +} + +static int32_t SpiAdatperSetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg) +{ + int32_t ret; + struct SpiDev *dev = NULL; + struct spi_device *spidev = NULL; + + if (cntlr == NULL || cfg == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); + if (dev == NULL || dev->priv == NULL) { + HDF_LOGE("%s: dev is invalid", __func__); + return HDF_FAILURE; + } + + spidev = (struct spi_device *)dev->priv; + spidev->bits_per_word = cfg->bitsPerWord; + spidev->max_speed_hz = cfg->maxSpeedHz; + spidev->mode = HdfSpiModeToLinuxMode(cfg->mode); + ret = spi_setup(spidev); + if (ret != 0) { + HDF_LOGE("%s: spi_setup fail, ret is %d", __func__, ret); + return HDF_FAILURE; + } + + dev->cfg = *cfg; + return HDF_SUCCESS; +} + +static int32_t SpiAdatperGetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg) +{ + struct SpiDev *dev = NULL; + + if (cntlr == NULL || cfg == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); + if (dev == NULL || dev->priv == NULL) { + HDF_LOGE("%s: fail, dev is invalid", __func__); + return HDF_FAILURE; + } + + *cfg = dev->cfg; + return HDF_SUCCESS; +} + +static int32_t SpiAdatperTransfer(struct SpiCntlr *cntlr, struct SpiMsg *msg, uint32_t count) +{ + int32_t ret; + uint32_t i; + struct spi_message xfer; + struct SpiDev *dev = NULL; + struct spi_transfer *transfer = NULL; + + if (cntlr == NULL || msg == NULL || count == 0) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); + if (dev == NULL || dev->priv == NULL) { + HDF_LOGE("%s fail, spidev is null\n", __func__); + return HDF_FAILURE; + } + + transfer = kcalloc(count, sizeof(*transfer), GFP_KERNEL); + if (transfer == NULL) { + HDF_LOGE("%s: transfer alloc memory failed", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + spi_message_init(&xfer); + for (i = 0; i < count; i++) { + transfer[i].tx_buf = msg[i].wbuf; + transfer[i].rx_buf = msg[i].rbuf; + transfer[i].len = msg[i].len; + if (msg[i].speed != 0){ + transfer[i].speed_hz = msg[i].speed; + } + if (msg[i].csChange != 0){ + transfer[i].cs_change = msg[i].csChange; + } + if (msg[i].delayUs != 0){ + transfer[i].delay_usecs = msg[i].delayUs; + } + spi_message_add_tail(&transfer[i], &xfer); + } + + ret = spi_sync(dev->priv, &xfer); + kfree(transfer); + return ret; +} + +static const char *GetSpiDevName(const struct device *dev) +{ + if (dev->init_name) { + return dev->init_name; + } + return kobject_name(&dev->kobj); +} + +static void SpiDevInit(struct SpiDev *dev, const struct spi_device *spidev) +{ + dev->cfg.bitsPerWord = spidev->bits_per_word; + dev->cfg.maxSpeedHz = spidev->max_speed_hz; + dev->cfg.mode = LinuxSpiModeToHdfMode(spidev->mode); + dev->cfg.transferMode = SPI_INTERRUPT_TRANSFER; + dev->priv = (struct spi_device *)spidev; +} + +static struct SpiDev *SpiDevCreat(struct SpiCntlr *cntlr) +{ + struct SpiDev *dev = NULL; + + dev = (struct SpiDev *)OsalMemCalloc(sizeof(*dev)); + if (dev == NULL) { + HDF_LOGE("%s: OsalMemCalloc dev error", __func__); + return NULL; + } + + DListHeadInit(&dev->list); + DListInsertTail(&dev->list, &cntlr->list); + return dev; +} + +static int32_t SpiFindDeviceFromBus(struct device *dev, void *para) +{ + struct spi_device *spidev = NULL; + struct SpiDev *spi = NULL; + struct SpiCntlr *cntlr = (struct SpiCntlr *)para; + + if (dev == NULL || cntlr == NULL) { + HDF_LOGE("%s: invalid parameter", __func__); + return HDF_ERR_INVALID_PARAM; + } + + spidev = CONTAINER_OF(dev, struct spi_device, dev); + get_device(&spidev->dev); + + if (spidev->master == NULL) { + put_device(&spidev->dev); + HDF_LOGE("%s: spi_device %s -> master is NULL", __func__, GetSpiDevName(&spidev->dev)); + return HDF_ERR_INVALID_PARAM; + } + HDF_LOGI("%s: spi_device %s, find success", __func__, GetSpiDevName(&spidev->dev)); + HDF_LOGI("%s: spi_device bus_num %d, chip_select %d", __func__, + spidev->master->bus_num, spidev->chip_select); + + if (spidev->master->bus_num == cntlr->busNum && spidev->chip_select == cntlr->curCs) { + spi = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); + if (spi == NULL) { + spi = SpiDevCreat(cntlr); + } + if (spi == NULL) { + put_device(&spidev->dev); + return SPI_DEV_CREAT_FAILURE; + } + SpiDevInit(spi, spidev); + return SPI_DEV_FIND_SUCCESS; + } else { + put_device(&spidev->dev); + return SPI_DEV_NEED_FIND_NEXT; + } +} + +static int32_t SpiAdatperOpen(struct SpiCntlr *cntlr) +{ + int32_t ret; + + if (cntlr == NULL) { + HDF_LOGE("%s: fail, cntlr is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + ret = bus_for_each_dev(&spi_bus_type, NULL, (void *)cntlr, SpiFindDeviceFromBus); + if (ret != SPI_DEV_FIND_SUCCESS) { + HDF_LOGE("%s: spidev find fail, ret is %d", __func__, ret); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int32_t SpiAdatperClose(struct SpiCntlr *cntlr) +{ + struct SpiDev *dev = NULL; + struct spi_device *spidev = NULL; + + if (cntlr == NULL) { + HDF_LOGE("%s: fail, cntlr is NULL", __func__); + return HDF_FAILURE; + } + + dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); + if (dev == NULL) { + HDF_LOGE("%s fail, dev is NULL", __func__); + return HDF_FAILURE; + } + + spidev = (struct spi_device *)dev->priv; + if (spidev == NULL) { + HDF_LOGE("%s fail, spidev is NULL", __func__); + return HDF_FAILURE; + } + put_device(&spidev->dev); + return HDF_SUCCESS; +} + +struct SpiCntlrMethod g_method = { + .Transfer = SpiAdatperTransfer, + .SetCfg = SpiAdatperSetCfg, + .GetCfg = SpiAdatperGetCfg, + .Open = SpiAdatperOpen, + .Close = SpiAdatperClose, +}; + +static int32_t SpiGetBaseCfgFromHcs(struct SpiCntlr *cntlr, const struct DeviceResourceNode *node) +{ + struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + + if (iface == NULL || iface->GetUint32 == NULL) { + HDF_LOGE("%s: face is invalid", __func__); + return HDF_FAILURE; + } + if (iface->GetUint32(node, "busNum", &cntlr->busNum, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read busNum fail", __func__); + return HDF_FAILURE; + } + if (iface->GetUint32(node, "numCs", &cntlr->numCs, 0) != HDF_SUCCESS) { + HDF_LOGE("%s: read numCs fail", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int SpiCntlrInit(struct SpiCntlr *cntlr, const struct HdfDeviceObject *device) +{ + int ret = HDF_SUCCESS; + + if (device->property == NULL) { + HDF_LOGE("%s: property is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + ret = SpiGetBaseCfgFromHcs(cntlr, device->property); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: SpiGetBaseCfgFromHcs error", __func__); + return HDF_FAILURE; + } + + cntlr->method = &g_method; + return HDF_SUCCESS; +} + +static int32_t HdfSpiDeviceBind(struct HdfDeviceObject *device) +{ + HDF_LOGI("%s: entry", __func__); + if (device == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + return (SpiCntlrCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS; +} + +static int32_t HdfSpiDeviceInit(struct HdfDeviceObject *device) +{ + int ret = HDF_SUCCESS; + struct SpiCntlr *cntlr = NULL; + + HDF_LOGI("%s: entry", __func__); + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + cntlr = SpiCntlrFromDevice(device); + if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL", __func__); + return HDF_FAILURE; + } + + ret = SpiCntlrInit(cntlr, device); + if (ret != 0) { + HDF_LOGE("%s: SpiCntlrInit error", __func__); + return HDF_FAILURE; + } + return ret; +} + +static void HdfSpiDeviceRelease(struct HdfDeviceObject *device) +{ + struct SpiCntlr *cntlr = NULL; + struct SpiDev *dev = NULL; + struct SpiDev *tmpDev = NULL; + + HDF_LOGI("%s: entry", __func__); + if (device == NULL) { + HDF_LOGE("%s: device is NULL", __func__); + return; + } + cntlr = SpiCntlrFromDevice(device); + if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL", __func__); + return; + } + + DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(cntlr->list), struct SpiDev, list) { + DListRemove(&(dev->list)); + OsalMemFree(dev); + } + SpiCntlrDestroy(cntlr); +} + +struct HdfDriverEntry g_hdfSpiDevice = { + .moduleVersion = 1, + .moduleName = "HDF_PLATFORM_SPI", + .Bind = HdfSpiDeviceBind, + .Init = HdfSpiDeviceInit, + .Release = HdfSpiDeviceRelease, +}; + +HDF_INIT(g_hdfSpiDevice); diff --git a/platform/uart/uart_adapter.c b/platform/uart/uart_adapter.c index e817626..c9bcf7b 100644 --- a/platform/uart/uart_adapter.c +++ b/platform/uart/uart_adapter.c @@ -484,7 +484,7 @@ static int32_t HdfUartInit(struct HdfDeviceObject *obj) HDF_LOGE("%s: read num fail", __func__); return HDF_FAILURE; } - if (iface->GetString(obj->property, "driver_name", &drName, "ttyAMA") != HDF_SUCCESS) { + if (iface->GetString(obj->property, "driver_name", &drName, "ttyS") != HDF_SUCCESS) { HDF_LOGE("%s: read driver_name fail", __func__); return HDF_FAILURE; } diff --git a/platform/watchdog/watchdog_adapter.c b/platform/watchdog/watchdog_adapter.c index 309a4d1..5014e9b 100644 --- a/platform/watchdog/watchdog_adapter.c +++ b/platform/watchdog/watchdog_adapter.c @@ -148,7 +148,7 @@ static struct watchdog_device *WdtCoreDataToWdd(void *wdCoreData) * } */ struct WdtCoreDataHead { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,182) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) struct device dev; #else struct kref kref; -- Gitee From 2010ab158b21b44bd3b26a025439f9846eae6251 Mon Sep 17 00:00:00 2001 From: zhaoxc0502 Date: Wed, 29 Dec 2021 22:53:23 +0800 Subject: [PATCH 2/9] merge vim3l content Signed-off-by: zhaoxc0502 --- model/audio/Makefile | 24 +++++++++++++++++------- model/network/wifi/hdfwifi.mk | 3 ++- platform/emmc/Makefile | 2 +- platform/pwm/Makefile | 9 ++++++--- platform/sdio/Makefile | 2 +- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/model/audio/Makefile b/model/audio/Makefile index c21d521..f1e088b 100755 --- a/model/audio/Makefile +++ b/model/audio/Makefile @@ -28,9 +28,13 @@ obj-y += \ $(KHDF_AUDIO_ROOT_DIR)/common/src/audio_platform_base.o \ $(KHDF_AUDIO_ROOT_DIR)/sapm/src/audio_sapm.o \ $(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_stream_dispatch.o \ - $(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_control_dispatch.o \ + $(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_control_dispatch.o + +obj-$(CONFIG_ARCH_TFA9879) += \ $(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/src/tfa9879_accessory_adapter.o \ - $(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/src/tfa9879_accessory_impl.o \ + $(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/src/tfa9879_accessory_impl.o + +obj-$(CONFIG_ARCH_HI3516DV300) += \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/src/hi3516_codec_adapter.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/src/hi3516_codec_impl.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/src/hi3516_codec_ops.o \ @@ -125,12 +129,18 @@ ccflags-y += -lm -lc -lgcc -std=gnu99 \ -Iinclude/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/sapm/include \ -Iinclude/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/dispatch/include \ -Iinclude/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/common/include \ - -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/include \ + -Iinclude/$(KHDF_AUDIO_PERIPHERAL_ROOT_DIR)/audio/interfaces/include \ + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/include + +ccflags-$(CONFIG_ARCH_TFA9879) += \ + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/include + +ccflags-$(CONFIG_ARCH_HI3516DV300) += \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/include \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/include \ - -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/include \ + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/include + +ccflags-$(CONFIG_VIM3L_AUDIO) += \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/include \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/include \ - -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter \ - -Iinclude/$(KHDF_AUDIO_PERIPHERAL_ROOT_DIR)/audio/interfaces/include \ - -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/include + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter diff --git a/model/network/wifi/hdfwifi.mk b/model/network/wifi/hdfwifi.mk index 63703c3..4521ace 100644 --- a/model/network/wifi/hdfwifi.mk +++ b/model/network/wifi/hdfwifi.mk @@ -14,7 +14,8 @@ HDF_WIFI_FRAMEWORKS_ROOT = $(HDF_DIR_PREFIX)/framework/model/network/wifi HDF_WIFI_KHDF_FRAMEWORKS_ROOT = $(HDF_DIR_PREFIX)/adapter/khdf/linux/model/network/wifi -HDF_WIFI_VENDOR_ROOT = $(HDF_VENDOR_PREFIX)/device/hisilicon/drivers/wifi/driver +#HDF_WIFI_VENDOR_ROOT = $(HDF_VENDOR_PREFIX)/device/hisilicon/drivers/wifi/driver +HDF_WIFI_VENDOR_ROOT = $(HDF_VENDOR_PREFIX)device/amlogic/drivers/wifi HDF_FRAMEWORKS_INC := \ -Idrivers/hdf/framework/ability/sbuf/include \ -Idrivers/hdf/framework/core/common/include/host \ diff --git a/platform/emmc/Makefile b/platform/emmc/Makefile index c22fa97..015b5e2 100644 --- a/platform/emmc/Makefile +++ b/platform/emmc/Makefile @@ -15,7 +15,7 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/emmc_if.o -#ifdef $(CONFIG_EMMC_IMX8MM) +#ifdef $(CONFIG_EMMC_VIM3L) obj-y += ./meson_emmc_adapter.o #else obj-y += ./emmc_adapter.o diff --git a/platform/pwm/Makefile b/platform/pwm/Makefile index 364638f..f2995f4 100644 --- a/platform/pwm/Makefile +++ b/platform/pwm/Makefile @@ -13,7 +13,10 @@ # include drivers/hdf/khdf/platform/platform.mk -obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o -obj-$(CONFIG_PWM_HI35XX) += pwm_adapter.o +obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o obj-$(CONFIG_PWM_HI35XX) += pwm_hi35xx_linux.o -obj-$(CONFIG_DRIVERS_HDF_PLATFORM_IMX8MM_PWM) += pwm_vim3l_adapter.o +#ifdef $(CONFIG_PWM_VIM3L) +obj-y += pwm_vim3l_adapter.o +#else +obj-y += pwm_adapter.o +#endif diff --git a/platform/sdio/Makefile b/platform/sdio/Makefile index 02358fc..019bed4 100644 --- a/platform/sdio/Makefile +++ b/platform/sdio/Makefile @@ -16,7 +16,7 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/sdio_if.o #ifdef $(CONFIG_SDIO_VIM3L) -obj-$(CONFIG_SDIO_VIM3L) += ./meson_sdio_adapter.o +obj-y += ./meson_sdio_adapter.o #else obj-y += ./sdio_adapter.o #endif -- Gitee From e8743b3a5eaa1321867b62ef797a682d02bb8704 Mon Sep 17 00:00:00 2001 From: zhaoxc0502 Date: Thu, 30 Dec 2021 15:26:22 +0800 Subject: [PATCH 3/9] merge vim3l content Signed-off-by: zhaoxc0502 --- model/audio/Makefile | 19 +++++++++-------- platform/Kconfig | 42 ++++++++++++++++++++++++++++++++++++++ platform/emmc/Makefile | 7 ++++--- platform/mipi_dsi/Makefile | 6 +++--- platform/pwm/Makefile | 6 +++--- platform/sdio/Makefile | 6 +++--- platform/spi/Makefile | 8 ++++---- 7 files changed, 69 insertions(+), 25 deletions(-) diff --git a/model/audio/Makefile b/model/audio/Makefile index f1e088b..c7d2eb9 100755 --- a/model/audio/Makefile +++ b/model/audio/Makefile @@ -34,7 +34,7 @@ obj-$(CONFIG_ARCH_TFA9879) += \ $(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/src/tfa9879_accessory_adapter.o \ $(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/src/tfa9879_accessory_impl.o -obj-$(CONFIG_ARCH_HI3516DV300) += \ +obj-$(CONFIG_ARCH_HI3516DV300) += \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/src/hi3516_codec_adapter.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/src/hi3516_codec_impl.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/src/hi3516_codec_ops.o \ @@ -44,8 +44,8 @@ obj-$(CONFIG_ARCH_HI3516DV300) += \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_ops.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_adapter.o -obj-$(CONFIG_VIM3L_AUDIO) += \ - $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/amlogic_dai_driver.o \ +obj-$(CONFIG_AUDIO_VIM3L) += \ + $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/amlogic_dai_driver.o \ $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/amlogic_platform_driver.o \ $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/audio_controller.o \ $(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter/audio_io.o \ @@ -130,17 +130,18 @@ ccflags-y += -lm -lc -lgcc -std=gnu99 \ -Iinclude/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/dispatch/include \ -Iinclude/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/common/include \ -Iinclude/$(KHDF_AUDIO_PERIPHERAL_ROOT_DIR)/audio/interfaces/include \ - -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/include - -ccflags-$(CONFIG_ARCH_TFA9879) += \ + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/include + +ccflags-$(CONFIG_ARCH_TFA9879) += \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/tfa9879/accessory/include -ccflags-$(CONFIG_ARCH_HI3516DV300) += \ +ccflags-$(CONFIG_ARCH_HI3516DV300) += \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/codec/include \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/include \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/include -ccflags-$(CONFIG_VIM3L_AUDIO) += \ +ccflags-$(CONFIG_AUDIO_VIM3L) += \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/include \ -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/include \ - -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter + -Iinclude/$(KHDF_AUDIO_CODEC_DIR)/amlogic/soc/src/linux_adapter \ + -Iinclude/$(KHDF_AUDIO_PERIPHERAL_ROOT_DIR)/audio/chipsets/amlogic/include diff --git a/platform/Kconfig b/platform/Kconfig index 658fbf5..1821438 100644 --- a/platform/Kconfig +++ b/platform/Kconfig @@ -85,3 +85,45 @@ config DRIVERS_HDF_PLATFORM_RTC depends on DRIVERS_HDF_PLATFORM help Answer Y to enable HDF platform rtc driver. + +config SPI_VIM3L + bool "Enable HDF platform vim3l spi driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform vim3l spi driver. + +config PWM_VIM3L + bool "Enable HDF platform vim3l pwm driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform vim3l pwm driver. + +config EMMC_VIM3L + bool "Enable HDF platform vim3l emmc driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform vim3l emmc driver. + +config MIPI_VIM3L + bool "Enable HDF platform vim3l mipi driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform vim3l mipi driver. + +config SDIO_VIM3L + bool "Enable HDF platform vim3l sdio driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform vim3l sdio driver. + +config AUDIO_VIM3L + bool "Enable HDF platform vim3l audio driver" + default n + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform vim3l audio driver. \ No newline at end of file diff --git a/platform/emmc/Makefile b/platform/emmc/Makefile index 015b5e2..6d19119 100644 --- a/platform/emmc/Makefile +++ b/platform/emmc/Makefile @@ -15,8 +15,9 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/emmc_if.o -#ifdef $(CONFIG_EMMC_VIM3L) + +ifeq ($(CONFIG_EMMC_VIM3L), y) obj-y += ./meson_emmc_adapter.o -#else +else obj-y += ./emmc_adapter.o -#endif +endif diff --git a/platform/mipi_dsi/Makefile b/platform/mipi_dsi/Makefile index fb57977..4313f31 100644 --- a/platform/mipi_dsi/Makefile +++ b/platform/mipi_dsi/Makefile @@ -18,11 +18,11 @@ obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mipi_dsi_core.o \ $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mipi_dsi_if.o \ mipi_dsi_adapter.o -#ifdef $(CONFIG_MIPI_VIM3L) +ifeq ($(CONFIG_MIPI_VIM3L), y) obj-y += mipi_tx_dev.o -#else +else obj-y += mipi_tx_dev.o obj-y += mipi_tx_hi35xx.o -#endif +endif EXTRA_CFLAGS += -Wno-error=date-time diff --git a/platform/pwm/Makefile b/platform/pwm/Makefile index f2995f4..0036da1 100644 --- a/platform/pwm/Makefile +++ b/platform/pwm/Makefile @@ -15,8 +15,8 @@ include drivers/hdf/khdf/platform/platform.mk obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o obj-$(CONFIG_PWM_HI35XX) += pwm_hi35xx_linux.o -#ifdef $(CONFIG_PWM_VIM3L) +ifeq ($(CONFIG_PWM_VIM3L), y) obj-y += pwm_vim3l_adapter.o -#else +else obj-y += pwm_adapter.o -#endif +endif diff --git a/platform/sdio/Makefile b/platform/sdio/Makefile index 019bed4..b94735a 100644 --- a/platform/sdio/Makefile +++ b/platform/sdio/Makefile @@ -15,9 +15,9 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/sdio_if.o -#ifdef $(CONFIG_SDIO_VIM3L) +ifeq ($(CONFIG_SDIO_VIM3L), y) obj-y += ./meson_sdio_adapter.o -#else +else obj-y += ./sdio_adapter.o -#endif +endif diff --git a/platform/spi/Makefile b/platform/spi/Makefile index acf6116..c9abf3a 100644 --- a/platform/spi/Makefile +++ b/platform/spi/Makefile @@ -16,10 +16,10 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_core.o \ $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_if.o - -#ifdef $(CONFIG_SPI_VIM3L) + +ifeq ($(CONFIG_SPI_VIM3L), y) obj-y += vim3l_spi_adapter.o -#else +else obj-y += hi35xx_spi_adapter.o -#endif +endif -- Gitee From c3480117bcc4ad5cf8322c3f93c9a0b63cff8a2a Mon Sep 17 00:00:00 2001 From: puyj0604 Date: Tue, 4 Jan 2022 19:20:23 +0800 Subject: [PATCH 4/9] modify for wifi Signed-off-by: puyj0604 Change-Id: Ica02887b7b5d21dd4274b499313e0a85114ee08e --- model/network/wifi/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/model/network/wifi/Makefile b/model/network/wifi/Makefile index c0d8f82..76d13e9 100755 --- a/model/network/wifi/Makefile +++ b/model/network/wifi/Makefile @@ -62,5 +62,11 @@ ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += \ $(HDF_WIFI_ADAPTER_INC) \ $(SECURE_LIB_INC) +HDF_WIFI_FLAGS +=-D_PRE_OS_VERSION_LINUX=1 +HDF_WIFI_FLAGS +=-D_PRE_OS_VERSION_LITEOS=2 +HDF_WIFI_FLAGS +=-D_PRE_OS_VERSION=_PRE_OS_VERSION_LINUX + +ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += $(HDF_WIFI_FLAGS) + obj-$(CONFIG_DRIVERS_HDF_WIFI) += vendor/ -- Gitee From 92dd19c93b8bddf7ec0d818c1b746bfcd0582351 Mon Sep 17 00:00:00 2001 From: puyj0604 Date: Thu, 6 Jan 2022 21:59:36 +0800 Subject: [PATCH 5/9] modify for wifi sdio Signed-off-by: puyj0604 Change-Id: I7634b8f768faaad3b9bd9cff218397eecd0b8e51 --- platform/sdio/meson_sdio_adapter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/sdio/meson_sdio_adapter.c b/platform/sdio/meson_sdio_adapter.c index 3af6b88..e5fc2ce 100644 --- a/platform/sdio/meson_sdio_adapter.c +++ b/platform/sdio/meson_sdio_adapter.c @@ -472,7 +472,7 @@ static int32_t LinuxSdioRescan(struct MmcCntlr *cntlr) } struct MmcCntlrOps g_sdiodntlrops = { - // .rescanSdioDev = LinuxSdioRescan, + .rescanSdioDev = LinuxSdioRescan, }; static void LinuxSdioDeleteCntlr(struct MmcCntlr *cntlr) -- Gitee From 7c31508da5b8e9775de9833fd605e8baf78590c9 Mon Sep 17 00:00:00 2001 From: zhaoxc0502 Date: Fri, 7 Jan 2022 15:15:06 +0800 Subject: [PATCH 6/9] push solved problem Signed-off-by: zhaoxc0502 --- Makefile | 4 ---- model/audio/Makefile | 2 +- model/network/wifi/Kconfig | 9 ++++++++- model/network/wifi/vendor/Makefile | 3 ++- osal/src/osal_mem.c | 20 ++++++++------------ 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index ece323f..33c8c23 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,3 @@ obj-$(CONFIG_DRIVERS_HDF_BT) += model/network/bluetooth/ obj-$(CONFIG_DRIVERS_HDF_VIBRATOR) += model/misc/vibrator/ obj-$(CONFIG_DRIVERS_HDF_AUDIO) += model/audio/ obj-$(CONFIG_DRIVERS_HDF_DSOFTBUS) += model/misc/dsoftbus/ -obj-y += network/ -obj-$(CONFIG_DRIVERS_HDF_VIM3L_ETHERNET) += ../../../../device/amlogic/drivers/ethernet/adapter/ -ccflags-$(CONFIG_DRIVERS_HDF_VIM3L_ETHERNET) += -Idrivers/net/ethernet/stmicro/stmmac/ -obj-$(CONFIG_DRIVERS_HDF_WIFI) += ../../../../device/amlogic/drivers/wifi/ap6212/ diff --git a/model/audio/Makefile b/model/audio/Makefile index c7d2eb9..a84b60f 100755 --- a/model/audio/Makefile +++ b/model/audio/Makefile @@ -107,7 +107,7 @@ obj-$(CONFIG_ARCH_HI3516DV300) += \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_ops.o \ $(KHDF_AUDIO_CODEC_DIR)/hi3516dv300/soc/src/hi3516_platform_adapter.o -ccflags-y += -lm -lc -lgcc -std=gnu99 \ +ccflags-y += -lm -lc -lgcc -std=gnu99 -Werror \ -Iinclude/$(KHDF_AUDIO_BASE_ROOT_DIR)/drivers/framework/include/platform \ -Iinclude/$(KHDF_AUDIO_BASE_ROOT_DIR)/utils/native/base/include \ -Iinclude/$(KHDF_AUDIO_KHDF_ROOT_DIR)/osal/include \ diff --git a/model/network/wifi/Kconfig b/model/network/wifi/Kconfig index c68d514..8f7c20c 100755 --- a/model/network/wifi/Kconfig +++ b/model/network/wifi/Kconfig @@ -10,4 +10,11 @@ config DRIVERS_HI3881 default n depends on DRIVERS_HDF_WIFI help - Answer Y to enable hi3881 wifi chip driver. \ No newline at end of file + Answer Y to enable hi3881 wifi chip driver. + +config DRIVERS_AP6212 + bool "Enable AP6212" + default n + depends on DRIVERS_HDF_WIFI + help + Answer Y to enable AP6212 wifi chip driver. \ No newline at end of file diff --git a/model/network/wifi/vendor/Makefile b/model/network/wifi/vendor/Makefile index ea4a0d1..d42a6c3 100755 --- a/model/network/wifi/vendor/Makefile +++ b/model/network/wifi/vendor/Makefile @@ -34,4 +34,5 @@ HDF_WIFI_FLAGS +=-D_PRE_OS_VERSION=_PRE_OS_VERSION_LINUX ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += $(HDF_WIFI_FLAGS) -obj-$(CONFIG_DRIVERS_HI3881) += hi3881/ \ No newline at end of file +obj-$(CONFIG_DRIVERS_HI3881) += hi3881/ +obj-$(CONFIG_DRIVERS_AP6212) += ap6212/ \ No newline at end of file diff --git a/osal/src/osal_mem.c b/osal/src/osal_mem.c index b3c3495..6ce3937 100644 --- a/osal/src/osal_mem.c +++ b/osal/src/osal_mem.c @@ -54,18 +54,14 @@ static void *osal_mem_alloc(size_t size, uint32_t *type) if (size > (KMALLOC_SIZE - mng_size)) { base = (char *)vmalloc(size + mng_size); - *type = TYPE_VMALLOC; - } else { - base = (char *)kmalloc(size + mng_size, GFP_NOWAIT); - if (base == NULL) { - HDF_LOGE("cannot allocate memory by no wait!\n"); - base = (char *)kmalloc(size + mng_size, GFP_ATOMIC); - if (base == NULL) { - HDF_LOGE("cannot allocate memory by atomic!\n"); - } - } - *type = TYPE_KMALLOC; - } + *type = TYPE_VMALLOC; + } else { + base = (char *)kmalloc(size + mng_size, GFP_NOWAIT); + if (base == NULL) { + base = (char *)kmalloc(size + mng_size, GFP_ATOMIC); + } + *type = TYPE_KMALLOC; + } return base; } -- Gitee From 883710d564617dfc422c39faaca99fa6c710cab8 Mon Sep 17 00:00:00 2001 From: zhaoxc0502 Date: Fri, 7 Jan 2022 18:04:28 +0800 Subject: [PATCH 7/9] push solved problem Signed-off-by: zhaoxc0502 --- model/network/wifi/vendor/ap6212/Makefile | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 model/network/wifi/vendor/ap6212/Makefile diff --git a/model/network/wifi/vendor/ap6212/Makefile b/model/network/wifi/vendor/ap6212/Makefile new file mode 100644 index 0000000..92bb0d5 --- /dev/null +++ b/model/network/wifi/vendor/ap6212/Makefile @@ -0,0 +1,27 @@ +# +# 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. +# +# + +MODULE_NAME := ap6212 + +HDF_VENDOR_PREFIX := ../../../../../../../../../ + +include drivers/hdf/khdf/model/network/wifi/hdfwifi.mk + +INC_TOP_PATH := $(PROJECT_ROOT) +VENDOR_WIFI_PATH := device/amlogic/drivers/wifi +WIFI_DRIVER_DIR := ap6212 + +obj-$(CONFIG_DRIVERS_HDF_VIM3L_ETHERNET) += $(HDF_VENDOR_PREFIX)/device/amlogic/drivers/ethernet/adapter/ +ccflags-$(CONFIG_DRIVERS_HDF_VIM3L_ETHERNET) += -Idrivers/net/ethernet/stmicro/stmmac/ +obj-$(CONFIG_DRIVERS_HDF_WIFI) += $(HDF_VENDOR_PREFIX)/device/amlogic/drivers/wifi/ap6212/ \ No newline at end of file -- Gitee From 6f197093f154b51d09b94eb65f0c7645052a4417 Mon Sep 17 00:00:00 2001 From: puyj0604 Date: Thu, 13 Jan 2022 20:04:46 +0800 Subject: [PATCH 8/9] modify for mipi_dsi Signed-off-by: puyj0604 Change-Id: I63cc2e5542526ebf8b2029edafe8c070f0620c81 --- platform/mipi_dsi/Makefile | 2 +- platform/mipi_dsi/mipi_tx_vim3l.c | 196 ++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 platform/mipi_dsi/mipi_tx_vim3l.c diff --git a/platform/mipi_dsi/Makefile b/platform/mipi_dsi/Makefile index 4313f31..e1425bc 100644 --- a/platform/mipi_dsi/Makefile +++ b/platform/mipi_dsi/Makefile @@ -19,7 +19,7 @@ obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mipi_dsi_core.o \ mipi_dsi_adapter.o ifeq ($(CONFIG_MIPI_VIM3L), y) -obj-y += mipi_tx_dev.o +obj-y += mipi_tx_vim3l.o else obj-y += mipi_tx_dev.o obj-y += mipi_tx_hi35xx.o diff --git a/platform/mipi_dsi/mipi_tx_vim3l.c b/platform/mipi_dsi/mipi_tx_vim3l.c new file mode 100644 index 0000000..9c3a220 --- /dev/null +++ b/platform/mipi_dsi/mipi_tx_vim3l.c @@ -0,0 +1,196 @@ +/* + * mipi_tx_vim3l.c + * + * vim3l 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. + * + */ + +#include "linux/amlogic/media/vout/lcd/lcd_mipi.h" +#include "linux/delay.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "mipi_dsi_core.h" +#include "mipi_dsi_if.h" +#include "osal_time.h" +#include "osal_mem.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* End of #ifdef __cplusplus */ + +#define HDF_LOG_TAG mipi_tx_vim3l + +static int32_t Vim3lSetCntlrCfg(struct MipiDsiCntlr *cntlr) +{ + return HDF_SUCCESS; +} + +static int32_t Vim3lSetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd) +{ + uint8_t *payload = NULL; + uint8_t data_end[2] = {0xFF, 0}; + uint8_t step = 0; + + (void)cntlr; + if (NULL == cmd) { + HDF_LOGE("%s failed, NULL == cmd", __func__); + return HDF_FAILURE; + } + + if (NULL == cmd->payload) { + HDF_LOGE("%s failed, cmd->payload", __func__); + return HDF_FAILURE; + } + + HDF_LOGE("%s cmd->dataLen = %d ", __func__, cmd->dataLen); + HDF_LOGE("%s cmd->dataType = %d ", __func__, cmd->dataType); + HDF_LOGE("%s cmd->delay = %d ", __func__, cmd->delay); + + payload = (uint8_t *)OsalMemAlloc((cmd->dataLen + 2 + 2) * sizeof(uint8_t)); + + if (NULL == payload) { + HDF_LOGE("%s create payload failed ", __func__); + return HDF_FAILURE; + } + payload[0] = cmd->dataType; + payload[1] = cmd->dataLen; + if (0 != cmd->dataLen) { + memcpy(&payload[2], cmd->payload, cmd->dataLen); + } + + /* end code */ + memcpy(&payload[2 + cmd->dataLen], data_end, 2); + + step = dsi_write_cmd(payload); + HDF_LOGE("%s step = %d ", __func__, step); + if (cmd->delay != 0) { + mdelay(cmd->delay); + } + + OsalMemFree(payload); + + return HDF_SUCCESS; +} + +static int32_t Vim3lGetCmd(struct MipiDsiCntlr *cntlr, struct DsiCmdDesc *cmd, uint32_t readLen, uint8_t *out) +{ + uint8_t *payload = NULL; + uint8_t data_end[2] = {0xFF, 0}; + uint8_t step = 0; + + (void)cntlr; + if (NULL == cmd) { + HDF_LOGE("%s failed, NULL == cmd", __func__); + return HDF_FAILURE; + } + + if (NULL == cmd->payload) { + HDF_LOGE("%s failed, cmd->payload", __func__); + return HDF_FAILURE; + } + + HDF_LOGE("%s cmd->dataLen = %d ", __func__, cmd->dataLen); + HDF_LOGE("%s cmd->dataType = %d ", __func__, cmd->dataType); + HDF_LOGE("%s cmd->delay = %d ", __func__, cmd->delay); + + payload = (uint8_t *)OsalMemAlloc((cmd->dataLen + 2 + 2) * sizeof(uint8_t)); + + if (NULL == payload) { + HDF_LOGE("%s create payload failed ", __func__); + return HDF_FAILURE; + } + payload[0] = cmd->dataType; + payload[1] = cmd->dataLen; + if (0 != cmd->dataLen) { + memcpy(&payload[2], cmd->payload, cmd->dataLen); + } + + /* end code */ + memcpy(&payload[2 + cmd->dataLen], data_end, 2); + + step = dsi_write_cmd(payload); + HDF_LOGE("%s step = %d ", __func__, step); + if (cmd->delay != 0) { + mdelay(cmd->delay); + } + + OsalMemFree(payload); + + return HDF_SUCCESS; +} + +static struct MipiDsiCntlr g_mipiTx = { + .devNo = 0 +}; + +static struct MipiDsiCntlrMethod g_method = { + .setCntlrCfg = Vim3lSetCntlrCfg, + .setCmd = Vim3lSetCmd, + .getCmd = Vim3lGetCmd, + .toHs = NULL, + .toLp = NULL +}; + +static int32_t Vim3lMipiTxInit(struct HdfDeviceObject *device) +{ + int32_t ret; + + 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("%s: success.", __func__); + + return ret; +} + +static void Vim3lMipiTxRelease(struct HdfDeviceObject *device) +{ + struct MipiDsiCntlr *cntlr; + + 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; + } + MipiDsiUnregisterCntlr(cntlr); + cntlr->priv = NULL; + + HDF_LOGI("%s: success.", __func__); +} + +struct HdfDriverEntry g_mipiTxDriverEntry = { + .moduleVersion = 1, + .Init = Vim3lMipiTxInit, + .Release = Vim3lMipiTxRelease, + .moduleName = "HDF_MIPI_TX", +}; +HDF_INIT(g_mipiTxDriverEntry); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* End of #ifdef __cplusplus */ -- Gitee From 9cb72501bce80172e58645ccf94a4c78654f249d Mon Sep 17 00:00:00 2001 From: zhaoxc0502 Date: Sat, 15 Jan 2022 14:54:32 +0800 Subject: [PATCH 9/9] push solved problem Signed-off-by: zhaoxc0502 --- platform/emmc/Makefile | 9 +- platform/emmc/emmc_adapter.c | 72 ++-- platform/emmc/meson_emmc_adapter.c | 189 --------- platform/pwm/Makefile | 11 +- platform/pwm/pwm_hi35xx.h | 13 + platform/pwm/pwm_hi35xx_linux.c | 15 + platform/pwm/pwm_vim3l.h | 112 ------ platform/pwm/pwm_vim3l_adapter.c | 153 -------- platform/pwm/pwm_vim3l_linux.c | 189 --------- platform/sdio/Makefile | 8 +- platform/sdio/meson_sdio_adapter.c | 599 ----------------------------- platform/sdio/sdio_adapter.c | 275 +++++++------ platform/spi/Makefile | 9 +- platform/spi/vim3l_spi_adapter.c | 395 ------------------- 14 files changed, 226 insertions(+), 1823 deletions(-) delete mode 100644 platform/emmc/meson_emmc_adapter.c delete mode 100644 platform/pwm/pwm_vim3l.h delete mode 100644 platform/pwm/pwm_vim3l_adapter.c delete mode 100644 platform/pwm/pwm_vim3l_linux.c delete mode 100644 platform/sdio/meson_sdio_adapter.c delete mode 100644 platform/spi/vim3l_spi_adapter.c diff --git a/platform/emmc/Makefile b/platform/emmc/Makefile index 6d19119..7cc5ea0 100644 --- a/platform/emmc/Makefile +++ b/platform/emmc/Makefile @@ -14,10 +14,5 @@ include drivers/hdf/khdf/platform/platform.mk -obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/emmc_if.o - -ifeq ($(CONFIG_EMMC_VIM3L), y) -obj-y += ./meson_emmc_adapter.o -else -obj-y += ./emmc_adapter.o -endif +obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/emmc_if.o \ + ./emmc_adapter.o diff --git a/platform/emmc/emmc_adapter.c b/platform/emmc/emmc_adapter.c index 449cab0..a5c30f1 100644 --- a/platform/emmc/emmc_adapter.c +++ b/platform/emmc/emmc_adapter.c @@ -27,45 +27,49 @@ #define HDF_LOG_TAG emmc_adapter_c +#if defined(CONFIG_EMMC_VIM3L) +struct mmc_host *meson_get_mmc_host(int slot); +#else struct mmc_host *himci_get_mmc_host(int slot); +#endif // CONFIG_EMMC_VIM3L -int32_t Hi35xxLinuxEmmcGetCid(struct EmmcDevice *dev, uint8_t *cid, uint32_t size) +int32_t LinuxEmmcGetCid(struct EmmcDevice *dev, uint8_t *cid, uint32_t size) { struct mmc_host *mmcHost = NULL; struct MmcCntlr *cntlr = NULL; if (dev == NULL || dev->mmc.cntlr == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcGetCid: dev or cntlr is null."); + HDF_LOGE("LinuxEmmcGetCid: dev or cntlr is null."); return HDF_ERR_INVALID_OBJECT; } if (cid == NULL || size < EMMC_CID_LEN) { - HDF_LOGE("Hi35xxLinuxEmmcGetCid: cid is null or size is invalid."); + HDF_LOGE("LinuxEmmcGetCid: cid is null or size is invalid."); return HDF_ERR_INVALID_PARAM; } cntlr = dev->mmc.cntlr; mmcHost = (struct mmc_host *)cntlr->priv; if (mmcHost == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcGetCid: mmcHost is NULL!"); + HDF_LOGE("LinuxEmmcGetCid: mmcHost is NULL!"); return HDF_ERR_NOT_SUPPORT; } if (mmcHost->card == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcGetCid: card is null."); + HDF_LOGE("LinuxEmmcGetCid: card is null."); return HDF_ERR_NOT_SUPPORT; } if (memcpy_s(cid, sizeof(uint8_t) * size, (uint8_t *)(mmcHost->card->raw_cid), sizeof(mmcHost->card->raw_cid)) != EOK) { - HDF_LOGE("Hi35xxLinuxEmmcGetCid: memcpy_s fail!"); + HDF_LOGE("LinuxEmmcGetCid: memcpy_s fail!"); return HDF_FAILURE; } return HDF_SUCCESS; } static struct EmmcDeviceOps g_emmcMethod = { - .getCid = Hi35xxLinuxEmmcGetCid, + .getCid = LinuxEmmcGetCid, }; -static void Hi35xxLinuxEmmcDeleteCntlr(struct MmcCntlr *cntlr) +static void LinuxEmmcDeleteCntlr(struct MmcCntlr *cntlr) { if (cntlr == NULL) { return; @@ -79,110 +83,114 @@ static void Hi35xxLinuxEmmcDeleteCntlr(struct MmcCntlr *cntlr) OsalMemFree(cntlr); } -static int32_t Hi35xxLinuxEmmcCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) +static int32_t LinuxEmmcCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) { const struct DeviceResourceNode *node = NULL; struct DeviceResourceIface *drsOps = NULL; int32_t ret; if (obj == NULL || cntlr == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcCntlrParse: input para is NULL."); + HDF_LOGE("LinuxEmmcCntlrParse: input para is NULL."); return HDF_FAILURE; } node = obj->property; if (node == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcCntlrParse: drs node is NULL."); + HDF_LOGE("LinuxEmmcCntlrParse: drs node is NULL."); return HDF_FAILURE; } drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcCntlrParse: invalid drs ops fail!"); + HDF_LOGE("LinuxEmmcCntlrParse: invalid drs ops fail!"); return HDF_FAILURE; } ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxEmmcCntlrParse: read hostIndex fail!"); + HDF_LOGE("LinuxEmmcCntlrParse: read hostIndex fail!"); return ret; } ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxEmmcCntlrParse: read devType fail!"); + HDF_LOGE("LinuxEmmcCntlrParse: read devType fail!"); return ret; } return HDF_SUCCESS; } -static int32_t Hi35xxLinuxEmmcBind(struct HdfDeviceObject *obj) +static int32_t LinuxEmmcBind(struct HdfDeviceObject *obj) { struct MmcCntlr *cntlr = NULL; int32_t ret; - HDF_LOGE("Hi35xxLinuxEmmcBind: entry!"); + HDF_LOGE("LinuxEmmcBind: entry!"); if (obj == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcBind: Fail, obj is NULL."); + HDF_LOGE("LinuxEmmcBind: Fail, obj is NULL."); return HDF_ERR_INVALID_OBJECT; } cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr)); if (cntlr == NULL) { - HDF_LOGE("Hi35xxLinuxEmmcBind: no mem for MmcCntlr."); + HDF_LOGE("LinuxEmmcBind: no mem for MmcCntlr."); return HDF_ERR_MALLOC_FAIL; } cntlr->ops = NULL; cntlr->hdfDevObj = obj; obj->service = &cntlr->service; - ret = Hi35xxLinuxEmmcCntlrParse(cntlr, obj); + ret = LinuxEmmcCntlrParse(cntlr, obj); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxEmmcBind: cntlr parse fail."); + HDF_LOGE("LinuxEmmcBind: cntlr parse fail."); goto _ERR; } +#if defined(CONFIG_EMMC_VIM3L) + cntlr->priv = (void *)meson_get_mmc_host((int32_t)cntlr->index); +#else cntlr->priv = (void *)himci_get_mmc_host((int32_t)cntlr->index); +#endif // CONFIG_EMMC_VIM3L ret = MmcCntlrAdd(cntlr); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxEmmcBind: cntlr add fail."); + HDF_LOGE("LinuxEmmcBind: cntlr add fail."); goto _ERR; } ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxEmmcBind: alloc dev fail."); + HDF_LOGE("LinuxEmmcBind: alloc dev fail."); goto _ERR; } MmcDeviceAddOps(cntlr->curDev, &g_emmcMethod); - HDF_LOGD("Hi35xxLinuxEmmcBind: Success!"); + HDF_LOGD("LinuxEmmcBind: Success!"); return HDF_SUCCESS; _ERR: - Hi35xxLinuxEmmcDeleteCntlr(cntlr); - HDF_LOGE("Hi35xxLinuxEmmcBind: Fail!"); + LinuxEmmcDeleteCntlr(cntlr); + HDF_LOGE("LinuxEmmcBind: Fail!"); return HDF_FAILURE; } -static int32_t Hi35xxLinuxEmmcInit(struct HdfDeviceObject *obj) +static int32_t LinuxEmmcInit(struct HdfDeviceObject *obj) { (void)obj; - HDF_LOGD("Hi35xxLinuxEmmcInit: Success!"); + HDF_LOGD("LinuxEmmcInit: Success!"); return HDF_SUCCESS; } -static void Hi35xxLinuxEmmcRelease(struct HdfDeviceObject *obj) +static void LinuxEmmcRelease(struct HdfDeviceObject *obj) { if (obj == NULL) { return; } - Hi35xxLinuxEmmcDeleteCntlr((struct MmcCntlr *)obj->service); + LinuxEmmcDeleteCntlr((struct MmcCntlr *)obj->service); } struct HdfDriverEntry g_emmcDriverEntry = { .moduleVersion = 1, - .Bind = Hi35xxLinuxEmmcBind, - .Init = Hi35xxLinuxEmmcInit, - .Release = Hi35xxLinuxEmmcRelease, + .Bind = LinuxEmmcBind, + .Init = LinuxEmmcInit, + .Release = LinuxEmmcRelease, .moduleName = "HDF_PLATFORM_EMMC", }; HDF_INIT(g_emmcDriverEntry); diff --git a/platform/emmc/meson_emmc_adapter.c b/platform/emmc/meson_emmc_adapter.c deleted file mode 100644 index 7c4799a..0000000 --- a/platform/emmc/meson_emmc_adapter.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * emmc_adapter.c - * - * linux emmc 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. - * - */ - -#include -#include -#include -#include "mmc_corex.h" -#include "mmc_emmc.h" -#include "device_resource_if.h" -#include "emmc_if.h" -#include "hdf_log.h" - -#define HDF_LOG_TAG emmc_adapter_c - -struct mmc_host *meson_get_mmc_host(int slot); - -int32_t LinuxEmmcGetCid(struct EmmcDevice *dev, uint8_t *cid, uint32_t size) -{ - struct mmc_host *mmcHost = NULL; - struct MmcCntlr *cntlr = NULL; - - if (dev == NULL || dev->mmc.cntlr == NULL) { - HDF_LOGE("LinuxEmmcGetCid: dev or cntlr is null."); - return HDF_ERR_INVALID_OBJECT; - } - if (cid == NULL || size < EMMC_CID_LEN) { - HDF_LOGE("LinuxEmmcGetCid: cid is null or size is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = dev->mmc.cntlr; - mmcHost = (struct mmc_host *)cntlr->priv; - if (mmcHost == NULL) { - HDF_LOGE("LinuxEmmcGetCid: mmcHost is NULL!"); - return HDF_ERR_NOT_SUPPORT; - } - if (mmcHost->card == NULL) { - HDF_LOGE("LinuxEmmcGetCid: card is null."); - return HDF_ERR_NOT_SUPPORT; - } - if (memcpy_s(cid, sizeof(uint8_t) * size, (uint8_t *)(mmcHost->card->raw_cid), - sizeof(mmcHost->card->raw_cid)) != EOK) { - HDF_LOGE("LinuxEmmcGetCid: memcpy_s fail!"); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -static struct EmmcDeviceOps g_emmcMethod = { - .getCid = LinuxEmmcGetCid, -}; - -static void LinuxEmmcDeleteCntlr(struct MmcCntlr *cntlr) -{ - if (cntlr == NULL) { - return; - } - - if (cntlr->curDev != NULL) { - MmcDeviceRemove(cntlr->curDev); - OsalMemFree(cntlr->curDev); - } - MmcCntlrRemove(cntlr); - OsalMemFree(cntlr); -} - -static int32_t LinuxEmmcCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (obj == NULL || cntlr == NULL) { - HDF_LOGE("LinuxEmmcCntlrParse: input para is NULL."); - return HDF_FAILURE; - } - - node = obj->property; - if (node == NULL) { - HDF_LOGE("LinuxEmmcCntlrParse: drs node is NULL."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("LinuxEmmcCntlrParse: invalid drs ops fail!"); - return HDF_FAILURE; - } - - ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxEmmcCntlrParse: read hostIndex fail!"); - return ret; - } - ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxEmmcCntlrParse: read devType fail!"); - return ret; - } - return HDF_SUCCESS; -} - -static int32_t LinuxEmmcBind(struct HdfDeviceObject *obj) -{ - struct MmcCntlr *cntlr = NULL; - int32_t ret; - - HDF_LOGE("LinuxEmmcBind: entry!"); - if (obj == NULL) { - HDF_LOGE("LinuxEmmcBind: Fail, obj is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr)); - if (cntlr == NULL) { - HDF_LOGE("LinuxEmmcBind: no mem for MmcCntlr."); - return HDF_ERR_MALLOC_FAIL; - } - - cntlr->ops = NULL; - cntlr->hdfDevObj = obj; - obj->service = &cntlr->service; - ret = LinuxEmmcCntlrParse(cntlr, obj); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxEmmcBind: cntlr parse fail."); - LinuxEmmcDeleteCntlr(cntlr); - HDF_LOGE("LinuxEmmcBind: Fail!"); - return HDF_FAILURE; - } - cntlr->priv = (void *)meson_get_mmc_host((int32_t)cntlr->index); - - ret = MmcCntlrAdd(cntlr); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxEmmcBind: cntlr add fail."); - LinuxEmmcDeleteCntlr(cntlr); - HDF_LOGE("LinuxEmmcBind: Fail!"); - return HDF_FAILURE; - } - - ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxEmmcBind: alloc dev fail."); - LinuxEmmcDeleteCntlr(cntlr); - HDF_LOGE("LinuxEmmcBind: Fail!"); - return HDF_FAILURE; - } - MmcDeviceAddOps(cntlr->curDev, &g_emmcMethod); - HDF_LOGD("LinuxEmmcBind: Success!"); - return HDF_SUCCESS; -} - -static int32_t LinuxEmmcInit(struct HdfDeviceObject *obj) -{ - (void)obj; - - HDF_LOGD("LinuxEmmcInit: Success!"); - return HDF_SUCCESS; -} - -static void LinuxEmmcRelease(struct HdfDeviceObject *obj) -{ - if (obj == NULL) { - return; - } - LinuxEmmcDeleteCntlr((struct MmcCntlr *)obj->service); -} - -struct HdfDriverEntry g_emmcdriverentry = { - .moduleVersion = 1, - .Bind = LinuxEmmcBind, - .Init = LinuxEmmcInit, - .Release = LinuxEmmcRelease, - .moduleName = "HDF_PLATFORM_EMMC", -}; -HDF_INIT(g_emmcdriverentry); diff --git a/platform/pwm/Makefile b/platform/pwm/Makefile index 0036da1..1a310f9 100644 --- a/platform/pwm/Makefile +++ b/platform/pwm/Makefile @@ -13,10 +13,7 @@ # include drivers/hdf/khdf/platform/platform.mk -obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o -obj-$(CONFIG_PWM_HI35XX) += pwm_hi35xx_linux.o -ifeq ($(CONFIG_PWM_VIM3L), y) -obj-y += pwm_vim3l_adapter.o -else -obj-y += pwm_adapter.o -endif +obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o \ + pwm_adapter.o \ + pwm_hi35xx_linux.o + diff --git a/platform/pwm/pwm_hi35xx.h b/platform/pwm/pwm_hi35xx.h index fab0859..1ac510a 100644 --- a/platform/pwm/pwm_hi35xx.h +++ b/platform/pwm/pwm_hi35xx.h @@ -36,9 +36,18 @@ #define PWM_INV_OFFSET 1 #define PWM_KEEP_OFFSET 2 +#if defined(CONFIG_PWM_VIM3L) +#define PWM_DEFAULT_PERIOD 0x018F +#else #define PWM_DEFAULT_PERIOD 0x3E7 +#endif // CONFIG_PWM_VIM3L #define PWM_DEFAULT_POLARITY 0 +#if defined(CONFIG_PWM_VIM3L) +#define PWM_DEFAULT_DUTY_CYCLE 0x00C7 +#else #define PWM_DEFAULT_DUTY_CYCLE 0x14D +#endif // CONFIG_PWM_VIM3L + struct HiPwmRegs { volatile uint32_t cfg0; @@ -55,7 +64,11 @@ static inline void HiPwmDisable(struct HiPwmRegs *reg) if (reg == NULL) { return; } +#if defined(CONFIG_PWM_VIM3L) + reg->ctrl = PWM_DISABLE; +#else reg->ctrl &= ~1; +#endif // CONFIG_PWM_VIM3L } static inline void HiPwmAlwaysOutput(struct HiPwmRegs *reg) diff --git a/platform/pwm/pwm_hi35xx_linux.c b/platform/pwm/pwm_hi35xx_linux.c index 68f1e7e..e0b296d 100644 --- a/platform/pwm/pwm_hi35xx_linux.c +++ b/platform/pwm/pwm_hi35xx_linux.c @@ -24,6 +24,16 @@ #include #include "hdf_log.h" +#if defined(CONFIG_PWM_VIM3L) +#include +#include +#include +#include +#include +#include +#include +#endif // CONFIG_PWM_VIM3L + #define HDF_LOG_TAG pwm_hi35xx_linux #define PWM_ENABLE_MASK 0x1 #define PWM_HI35XX_N_CELLS 2 @@ -100,9 +110,14 @@ static void Hi35xxGetState(struct pwm_chip *chip, struct pwm_device *pwm, struct return; } reg = (struct HiPwmRegs *)hi35xxChip->base; +#if defined(CONFIG_PWM_VIM3L) + state->period = reg->cfg0; + state->duty_cycle = reg->cfg1; +#else state->period = reg->cfg0 * PWM_CLK_PERIOD; state->duty_cycle = reg->cfg1 * PWM_CLK_PERIOD; state->polarity = (reg->ctrl & (1 << PWM_INV_OFFSET)) >> PWM_INV_OFFSET; +#endif state->enabled = reg->ctrl & PWM_ENABLE_MASK; HDF_LOGI("%s: get PwmConfig: number none, period %llu, duty %llu, polarity %u, enable %u.", diff --git a/platform/pwm/pwm_vim3l.h b/platform/pwm/pwm_vim3l.h deleted file mode 100644 index ecdb5a7..0000000 --- a/platform/pwm/pwm_vim3l.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * pwm_hi35xx.h - * - * hi35xx pwm 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 PWM_HI35XX_H -#define PWM_HI35XX_H - -#include "hdf_base.h" - -#define PWM_CLK_HZ 3000000 // 3MHz -#define PWM_CLK_PERIOD 333 // 333ns - -#define PWM_MAX_HZ 1500000 // 1.5MHz -#define PWM_MIN_PERIOD 666 // 666ns - -#define PWM_MIN_HZ 0.045 // 0.045Hz -#define PWM_MAX_PERIOD 22222222222 // 22222222222ns > 4294967295ns (UINT32_MAX) - -#define PWM_ENABLE 1 -#define PWM_DISABLE 0 - -#define PWM_INV_OFFSET 1 -#define PWM_KEEP_OFFSET 2 - -#define PWM_DEFAULT_PERIOD 0x018F -#define PWM_DEFAULT_POLARITY 0 -#define PWM_DEFAULT_DUTY_CYCLE 0x00C7 - -struct HiPwmRegs { - volatile uint32_t cfg0; - volatile uint32_t cfg1; - volatile uint32_t cfg2; - volatile uint32_t ctrl; - volatile uint32_t state0; - volatile uint32_t state1; - volatile uint32_t state2; -}; - -static inline void HiPwmDisable(struct HiPwmRegs *reg) -{ - if (reg == NULL) { - return; - } - reg->ctrl = PWM_DISABLE; -} - -static inline void HiPwmAlwaysOutput(struct HiPwmRegs *reg) -{ - if (reg == NULL) { - return; - } - /* keep the pwm always output */ - reg->ctrl |= ((1 << PWM_KEEP_OFFSET) | PWM_ENABLE); -} - -static inline void HiPwmOutputNumberSquareWaves(struct HiPwmRegs *reg, uint32_t number) -{ - uint32_t mask; - - if (reg == NULL) { - return; - } - /* pwm output number square waves */ - reg->cfg2 = number; - mask = ~(1 << PWM_KEEP_OFFSET); - reg->ctrl &= mask; - reg->ctrl |= PWM_ENABLE; -} - -static inline void HiPwmSetPolarity(struct HiPwmRegs *reg, uint8_t polarity) -{ - uint32_t mask; - - if (reg == NULL) { - return; - } - mask = ~(1 << PWM_INV_OFFSET); - reg->ctrl &= mask; - reg->ctrl |= (polarity << PWM_INV_OFFSET); -} - -static inline void HiPwmSetPeriod(struct HiPwmRegs *reg, uint32_t period) -{ - if (reg == NULL) { - return; - } - reg->cfg0 = period / PWM_CLK_PERIOD; -} - -static inline void HiPwmSetDuty(struct HiPwmRegs *reg, uint32_t duty) -{ - if (reg == NULL) { - return; - } - reg->cfg1 = duty / PWM_CLK_PERIOD; -} - -#endif /* PWM_HI35XX_H */ diff --git a/platform/pwm/pwm_vim3l_adapter.c b/platform/pwm/pwm_vim3l_adapter.c deleted file mode 100644 index e94cb71..0000000 --- a/platform/pwm/pwm_vim3l_adapter.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * pwm_adapter.c - * - * pwm driver adapter of linux - * - * 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. - * - */ - -#include -#include "device_resource_if.h" -#include "hdf_base.h" -#include "hdf_log.h" -#include "osal_io.h" -#include "osal_mem.h" -#include "pwm_core.h" -#include "pwm_if.h" - -#define HDF_LOG_TAG HDF_PWM_LINUX_ADAPTER - -int32_t HdfPwmOpen(struct PwmDev *pwm) -{ - struct pwm_device *device = NULL; - - if (pwm == NULL) { - HDF_LOGE("%s: pwm is null", __func__); - return HDF_ERR_INVALID_PARAM; - } - device = pwm_request(pwm->num, NULL); - if (IS_ERR(device)) { - HDF_LOGE("%s: pwm_request pwm%d fail", __func__, pwm->num); - return HDF_FAILURE; - } - pwm->cfg.period = device->state.period; - pwm->cfg.duty = device->state.duty_cycle; - pwm->cfg.polarity = device->state.polarity; - pwm->cfg.status = device->state.enabled ? PWM_ENABLE_STATUS : PWM_DISABLE_STATUS; - pwm->priv = device; - return HDF_SUCCESS; -} - -int32_t HdfPwmClose(struct PwmDev *pwm) -{ - if (pwm == NULL) { - HDF_LOGE("%s: pwm is null", __func__); - return HDF_ERR_INVALID_PARAM; - } - pwm_free((struct pwm_device *)pwm->priv); - return HDF_SUCCESS; -} - -int32_t HdfPwmSetConfig(struct PwmDev *pwm, struct PwmConfig *config) -{ - struct pwm_state state; - - if (pwm == NULL || pwm->priv == NULL || config == NULL) { - HDF_LOGE("%s: hp reg or config is null", __func__); - return HDF_ERR_INVALID_PARAM; - } - - state.duty_cycle = config->duty; - state.enabled = (config->status == PWM_ENABLE_STATUS) ? true : false; - state.period = config->period; - state.polarity = config->polarity; - return pwm_apply_state(pwm->priv, &state); -} - -struct PwmMethod g_pwmOps = { - .setConfig = HdfPwmSetConfig, - .open = HdfPwmOpen, - .close = HdfPwmClose, -}; - -static int32_t HdfPwmBind(struct HdfDeviceObject *obj) -{ - (void)obj; - return HDF_SUCCESS; -} - -static int32_t HdfPwmInit(struct HdfDeviceObject *obj) -{ - int32_t ret; - uint32_t num; - struct PwmDev *pwm = NULL; - struct DeviceResourceIface *iface = NULL; - - HDF_LOGI("%s: entry", __func__); - if (obj == NULL) { - HDF_LOGE("%s: obj is null", __func__); - return HDF_ERR_INVALID_OBJECT; - } - iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (iface == NULL || iface->GetUint32 == NULL) { - HDF_LOGE("%s: face is invalid", __func__); - return HDF_FAILURE; - } - if (iface->GetUint32(obj->property, "num", &num, 0) != HDF_SUCCESS) { - HDF_LOGE("%s: read num fail", __func__); - return HDF_FAILURE; - } - pwm = (struct PwmDev *)OsalMemCalloc(sizeof(*pwm)); - if (pwm == NULL) { - HDF_LOGE("%s: OsalMemCalloc pwm error", __func__); - return HDF_ERR_MALLOC_FAIL; - } - pwm->cfg.number = 0; - pwm->num = num; - pwm->method = &g_pwmOps; - pwm->busy = false; - ret = PwmDeviceAdd(obj, pwm); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error probe, ret is %d", __func__, ret); - OsalMemFree(pwm); - } - return ret; -} - -static void HdfPwmRelease(struct HdfDeviceObject *obj) -{ - struct PwmDev *pwm = NULL; - - HDF_LOGI("%s: entry", __func__); - if (obj == NULL) { - HDF_LOGE("%s: obj is null", __func__); - return; - } - pwm = (struct PwmDev *)obj->service; - if (pwm == NULL) { - HDF_LOGE("%s: pwm is null", __func__); - return; - } - PwmDeviceRemove(obj, pwm); - OsalMemFree(pwm); -} - -struct HdfDriverEntry g_hdfPwm = { - .moduleVersion = 1, - .moduleName = "HDF_PLATFORM_PWM", - .Bind = HdfPwmBind, - .Init = HdfPwmInit, - .Release = HdfPwmRelease, -}; - -HDF_INIT(g_hdfPwm); diff --git a/platform/pwm/pwm_vim3l_linux.c b/platform/pwm/pwm_vim3l_linux.c deleted file mode 100644 index 38c411d..0000000 --- a/platform/pwm/pwm_vim3l_linux.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * pwm_hi35xx_linux.c - * - * pwm driver of hi35xx - * - * 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. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pwm_hi35xx.h" - -#define PWM_ENABLE_MASK 0x1 -#define PWM_HI35XX_N_CELLS 2 - -struct Hi35xxPwmChip { - struct pwm_chip chip; - struct HiPwmRegs *reg; - void __iomem *base; - struct clk *clk; -}; - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) -static int Hi35xxPwmApply(struct pwm_chip *chip, struct pwm_device *pwm, const struct pwm_state *state) -#else -static int Hi35xxPwmApply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) -#endif -{ - struct HiPwmRegs *reg = NULL; - struct Hi35xxPwmChip *hi35xxChip = (struct Hi35xxPwmChip *)chip; - - if (hi35xxChip == NULL || pwm == NULL || state == NULL) { - pr_err("%s: parameter is null\n", __func__); - return -EINVAL; - } - reg = (struct HiPwmRegs *)hi35xxChip->base; - if (state->polarity != PWM_POLARITY_NORMAL && state->polarity != PWM_POLARITY_INVERSED) { - pr_err("%s: polarity %u is invalid", __func__, state->polarity); - return -EINVAL; - } - - if (state->period < PWM_MIN_PERIOD) { - pr_err("%s: period %u is not support, min period %u", __func__, state->period, PWM_MIN_PERIOD); - return -EINVAL; - } - if (state->duty_cycle < 1 || state->duty_cycle > state->period) { - pr_err("%s: duty_cycle %u is not support, min duty_cycle 1 max duty_cycle %u", - __func__, state->duty_cycle , state->period); - return -EINVAL; - } - - HiPwmDisable(reg); - if (pwm->state.polarity != state->polarity) { - HiPwmSetPolarity(reg, state->polarity); - } - if (pwm->state.period != state->period) { - HiPwmSetPeriod(reg, state->period); - } - if (pwm->state.duty_cycle != state->duty_cycle) { - HiPwmSetDuty(reg, state->duty_cycle); - } - if (state->enabled) { - HiPwmAlwaysOutput(reg); - } - return 0; -} - - -static void Hi35xxGetState(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) -{ - struct HiPwmRegs *reg = NULL; - struct Hi35xxPwmChip *hi35xxChip = (struct Hi35xxPwmChip *)chip; - - if (hi35xxChip == NULL || pwm == NULL || state == NULL) { - pr_err("%s: parameter is null\n", __func__); - return; - } - reg = (struct HiPwmRegs *)hi35xxChip->base; - state->period = reg->cfg0; - state->duty_cycle = reg->cfg1; - state->enabled = reg->ctrl & PWM_ENABLE_MASK; -} - -static struct pwm_ops Hi35xxPwmOps = { - .apply = Hi35xxPwmApply, - .get_state = Hi35xxGetState, - .owner = THIS_MODULE, -}; - -static int PwmProbe(struct platform_device *pdev) -{ - int ret; - struct resource *r = NULL; - struct Hi35xxPwmChip *chip = NULL; - struct device_node *np = pdev->dev.of_node; - - if (!np) { - dev_err(&pdev->dev, "invalid devicetree node\n"); - return -EINVAL; - } - - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - return -ENOMEM; - } - chip->chip.dev = &pdev->dev; - chip->chip.ops = &Hi35xxPwmOps; - chip->chip.of_xlate = NULL; - chip->chip.of_pwm_n_cells = PWM_HI35XX_N_CELLS; - chip->chip.base = -1; - chip->chip.npwm = 1; - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); - chip->base = devm_ioremap_resource(&pdev->dev, r); - if (IS_ERR(chip->base)) { - return PTR_ERR(chip->base); - } - chip->reg = (struct HiPwmRegs *)chip->base; - chip->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(chip->clk)) { - dev_err(&pdev->dev, "failed to get clock\n"); - return PTR_ERR(chip->clk); - } - ret = clk_prepare_enable(chip->clk); - if (ret < 0) { - dev_err(&pdev->dev, "failed to enable clock\n"); - return ret; - } - ret = pwmchip_add(&chip->chip); - if (ret < 0) { - dev_err(&pdev->dev, "failed to add PWM chip\n"); - return ret; - } - - platform_set_drvdata(pdev, chip); - return ret; -} - -static int PwmRemove(struct platform_device *pdev) -{ - int ret; - struct Hi35xxPwmChip *chip = NULL; - - chip = platform_get_drvdata(pdev); - if (chip == NULL) { - return -ENODEV; - } - ret = pwmchip_remove(&chip->chip); - if (ret < 0) { - return ret; - } - clk_disable_unprepare(chip->clk); - return 0; -} - -static const struct of_device_id g_pwmMatch[] = { - { .compatible = "hisilicon,pwm" }, - {}, -}; - -static struct platform_driver g_pwmDriver = { - .probe = PwmProbe, - .remove = PwmRemove, - .driver = { - .name = "pwm", - .of_match_table = g_pwmMatch, - } -}; -module_platform_driver(g_pwmDriver); -MODULE_LICENSE("GPL"); diff --git a/platform/sdio/Makefile b/platform/sdio/Makefile index b94735a..b0febe1 100644 --- a/platform/sdio/Makefile +++ b/platform/sdio/Makefile @@ -14,10 +14,6 @@ include drivers/hdf/khdf/platform/platform.mk -obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/sdio_if.o -ifeq ($(CONFIG_SDIO_VIM3L), y) -obj-y += ./meson_sdio_adapter.o -else -obj-y += ./sdio_adapter.o -endif +obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mmc/sdio_if.o \ + ./sdio_adapter.o diff --git a/platform/sdio/meson_sdio_adapter.c b/platform/sdio/meson_sdio_adapter.c deleted file mode 100644 index e5fc2ce..0000000 --- a/platform/sdio/meson_sdio_adapter.c +++ /dev/null @@ -1,599 +0,0 @@ -/* - * sdio_adapter.c - * - * linux sdio 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. - * - */ - -#include -#include -#include -#include -#include "plat_log.h" -#include "device_resource_if.h" -#include "mmc_corex.h" -#include "mmc_sdio.h" - -#define HDF_LOG_TAG sdio_adapter_c - -#define DATA_LEN_ONE_BYTE 1 -#define DATA_LEN_TWO_BYTES 2 -#define DATA_LEN_FOUR_BYTES 4 -#define MMC_SLOT_NUM 3 -#define SDIO_RESCAN_WAIT_TIME 40 - -struct mmc_host *meson_get_mmc_host(int slot); -void meson_mmc_sdio_rescan(int slot); - -static struct sdio_func *LinuxSdioGetFunc(struct SdioDevice *dev) -{ - if (dev == NULL) { - HDF_LOGE("LinuxSdioGetFunc: dev is null."); - return NULL; - } - return (struct sdio_func *)dev->sd.mmc.priv; -} - -static int32_t LinuxSdioIncrAddrReadBytes(struct SdioDevice *dev, - uint8_t *data, uint32_t addr, uint32_t size) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - int32_t ret = HDF_SUCCESS; - uint16_t *output16 = NULL; - uint32_t *output32 = NULL; - - if (func == NULL) { - HDF_LOGE("LinuxSdioIncrAddrReadBytes: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if ((data == NULL) || (size == 0)) { - HDF_LOGE("LinuxSdioIncrAddrReadBytes: data or size is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - if (size == DATA_LEN_ONE_BYTE) { - *data = sdio_readb(func, addr, &ret); - return ret; - } - if (size == DATA_LEN_TWO_BYTES) { - output16 = (uint16_t *)data; - *output16 = sdio_readw(func, addr, &ret); - return ret; - } - if (size == DATA_LEN_FOUR_BYTES) { - output32 = (uint32_t *)data; - *output32 = sdio_readl(func, addr, &ret); - return ret; - } - return sdio_memcpy_fromio(func, data, addr, size); -} - -static int32_t LinuxSdioIncrAddrWriteBytes(struct SdioDevice *dev, - uint8_t *data, uint32_t addr, uint32_t size) -{ - int32_t ret = HDF_SUCCESS; - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioIncrAddrWriteBytes: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if ((data == NULL) || (size == 0)) { - HDF_LOGE("LinuxSdioIncrAddrWriteBytes: data or size is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - if (size == DATA_LEN_ONE_BYTE) { - sdio_writeb(func, *data, addr, &ret); - return ret; - } - if (size == DATA_LEN_TWO_BYTES) { - sdio_writew(func, *(uint16_t *)data, addr, &ret); - return ret; - } - if (size == DATA_LEN_FOUR_BYTES) { - sdio_writel(func, *(uint32_t *)data, addr, &ret); - return ret; - } - return sdio_memcpy_toio(func, addr, data, size); -} - -static int32_t LinuxSdioFixedAddrReadBytes(struct SdioDevice *dev, - uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioFixedAddrReadBytes: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if ((data == NULL) || (size == 0)) { - HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - if (scatterLen > 0) { - HDF_LOGE("LinuxSdioFixedAddrReadBytes: not support!"); - return HDF_ERR_NOT_SUPPORT; - } - return sdio_readsb(func, data, addr, size); -} - -static int32_t LinuxSdioFixedAddrWriteBytes(struct SdioDevice *dev, - uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioFixedAddrWriteBytes: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if ((data == NULL) || (size == 0)) { - HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - if (scatterLen > 0) { - HDF_LOGE("LinuxSdioFixedAddrWriteBytes: not support!"); - return HDF_ERR_NOT_SUPPORT; - } - return sdio_writesb(func, addr, data, size); -} - -static int32_t LinuxSdioFunc0ReadBytes(struct SdioDevice *dev, - uint8_t *data, uint32_t addr, uint32_t size) -{ - int32_t ret = HDF_SUCCESS; - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioFunc0ReadBytes: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if ((data == NULL) || (size == 0)) { - HDF_LOGE("LinuxSdioFunc0ReadBytes: data or size is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - *data = sdio_f0_readb(func, addr, &ret); - return ret; -} - -static int32_t LinuxSdioFunc0WriteBytes(struct SdioDevice *dev, - uint8_t *data, uint32_t addr, uint32_t size) -{ - int32_t ret = HDF_SUCCESS; - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioFunc0WriteBytes: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if ((data == NULL) || (size == 0)) { - HDF_LOGE("LinuxSdioFunc0WriteBytes: data or size is invalid."); - return HDF_ERR_INVALID_PARAM; - } - - sdio_f0_writeb(func, *data, addr, &ret); - return ret; -} - -static int32_t LinuxSdioSetBlockSize(struct SdioDevice *dev, uint32_t blockSize) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioSetBlockSize, func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - return sdio_set_block_size(func, blockSize); -} - -static int32_t LinuxSdioGetCommonInfo(struct SdioDevice *dev, - SdioCommonInfo *info, uint32_t infoType) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioGetCommonInfo: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if (info == NULL) { - HDF_LOGE("LinuxSdioGetCommonInfo: info is null."); - return HDF_ERR_INVALID_PARAM; - } - if (infoType != SDIO_FUNC_INFO) { - HDF_LOGE("LinuxSdioGetCommonInfo: cur type %d is not support.", infoType); - return HDF_ERR_NOT_SUPPORT; - } - - if (func->card == NULL) { - HDF_LOGE("LinuxSdioGetCommonInfo fail, card is null."); - return HDF_ERR_INVALID_PARAM; - } - if (func->card->host == NULL) { - HDF_LOGE("LinuxSdioGetCommonInfo fail, host is null."); - return HDF_ERR_INVALID_PARAM; - } - info->funcInfo.enTimeout = func->enable_timeout; - info->funcInfo.maxBlockNum = func->card->host->max_blk_count; - info->funcInfo.maxBlockSize = func->card->host->max_blk_size; - info->funcInfo.maxRequestSize = func->card->host->max_req_size; - info->funcInfo.funcNum = func->num; - info->funcInfo.irqCap = func->card->host->caps & MMC_CAP_SDIO_IRQ; - info->funcInfo.data = func; - return HDF_SUCCESS; -} - -static int32_t LinuxSdioSetCommonInfo(struct SdioDevice *dev, - SdioCommonInfo *info, uint32_t infoType) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioSetCommonInfo: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if (info == NULL) { - HDF_LOGE("LinuxSdioSetCommonInfo: info is null."); - return HDF_ERR_INVALID_PARAM; - } - if (infoType != SDIO_FUNC_INFO) { - HDF_LOGE("LinuxSdioSetCommonInfo: cur type %d is not support.", infoType); - return HDF_ERR_NOT_SUPPORT; - } - - if (func->card == NULL) { - HDF_LOGE("LinuxSdioSetCommonInfo fail, card is null."); - return HDF_ERR_INVALID_PARAM; - } - if (func->card->host == NULL) { - HDF_LOGE("LinuxSdioSetCommonInfo fail, host is null."); - return HDF_ERR_INVALID_PARAM; - } - func->enable_timeout = info->funcInfo.enTimeout; - func->card->host->max_blk_count = info->funcInfo.maxBlockNum; - func->card->host->max_blk_size = info->funcInfo.maxBlockSize; - func->card->host->max_req_size = info->funcInfo.maxRequestSize; - func->num = info->funcInfo.funcNum; - return HDF_SUCCESS; -} - -static int32_t LinuxSdioFlushData(struct SdioDevice *dev) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioFlushData: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if (func->card == NULL) { - HDF_LOGE("LinuxSdioFlushData: card is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - return mmc_hw_reset(func->card->host); -} - -static int32_t LinuxSdioClaimHost(struct SdioDevice *dev) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioClaimHost: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - sdio_claim_host(func); - return HDF_SUCCESS; -} - -static int32_t LinuxSdioReleaseHost(struct SdioDevice *dev) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioReleaseHost: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - sdio_release_host(func); - return HDF_SUCCESS; -} - -static int32_t LinuxSdioEnableFunc(struct SdioDevice *dev) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioEnableFunc: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - return sdio_enable_func(func); -} - -static int32_t LinuxSdioDisableFunc(struct SdioDevice *dev) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioDisableFunc: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - return sdio_disable_func(func); -} - -static int32_t LinuxSdioClaimIrq(struct SdioDevice *dev, SdioIrqHandler *handler) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioClaimIrq: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - if (handler == NULL) { - HDF_LOGE("LinuxSdioClaimIrq: handler is null."); - return HDF_ERR_INVALID_PARAM; - } - return sdio_claim_irq(func, (sdio_irq_handler_t *)handler); -} - -static int32_t LinuxSdioReleaseIrq(struct SdioDevice *dev) -{ - struct sdio_func *func = LinuxSdioGetFunc(dev); - - if (func == NULL) { - HDF_LOGE("LinuxSdioReleaseIrq: func is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - return sdio_release_irq(func); -} - -static struct sdio_func *LinuxSdioSearchFunc(uint32_t funcNum, uint16_t vendorId, uint16_t deviceId) -{ - struct mmc_card *card = NULL; - struct mmc_host *host = NULL; - struct sdio_func *func = NULL; - uint32_t i, j; - - for (i = 0; i < MMC_SLOT_NUM; i++) { - host = meson_get_mmc_host(i); - if (host == NULL) { - continue; - } - card = host->card; - if (card == NULL) { - continue; - } - for (j = 0; j <= card->sdio_funcs; j++) { - func = card->sdio_func[j]; - if ((func != NULL) && - (func->num == funcNum) && - (func->vendor == vendorId) && - (func->device == deviceId)) { - HDF_LOGD("LinuxSdioSearchFunc: find func!"); - return func; - } - } - } - - HDF_LOGE("LinuxSdioSearchFunc: get sdio func fail!"); - return NULL; -} - -static int32_t LinuxSdioFindFunc(struct SdioDevice *dev, struct SdioFunctionConfig *configData) -{ - if (dev == NULL || configData == NULL) { - HDF_LOGE("LinuxSdioFindFunc: dev or configData is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - dev->sd.mmc.priv = LinuxSdioSearchFunc(configData->funcNr, configData->vendorId, configData->deviceId); - if (dev->sd.mmc.priv == NULL) { - HDF_LOGE("LinuxSdioFindFunc: LinuxSdioSearchFunc fail."); - return HDF_ERR_NOT_SUPPORT; - } - return HDF_SUCCESS; -} - -static struct SdioDeviceOps g_sdioDeviceOps = { - .incrAddrReadBytes = LinuxSdioIncrAddrReadBytes, - .incrAddrWriteBytes = LinuxSdioIncrAddrWriteBytes, - .fixedAddrReadBytes = LinuxSdioFixedAddrReadBytes, - .fixedAddrWriteBytes = LinuxSdioFixedAddrWriteBytes, - .func0ReadBytes = LinuxSdioFunc0ReadBytes, - .func0WriteBytes = LinuxSdioFunc0WriteBytes, - .setBlockSize = LinuxSdioSetBlockSize, - .getCommonInfo = LinuxSdioGetCommonInfo, - .setCommonInfo = LinuxSdioSetCommonInfo, - .flushData = LinuxSdioFlushData, - .enableFunc = LinuxSdioEnableFunc, - .disableFunc = LinuxSdioDisableFunc, - .claimIrq = LinuxSdioClaimIrq, - .releaseIrq = LinuxSdioReleaseIrq, - .findFunc = LinuxSdioFindFunc, - .claimHost = LinuxSdioClaimHost, - .releaseHost = LinuxSdioReleaseHost, -}; - -static bool LinuxSdioRescanFinish(struct MmcCntlr *cntlr) -{ - struct mmc_host *host = NULL; - struct mmc_card *card = NULL; - - host = meson_get_mmc_host(cntlr->index); - if (host == NULL) { - return false; - } - - card = host->card; - if (card == NULL) { - return false; - } - if (card->sdio_funcs > 0) { - return true; - } - return false; -} - -static int32_t LinuxSdioRescan(struct MmcCntlr *cntlr) -{ - bool rescanFinish = false; - uint32_t count = 0; - - if (cntlr == NULL) { - HDF_LOGE("LinuxSdioRescan: cntlr is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - meson_mmc_sdio_rescan(cntlr->index); - while (rescanFinish == false && count < SDIO_RESCAN_WAIT_TIME) { - OsalMSleep(50); - count++; - rescanFinish = LinuxSdioRescanFinish(cntlr); - } - - if (rescanFinish == false) { - HDF_LOGE("LinuxSdioRescan: fail!"); - return HDF_FAILURE; - } - - OsalMSleep(10); - return HDF_SUCCESS; -} - -struct MmcCntlrOps g_sdiodntlrops = { - .rescanSdioDev = LinuxSdioRescan, -}; - -static void LinuxSdioDeleteCntlr(struct MmcCntlr *cntlr) -{ - if (cntlr == NULL) { - return; - } - - if (cntlr->curDev != NULL) { - MmcDeviceRemove(cntlr->curDev); - OsalMemFree(cntlr->curDev); - } - MmcCntlrRemove(cntlr); - OsalMemFree(cntlr); -} - -static int32_t LinuxSdioCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (obj == NULL || cntlr == NULL) { - HDF_LOGE("LinuxSdioCntlrParse: input para is NULL."); - return HDF_FAILURE; - } - - node = obj->property; - if (node == NULL) { - HDF_LOGE("LinuxSdioCntlrParse: drs node is NULL."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("LinuxSdioCntlrParse: invalid drs ops fail!"); - return HDF_FAILURE; - } - - ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxSdioCntlrParse: read hostIndex fail!"); - return ret; - } - ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxSdioCntlrParse: read devType fail!"); - return ret; - } - HDF_LOGD("LinuxSdioCntlrParse: hostIndex = %d, devType = %d.", cntlr->index, cntlr->devType); - return HDF_SUCCESS; -} - -static int32_t LinuxSdioBind(struct HdfDeviceObject *obj) -{ - struct MmcCntlr *cntlr = NULL; - int32_t ret; - - HDF_LOGE("LinuxSdioBind: entry!"); - if (obj == NULL) { - HDF_LOGE("LinuxSdioBind: Fail, obj is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - - cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr)); - if (cntlr == NULL) { - HDF_LOGE("LinuxSdioBind: no mem for MmcCntlr."); - return HDF_ERR_MALLOC_FAIL; - } - - cntlr->ops = &g_sdiodntlrops; - cntlr->hdfDevObj = obj; - obj->service = &cntlr->service; - /* init cntlr. */ - ret = LinuxSdioCntlrParse(cntlr, obj); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxSdioBind: cntlr parse fail."); - LinuxSdioDeleteCntlr(cntlr); - HDF_LOGE("LinuxSdioBind: Fail!"); - return HDF_FAILURE; - } - - ret = MmcCntlrAdd(cntlr); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxSdioBind: cntlr add fail."); - LinuxSdioDeleteCntlr(cntlr); - HDF_LOGE("LinuxSdioBind: Fail!"); - return HDF_FAILURE; - } - - ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType); - if (ret != HDF_SUCCESS) { - HDF_LOGE("LinuxSdioBind: alloc dev fail."); - LinuxSdioDeleteCntlr(cntlr); - HDF_LOGE("LinuxSdioBind: Fail!"); - return HDF_FAILURE; - } - MmcDeviceAddOps(cntlr->curDev, &g_sdioDeviceOps); - HDF_LOGD("LinuxSdioBind: Success!"); - return HDF_SUCCESS; -} - -static int32_t LinuxSdioInit(struct HdfDeviceObject *obj) -{ - (void)obj; - HDF_LOGD("LinuxSdioInit: Success!"); - return HDF_SUCCESS; -} - -static void LinuxSdioRelease(struct HdfDeviceObject *obj) -{ - if (obj == NULL) { - return; - } - LinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service); -} - -struct HdfDriverEntry g_sdiodriverentry = { - .moduleVersion = 1, - .Bind = LinuxSdioBind, - .Init = LinuxSdioInit, - .Release = LinuxSdioRelease, - .moduleName = "HDF_PLATFORM_SDIO", -}; -HDF_INIT(g_sdiodriverentry); diff --git a/platform/sdio/sdio_adapter.c b/platform/sdio/sdio_adapter.c index 59fdba5..72d4494 100644 --- a/platform/sdio/sdio_adapter.c +++ b/platform/sdio/sdio_adapter.c @@ -1,7 +1,7 @@ /* * sdio_adapter.c * - * hi35xx linux sdio driver implement. + * linux sdio driver implement. * * Copyright (c) 2020-2021 Huawei Device Co., Ltd. * @@ -33,32 +33,37 @@ #define MMC_SLOT_NUM 3 #define SDIO_RESCAN_WAIT_TIME 40 +#if defined(CONFIG_SDIO_VIM3L) +struct mmc_host *meson_get_mmc_host(int slot); +void meson_mmc_sdio_rescan(int slot); +#else struct mmc_host *himci_get_mmc_host(int slot); void hisi_sdio_rescan(int slot); +#endif // CONFIG_SDIO_VIM3L -static struct sdio_func *Hi35xxLinuxSdioGetFunc(struct SdioDevice *dev) +static struct sdio_func *LinuxSdioGetFunc(struct SdioDevice *dev) { if (dev == NULL) { - HDF_LOGE("Hi35xxLinuxSdioGetFunc: dev is null."); + HDF_LOGE("LinuxSdioGetFunc: dev is null."); return NULL; } return (struct sdio_func *)dev->sd.mmc.priv; } -static int32_t Hi35xxLinuxSdioIncrAddrReadBytes(struct SdioDevice *dev, +static int32_t LinuxSdioIncrAddrReadBytes(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); int32_t ret = HDF_SUCCESS; uint16_t *output16 = NULL; uint32_t *output32 = NULL; if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioIncrAddrReadBytes: func is NULL."); + HDF_LOGE("LinuxSdioIncrAddrReadBytes: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if ((data == NULL) || (size == 0)) { - HDF_LOGE("Hi35xxLinuxSdioIncrAddrReadBytes: data or size is invalid."); + HDF_LOGE("LinuxSdioIncrAddrReadBytes: data or size is invalid."); return HDF_ERR_INVALID_PARAM; } @@ -79,18 +84,18 @@ static int32_t Hi35xxLinuxSdioIncrAddrReadBytes(struct SdioDevice *dev, return sdio_memcpy_fromio(func, data, addr, size); } -static int32_t Hi35xxLinuxSdioIncrAddrWriteBytes(struct SdioDevice *dev, +static int32_t LinuxSdioIncrAddrWriteBytes(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size) { int32_t ret = HDF_SUCCESS; - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioIncrAddrWriteBytes: func is NULL."); + HDF_LOGE("LinuxSdioIncrAddrWriteBytes: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if ((data == NULL) || (size == 0)) { - HDF_LOGE("Hi35xxLinuxSdioIncrAddrWriteBytes: data or size is invalid."); + HDF_LOGE("LinuxSdioIncrAddrWriteBytes: data or size is invalid."); return HDF_ERR_INVALID_PARAM; } @@ -109,60 +114,60 @@ static int32_t Hi35xxLinuxSdioIncrAddrWriteBytes(struct SdioDevice *dev, return sdio_memcpy_toio(func, addr, data, size); } -static int32_t Hi35xxLinuxSdioFixedAddrReadBytes(struct SdioDevice *dev, +static int32_t LinuxSdioFixedAddrReadBytes(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFixedAddrReadBytes: func is NULL."); + HDF_LOGE("LinuxSdioFixedAddrReadBytes: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if ((data == NULL) || (size == 0)) { - HDF_LOGE("Hi35xxLinuxSdioFixedAddrReadBytes: data or size is invalid."); + HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid."); return HDF_ERR_INVALID_PARAM; } if (scatterLen > 0) { - HDF_LOGE("Hi35xxLinuxSdioFixedAddrReadBytes: not support!"); + HDF_LOGE("LinuxSdioFixedAddrReadBytes: not support!"); return HDF_ERR_NOT_SUPPORT; } return sdio_readsb(func, data, addr, size); } -static int32_t Hi35xxLinuxSdioFixedAddrWriteBytes(struct SdioDevice *dev, +static int32_t LinuxSdioFixedAddrWriteBytes(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFixedAddrWriteBytes: func is NULL."); + HDF_LOGE("LinuxSdioFixedAddrWriteBytes: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if ((data == NULL) || (size == 0)) { - HDF_LOGE("Hi35xxLinuxSdioFixedAddrReadBytes: data or size is invalid."); + HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid."); return HDF_ERR_INVALID_PARAM; } if (scatterLen > 0) { - HDF_LOGE("Hi35xxLinuxSdioFixedAddrWriteBytes: not support!"); + HDF_LOGE("LinuxSdioFixedAddrWriteBytes: not support!"); return HDF_ERR_NOT_SUPPORT; } return sdio_writesb(func, addr, data, size); } -static int32_t Hi35xxLinuxSdioFunc0ReadBytes(struct SdioDevice *dev, +static int32_t LinuxSdioFunc0ReadBytes(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size) { int32_t ret = HDF_SUCCESS; - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFunc0ReadBytes: func is NULL."); + HDF_LOGE("LinuxSdioFunc0ReadBytes: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if ((data == NULL) || (size == 0)) { - HDF_LOGE("Hi35xxLinuxSdioFunc0ReadBytes: data or size is invalid."); + HDF_LOGE("LinuxSdioFunc0ReadBytes: data or size is invalid."); return HDF_ERR_INVALID_PARAM; } @@ -170,18 +175,18 @@ static int32_t Hi35xxLinuxSdioFunc0ReadBytes(struct SdioDevice *dev, return ret; } -static int32_t Hi35xxLinuxSdioFunc0WriteBytes(struct SdioDevice *dev, +static int32_t LinuxSdioFunc0WriteBytes(struct SdioDevice *dev, uint8_t *data, uint32_t addr, uint32_t size) { int32_t ret = HDF_SUCCESS; - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFunc0WriteBytes: func is NULL."); + HDF_LOGE("LinuxSdioFunc0WriteBytes: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if ((data == NULL) || (size == 0)) { - HDF_LOGE("Hi35xxLinuxSdioFunc0WriteBytes: data or size is invalid."); + HDF_LOGE("LinuxSdioFunc0WriteBytes: data or size is invalid."); return HDF_ERR_INVALID_PARAM; } @@ -189,41 +194,41 @@ static int32_t Hi35xxLinuxSdioFunc0WriteBytes(struct SdioDevice *dev, return ret; } -static int32_t Hi35xxLinuxSdioSetBlockSize(struct SdioDevice *dev, uint32_t blockSize) +static int32_t LinuxSdioSetBlockSize(struct SdioDevice *dev, uint32_t blockSize) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioSetBlockSize, func is NULL."); + HDF_LOGE("LinuxSdioSetBlockSize, func is NULL."); return HDF_ERR_INVALID_OBJECT; } return sdio_set_block_size(func, blockSize); } -static int32_t Hi35xxLinuxSdioGetCommonInfo(struct SdioDevice *dev, +static int32_t LinuxSdioGetCommonInfo(struct SdioDevice *dev, SdioCommonInfo *info, uint32_t infoType) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo: func is NULL."); + HDF_LOGE("LinuxSdioGetCommonInfo: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if (info == NULL) { - HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo: info is null."); + HDF_LOGE("LinuxSdioGetCommonInfo: info is null."); return HDF_ERR_INVALID_PARAM; } if (infoType != SDIO_FUNC_INFO) { - HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo: cur type %d is not support.", infoType); + HDF_LOGE("LinuxSdioGetCommonInfo: cur type %d is not support.", infoType); return HDF_ERR_NOT_SUPPORT; } if (func->card == NULL) { - HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo fail, card is null."); + HDF_LOGE("LinuxSdioGetCommonInfo fail, card is null."); return HDF_ERR_INVALID_PARAM; } if (func->card->host == NULL) { - HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo fail, host is null."); + HDF_LOGE("LinuxSdioGetCommonInfo fail, host is null."); return HDF_ERR_INVALID_PARAM; } info->funcInfo.enTimeout = func->enable_timeout; @@ -236,30 +241,30 @@ static int32_t Hi35xxLinuxSdioGetCommonInfo(struct SdioDevice *dev, return HDF_SUCCESS; } -static int32_t Hi35xxLinuxSdioSetCommonInfo(struct SdioDevice *dev, +static int32_t LinuxSdioSetCommonInfo(struct SdioDevice *dev, SdioCommonInfo *info, uint32_t infoType) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo: func is NULL."); + HDF_LOGE("LinuxSdioSetCommonInfo: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if (info == NULL) { - HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo: info is null."); + HDF_LOGE("LinuxSdioSetCommonInfo: info is null."); return HDF_ERR_INVALID_PARAM; } if (infoType != SDIO_FUNC_INFO) { - HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo: cur type %d is not support.", infoType); + HDF_LOGE("LinuxSdioSetCommonInfo: cur type %d is not support.", infoType); return HDF_ERR_NOT_SUPPORT; } if (func->card == NULL) { - HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo fail, card is null."); + HDF_LOGE("LinuxSdioSetCommonInfo fail, card is null."); return HDF_ERR_INVALID_PARAM; } if (func->card->host == NULL) { - HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo fail, host is null."); + HDF_LOGE("LinuxSdioSetCommonInfo fail, host is null."); return HDF_ERR_INVALID_PARAM; } func->enable_timeout = info->funcInfo.enTimeout; @@ -270,95 +275,99 @@ static int32_t Hi35xxLinuxSdioSetCommonInfo(struct SdioDevice *dev, return HDF_SUCCESS; } -static int32_t Hi35xxLinuxSdioFlushData(struct SdioDevice *dev) +static int32_t LinuxSdioFlushData(struct SdioDevice *dev) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFlushData: func is NULL."); + HDF_LOGE("LinuxSdioFlushData: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if (func->card == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFlushData: card is NULL."); + HDF_LOGE("LinuxSdioFlushData: card is NULL."); return HDF_ERR_INVALID_OBJECT; } +#if defined(CONFIG_SDIO_VIM3L) + return mmc_hw_reset(func->card->host); +#else return mmc_sw_reset(func->card->host); +#endif // CONFIG_SDIO_VIM3L } -static int32_t Hi35xxLinuxSdioClaimHost(struct SdioDevice *dev) +static int32_t LinuxSdioClaimHost(struct SdioDevice *dev) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioClaimHost: func is NULL."); + HDF_LOGE("LinuxSdioClaimHost: func is NULL."); return HDF_ERR_INVALID_OBJECT; } sdio_claim_host(func); return HDF_SUCCESS; } -static int32_t Hi35xxLinuxSdioReleaseHost(struct SdioDevice *dev) +static int32_t LinuxSdioReleaseHost(struct SdioDevice *dev) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioReleaseHost: func is NULL."); + HDF_LOGE("LinuxSdioReleaseHost: func is NULL."); return HDF_ERR_INVALID_OBJECT; } sdio_release_host(func); return HDF_SUCCESS; } -static int32_t Hi35xxLinuxSdioEnableFunc(struct SdioDevice *dev) +static int32_t LinuxSdioEnableFunc(struct SdioDevice *dev) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioEnableFunc: func is NULL."); + HDF_LOGE("LinuxSdioEnableFunc: func is NULL."); return HDF_ERR_INVALID_OBJECT; } return sdio_enable_func(func); } -static int32_t Hi35xxLinuxSdioDisableFunc(struct SdioDevice *dev) +static int32_t LinuxSdioDisableFunc(struct SdioDevice *dev) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioDisableFunc: func is NULL."); + HDF_LOGE("LinuxSdioDisableFunc: func is NULL."); return HDF_ERR_INVALID_OBJECT; } return sdio_disable_func(func); } -static int32_t Hi35xxLinuxSdioClaimIrq(struct SdioDevice *dev, SdioIrqHandler *handler) +static int32_t LinuxSdioClaimIrq(struct SdioDevice *dev, SdioIrqHandler *handler) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioClaimIrq: func is NULL."); + HDF_LOGE("LinuxSdioClaimIrq: func is NULL."); return HDF_ERR_INVALID_OBJECT; } if (handler == NULL) { - HDF_LOGE("Hi35xxLinuxSdioClaimIrq: handler is null."); + HDF_LOGE("LinuxSdioClaimIrq: handler is null."); return HDF_ERR_INVALID_PARAM; } return sdio_claim_irq(func, (sdio_irq_handler_t *)handler); } -static int32_t Hi35xxLinuxSdioReleaseIrq(struct SdioDevice *dev) +static int32_t LinuxSdioReleaseIrq(struct SdioDevice *dev) { - struct sdio_func *func = Hi35xxLinuxSdioGetFunc(dev); + struct sdio_func *func = LinuxSdioGetFunc(dev); if (func == NULL) { - HDF_LOGE("Hi35xxLinuxSdioReleaseIrq: func is NULL."); + HDF_LOGE("LinuxSdioReleaseIrq: func is NULL."); return HDF_ERR_INVALID_OBJECT; } return sdio_release_irq(func); } -static struct sdio_func *Hi35xxLinuxSdioSearchFunc(uint32_t funcNum, uint16_t vendorId, uint16_t deviceId) +static struct sdio_func *LinuxSdioSearchFunc(uint32_t funcNum, uint16_t vendorId, uint16_t deviceId) { struct mmc_card *card = NULL; struct mmc_host *host = NULL; @@ -366,7 +375,11 @@ static struct sdio_func *Hi35xxLinuxSdioSearchFunc(uint32_t funcNum, uint16_t ve uint32_t i, j; for (i = 0; i < MMC_SLOT_NUM; i++) { - host = himci_get_mmc_host(i); +#if defined(CONFIG_SDIO_VIM3L) + host = meson_get_mmc_host(i); +#else + host = himci_get_mmc_host(i); +#endif // CONFIG_SDIO_VIM3L if (host == NULL) { continue; } @@ -380,57 +393,61 @@ static struct sdio_func *Hi35xxLinuxSdioSearchFunc(uint32_t funcNum, uint16_t ve (func->num == funcNum) && (func->vendor == vendorId) && (func->device == deviceId)) { - HDF_LOGD("Hi35xxLinuxSdioSearchFunc: find func!"); + HDF_LOGD("LinuxSdioSearchFunc: find func!"); return func; } } } - HDF_LOGE("Hi35xxLinuxSdioSearchFunc: get sdio func fail!"); + HDF_LOGE("LinuxSdioSearchFunc: get sdio func fail!"); return NULL; } -static int32_t Hi35xxLinuxSdioFindFunc(struct SdioDevice *dev, struct SdioFunctionConfig *configData) +static int32_t LinuxSdioFindFunc(struct SdioDevice *dev, struct SdioFunctionConfig *configData) { if (dev == NULL || configData == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFindFunc: dev or configData is NULL."); + HDF_LOGE("LinuxSdioFindFunc: dev or configData is NULL."); return HDF_ERR_INVALID_OBJECT; } - dev->sd.mmc.priv = Hi35xxLinuxSdioSearchFunc(configData->funcNr, configData->vendorId, configData->deviceId); + dev->sd.mmc.priv = LinuxSdioSearchFunc(configData->funcNr, configData->vendorId, configData->deviceId); if (dev->sd.mmc.priv == NULL) { - HDF_LOGE("Hi35xxLinuxSdioFindFunc: Hi35xxLinuxSdioSearchFunc fail."); + HDF_LOGE("LinuxSdioFindFunc: LinuxSdioSearchFunc fail."); return HDF_ERR_NOT_SUPPORT; } return HDF_SUCCESS; } static struct SdioDeviceOps g_sdioDeviceOps = { - .incrAddrReadBytes = Hi35xxLinuxSdioIncrAddrReadBytes, - .incrAddrWriteBytes = Hi35xxLinuxSdioIncrAddrWriteBytes, - .fixedAddrReadBytes = Hi35xxLinuxSdioFixedAddrReadBytes, - .fixedAddrWriteBytes = Hi35xxLinuxSdioFixedAddrWriteBytes, - .func0ReadBytes = Hi35xxLinuxSdioFunc0ReadBytes, - .func0WriteBytes = Hi35xxLinuxSdioFunc0WriteBytes, - .setBlockSize = Hi35xxLinuxSdioSetBlockSize, - .getCommonInfo = Hi35xxLinuxSdioGetCommonInfo, - .setCommonInfo = Hi35xxLinuxSdioSetCommonInfo, - .flushData = Hi35xxLinuxSdioFlushData, - .enableFunc = Hi35xxLinuxSdioEnableFunc, - .disableFunc = Hi35xxLinuxSdioDisableFunc, - .claimIrq = Hi35xxLinuxSdioClaimIrq, - .releaseIrq = Hi35xxLinuxSdioReleaseIrq, - .findFunc = Hi35xxLinuxSdioFindFunc, - .claimHost = Hi35xxLinuxSdioClaimHost, - .releaseHost = Hi35xxLinuxSdioReleaseHost, + .incrAddrReadBytes = LinuxSdioIncrAddrReadBytes, + .incrAddrWriteBytes = LinuxSdioIncrAddrWriteBytes, + .fixedAddrReadBytes = LinuxSdioFixedAddrReadBytes, + .fixedAddrWriteBytes = LinuxSdioFixedAddrWriteBytes, + .func0ReadBytes = LinuxSdioFunc0ReadBytes, + .func0WriteBytes = LinuxSdioFunc0WriteBytes, + .setBlockSize = LinuxSdioSetBlockSize, + .getCommonInfo = LinuxSdioGetCommonInfo, + .setCommonInfo = LinuxSdioSetCommonInfo, + .flushData = LinuxSdioFlushData, + .enableFunc = LinuxSdioEnableFunc, + .disableFunc = LinuxSdioDisableFunc, + .claimIrq = LinuxSdioClaimIrq, + .releaseIrq = LinuxSdioReleaseIrq, + .findFunc = LinuxSdioFindFunc, + .claimHost = LinuxSdioClaimHost, + .releaseHost = LinuxSdioReleaseHost, }; -static bool Hi35xxLinuxSdioRescanFinish(struct MmcCntlr *cntlr) +static bool LinuxSdioRescanFinish(struct MmcCntlr *cntlr) { struct mmc_host *host = NULL; struct mmc_card *card = NULL; - host = himci_get_mmc_host(cntlr->index); +#if defined(CONFIG_SDIO_VIM3L) + meson_get_mmc_host(cntlr->index); +#else + host = himci_get_mmc_host(cntlr->index); +#endif // CONFIG_SDIO_VIM3L if (host == NULL) { return false; } @@ -445,25 +462,29 @@ static bool Hi35xxLinuxSdioRescanFinish(struct MmcCntlr *cntlr) return false; } -static int32_t Hi35xxLinuxSdioRescan(struct MmcCntlr *cntlr) +static int32_t LinuxSdioRescan(struct MmcCntlr *cntlr) { bool rescanFinish = false; uint32_t count = 0; if (cntlr == NULL) { - HDF_LOGE("Hi35xxLinuxSdioRescan: cntlr is NULL."); + HDF_LOGE("LinuxSdioRescan: cntlr is NULL."); return HDF_ERR_INVALID_OBJECT; } +#if defined(CONFIG_SDIO_VIM3L) + meson_mmc_sdio_rescan(cntlr->index); +#else hisi_sdio_rescan(cntlr->index); +#endif // CONFIG_SDIO_VIM3L while (rescanFinish == false && count < SDIO_RESCAN_WAIT_TIME) { OsalMSleep(50); count++; - rescanFinish = Hi35xxLinuxSdioRescanFinish(cntlr); + rescanFinish = LinuxSdioRescanFinish(cntlr); } if (rescanFinish == false) { - HDF_LOGE("Hi35xxLinuxSdioRescan: fail!"); + HDF_LOGE("LinuxSdioRescan: fail!"); return HDF_FAILURE; } @@ -472,10 +493,10 @@ static int32_t Hi35xxLinuxSdioRescan(struct MmcCntlr *cntlr) } struct MmcCntlrOps g_sdioCntlrOps = { - .rescanSdioDev = Hi35xxLinuxSdioRescan, + .rescanSdioDev = LinuxSdioRescan, }; -static void Hi35xxLinuxSdioDeleteCntlr(struct MmcCntlr *cntlr) +static void LinuxSdioDeleteCntlr(struct MmcCntlr *cntlr) { if (cntlr == NULL) { return; @@ -489,56 +510,56 @@ static void Hi35xxLinuxSdioDeleteCntlr(struct MmcCntlr *cntlr) OsalMemFree(cntlr); } -static int32_t Hi35xxLinuxSdioCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) +static int32_t LinuxSdioCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj) { const struct DeviceResourceNode *node = NULL; struct DeviceResourceIface *drsOps = NULL; int32_t ret; if (obj == NULL || cntlr == NULL) { - HDF_LOGE("Hi35xxLinuxSdioCntlrParse: input para is NULL."); + HDF_LOGE("LinuxSdioCntlrParse: input para is NULL."); return HDF_FAILURE; } node = obj->property; if (node == NULL) { - HDF_LOGE("Hi35xxLinuxSdioCntlrParse: drs node is NULL."); + HDF_LOGE("LinuxSdioCntlrParse: drs node is NULL."); return HDF_FAILURE; } drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("Hi35xxLinuxSdioCntlrParse: invalid drs ops fail!"); + HDF_LOGE("LinuxSdioCntlrParse: invalid drs ops fail!"); return HDF_FAILURE; } ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxSdioCntlrParse: read hostIndex fail!"); + HDF_LOGE("LinuxSdioCntlrParse: read hostIndex fail!"); return ret; } ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxSdioCntlrParse: read devType fail!"); + HDF_LOGE("LinuxSdioCntlrParse: read devType fail!"); return ret; } - HDF_LOGD("Hi35xxLinuxSdioCntlrParse: hostIndex = %d, devType = %d.", cntlr->index, cntlr->devType); + HDF_LOGD("LinuxSdioCntlrParse: hostIndex = %d, devType = %d.", cntlr->index, cntlr->devType); return HDF_SUCCESS; } -static int32_t Hi35xxLinuxSdioBind(struct HdfDeviceObject *obj) +static int32_t LinuxSdioBind(struct HdfDeviceObject *obj) { struct MmcCntlr *cntlr = NULL; int32_t ret; - HDF_LOGE("Hi35xxLinuxSdioBind: entry!"); + HDF_LOGE("LinuxSdioBind: entry!"); if (obj == NULL) { - HDF_LOGE("Hi35xxLinuxSdioBind: Fail, obj is NULL."); + HDF_LOGE("LinuxSdioBind: Fail, obj is NULL."); return HDF_ERR_INVALID_OBJECT; } cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr)); if (cntlr == NULL) { - HDF_LOGE("Hi35xxLinuxSdioBind: no mem for MmcCntlr."); + HDF_LOGE("LinuxSdioBind: no mem for MmcCntlr."); return HDF_ERR_MALLOC_FAIL; } @@ -546,53 +567,53 @@ static int32_t Hi35xxLinuxSdioBind(struct HdfDeviceObject *obj) cntlr->hdfDevObj = obj; obj->service = &cntlr->service; /* init cntlr. */ - ret = Hi35xxLinuxSdioCntlrParse(cntlr, obj); + ret = LinuxSdioCntlrParse(cntlr, obj); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxSdioBind: cntlr parse fail."); + HDF_LOGE("LinuxSdioBind: cntlr parse fail."); goto _ERR; } ret = MmcCntlrAdd(cntlr); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxSdioBind: cntlr add fail."); + HDF_LOGE("LinuxSdioBind: cntlr add fail."); goto _ERR; } ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType); if (ret != HDF_SUCCESS) { - HDF_LOGE("Hi35xxLinuxSdioBind: alloc dev fail."); + HDF_LOGE("LinuxSdioBind: alloc dev fail."); goto _ERR; } MmcDeviceAddOps(cntlr->curDev, &g_sdioDeviceOps); - HDF_LOGD("Hi35xxLinuxSdioBind: Success!"); + HDF_LOGD("LinuxSdioBind: Success!"); return HDF_SUCCESS; _ERR: - Hi35xxLinuxSdioDeleteCntlr(cntlr); - HDF_LOGE("Hi35xxLinuxSdioBind: Fail!"); + LinuxSdioDeleteCntlr(cntlr); + HDF_LOGE("LinuxSdioBind: Fail!"); return HDF_FAILURE; } -static int32_t Hi35xxLinuxSdioInit(struct HdfDeviceObject *obj) +static int32_t LinuxSdioInit(struct HdfDeviceObject *obj) { (void)obj; - HDF_LOGD("Hi35xxLinuxSdioInit: Success!"); + HDF_LOGD("LinuxSdioInit: Success!"); return HDF_SUCCESS; } -static void Hi35xxLinuxSdioRelease(struct HdfDeviceObject *obj) +static void LinuxSdioRelease(struct HdfDeviceObject *obj) { if (obj == NULL) { return; } - Hi35xxLinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service); + LinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service); } struct HdfDriverEntry g_sdioDriverEntry = { .moduleVersion = 1, - .Bind = Hi35xxLinuxSdioBind, - .Init = Hi35xxLinuxSdioInit, - .Release = Hi35xxLinuxSdioRelease, + .Bind = LinuxSdioBind, + .Init = LinuxSdioInit, + .Release = LinuxSdioRelease, .moduleName = "HDF_PLATFORM_SDIO", }; HDF_INIT(g_sdioDriverEntry); diff --git a/platform/spi/Makefile b/platform/spi/Makefile index c9abf3a..d049969 100644 --- a/platform/spi/Makefile +++ b/platform/spi/Makefile @@ -15,11 +15,6 @@ include drivers/hdf/khdf/platform/platform.mk obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_core.o \ - $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_if.o - -ifeq ($(CONFIG_SPI_VIM3L), y) -obj-y += vim3l_spi_adapter.o -else -obj-y += hi35xx_spi_adapter.o -endif + $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_if.o \ + hi35xx_spi_adapter.o diff --git a/platform/spi/vim3l_spi_adapter.c b/platform/spi/vim3l_spi_adapter.c deleted file mode 100644 index 4f60cb5..0000000 --- a/platform/spi/vim3l_spi_adapter.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * spi_adapter.c - * - * spi driver adapter of linux - * - * 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. - * - */ - -#include -#include "device_resource_if.h" -#include "hdf_base.h" -#include "hdf_dlist.h" -#include "hdf_log.h" -#include "osal_io.h" -#include "osal_mem.h" -#include "osal_time.h" -#include "spi_core.h" -#include "spi_if.h" - -#define HDF_LOG_TAG HDF_SPI_LINUX_ADAPTER -#define SPI_DEV_NEED_FIND_NEXT 0 -#define SPI_DEV_CREAT_FAILURE 1 -#define SPI_DEV_FIND_SUCCESS 2 - -static uint16_t HdfSpiModeToLinuxMode(uint16_t mode) -{ - return ((!!(mode & SPI_CLK_PHASE) ? SPI_CPHA : 0) | - (!!(mode & SPI_CLK_POLARITY) ? SPI_CPOL : 0) | - (!!(mode & SPI_MODE_CS_HIGH) ? SPI_CS_HIGH : 0) | - (!!(mode & SPI_MODE_LSBFE) ? SPI_LSB_FIRST : 0) | - (!!(mode & SPI_MODE_3WIRE) ? SPI_3WIRE : 0) | - (!!(mode & SPI_MODE_LOOP) ? SPI_LOOP : 0) | - (!!(mode & SPI_MODE_NOCS) ? SPI_NO_CS : 0) | - (!!(mode & SPI_MODE_READY) ? SPI_READY : 0)); -} - -static uint16_t LinuxSpiModeToHdfMode(uint16_t mode) -{ - return ((!!(mode & SPI_CPHA) ? SPI_CLK_PHASE : 0) | - (!!(mode & SPI_CPOL) ? SPI_CLK_POLARITY : 0) | - (!!(mode & SPI_CS_HIGH) ? SPI_MODE_CS_HIGH : 0) | - (!!(mode & SPI_LSB_FIRST) ? SPI_MODE_LSBFE : 0) | - (!!(mode & SPI_3WIRE) ? SPI_MODE_3WIRE : 0) | - (!!(mode & SPI_LOOP) ? SPI_MODE_LOOP : 0) | - (!!(mode & SPI_NO_CS) ? SPI_MODE_NOCS : 0) | - (!!(mode & SPI_READY) ? SPI_MODE_READY : 0)); -} - -static struct SpiDev *SpiFindDeviceByCsNum(const struct SpiCntlr *cntlr, uint32_t cs) -{ - struct SpiDev *dev = NULL; - struct SpiDev *tmpDev = NULL; - - if (cntlr->numCs <= cs) { - HDF_LOGE("%s: invalid cs %u", __func__, cs); - return NULL; - } - DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(cntlr->list), struct SpiDev, list) { - if (dev->csNum == cs) { - return dev; - } - } - return NULL; -} - -static int32_t SpiAdatperSetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg) -{ - int32_t ret; - struct SpiDev *dev = NULL; - struct spi_device *spidev = NULL; - - if (cntlr == NULL || cfg == NULL) { - HDF_LOGE("%s: invalid parameter", __func__); - return HDF_ERR_INVALID_PARAM; - } - dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); - if (dev == NULL || dev->priv == NULL) { - HDF_LOGE("%s: dev is invalid", __func__); - return HDF_FAILURE; - } - - spidev = (struct spi_device *)dev->priv; - spidev->bits_per_word = cfg->bitsPerWord; - spidev->max_speed_hz = cfg->maxSpeedHz; - spidev->mode = HdfSpiModeToLinuxMode(cfg->mode); - ret = spi_setup(spidev); - if (ret != 0) { - HDF_LOGE("%s: spi_setup fail, ret is %d", __func__, ret); - return HDF_FAILURE; - } - - dev->cfg = *cfg; - return HDF_SUCCESS; -} - -static int32_t SpiAdatperGetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg) -{ - struct SpiDev *dev = NULL; - - if (cntlr == NULL || cfg == NULL) { - HDF_LOGE("%s: invalid parameter", __func__); - return HDF_ERR_INVALID_PARAM; - } - dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); - if (dev == NULL || dev->priv == NULL) { - HDF_LOGE("%s: fail, dev is invalid", __func__); - return HDF_FAILURE; - } - - *cfg = dev->cfg; - return HDF_SUCCESS; -} - -static int32_t SpiAdatperTransfer(struct SpiCntlr *cntlr, struct SpiMsg *msg, uint32_t count) -{ - int32_t ret; - uint32_t i; - struct spi_message xfer; - struct SpiDev *dev = NULL; - struct spi_transfer *transfer = NULL; - - if (cntlr == NULL || msg == NULL || count == 0) { - HDF_LOGE("%s: invalid parameter", __func__); - return HDF_ERR_INVALID_PARAM; - } - - dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); - if (dev == NULL || dev->priv == NULL) { - HDF_LOGE("%s fail, spidev is null\n", __func__); - return HDF_FAILURE; - } - - transfer = kcalloc(count, sizeof(*transfer), GFP_KERNEL); - if (transfer == NULL) { - HDF_LOGE("%s: transfer alloc memory failed", __func__); - return HDF_ERR_MALLOC_FAIL; - } - - spi_message_init(&xfer); - for (i = 0; i < count; i++) { - transfer[i].tx_buf = msg[i].wbuf; - transfer[i].rx_buf = msg[i].rbuf; - transfer[i].len = msg[i].len; - if (msg[i].speed != 0){ - transfer[i].speed_hz = msg[i].speed; - } - if (msg[i].csChange != 0){ - transfer[i].cs_change = msg[i].csChange; - } - if (msg[i].delayUs != 0){ - transfer[i].delay_usecs = msg[i].delayUs; - } - spi_message_add_tail(&transfer[i], &xfer); - } - - ret = spi_sync(dev->priv, &xfer); - kfree(transfer); - return ret; -} - -static const char *GetSpiDevName(const struct device *dev) -{ - if (dev->init_name) { - return dev->init_name; - } - return kobject_name(&dev->kobj); -} - -static void SpiDevInit(struct SpiDev *dev, const struct spi_device *spidev) -{ - dev->cfg.bitsPerWord = spidev->bits_per_word; - dev->cfg.maxSpeedHz = spidev->max_speed_hz; - dev->cfg.mode = LinuxSpiModeToHdfMode(spidev->mode); - dev->cfg.transferMode = SPI_INTERRUPT_TRANSFER; - dev->priv = (struct spi_device *)spidev; -} - -static struct SpiDev *SpiDevCreat(struct SpiCntlr *cntlr) -{ - struct SpiDev *dev = NULL; - - dev = (struct SpiDev *)OsalMemCalloc(sizeof(*dev)); - if (dev == NULL) { - HDF_LOGE("%s: OsalMemCalloc dev error", __func__); - return NULL; - } - - DListHeadInit(&dev->list); - DListInsertTail(&dev->list, &cntlr->list); - return dev; -} - -static int32_t SpiFindDeviceFromBus(struct device *dev, void *para) -{ - struct spi_device *spidev = NULL; - struct SpiDev *spi = NULL; - struct SpiCntlr *cntlr = (struct SpiCntlr *)para; - - if (dev == NULL || cntlr == NULL) { - HDF_LOGE("%s: invalid parameter", __func__); - return HDF_ERR_INVALID_PARAM; - } - - spidev = CONTAINER_OF(dev, struct spi_device, dev); - get_device(&spidev->dev); - - if (spidev->master == NULL) { - put_device(&spidev->dev); - HDF_LOGE("%s: spi_device %s -> master is NULL", __func__, GetSpiDevName(&spidev->dev)); - return HDF_ERR_INVALID_PARAM; - } - HDF_LOGI("%s: spi_device %s, find success", __func__, GetSpiDevName(&spidev->dev)); - HDF_LOGI("%s: spi_device bus_num %d, chip_select %d", __func__, - spidev->master->bus_num, spidev->chip_select); - - if (spidev->master->bus_num == cntlr->busNum && spidev->chip_select == cntlr->curCs) { - spi = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); - if (spi == NULL) { - spi = SpiDevCreat(cntlr); - } - if (spi == NULL) { - put_device(&spidev->dev); - return SPI_DEV_CREAT_FAILURE; - } - SpiDevInit(spi, spidev); - return SPI_DEV_FIND_SUCCESS; - } else { - put_device(&spidev->dev); - return SPI_DEV_NEED_FIND_NEXT; - } -} - -static int32_t SpiAdatperOpen(struct SpiCntlr *cntlr) -{ - int32_t ret; - - if (cntlr == NULL) { - HDF_LOGE("%s: fail, cntlr is NULL", __func__); - return HDF_ERR_INVALID_PARAM; - } - ret = bus_for_each_dev(&spi_bus_type, NULL, (void *)cntlr, SpiFindDeviceFromBus); - if (ret != SPI_DEV_FIND_SUCCESS) { - HDF_LOGE("%s: spidev find fail, ret is %d", __func__, ret); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -static int32_t SpiAdatperClose(struct SpiCntlr *cntlr) -{ - struct SpiDev *dev = NULL; - struct spi_device *spidev = NULL; - - if (cntlr == NULL) { - HDF_LOGE("%s: fail, cntlr is NULL", __func__); - return HDF_FAILURE; - } - - dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs); - if (dev == NULL) { - HDF_LOGE("%s fail, dev is NULL", __func__); - return HDF_FAILURE; - } - - spidev = (struct spi_device *)dev->priv; - if (spidev == NULL) { - HDF_LOGE("%s fail, spidev is NULL", __func__); - return HDF_FAILURE; - } - put_device(&spidev->dev); - return HDF_SUCCESS; -} - -struct SpiCntlrMethod g_method = { - .Transfer = SpiAdatperTransfer, - .SetCfg = SpiAdatperSetCfg, - .GetCfg = SpiAdatperGetCfg, - .Open = SpiAdatperOpen, - .Close = SpiAdatperClose, -}; - -static int32_t SpiGetBaseCfgFromHcs(struct SpiCntlr *cntlr, const struct DeviceResourceNode *node) -{ - struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - - if (iface == NULL || iface->GetUint32 == NULL) { - HDF_LOGE("%s: face is invalid", __func__); - return HDF_FAILURE; - } - if (iface->GetUint32(node, "busNum", &cntlr->busNum, 0) != HDF_SUCCESS) { - HDF_LOGE("%s: read busNum fail", __func__); - return HDF_FAILURE; - } - if (iface->GetUint32(node, "numCs", &cntlr->numCs, 0) != HDF_SUCCESS) { - HDF_LOGE("%s: read numCs fail", __func__); - return HDF_FAILURE; - } - return HDF_SUCCESS; -} - -static int SpiCntlrInit(struct SpiCntlr *cntlr, const struct HdfDeviceObject *device) -{ - int ret = HDF_SUCCESS; - - if (device->property == NULL) { - HDF_LOGE("%s: property is NULL", __func__); - return HDF_ERR_INVALID_PARAM; - } - - ret = SpiGetBaseCfgFromHcs(cntlr, device->property); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: SpiGetBaseCfgFromHcs error", __func__); - return HDF_FAILURE; - } - - cntlr->method = &g_method; - return HDF_SUCCESS; -} - -static int32_t HdfSpiDeviceBind(struct HdfDeviceObject *device) -{ - HDF_LOGI("%s: entry", __func__); - if (device == NULL) { - return HDF_ERR_INVALID_OBJECT; - } - return (SpiCntlrCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS; -} - -static int32_t HdfSpiDeviceInit(struct HdfDeviceObject *device) -{ - int ret = HDF_SUCCESS; - struct SpiCntlr *cntlr = NULL; - - HDF_LOGI("%s: entry", __func__); - if (device == NULL) { - HDF_LOGE("%s: device is NULL", __func__); - return HDF_ERR_INVALID_OBJECT; - } - cntlr = SpiCntlrFromDevice(device); - if (cntlr == NULL) { - HDF_LOGE("%s: cntlr is NULL", __func__); - return HDF_FAILURE; - } - - ret = SpiCntlrInit(cntlr, device); - if (ret != 0) { - HDF_LOGE("%s: SpiCntlrInit error", __func__); - return HDF_FAILURE; - } - return ret; -} - -static void HdfSpiDeviceRelease(struct HdfDeviceObject *device) -{ - struct SpiCntlr *cntlr = NULL; - struct SpiDev *dev = NULL; - struct SpiDev *tmpDev = NULL; - - HDF_LOGI("%s: entry", __func__); - if (device == NULL) { - HDF_LOGE("%s: device is NULL", __func__); - return; - } - cntlr = SpiCntlrFromDevice(device); - if (cntlr == NULL) { - HDF_LOGE("%s: cntlr is NULL", __func__); - return; - } - - DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(cntlr->list), struct SpiDev, list) { - DListRemove(&(dev->list)); - OsalMemFree(dev); - } - SpiCntlrDestroy(cntlr); -} - -struct HdfDriverEntry g_hdfSpiDevice = { - .moduleVersion = 1, - .moduleName = "HDF_PLATFORM_SPI", - .Bind = HdfSpiDeviceBind, - .Init = HdfSpiDeviceInit, - .Release = HdfSpiDeviceRelease, -}; - -HDF_INIT(g_hdfSpiDevice); -- Gitee