diff --git a/.gitignore b/.gitignore
index 90fb50a3dc5c..2cd966ff705a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -140,3 +140,10 @@ kernel/configs/android-*.cfg
#Ignoring Android.bp link file
#
Android.bp
+
+# ln the wakelock_profiler
+drivers/soc/oplus/owakelock
+include/soc/oplus/oplus_wakelock_profiler.h
+
+# ignore net/oplus_modules
+net/oplus_modules
diff --git a/AndroidKernel.mk b/AndroidKernel.mk
index f404b5abe9c0..887a5c6f47f8 100644
--- a/AndroidKernel.mk
+++ b/AndroidKernel.mk
@@ -208,7 +208,7 @@ $(KERNEL_HEADERS_INSTALL): $(KERNEL_OUT)
# Creating a dtb.img once the kernel is compiled if TARGET_KERNEL_APPEND_DTB is set to be false
$(INSTALLED_DTBIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL)
- cat $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/qcom/*.dtb > $@
+ cat $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/*/*.dtb > $@
.PHONY: kerneltags
kerneltags: $(KERNEL_OUT) $(KERNEL_CONFIG)
diff --git a/Kconfig b/Kconfig
index 0f27b9e7ae30..edbf510b29a3 100644
--- a/Kconfig
+++ b/Kconfig
@@ -7,6 +7,85 @@ mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration"
comment "Compiler: $(CC_VERSION_TEXT)"
+#ifdef CONFIG_OPLUS_SYSTEM_KERNEL
+config OPLUS_SYSTEM_KERNEL_QCOM
+ bool "config oplus system feature "
+ default y
+ help
+ define this config to Distinguish between qcom and mtk platform
+
+config OPLUS_SYSTEM_KERNEL_MTK
+ bool "config oplus system feature "
+ default n
+ help
+ define this config to Distinguish between qcom and mtk platform
+
+config OPLUS_SLUB_TEST
+ string
+ default "$(OPLUS_SLUB_TEST)"
+
+config OPLUS_KASAN_TEST
+ string
+ default "$(OPLUS_KASAN_TEST)"
+
+config OPLUS_KMEMLEAK_TEST
+ string
+ default "$(OPLUS_KMEMLEAK_TEST)"
+
+config OPLUS_AGING_TEST
+ string
+ default "$(OPLUS_AGING_TEST)"
+
+config OPLUS_PAGEOWNER_TEST
+ string
+ default "$(OPLUS_PAGEOWNER_TEST)"
+
+config OPLUS_AGING_DEBUG
+ bool "oplus aging add config"
+ select IPC_LOGGING
+ select QCOM_RTB
+ select QCOM_RTB_SEPARATE_CPUS
+ select SCSI_LOGGING
+ select SCSI_UFSHCD_CMD_LOGGING
+ select KPROBES
+ select MHI_DEBUG
+ default y if OPLUS_AGING_TEST = "true"
+ default n
+
+config OPLUS_KASAN_DEBUG
+ bool "oplus kasan debug"
+ select KASAN
+ select KASAN_GENERIC
+ #select KCOV
+ #select KCOV_ENABLE_COMPARISONS
+ default y if OPLUS_KASAN_TEST = "true"
+ default n
+
+config OPLUS_KMEMLEAK_DEBUG
+ bool "oplus kmemleak debug"
+ select DEBUG_KMEMLEAK
+ select SLUB_DEBUG
+ select SLABTRACE_DEBUG
+ default y if OPLUS_KMEMLEAK_TEST = "true"
+ default n
+
+config OPLUS_SLUB_DEBUG
+ bool "oplus slub debug"
+ select SLUB_DEBUG
+ select SLUB_DEBUG_ON
+ select SLUB_DEBUG_PANIC_ON
+ default y if OPLUS_SLUB_TEST = "true"
+ default n
+
+config OPLUS_PAGEOWNER_DEBUG
+ bool "oplus pageowner debug"
+ select PAGE_OWNER
+ select PAGE_OWNER_ENABLE_DEFAULT
+ default y if OPLUS_PAGEOWNER_TEST = "true"
+ default n
+#endif /*CONFIG_OPLUS_SYSTEM_KERNEL*/
+
+
source "scripts/Kconfig.include"
source "init/Kconfig"
diff --git a/Makefile b/Makefile
index 771da222fcd4..f62794a79ffb 100644
--- a/Makefile
+++ b/Makefile
@@ -450,7 +450,82 @@ KBUILD_LDFLAGS :=
GCC_PLUGINS_CFLAGS :=
CLANG_FLAGS :=
-export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
+# ifdef VENDOR_EDIT
+KBUILD_CFLAGS += -DVENDOR_EDIT
+KBUILD_CPPFLAGS += -DVENDOR_EDIT
+CFLAGS_KERNEL += -DVENDOR_EDIT
+CFLAGS_MODULE += -DVENDOR_EDIT
+# endif
+ifeq ($(BRAND_SHOW_FLAG),oneplus)
+KBUILD_CFLAGS += -DOPLUS_CUSTOM_OP_DEF
+endif
+
+# ifdef OPLUS_FEATURE_POWER_EFFICIENCY
+KBUILD_CFLAGS += -DOPLUS_FEATURE_POWER_EFFICIENCY
+KBUILD_CPPFLAGS += -DOPLUS_FEATURE_POWER_EFFICIENCY
+CFLAGS_KERNEL += -DOPLUS_FEATURE_POWER_EFFICIENCY
+CFLAGS_MODULE += -DOPLUS_FEATURE_POWER_EFFICIENCY
+# endif
+
+-include OplusKernelEnvConfig.mk
+
+#ifdef VENDOR_EDIT
+ifneq (,$(findstring Aging,$(SPECIAL_VERSION)))
+OPLUS_F2FS_DEBUG := true
+endif
+
+export OPLUS_F2FS_DEBUG
+#endif /* VENDOR_EDIT */
+
+#ifdef OPLUS_BUG_STABILITY
+#Add for Debug Config, slub/kmemleak/kasan config
+ifeq ($(AGING_DEBUG_MASK),1)
+#Agingtest enable rtb
+OPLUS_MEMLEAK_DETECT := true
+OPLUS_AGING_TEST := true
+endif
+
+ifeq ($(AGING_DEBUG_MASK),2)
+#enable kasan
+OPLUS_KASAN_TEST := true
+endif
+
+ifeq ($(AGING_DEBUG_MASK),3)
+#enable kmemleak
+OPLUS_KMEMLEAK_TEST := true
+endif
+
+ifeq ($(AGING_DEBUG_MASK),4)
+#enable rtb
+OPLUS_AGING_TEST := true
+#enable kasan
+OPLUS_SLUB_TEST := true
+endif
+
+ifeq ($(AGING_DEBUG_MASK),5)
+#enable rtb
+OPLUS_AGING_TEST := true
+#enable kasan
+OPLUS_PAGEOWNER_TEST := true
+endif
+
+export OPLUS_AGING_TEST OPLUS_KASAN_TEST OPLUS_KMEMLEAK_TEST OPLUS_SLUB_TEST OPLUS_PAGEOWNER_TEST
+#endif
+
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+#Add for memleak test
+ifeq ($(TARGET_MEMLEAK_DETECT_TEST),0)
+OPLUS_MEMLEAK_DETECT := false
+else ifeq ($(TARGET_MEMLEAK_DETECT_TEST),1)
+OPLUS_MEMLEAK_DETECT := true
+OPLUS_SLUB_TEST := true
+endif
+
+#Add for memleak test
+export OPLUS_MEMLEAK_DETECT
+#endif
+
+export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
export MAKE LEX YACC AWK GENKSYMS INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE
export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
diff --git a/OplusKernelEnvConfig.mk b/OplusKernelEnvConfig.mk
new file mode 100644
index 000000000000..2f83a55c5c5a
--- /dev/null
+++ b/OplusKernelEnvConfig.mk
@@ -0,0 +1,189 @@
+# Copyright (C), 2008-2030, OPLUS Mobile Comm Corp., Ltd
+### All rights reserved.
+###
+### File: - OplusKernelEnvConfig.mk
+### Description:
+### you can get the oplus feature variables set in android side in this file
+### this file will add global macro for common oplus added feature
+### BSP team can do customzation by referring the feature variables
+### Version: 1.0
+### Date: 2020-03-18
+### Author: Liang.Sun
+###
+### ------------------------------- Revision History: ----------------------------
+###
+### ------------------------------------------------------------------------------
+##################################################################################
+
+-include oplus_native_features.mk
+
+###ifdef OPLUS_ARCH_INJECT
+OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET :=
+
+##Add OPLUS Debug/Feature Macro Support for kernel/driver
+##ifeq ($(OPLUS_FEATURE_TEST), yes)
+## OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET += OPLUS_FEATURE_TEST
+##endif
+
+ifeq ($(OPLUS_FEATURE_WIFI_MTUDETECT), yes)
+OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET += OPLUS_FEATURE_WIFI_MTUDETECT
+endif
+
+$(foreach myfeature,$(OPLUS_CONNECTIVITY_NATIVE_FEATURE_SET),\
+ $( \
+ $(eval KBUILD_CFLAGS += -D$(myfeature)) \
+ $(eval KBUILD_CPPFLAGS += -D$(myfeature)) \
+ $(eval CFLAGS_KERNEL += -D$(myfeature)) \
+ $(eval CFLAGS_MODULE += -D$(myfeature)) \
+ ) \
+)
+###endif OPLUS_ARCH_INJECT
+
+ALLOWED_MCROS := OPLUS_FEATURE_FG_IO_OPT \
+OPLUS_FEATURE_SPECIALOPT \
+OPLUS_FEATURE_PERFORMANCE \
+OPLUS_FEATURE_STORAGE_TOOL \
+OPLUS_FEATURE_UFS_DRIVER \
+OPLUS_FEATURE_UFS_SHOW_LATENCY \
+OPLUS_FEATURE_UFSPLUS \
+OPLUS_FEATURE_PADL_STATISTICS \
+OPLUS_FEATURE_EMMC_SDCARD_OPTIMIZE \
+OPLUS_FEATURE_EMMC_DRIVER \
+OPLUS_FEATURE_HEALTHINFO \
+OPLUS_FEATURE_TASK_CPUSTATS \
+OPLUS_FEATURE_HANS_FREEZE \
+OPLUS_FEATURE_SCHED_ASSIST \
+OPLUS_FEATURE_IOMONITOR \
+OPLUS_FEATURE_TP_BSPFWUPDATE \
+OPLUS_FEATURE_LOWMEM_DBG \
+OPLUS_FEATURE_QCOM_PMICWD \
+OPLUS_FEATURE_CHG_BASIC \
+OPLUS_FEATURE_NWPOWER \
+OPLUS_FEATURE_WIFI_BDF \
+OPLUS_FEATURE_CONNFCSOFT \
+OPLUS_FEATURE_AGINGTEST \
+OPLUS_FEATURE_SENSOR_SMEM \
+OPLUS_FEATURE_SSR \
+OPLUS_FEATURE_TP_BASIC \
+OPLUS_FEATURE_EDTASK_IMPROVE \
+OPLUS_FEATURE_WIFI_SLA \
+OPLUS_FEATURE_WIFI_ROUTERBOOST \
+OPLUS_FEATURE_IPV6_OPTIMIZE \
+OPLUS_FEATURE_DATA_EVAL \
+OPLUS_FEATURE_DHCP \
+OPLUS_FEATURE_PHOENIX \
+OPLUS_FEATURE_PHOENIX_REBOOT_SPEED \
+OPLUS_FEATURE_KMSG_WB \
+OPLUS_FEATURE_SHUTDOWN_SPEED \
+OPLUS_FEATURE_OLC \
+OPLUS_FEATURE_DUMPDEVICE \
+OPLUS_FEATURE_SAUPWK \
+OPLUS_FEATURE_MEMORY_ISOLATE \
+OPLUS_FEATURE_MULTI_KSWAPD \
+OPLUS_FEATURE_WIFI_MTUDETECT \
+OPLUS_FEATURE_XTOWNER_INPUT \
+OPLUS_FEATURE_SELINUX_CONTROL_LOG \
+OPLUS_FEATURE_PXLW_IRIS5 \
+OPLUS_FEATURE_MULTI_FREEAREA \
+OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY \
+OPLUS_FEATURE_GPU_MINIDUMP \
+OPLUS_FEATURE_PROCESS_RECLAIM \
+OPLUS_FEATURE_ZRAM_OPT \
+OPLUS_FEATURE_AUDIO_FTM \
+OPLUS_FEATURE_SPEAKER_MUTE \
+OPLUS_FEATURE_MM_FEEDBACK \
+OPLUS_FEATURE_MI2S_SLAVE \
+OPLUS_FEATURE_KTV \
+OPLUS_FEATURE_QCOM_WATCHDOG \
+OPLUS_FEATURE_MEMLEAK_DETECT \
+OPLUS_FEATURE_EXFAT_SUPPORT \
+OPLUS_FEATURE_SDCARDFS_SUPPORT \
+OPLUS_FEATURE_CAMERA_OIS \
+OPLUS_BUG_COMPATIBILITY \
+OPLUS_BUG_STABILITY \
+OPLUS_BUG_DEBUG \
+OPLUS_ARCH_INJECT \
+OPLUS_ARCH_EXTENDS \
+OPLUS_FEATURE_AUDIODETECT \
+VENDOR_EDIT \
+OPLUS_FEATURE_DC \
+OPLUS_FEATURE_POWERINFO_STANDBY \
+OPLUS_FEATURE_POWERINFO_RPMH \
+OPLUS_FEATURE_CAMERA_COMMON \
+OPLUS_FEATURE_ADSP_RECOVERY \
+OPLUS_FEATURE_SMARTPA_PM \
+OPLUS_FEATURE_IMPEDANCE_MATCH \
+OPLUS_FEATURE_MODEM_MINIDUMP \
+OPLUS_FEATURE_THEIA \
+OPLUS_FEATURE_POWER_CPUFREQ \
+OPLUS_FEATURE_MIDAS \
+OPLUS_FEATURE_WIFI_OPLUSWFD \
+OPLUS_FEATURE_WIFI_DUALSTA_AP_BLACKLIST \
+OPLUS_FEATURE_WIFI_DCS_SWITCH \
+OPLUS_FEATURE_IM \
+OPLUS_FEATURE_TPD \
+OPLUS_FEATURE_APP_MONITOR\
+OPLUS_FEATURE_RT_INFO \
+OPLUS_FEATURE_MIC_VA_MIC_CLK_SWITCH
+
+ifeq ($(OPLUS_FEATURE_ADFR_KERNEL), yes)
+ $(warning add OPLUS_FEATURE_ADFR in kernel)
+ ALLOWED_MCROS += OPLUS_FEATURE_ADFR
+endif
+
+ifeq ($(OPLUS_FEATURE_GAMMA_SWITCH_KERNEL), yes)
+ $(warning add OPLUS_FEATURE_GAMMA_SWITCH_KERNEL in kernel)
+ ALLOWED_MCROS += OPLUS_FEATURE_GAMMA_SWITCH
+endif
+
+
+$(foreach myfeature,$(ALLOWED_MCROS),\
+ $(warning make $(myfeature) to be a macro here) \
+ $(eval KBUILD_CFLAGS += -D$(myfeature)) \
+ $(eval KBUILD_CPPFLAGS += -D$(myfeature)) \
+ $(eval CFLAGS_KERNEL += -D$(myfeature)) \
+ $(eval CFLAGS_MODULE += -D$(myfeature)) \
+)
+
+# BSP team can do customzation by referring the feature variables
+
+ifeq ($(OPLUS_FEATURE_SECURE_GUARD),yes)
+export CONFIG_OPLUS_SECURE_GUARD=y
+KBUILD_CFLAGS += -DCONFIG_OPLUS_SECURE_GUARD
+endif
+
+ifeq ($(OPLUS_FEATURE_SECURE_ROOTGUARD),yes)
+export CONFIG_OPLUS_ROOT_CHECK=y
+KBUILD_CFLAGS += -DCONFIG_OPLUS_ROOT_CHECK
+endif
+
+ifeq ($(OPLUS_FEATURE_SECURE_MOUNTGUARD),yes)
+export CONFIG_OPLUS_MOUNT_BLOCK=y
+KBUILD_CFLAGS += -DCONFIG_OPLUS_MOUNT_BLOCK
+endif
+
+ifeq ($(OPLUS_FEATURE_SECURE_EXECGUARD),yes)
+export CONFIG_OPLUS_EXECVE_BLOCK=y
+KBUILD_CFLAGS += -DCONFIG_OPLUS_EXECVE_BLOCK
+KBUILD_CFLAGS += -DCONFIG_OPLUS_EXECVE_REPORT
+endif
+
+ifeq ($(OPLUS_FEATURE_SECURE_KEVENTUPLOAD),yes)
+export CONFIG_OPLUS_KEVENT_UPLOAD=y
+KBUILD_CFLAGS += -DCONFIG_OPLUS_KEVENT_UPLOAD
+endif
+
+ifeq ($(OPLUS_FEATURE_SECURE_KEYINTERFACESGUARD),yes)
+KBUILD_CFLAGS += -DOPLUS_DISALLOW_KEY_INTERFACES
+endif
+
+ifeq ($(OPLUS_FEATURE_AOD_RAMLESS),yes)
+KBUILD_CFLAGS += -DOPLUS_FEATURE_AOD_RAMLESS
+KBUILD_CPPFLAGS += -DOPLUS_FEATURE_AOD_RAMLESS
+CFLAGS_KERNEL += -DOPLUS_FEATURE_AOD_RAMLESS
+CFLAGS_MODULE += -DOPLUS_FEATURE_AOD_RAMLESS
+endif
+
+ifeq ($(OPLUS_FEATURE_OP_SPECIFIC_AUDIO_KERNEL),yes)
+KBUILD_CFLAGS += -DOPLUS_FEATURE_OP_SPECIFIC_AUDIO_KERNEL
+endif
diff --git a/arch/Kconfig b/arch/Kconfig
index b892d0781c4e..65b7fc74b2ad 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -1008,6 +1008,15 @@ config RELR
well as compatible NM and OBJCOPY utilities (llvm-nm and llvm-objcopy
are compatible).
+config ARCH_HAS_NONLEAF_PMD_YOUNG
+ bool
+ depends on PGTABLE_LEVELS > 2
+ help
+ Architectures that select this option are capable of setting the
+ accessed bit in non-leaf PMD entries when using them as part of linear
+ address translations. Page table walkers that clear the accessed bit
+ may use this capability to reduce their search space.
+
source "kernel/gcov/Kconfig"
source "scripts/gcc-plugins/Kconfig"
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 28a3fa76fb3c..aa3f1784e9f2 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1421,6 +1421,7 @@ config RELOCATABLE
config RANDOMIZE_BASE
bool "Randomize the address of the kernel image"
+ depends on !KASAN
select ARM64_MODULE_PLTS if MODULES
select RELOCATABLE
help
diff --git a/arch/arm64/configs/vendor/bengal-perf_defconfig b/arch/arm64/configs/vendor/bengal-perf_defconfig
index b7dadf49a69a..85ef86e28254 100644
--- a/arch/arm64/configs/vendor/bengal-perf_defconfig
+++ b/arch/arm64/configs/vendor/bengal-perf_defconfig
@@ -378,7 +378,9 @@ CONFIG_SMB1355_SLAVE_CHARGER=y
CONFIG_QPNP_QG=y
CONFIG_SMB1398_CHARGER=y
CONFIG_THERMAL=y
-CONFIG_THERMAL_STATISTICS=y
+#ifndef OPLUS_FEATURE_THERMAL_STATISTICS
+#CONFIG_THERMAL_STATISTICS=y
+#endif
CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=10000
CONFIG_THERMAL_WRITABLE_TRIPS=y
CONFIG_THERMAL_GOV_USER_SPACE=y
@@ -632,6 +634,10 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_EFIVAR_FS=y
diff --git a/arch/arm64/configs/vendor/bengal_defconfig b/arch/arm64/configs/vendor/bengal_defconfig
index c682f557d605..ae55bfeed25e 100644
--- a/arch/arm64/configs/vendor/bengal_defconfig
+++ b/arch/arm64/configs/vendor/bengal_defconfig
@@ -391,7 +391,9 @@ CONFIG_SMB1355_SLAVE_CHARGER=y
CONFIG_QPNP_QG=y
CONFIG_SMB1398_CHARGER=y
CONFIG_THERMAL=y
-CONFIG_THERMAL_STATISTICS=y
+#ifndef OPLUS_FEATURE_THERMAL_STATISTICS
+#CONFIG_THERMAL_STATISTICS=y
+#endif
CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=10000
CONFIG_THERMAL_WRITABLE_TRIPS=y
CONFIG_THERMAL_GOV_USER_SPACE=y
@@ -661,6 +663,10 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_EFIVAR_FS=y
diff --git a/arch/arm64/configs/vendor/kona-iot-perf_defconfig b/arch/arm64/configs/vendor/kona-iot-perf_defconfig
index f7c78cf985ac..58b9f61fc415 100644
--- a/arch/arm64/configs/vendor/kona-iot-perf_defconfig
+++ b/arch/arm64/configs/vendor/kona-iot-perf_defconfig
@@ -654,6 +654,10 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_ECRYPT_FS=y
diff --git a/arch/arm64/configs/vendor/kona-iot_defconfig b/arch/arm64/configs/vendor/kona-iot_defconfig
index 149c475cf998..d99b15669bd0 100644
--- a/arch/arm64/configs/vendor/kona-iot_defconfig
+++ b/arch/arm64/configs/vendor/kona-iot_defconfig
@@ -685,6 +685,10 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_EFIVAR_FS=y
diff --git a/arch/arm64/configs/vendor/kona-perf_defconfig b/arch/arm64/configs/vendor/kona-perf_defconfig
index 6853fe5364ca..9f9185dc820e 100644
--- a/arch/arm64/configs/vendor/kona-perf_defconfig
+++ b/arch/arm64/configs/vendor/kona-perf_defconfig
@@ -5,6 +5,7 @@ CONFIG_HIGH_RES_TIMERS=y
CONFIG_PREEMPT=y
CONFIG_IRQ_TIME_ACCOUNTING=y
CONFIG_SCHED_WALT=y
+CONFIG_MMAP_LOCK_OPT=y
CONFIG_TASKSTATS=y
CONFIG_TASK_XACCT=y
CONFIG_TASK_IO_ACCOUNTING=y
@@ -21,6 +22,10 @@ CONFIG_MEMCG_SWAP=y
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CPUSETS=y
+#ifdef OPLUS_FEATURE_TASK_CPUSTATS
+CONFIG_OPLUS_SCHED=y
+CONFIG_OPLUS_CTP=y
+#endif /* OPLUS_FEATURE_TASK_CPUSTATS */
CONFIG_CGROUP_CPUACCT=y
CONFIG_CGROUP_BPF=y
CONFIG_SCHED_CORE_CTL=y
@@ -53,7 +58,7 @@ CONFIG_SCHED_MC=y
CONFIG_NR_CPUS=8
CONFIG_SECCOMP=y
CONFIG_OKL4_GUEST=y
-# CONFIG_UNMAP_KERNEL_AT_EL0 is not set
+CONFIG_UNMAP_KERNEL_AT_EL0=y
CONFIG_ARM64_SSBD=y
CONFIG_ARMV8_DEPRECATED=y
CONFIG_SWP_EMULATION=y
@@ -82,6 +87,9 @@ CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
CONFIG_CPU_BOOST=y
CONFIG_CPU_FREQ_GOV_SCHEDUTIL=y
+#ifdef VENDOR_EDIT
+CONFIG_CPU_FREQ_STAT=y
+#endif
CONFIG_ARM_QCOM_CPUFREQ_HW=y
CONFIG_MSM_TZ_LOG=y
CONFIG_ARM64_CRYPTO=y
@@ -92,6 +100,10 @@ CONFIG_CRYPTO_AES_ARM64_CE_CCM=y
CONFIG_CRYPTO_AES_ARM64_CE_BLK=y
CONFIG_CRYPTO_AES_ARM64_NEON_BLK=y
CONFIG_PANIC_ON_REFCOUNT_ERROR=y
+#ifdef OPLUS_FEATURE_UID_PERF
+CONFIG_OPLUS_FEATURE_UID_PERF=y
+#endif
+
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODVERSIONS=y
@@ -105,7 +117,10 @@ CONFIG_CFQ_GROUP_IOSCHED=y
CONFIG_IOSCHED_BFQ=y
CONFIG_BFQ_GROUP_IOSCHED=y
# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
-CONFIG_MEMORY_HOTPLUG=y
+#ifdef OPLUS_DEBUG_STABILITY
+##CONFIG_MEMORY_HOTPLUG=y
+# CONFIG_MEMORY_HOTPLUG is not set
+# endif
CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y
CONFIG_MEMORY_HOTPLUG_MOVABLE_NODE=y
CONFIG_MEMORY_HOTREMOVE=y
@@ -283,6 +298,10 @@ CONFIG_MHI_NETDEV=y
CONFIG_MHI_UCI=y
CONFIG_MHI_SATELLITE=y
CONFIG_ZRAM=y
+#ifdef OPLUS_FEATURE_ZRAM_WRITEBACK
+#CONFIG_ZRAM_WRITEBACK=y
+#CONFIG_ZWB_HANDLE=y
+#endif /* OPLUS_FEATURE_ZRAM_WRITEBACK */
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_LOOP_MIN_COUNT=16
CONFIG_BLK_DEV_RAM=y
@@ -305,6 +324,16 @@ CONFIG_SCSI_SCAN_ASYNC=y
CONFIG_SCSI_UFSHCD=y
CONFIG_SCSI_UFSHCD_PLATFORM=y
CONFIG_SCSI_UFS_QCOM=y
+CONFIG_SCSI_UFS_QCOM_ICE=y
+#ifdef OPLUS_FEATURE_UFSPLUS
+CONFIG_UFSFEATURE=y
+# CONFIG_UFSHPB is not set
+CONFIG_UFSTW=y
+CONFIG_UFSTW_IGNORE_GUARANTEE_BIT=y
+CONFIG_UFSTW_BOOT_ENABLED=y
+CONFIG_UFSHID=y
+CONFIG_UFSHID_POC=y
+#endif /*OPLUS_FEATURE_UFSPLUS*/
CONFIG_SCSI_UFS_CRYPTO=y
CONFIG_SCSI_UFS_CRYPTO_QTI=y
CONFIG_MD=y
@@ -357,6 +386,47 @@ CONFIG_TABLET_USB_HANWANG=y
CONFIG_TABLET_USB_KBTAB=y
CONFIG_INPUT_TOUCHSCREEN=y
CONFIG_TOUCHSCREEN_FTS=y
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY791=y
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY792=y
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY771=y
+CONFIG_TOUCHPANEL_SYNAPTICS=y
+CONFIG_TOUCHPANEL_SYNAPTICS_TCM_ONCELL=y
+CONFIG_TOUCHPANEL_SYNAPTICS_S3706=y
+CONFIG_TOUCHPANEL_SAMSUNG=y
+CONFIG_TOUCHPANEL_OPLUS=y
+CONFIG_TOUCHPANEL_GOODIX=y
+CONFIG_TOUCHPANEL_GOODIX_GT9886=y
+CONFIG_TOUCHPANEL_FOCAL=y
+CONFIG_TOUCHPANEL_FOCAL_FT3658U=y
+CONFIG_TOUCHIRQ_UPDATE_QOS=y
+CONFIG_TOUCHPANEL_NEW_SET_IRQ_WAKE=y
+CONFIG_OPLUS_TP_APK=y
+CONFIG_TOUCHPANEL_ALGORITHM=y
+#endif /* OPLUS_FEATURE_TP_BASIC */
+
+CONFIG_OPLUS_TRIKEY=y
+CONFIG_OPLUS_TRIKEY_MAIN=y
+CONFIG_OPLUS_TRIKEY_HALL=y
+CONFIG_IST_UP=y
+CONFIG_IST_DOWN=y
+CONFIG_MXM_UP=y
+CONFIG_MXM_DOWN=y
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_OPLUS_FW_UPDATE=y
+CONFIG_TOUCHPANEL_NOVA=y
+CONFIG_TOUCHPANEL_NOVA_NT36523_NOFLASH=y
+CONFIG_TOUCHPANEL_NT_PEN_SUPPORT=y
+CONFIG_TOUCHPANEL_NT_DIGITALNOISE_TEST=y
+#endif /*OPLUS_FEATURE_TP_BASIC*/
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_COLOR_CTRL=y
+#endif /* OPLUS_FEATURE_TP_BASIC */
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_COLOR_CTRL_V2=y
+#endif /* OPLUS_FEATURE_TP_BASIC */
CONFIG_INPUT_MISC=y
CONFIG_INPUT_QPNP_POWER_ON=y
CONFIG_INPUT_QTI_HAPTICS=y
@@ -365,6 +435,7 @@ CONFIG_INPUT_UINPUT=y
# CONFIG_LEGACY_PTYS is not set
# CONFIG_DEVMEM is not set
CONFIG_SERIAL_MSM_GENI=y
+CONFIG_SERIAL_MSM_GENI_CONSOLE=y
CONFIG_SERIAL_MSM_GENI_HALF_SAMPLING=y
CONFIG_HW_RANDOM=y
CONFIG_HW_RANDOM_MSM_LEGACY=y
@@ -390,11 +461,43 @@ CONFIG_POWER_RESET_QCOM=y
CONFIG_POWER_RESET_XGENE=y
CONFIG_POWER_RESET_SYSCON=y
CONFIG_QPNP_SMB5=y
-CONFIG_SMB1390_CHARGE_PUMP_PSY=y
-CONFIG_SMB1355_SLAVE_CHARGER=y
-CONFIG_QPNP_QNOVO5=y
+#ifdef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/06/22 for charger
+CONFIG_OPLUS_SM8250_CHARGER=y
+CONFIG_OPLUS_CHIP_SOC_NODE=y
CONFIG_QPNP_FG_GEN4=y
-CONFIG_HL6111R=y
+CONFIG_OPLUS_CHARGER_WIRELESS_PEN=y
+CONFIG_OPLUS_CHARGER_WIRELESS_RA9530=y
+#else
+#CONFIG_SMB1390_CHARGE_PUMP_PSY=y
+#CONFIG_SMB1355_SLAVE_CHARGER=y
+#CONFIG_QPNP_QNOVO5=y
+#CONFIG_QPNP_FG_GEN4=y
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_OPLUS_SHORT_HW_CHECK=y
+CONFIG_OPLUS_SHORT_USERSPACE=y
+CONFIG_OPLUS_SHIP_MODE_SUPPORT=y
+CONFIG_OPLUS_SMART_CHARGER_SUPPORT=y
+CONFIG_OPLUS_CALL_MODE_SUPPORT=y
+CONFIG_OPLUS_SHORT_C_BATT_CHECK=y
+CONFIG_OPLUS_CHECK_CHARGERID_VOLT=y
+CONFIG_OPLUS_SHORT_IC_CHECK=y
+CONFIG_SONY_FF=y
+CONFIG_HID_BETOP_FF=y
+CONFIG_HID_PLAYSTATION=y
+CONFIG_PLAYSTATION_FF=y
+#endif
+#ifndef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/12/22 for charger
+#CONFIG_HL6111R=y
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_INPUT_JOYSTICK=y
+CONFIG_JOYSTICK_XPAD=y
+CONFIG_JOYSTICK_XPAD_FF=y
+CONFIG_JOYSTICK_XPAD_LEDS=y
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
CONFIG_THERMAL=y
CONFIG_THERMAL_WRITABLE_TRIPS=y
CONFIG_THERMAL_GOV_USER_SPACE=y
@@ -442,6 +545,9 @@ CONFIG_DVB_MPQ_SW=y
CONFIG_VIDEO_V4L2_VIDEOBUF2_CORE=y
CONFIG_I2C_RTC6226_QCA=y
CONFIG_DRM=y
+#ifdef VENDOR_EDIT
+CONFIG_DRM_MSM=y
+#endif /* VENDOR_EDIT */
CONFIG_DRM_LONTIUM_LT9611UXC=y
CONFIG_BACKLIGHT_LCD_SUPPORT=y
CONFIG_BACKLIGHT_CLASS_DEVICE=y
@@ -570,8 +676,10 @@ CONFIG_MSM_QMP=y
CONFIG_IOMMU_IO_PGTABLE_FAST=y
CONFIG_ARM_SMMU=y
CONFIG_QCOM_LAZY_MAPPING=y
-CONFIG_IOMMU_DEBUG=y
-CONFIG_IOMMU_TESTS=y
+#ifdef VENDOR_EDIT
+#CONFIG_IOMMU_DEBUG=y
+#CONFIG_IOMMU_TESTS=y
+#endif
CONFIG_RPMSG_CHAR=y
CONFIG_RPMSG_QCOM_GLINK_SMEM=y
CONFIG_RPMSG_QCOM_GLINK_SPSS=y
@@ -673,11 +781,13 @@ CONFIG_ESOC_CLIENT=y
CONFIG_ESOC_MDM_4x=y
CONFIG_ESOC_MDM_DRV=y
CONFIG_SENSORS_SSC=y
+CONFIG_SENSORS_SIMULATED_HALL=y
CONFIG_QCOM_KGSL=y
CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_EXT4_FS_SECURITY=y
CONFIG_EXT4_ENCRYPTION=y
+CONFIG_OPLUS_FEATURE_OEXT4=y
CONFIG_F2FS_FS=y
CONFIG_F2FS_FS_SECURITY=y
CONFIG_FS_ENCRYPTION_INLINE_CRYPT=y
@@ -691,6 +801,13 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
+#ifdef OPLUS_FEATURE_EMMC_SDCARD_OPTIMIZE
+CONFIG_EMMC_SDCARD_OPTIMIZE=y
+#endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_ECRYPT_FS=y
@@ -737,3 +854,283 @@ CONFIG_CORESIGHT_HWEVENT=y
CONFIG_CORESIGHT_DUMMY=y
CONFIG_CORESIGHT_REMOTE_ETM=y
CONFIG_CORESIGHT_TGU=y
+#ifdef OPLUS_SYSTEM_KERNEL
+CONFIG_OPLUS_COMMON_SOFT=y
+CONFIG_OPLUS_DEVICE_IFNO=y
+CONFIG_OPLUS_RF_CABLE_MONITOR=y
+CONFIG_RECORD_MDMRST=y
+#endif
+# ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+CONFIG_OPLUS_WAKELOCK_PROFILER=y
+#endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+# ifdef VENDOR_EDIT
+CONFIG_CS_F61_NDT=y
+# endif /* VENDOR_EDIT */
+
+#ifdef OPLUS_FEATURE_INPUT_BOOST_V4
+# CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4 is not set
+#endif
+
+#ifdef OPLUS_SYSTEM_KERNEL
+#all system oplus feature writer here
+CONFIG_OPLUS_FEATURE_UBOOT_LOG=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE=y
+CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=60
+CONFIG_OPLUS_FEATURE_FEEDBACK=y
+CONFIG_OPLUS_FEATURE_OPROJECT=y
+CONFIG_OPLUS_FEATURE_CMDLINE=y
+CONFIG_OPLUS_FEATURE_PROJECTINFO=y
+CONFIG_OPLUS_FEATURE_PHOENIX=y
+CONFIG_OPLUS_FEATURE_PHOENIX_REBOOT_SPEED=y
+CONFIG_OPLUS_FEATURE_KMSG_WB=y
+CONFIG_OPLUS_FEATURE_SHUTDOWN_SPEED=y
+CONFIG_OPLUS_FEATURE_OLC=y
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
+CONFIG_OPLUS_FEATURE_FDLEAK_CHECK=y
+CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO=y
+#add for qcom minidump customized
+CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE=y
+# Add for shutdown detect
+CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT=y
+#add slabtrace function
+#CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG=y
+#endif
+#ifdef OPLUS_FEATURE_QCOM_PMICWD
+#Add for qcom pmic watchdog
+CONFIG_OPLUS_FEATURE_QCOM_PMICWD=y
+#endif
+#ifdef OPLUS_FEATURE_FINGERPRINT
+CONFIG_OPLUS_FINGERPRINT=y
+CONFIG_OPLUS_FINGERPRINT_QCOM=y
+CONFIG_OPLUS_FINGERPRINT_GOODIX_OPTICAL=y
+CONFIG_OPLUS_FINGERPRINT_JIIOV_OPTICAL=y
+#endif
+CONFIG_OPLUS_FINGERPRINT_GKI_DISABLE=y
+
+#ifdef OPLUS_FEATURE_SECURITY_COMMON
+CONFIG_OPLUS_SECURE=y
+CONFIG_OPLUS_SECURE_QCOM=y
+CONFIG_OPLUS_SECURE_COMMON=y
+#endif /* OPLUS_FEATURE_SECURITY_COMMON */
+
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+CONFIG_OPLUS_HANS=y
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
+#ifdef VENDOR_EDIT//Qingjun.Wang@BSP.Haptic,add 2020/03/17 for vib aw8697
+CONFIG_AW8697_HAPTIC=y
+CONFIG_HAPTIC_FEEDBACK=y
+#endif
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_MEM_MONITOR=y
+CONFIG_FG_TASK_UID=y
+CONFIG_OPLUS_HEALTHINFO=y
+CONFIG_SLUB_DEBUG=y
+#endif /*OPLUS_FEATURE_HEALTHINFO*/
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_JANK_INFO=y
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+CONFIG_OPLUS_FEATURE_AUDIO_OPT=y
+#endif
+
+#ifdef OPLUS_FEATURE_ZRAM_OPT
+CONFIG_OPLUS_ZRAM_OPT=y
+CONFIG_CRYPTO_LZ4=y
+CONFIG_PGTABLE_MAPPING=y
+CONFIG_CRYPTO_ZSTD=y
+#endif
+
+#ifdef OPLUS_FEATURE_MULTI_KSWAPD
+CONFIG_OPLUS_MULTI_KSWAPD=y
+CONFIG_KSWAPD_UNBIND_MAX_CPU=y
+#endif
+
+#ifdef VENDOR_EDIT
+CONFIG_REGULATOR_PM8008=y
+
+#ifdef OPLUS_FEATURE_DUMPDEVICE
+CONFIG_PSTORE=y
+CONFIG_PSTORE_CONSOLE=y
+CONFIG_PSTORE_PMSG=y
+CONFIG_PSTORE_RAM=y
+#endif
+
+CONFIG_OPLUS_FEATURE_EROFS=y
+CONFIG_EROFS_FS=y
+
+#ifdef OPLUS_FEATURE_IOMONITOR
+CONFIG_IOMONITOR=y
+#CONFIG_IOMONITOR_WITH_F2FS=n
+#endif /*OPLUS_FEATURE_IOMONITOR*/
+
+CONFIG_OPLUS_FEATURE_PMIC_MONITOR=y
+
+CONFIG_OPLUS_FEATURE_OF2FS=y
+CONFIG_OPLUS_FEATURE_PANIC_FLUSH=y
+CONFIG_F2FS_BD_STAT=y
+#CONFIG_F2FS_GRADING_SSR is not set
+
+#ifdef OPLUS_FEATURE_LOWMEM_DBG
+CONFIG_OPLUS_FEATURE_LOWMEM_DBG=y
+#endif /* OPLUS_FEATURE_LOWMEM_DBG */
+
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+CONFIG_BLK_WBT_SQ=y
+CONFIG_BLK_WBT=y
+CONFIG_OPLUS_FEATURE_UXIO_FIRST=y
+#CONFIG_OPLUS_FEATURE_SCHED_SPREAD=y
+#endif /*OPLUS_FEATURE_SCHED_ASSIST*/
+
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_KMALLOC_DEBUG=y
+CONFIG_VMALLOC_DEBUG=y
+CONFIG_DUMP_TASKS_MEM=y
+#endif /*OPLUS_FEATURE_MEMLEAK_DETECT*/
+
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_SVELTE=y
+#endif
+
+#ifdef OPLUS_FEATURE_SENSOR_DRIVER
+CONFIG_OPLUS_SENSOR_FB_QC=y
+#endif
+
+#ifdef VEDOR_EDIT
+CONFIG_OPLUS_FEATURE_RECORD_MDMRST=y
+#endif
+
+#ifdef OPLUS_ARCH_EXTENDS
+CONFIG_OPLUS_FEATURE_MM_FEEDBACK=y
+#endif
+
+#ifdef VENDOR_EDIT
+CONFIG_OPLUS_FEATURE_MIDAS=y
+#endif
+
+#ifdef CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE
+CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE=y
+#endif
+
+#ifdef OPLUS_FEATURE_ACM
+CONFIG_OPLUS_FEATURE_ACM=y
+CONFIG_OPLUS_FEATURE_ACM_LOGGING=y
+#endif /* OPLUS_FEATURE_ACM */
+
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_HARDEN_BRANCH_PREDICTOR=y
+#endif
+
+#add by shaojun.zou for cobuck opt 2021/08/16
+CONFIG_SCHED_WALT_COBUCK=y
+
+#ifdef OPLUS_FEATURE_SIM_DETECT
+CONFIG_SIM_DETECT=y
+#endif
+
+#ifdef OPLUS_FEATURE_SIM_DETECT
+CONFIG_OEM_QMI=y
+#endif
+
+CONFIG_OPLUS_FEATURE_THEIA=y
+##endif /* OPLUS_FEATURE_THEIA */
+
+#ifdef OPLUS_FEATURE_ESIM
+CONFIG_OPLUS_GPIO=y
+#endif
+
+#ifdef OPLUS_FEATURE_SAUPWK
+CONFIG_OPLUS_FEATURE_SAUPWK=y
+#endif /* OPLUS_FEATURE_SAUPWK */
+
+#ifdef OPLUS_FEATURE_RT_INFO
+CONFIG_OPLUS_FEATURE_RT_INFO=n
+#endif
+
+#ifdef OPLUS_FEATURE_TPP
+#jacky.ho@optimization add for tpp module
+CONFIG_OPLUS_FEATURE_TPP=y
+#endif /* OPLUS_FEATURE_TPP */
+
+#ifdef OPLUS_FEATURE_IM
+#ted.lin@optimization add for im module
+CONFIG_OPLUS_FEATURE_IM=y
+#endif /* OPLUS_FEATURE_IM */
+
+#ifdef OPLUS_FEATURE_ION_BOOSTPOOL
+CONFIG_OPLUS_ION_BOOSTPOOL=y
+#endif /* OPLUS_FEATURE_ION_BOOSTPOOL */
+
+#ifdef OPLUS_FEATURE_TPD
+CONFIG_OPLUS_FEATURE_TPD=y
+#endif
+#ifdef OPLUS_FEATURE_SENSOR
+CONFIG_SSC_INTERACTIVE=y
+#endif
+
+#ifdef OPLUS_FEATURE_WIFI_SLA
+#todo: need to change to m when GKI
+CONFIG_OPLUS_FEATURE_WIFI_SLA=y
+#endif /* OPLUS_FEATURE_WIFI_SLA */
+
+#ifdef OPLUS_FEATURE_WIFI_ROUTERBOOST
+CONFIG_OPLUS_FEATURE_WIFI_ROUTERBOOST=m
+#endif /* OPLUS_FEATURE_WIFI_ROUTERBOOST */
+
+CONFIG_DYNAMIC_TUNNING_SWAPPINESS=y
+
+#ifdef OPLUS_FEATURE_DATA_EVAL
+CONFIG_OPLUS_FEATURE_DATA_EVAL=y
+#endif /* OPLUS_FEATURE_DATA_VAL */
+
+#ifdef OPLUS_FEATURE_DATA_LIMIT
+CONFIG_IFB=y
+CONFIG_NET_SCH_MULTIQ=y
+CONFIG_NET_SCH_NETEM=y
+CONFIG_CLS_U32_MARK=y
+CONFIG_NET_CLS_FLOW=y
+CONFIG_NET_EMATCH_CMP=y
+CONFIG_NET_EMATCH_NBYTE=y
+CONFIG_NET_EMATCH_META=y
+CONFIG_NET_EMATCH_TEXT=y
+CONFIG_NET_ACT_GACT=y
+CONFIG_NET_ACT_MIRRED=y
+CONFIG_NET_ACT_SKBEDIT=y
+#endif /* OPLUS_FEATURE_DATA_LIMIT */
+
+#CONFIG_NANDSWAP=y
+#CONFIG_NANDSWAP_DEBUG=y
+CONFIG_FRAME_WARN=4096
+#ifdef OPLUS_FEATURE_HYBRIDSWAP
+CONFIG_HYBRIDSWAP=y
+CONFIG_HYBRIDSWAP_SWAPD=y
+CONFIG_HYBRIDSWAP_CORE=y
+#endif
+
+#ifdef OPLUS_FEATURE_DNS_HOOK
+CONFIG_OPLUS_FEATURE_DNS_HOOK=y
+#endif /* OPLUS_FEATURE_DNS_HOOK */
+
+#ifdef OPLUS_FEATURE_STATS_CALC
+CONFIG_OPLUS_FEATURE_STATS_CALC=y
+#endif /* OPLUS_FEATURE_STATS_CALC */
+CONFIG_OPLUS_BINDER_STRATEGY=n
+
+#ifdef OPLUS_FEATURE_MDMFEATURE
+CONFIG_OPLUS_FEATURE_MDMFEATURE=y
+#endif
+
+#ifdef OPLUS_FEATURE_GAME_OPT
+CONFIG_OPLUS_FEATURE_GAME_OPT=y
+#endif
+
+#ifdef Multi-gen LRU
+CONFIG_LRU_GEN=y
+CONFIG_LRU_GEN_ENABLED=n
+CONFIG_LRU_GEN_STATS=n
+#endif
+CONFIG_OPLUS_FEATURE_CPU_JANKINFO=y
+
+CONFIG_CRYPTO_CHACHA20POLY1305=y
diff --git a/arch/arm64/configs/vendor/kona_defconfig b/arch/arm64/configs/vendor/kona_defconfig
index f6dade1f20b7..406de899c463 100644
--- a/arch/arm64/configs/vendor/kona_defconfig
+++ b/arch/arm64/configs/vendor/kona_defconfig
@@ -4,6 +4,7 @@ CONFIG_HIGH_RES_TIMERS=y
CONFIG_PREEMPT=y
CONFIG_IRQ_TIME_ACCOUNTING=y
CONFIG_SCHED_WALT=y
+CONFIG_MMAP_LOCK_OPT=y
CONFIG_TASKSTATS=y
CONFIG_TASK_XACCT=y
CONFIG_TASK_IO_ACCOUNTING=y
@@ -22,11 +23,18 @@ CONFIG_BLK_CGROUP=y
CONFIG_DEBUG_BLK_CGROUP=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CPUSETS=y
+#ifdef OPLUS_FEATURE_TASK_CPUSTATS
+CONFIG_OPLUS_SCHED=y
+CONFIG_OPLUS_CTP=y
+#endif /* OPLUS_FEATURE_TASK_CPUSTATS */
CONFIG_CGROUP_CPUACCT=y
CONFIG_CGROUP_BPF=y
CONFIG_CGROUP_DEBUG=y
CONFIG_SCHED_CORE_CTL=y
CONFIG_NAMESPACES=y
+#ifdef OPLUS_FEATURE_UID_PERF
+CONFIG_OPLUS_FEATURE_UID_PERF=y
+#endif
# CONFIG_PID_NS is not set
CONFIG_SCHED_AUTOGROUP=y
CONFIG_SCHED_TUNE=y
@@ -53,7 +61,7 @@ CONFIG_SCHED_MC=y
CONFIG_NR_CPUS=8
CONFIG_SECCOMP=y
CONFIG_OKL4_GUEST=y
-# CONFIG_UNMAP_KERNEL_AT_EL0 is not set
+CONFIG_UNMAP_KERNEL_AT_EL0=y
CONFIG_ARM64_SSBD=y
CONFIG_PRINT_VMEMLAYOUT=y
CONFIG_ARMV8_DEPRECATED=y
@@ -63,6 +71,7 @@ CONFIG_SETEND_EMULATION=y
CONFIG_ARM64_SW_TTBR0_PAN=y
# CONFIG_ARM64_VHE is not set
CONFIG_RANDOMIZE_BASE=y
+CONFIG_BUILD_ARM64_KERNEL_COMPRESSION_GZIP=n
CONFIG_CMDLINE="cgroup_disable=pressure"
CONFIG_CMDLINE_EXTEND=y
CONFIG_BUILD_ARM64_UNCOMPRESSED_KERNEL=y
@@ -83,6 +92,9 @@ CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
CONFIG_CPU_BOOST=y
CONFIG_CPU_FREQ_GOV_SCHEDUTIL=y
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_CPU_FREQ_STAT=y
+#endif
CONFIG_ARM_QCOM_CPUFREQ_HW=y
CONFIG_MSM_TZ_LOG=y
CONFIG_ARM64_CRYPTO=y
@@ -109,7 +121,10 @@ CONFIG_CFQ_GROUP_IOSCHED=y
CONFIG_IOSCHED_BFQ=y
CONFIG_BFQ_GROUP_IOSCHED=y
# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
-CONFIG_MEMORY_HOTPLUG=y
+#ifdef OPLUS_DEBUG_STABILITY
+##CONFIG_MEMORY_HOTPLUG=y
+# CONFIG_MEMORY_HOTPLUG is not set
+# endif
CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y
CONFIG_MEMORY_HOTPLUG_MOVABLE_NODE=y
CONFIG_MEMORY_HOTREMOVE=y
@@ -295,6 +310,10 @@ CONFIG_MHI_NETDEV=y
CONFIG_MHI_UCI=y
CONFIG_MHI_SATELLITE=y
CONFIG_ZRAM=y
+#ifdef OPLUS_FEATURE_ZRAM_WRITEBACK
+#CONFIG_ZRAM_WRITEBACK=y
+#CONFIG_ZWB_HANDLE=y
+#endif /* OPLUS_FEATURE_ZRAM_WRITEBACK */
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_LOOP_MIN_COUNT=16
CONFIG_BLK_DEV_RAM=y
@@ -318,6 +337,15 @@ CONFIG_SCSI_UFSHCD=y
CONFIG_SCSI_UFSHCD_PLATFORM=y
CONFIG_SCSI_UFS_QCOM=y
CONFIG_SCSI_UFSHCD_CMD_LOGGING=y
+#ifdef OPLUS_FEATURE_UFSPLUS
+CONFIG_UFSFEATURE=y
+# CONFIG_UFSHPB is not set
+CONFIG_UFSTW=y
+CONFIG_UFSTW_IGNORE_GUARANTEE_BIT=y
+CONFIG_UFSTW_BOOT_ENABLED=y
+CONFIG_UFSHID=y
+CONFIG_UFSHID_POC=y
+#endif /*OPLUS_FEATURE_UFSPLUS*/
CONFIG_SCSI_UFS_CRYPTO=y
CONFIG_SCSI_UFS_CRYPTO_QTI=y
CONFIG_MD=y
@@ -369,7 +397,47 @@ CONFIG_TABLET_USB_HANWANG=y
CONFIG_TABLET_USB_KBTAB=y
CONFIG_INPUT_TOUCHSCREEN=y
CONFIG_TOUCHSCREEN_FTS=y
-CONFIG_TOUCHSCREEN_NT36XXX=y
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY791=y
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY792=y
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY771=y
+CONFIG_TOUCHPANEL_SYNAPTICS=y
+CONFIG_TOUCHPANEL_SYNAPTICS_TCM_ONCELL=y
+CONFIG_TOUCHPANEL_SYNAPTICS_S3706=y
+CONFIG_TOUCHPANEL_SAMSUNG=y
+CONFIG_TOUCHPANEL_OPLUS=y
+CONFIG_TOUCHPANEL_GOODIX=y
+CONFIG_TOUCHPANEL_GOODIX_GT9886=y
+CONFIG_TOUCHPANEL_FOCAL=y
+CONFIG_TOUCHPANEL_FOCAL_FT3658U=y
+CONFIG_TOUCHIRQ_UPDATE_QOS=y
+CONFIG_TOUCHPANEL_NEW_SET_IRQ_WAKE=y
+CONFIG_OPLUS_TP_APK=y
+CONFIG_TOUCHPANEL_ALGORITHM=y
+CONFIG_TOUCHPANEL_NOVA=y
+CONFIG_TOUCHPANEL_NOVA_NT36523_NOFLASH=y
+CONFIG_TOUCHPANEL_NT_PEN_SUPPORT=y
+CONFIG_TOUCHPANEL_NT_DIGITALNOISE_TEST=y
+#endif /* OPLUS_FEATURE_TP_BASIC */
+
+CONFIG_OPLUS_TRIKEY=y
+CONFIG_OPLUS_TRIKEY_MAIN=y
+CONFIG_OPLUS_TRIKEY_HALL=y
+CONFIG_IST_UP=y
+CONFIG_IST_DOWN=y
+CONFIG_MXM_UP=y
+CONFIG_MXM_DOWN=y
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_OPLUS_FW_UPDATE=y
+#endif /*OPLUS_FEATURE_TP_BASIC*/
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_COLOR_CTRL=y
+#endif /* OPLUS_FEATURE_TP_BASIC */
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_COLOR_CTRL_V2=y
+#endif /* OPLUS_FEATURE_TP_BASIC */
+#CONFIG_TOUCHSCREEN_NT36XXX=y
CONFIG_INPUT_MISC=y
CONFIG_INPUT_QPNP_POWER_ON=y
CONFIG_INPUT_QTI_HAPTICS=y
@@ -407,11 +475,43 @@ CONFIG_POWER_RESET_QCOM=y
CONFIG_POWER_RESET_XGENE=y
CONFIG_POWER_RESET_SYSCON=y
CONFIG_QPNP_SMB5=y
-CONFIG_SMB1390_CHARGE_PUMP_PSY=y
-CONFIG_SMB1355_SLAVE_CHARGER=y
-CONFIG_QPNP_QNOVO5=y
+#ifdef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/06/22 for charger
+CONFIG_OPLUS_SM8250_CHARGER=y
+CONFIG_OPLUS_CHIP_SOC_NODE=y
CONFIG_QPNP_FG_GEN4=y
-CONFIG_HL6111R=y
+CONFIG_OPLUS_CHARGER_WIRELESS_PEN=y
+CONFIG_OPLUS_CHARGER_WIRELESS_RA9530=y
+#else
+#CONFIG_SMB1390_CHARGE_PUMP_PSY=y
+#CONFIG_SMB1355_SLAVE_CHARGER=y
+#CONFIG_QPNP_QNOVO5=y
+#CONFIG_QPNP_FG_GEN4=y
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_OPLUS_SHORT_HW_CHECK=y
+CONFIG_OPLUS_SHORT_USERSPACE=y
+CONFIG_OPLUS_SHIP_MODE_SUPPORT=y
+CONFIG_OPLUS_SMART_CHARGER_SUPPORT=y
+CONFIG_OPLUS_CALL_MODE_SUPPORT=y
+CONFIG_OPLUS_SHORT_C_BATT_CHECK=y
+CONFIG_OPLUS_CHECK_CHARGERID_VOLT=y
+CONFIG_OPLUS_SHORT_IC_CHECK=y
+CONFIG_SONY_FF=y
+CONFIG_HID_BETOP_FF=y
+CONFIG_HID_PLAYSTATION=y
+CONFIG_PLAYSTATION_FF=y
+#endif
+#ifndef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/12/22 for charger
+#CONFIG_HL6111R=y
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_INPUT_JOYSTICK=y
+CONFIG_JOYSTICK_XPAD=y
+CONFIG_JOYSTICK_XPAD_FF=y
+CONFIG_JOYSTICK_XPAD_LEDS=y
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
CONFIG_THERMAL=y
CONFIG_THERMAL_WRITABLE_TRIPS=y
CONFIG_THERMAL_GOV_USER_SPACE=y
@@ -459,6 +559,9 @@ CONFIG_DVB_MPQ_SW=y
CONFIG_VIDEO_V4L2_VIDEOBUF2_CORE=y
CONFIG_I2C_RTC6226_QCA=y
CONFIG_DRM=y
+#ifdef VENDOR_EDIT
+CONFIG_DRM_MSM=y
+#endif /* VENDOR_EDIT */
CONFIG_DRM_LONTIUM_LT9611UXC=y
CONFIG_BACKLIGHT_LCD_SUPPORT=y
CONFIG_BACKLIGHT_CLASS_DEVICE=y
@@ -706,6 +809,7 @@ CONFIG_ESOC_MDM_4x=y
CONFIG_ESOC_MDM_DRV=y
CONFIG_ESOC_MDM_DBG_ENG=y
CONFIG_SENSORS_SSC=y
+CONFIG_SENSORS_SIMULATED_HALL=y
CONFIG_QCOM_KGSL=y
CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_POSIX_ACL=y
@@ -724,6 +828,13 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
+#ifdef OPLUS_FEATURE_EMMC_SDCARD_OPTIMIZE
+CONFIG_EMMC_SDCARD_OPTIMIZE=y
+#endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_EFIVAR_FS=y
@@ -754,7 +865,7 @@ CONFIG_CRYPTO_DEV_QCOM_ICE=y
CONFIG_XZ_DEC=y
CONFIG_PRINTK_TIME=y
CONFIG_DYNAMIC_DEBUG=y
-CONFIG_DEBUG_CONSOLE_UNHASHED_POINTERS=y
+# CONFIG_DEBUG_CONSOLE_UNHASHED_POINTERS is not set
CONFIG_DEBUG_MODULE_LOAD_INFO=y
CONFIG_DEBUG_INFO=y
CONFIG_PAGE_OWNER=y
@@ -822,3 +933,286 @@ CONFIG_CORESIGHT_HWEVENT=y
CONFIG_CORESIGHT_DUMMY=y
CONFIG_CORESIGHT_REMOTE_ETM=y
CONFIG_CORESIGHT_TGU=y
+#ifdef OPLUS_SYSTEM_KERNEL
+#/*Add for oplus project*/
+CONFIG_OPLUS_COMMON_SOFT=y
+CONFIG_OPLUS_DEVICE_IFNO=y
+CONFIG_OPLUS_RF_CABLE_MONITOR=y
+CONFIG_RECORD_MDMRST=y
+#endif
+#ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+CONFIG_OPLUS_WAKELOCK_PROFILER=y
+#endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+# ifdef VENDOR_EDIT
+CONFIG_CS_F61_NDT=y
+# endif /* VENDOR_EDIT */
+
+#ifdef OPLUS_FEATURE_INPUT_BOOST_V4
+# CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4 is not set
+#endif
+
+#ifdef OPLUS_SYSTEM_KERNEL
+#all system oplus feature writer here
+CONFIG_OPLUS_FEATURE_UBOOT_LOG=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE=y
+CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=60
+CONFIG_OPLUS_FEATURE_FEEDBACK=y
+CONFIG_OPLUS_FEATURE_OPROJECT=y
+CONFIG_OPLUS_FEATURE_CMDLINE=y
+CONFIG_OPLUS_FEATURE_PROJECTINFO=y
+CONFIG_OPLUS_FEATURE_PHOENIX=y
+CONFIG_OPLUS_FEATURE_PHOENIX_REBOOT_SPEED=y
+CONFIG_OPLUS_FEATURE_KMSG_WB=y
+CONFIG_OPLUS_FEATURE_SHUTDOWN_SPEED=y
+CONFIG_OPLUS_FEATURE_OLC=y
+CONFIG_OPLUS_FEATURE_FDLEAK_CHECK=y
+CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO=y
+#add for qcom minidump customized
+CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE=y
+#Add for shutdown detect
+CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT=y
+#add slabtrace function
+CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG=y
+#endif
+#ifdef OPLUS_FEATURE_QCOM_PMICWD
+#Add for qcom pmic watchdog
+CONFIG_OPLUS_FEATURE_QCOM_PMICWD=y
+#endif
+#ifdef OPLUS_FEATURE_FINGERPRINT
+CONFIG_OPLUS_FINGERPRINT=y
+CONFIG_OPLUS_FINGERPRINT_QCOM=y
+CONFIG_OPLUS_FINGERPRINT_GOODIX_OPTICAL=y
+CONFIG_OPLUS_FINGERPRINT_JIIOV_OPTICAL=y
+#endif
+CONFIG_OPLUS_FINGERPRINT_GKI_DISABLE=y
+
+#ifdef OPLUS_FEATURE_SECURITY_COMMON
+CONFIG_OPLUS_SECURE=y
+CONFIG_OPLUS_SECURE_QCOM=y
+CONFIG_OPLUS_SECURE_COMMON=y
+#endif /* OPLUS_FEATURE_SECURITY_COMMON */
+
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+CONFIG_OPLUS_HANS=y
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
+#ifdef VENDOR_EDIT//Qingjun.Wang@BSP.Haptic,add 2020/03/17 for vib aw8697
+CONFIG_AW8697_HAPTIC=y
+CONFIG_HAPTIC_FEEDBACK=y
+#endif
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_MEM_MONITOR=y
+CONFIG_FG_TASK_UID=y
+CONFIG_OPLUS_HEALTHINFO=y
+CONFIG_SLUB_DEBUG=y
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_JANK_INFO=y
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+CONFIG_OPLUS_FEATURE_AUDIO_OPT=y
+#endif
+
+#ifdef OPLUS_FEATURE_ZRAM_OPT
+CONFIG_OPLUS_ZRAM_OPT=y
+CONFIG_CRYPTO_LZ4=y
+CONFIG_PGTABLE_MAPPING=y
+CONFIG_CRYPTO_ZSTD=y
+#endif
+
+#ifdef OPLUS_FEATURE_MULTI_KSWAPD
+CONFIG_OPLUS_MULTI_KSWAPD=y
+CONFIG_KSWAPD_UNBIND_MAX_CPU=y
+#endif
+
+#ifdef VENDOR_EDIT
+CONFIG_REGULATOR_PM8008=y
+
+#ifdef OPLUS_FEATURE_DUMPDEVICE
+#Add for dump device info
+CONFIG_PSTORE=y
+CONFIG_PSTORE_CONSOLE=y
+CONFIG_PSTORE_PMSG=y
+CONFIG_PSTORE_RAM=y
+#endif
+
+CONFIG_OPLUS_FEATURE_EROFS=y
+CONFIG_EROFS_FS=y
+
+#ifdef OPLUS_FEATURE_IOMONITOR
+CONFIG_IOMONITOR=y
+#CONFIG_IOMONITOR_WITH_F2FS=n
+#endif /*OPLUS_FEATURE_IOMONITOR*/
+
+CONFIG_OPLUS_FEATURE_PMIC_MONITOR=y
+
+CONFIG_OPLUS_FEATURE_OF2FS=y
+CONFIG_OPLUS_FEATURE_PANIC_FLUSH=y
+CONFIG_OPLUS_FEATURE_OEXT4=y
+CONFIG_F2FS_BD_STAT=y
+#CONFIG_F2FS_GRADING_SSR is not set
+
+#ifdef OPLUS_FEATURE_LOWMEM_DBG
+CONFIG_OPLUS_FEATURE_LOWMEM_DBG=y
+#endif /* OPLUS_FEATURE_LOWMEM_DBG */
+
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+CONFIG_BLK_WBT_SQ=y
+CONFIG_BLK_WBT=y
+CONFIG_OPLUS_FEATURE_UXIO_FIRST=y
+#CONFIG_OPLUS_FEATURE_SCHED_SPREAD=y
+#endif /*OPLUS_FEATURE_SCHED_ASSIST*/
+
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_KMALLOC_DEBUG=y
+CONFIG_VMALLOC_DEBUG=y
+CONFIG_DUMP_TASKS_MEM=y
+#endif /*OPLUS_FEATURE_MEMLEAK_DETECT*/
+
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_SVELTE=y
+#endif
+
+#ifdef VEDOR_EDIT
+CONFIG_OPLUS_FEATURE_RECORD_MDMRST=y
+#endif
+
+#ifdef OPLUS_ARCH_EXTENDS
+CONFIG_OPLUS_FEATURE_MM_FEEDBACK=y
+#endif
+
+#ifdef VENDOR_EDIT
+CONFIG_OPLUS_FEATURE_MIDAS=y
+#endif
+
+#ifdef CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE
+CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE=y
+#endif
+
+#ifdef OPLUS_FEATURE_ACM
+CONFIG_OPLUS_FEATURE_ACM=y
+CONFIG_OPLUS_FEATURE_ACM_LOGGING=y
+#endif /* OPLUS_FEATURE_ACM */
+
+#ifdef OPLUS_FEATURE_SENSOR_DRIVER
+CONFIG_OPLUS_SENSOR_FB_QC=y
+#endif
+
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_HARDEN_BRANCH_PREDICTOR=y
+#endif
+
+#add by shaojun.zou for cobuck opt 2021/08/16
+CONFIG_SCHED_WALT_COBUCK=y
+
+#ifdef OPLUS_FEATURE_SIM_DETECT
+CONFIG_SIM_DETECT=y
+#endif
+
+#ifdef OPLUS_FEATURE_SIM_DETECT
+CONFIG_OEM_QMI=y
+#endif
+
+#Add for theia
+CONFIG_OPLUS_FEATURE_THEIA=y
+##endif /* OPLUS_FEATURE_THEIA */
+
+#ifdef OPLUS_FEATURE_ESIM
+CONFIG_OPLUS_GPIO=y
+#endif
+
+#ifdef OPLUS_FEATURE_SAUPWK
+#Add for theia saupwrkey
+CONFIG_OPLUS_FEATURE_SAUPWK=y
+#endif /* OPLUS_FEATURE_SAUPWK */
+
+#ifdef OPLUS_FEATURE_RT_INFO
+CONFIG_OPLUS_FEATURE_RT_INFO=n
+#endif
+
+#ifdef OPLUS_FEATURE_TPP
+#jacky.ho@optimization add for tpp module
+CONFIG_OPLUS_FEATURE_TPP=y
+#endif /* OPLUS_FEATURE_TPP */
+
+#ifdef OPLUS_FEATURE_IM
+#ted.lin@optimization add for im module
+CONFIG_OPLUS_FEATURE_IM=y
+#endif /* OPLUS_FEATURE_IM */
+
+#ifdef OPLUS_FEATURE_ION_BOOSTPOOL
+CONFIG_OPLUS_ION_BOOSTPOOL=y
+#endif /* OPLUS_FEATURE_ION_BOOSTPOOL */
+
+#ifdef OPLUS_FEATURE_TPD
+CONFIG_OPLUS_FEATURE_TPD=y
+#endif
+#ifdef OPLUS_FEATURE_SENSOR
+CONFIG_SSC_INTERACTIVE=y
+#endif
+
+#ifdef OPLUS_FEATURE_WIFI_SLA
+#todo: need to change to m when GKI
+CONFIG_OPLUS_FEATURE_WIFI_SLA=y
+#endif /* OPLUS_FEATURE_WIFI_SLA */
+
+#ifdef OPLUS_FEATURE_WIFI_ROUTERBOOST
+CONFIG_OPLUS_FEATURE_WIFI_ROUTERBOOST=m
+#endif /* OPLUS_FEATURE_WIFI_ROUTERBOOST */
+
+CONFIG_DYNAMIC_TUNNING_SWAPPINESS=y
+
+#ifdef OPLUS_FEATURE_DATA_EVAL
+CONFIG_OPLUS_FEATURE_DATA_EVAL=y
+#endif /* OPLUS_FEATURE_DATA_VAL */
+
+#ifdef OPLUS_FEATURE_DATA_LIMIT
+CONFIG_IFB=y
+CONFIG_NET_SCH_MULTIQ=y
+CONFIG_NET_SCH_NETEM=y
+CONFIG_CLS_U32_MARK=y
+CONFIG_NET_CLS_FLOW=y
+CONFIG_NET_EMATCH_CMP=y
+CONFIG_NET_EMATCH_NBYTE=y
+CONFIG_NET_EMATCH_META=y
+CONFIG_NET_EMATCH_TEXT=y
+CONFIG_NET_ACT_GACT=y
+CONFIG_NET_ACT_MIRRED=y
+CONFIG_NET_ACT_SKBEDIT=y
+#endif /* OPLUS_FEATURE_DATA_LIMIT */
+
+#CONFIG_NANDSWAP=y
+#CONFIG_NANDSWAP_DEBUG=y
+CONFIG_FRAME_WARN=4096
+#ifdef OPLUS_FEATURE_HYBRIDSWAP
+CONFIG_HYBRIDSWAP=y
+CONFIG_HYBRIDSWAP_SWAPD=y
+CONFIG_HYBRIDSWAP_CORE=y
+#endif
+
+#ifdef OPLUS_FEATURE_DNS_HOOK
+CONFIG_OPLUS_FEATURE_DNS_HOOK=y
+#endif /* OPLUS_FEATURE_DNS_HOOK */
+
+#ifdef OPLUS_FEATURE_STATS_CALC
+CONFIG_OPLUS_FEATURE_STATS_CALC=y
+#endif /* OPLUS_FEATURE_STATS_CALC */
+
+#ifdef OPLUS_FEATURE_MDMFEATURE
+CONFIG_OPLUS_FEATURE_MDMFEATURE=y
+#endif
+
+#ifdef OPLUS_FEATURE_GAME_OPT
+CONFIG_OPLUS_FEATURE_GAME_OPT=y
+#endif
+CONFIG_OPLUS_BINDER_STRATEGY=n
+
+#ifdef Multi-gen LRU
+CONFIG_LRU_GEN=y
+CONFIG_LRU_GEN_ENABLED=n
+CONFIG_LRU_GEN_STATS=n
+#endif
+CONFIG_OPLUS_FEATURE_CPU_JANKINFO=y
+
+CONFIG_CRYPTO_CHACHA20POLY1305=y
diff --git a/arch/arm64/configs/vendor/lito-perf_defconfig b/arch/arm64/configs/vendor/lito-perf_defconfig
index 5eab5980de62..c321d26e630f 100644
--- a/arch/arm64/configs/vendor/lito-perf_defconfig
+++ b/arch/arm64/configs/vendor/lito-perf_defconfig
@@ -6,6 +6,7 @@ CONFIG_HIGH_RES_TIMERS=y
CONFIG_PREEMPT=y
CONFIG_IRQ_TIME_ACCOUNTING=y
CONFIG_SCHED_WALT=y
+CONFIG_MMAP_LOCK_OPT=y
CONFIG_TASKSTATS=y
CONFIG_TASK_XACCT=y
CONFIG_TASK_IO_ACCOUNTING=y
@@ -22,6 +23,10 @@ CONFIG_MEMCG_SWAP=y
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CPUSETS=y
+#ifdef OPLUS_FEATURE_TASK_CPUSTATS
+CONFIG_OPLUS_SCHED=y
+CONFIG_OPLUS_CTP=y
+#endif /* OPLUS_FEATURE_TASK_CPUSTATS */
CONFIG_CGROUP_CPUACCT=y
CONFIG_CGROUP_BPF=y
CONFIG_SCHED_CORE_CTL=y
@@ -38,7 +43,6 @@ CONFIG_KALLSYMS_ALL=y
CONFIG_BPF_SYSCALL=y
CONFIG_BPF_JIT_ALWAYS_ON=y
CONFIG_EMBEDDED=y
-# CONFIG_SLUB_DEBUG is not set
# CONFIG_COMPAT_BRK is not set
CONFIG_SLAB_FREELIST_RANDOM=y
CONFIG_SLAB_FREELIST_HARDENED=y
@@ -64,6 +68,8 @@ CONFIG_RANDOMIZE_BASE=y
CONFIG_CMDLINE="cgroup_disable=pressure"
CONFIG_CMDLINE_EXTEND=y
# CONFIG_EFI is not set
+CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE=y
+CONFIG_IMG_GZ_DTB=y
CONFIG_BUILD_ARM64_UNCOMPRESSED_KERNEL=y
CONFIG_COMPAT=y
CONFIG_PM_WAKELOCKS=y
@@ -80,6 +86,9 @@ CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
CONFIG_CPU_BOOST=y
CONFIG_CPU_FREQ_GOV_SCHEDUTIL=y
+#ifdef VENDOR_EDIT
+CONFIG_CPU_FREQ_STAT=y
+#endif
CONFIG_ARM_QCOM_CPUFREQ_HW=y
CONFIG_ARM_QCOM_CPUFREQ_HW_DEBUG=y
CONFIG_MSM_TZ_LOG=y
@@ -106,7 +115,10 @@ CONFIG_CFQ_GROUP_IOSCHED=y
CONFIG_IOSCHED_BFQ=y
CONFIG_BFQ_GROUP_IOSCHED=y
# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
-CONFIG_MEMORY_HOTPLUG=y
+#ifdef OPLUS_DEBUG_STABILITY
+##CONFIG_MEMORY_HOTPLUG=y
+# CONFIG_MEMORY_HOTPLUG is not set
+# endif
CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y
CONFIG_MEMORY_HOTPLUG_MOVABLE_NODE=y
CONFIG_MEMORY_HOTREMOVE=y
@@ -271,6 +283,11 @@ CONFIG_CFG80211=y
CONFIG_CFG80211_INTERNAL_REGDB=y
CONFIG_RFKILL=y
CONFIG_NFC_NQ=y
+#ifdef OPLUS_NFC_BRINGUP
+#Add for the kernel Macro for NXP PN557 NFC kernel
+CONFIG_NFC_PN553_DEVICES=y
+CONFIG_NXP_P73_DEVICES=y
+#endif /*OPLUS_NFC_BRINGUP*/
CONFIG_FW_LOADER_USER_HELPER=y
CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
# CONFIG_FW_CACHE is not set
@@ -279,7 +296,7 @@ CONFIG_REGMAP_ALLOW_WRITE_DEBUGFS=y
CONFIG_DMA_CMA=y
CONFIG_MHI_BUS=y
CONFIG_ZRAM=y
-CONFIG_ZRAM_DEDUP=y
+#CONFIG_ZRAM_DEDUP=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_LOOP_MIN_COUNT=16
CONFIG_BLK_DEV_RAM=y
@@ -293,11 +310,21 @@ CONFIG_BLK_DEV_SD=y
CONFIG_CHR_DEV_SG=y
CONFIG_CHR_DEV_SCH=y
CONFIG_SCSI_CONSTANTS=y
-CONFIG_SCSI_LOGGING=y
+#CONFIG_SCSI_LOGGING=y
CONFIG_SCSI_SCAN_ASYNC=y
CONFIG_SCSI_UFSHCD=y
CONFIG_SCSI_UFSHCD_PLATFORM=y
CONFIG_SCSI_UFS_QCOM=y
+CONFIG_SCSI_UFS_QCOM_ICE=y
+#ifdef OPLUS_FEATURE_UFSPLUS
+CONFIG_UFSFEATURE=y
+# CONFIG_UFSHPB is not set
+CONFIG_UFSTW=y
+# CONFIG_HPB_SUP_ONLY_4 is not set
+# CONFIG_HPB_SUP_8_TO_32 is not set
+# CONFIG_HPB_SUP_OVER_36 is not set
+CONFIG_UFSTW_IGNORE_GUARANTEE_BIT=y
+#endif /*OPLUS_FEATURE_UFSPLUS*/
CONFIG_SCSI_UFS_CRYPTO=y
CONFIG_SCSI_UFS_CRYPTO_QTI=y
CONFIG_MD=y
@@ -344,10 +371,29 @@ CONFIG_TABLET_USB_GTCO=y
CONFIG_TABLET_USB_HANWANG=y
CONFIG_TABLET_USB_KBTAB=y
CONFIG_INPUT_TOUCHSCREEN=y
-CONFIG_SECURE_TOUCH_SYNAPTICS_DSX=y
+CONFIG_OPLUS_TRI_STATE_KEY=y
+CONFIG_TOUCHIRQ_UPDATE_QOS=y
+CONFIG_TOUCHPANEL_NEW_SET_IRQ_WAKE=y
+CONFIG_TOUCHPANEL_OPLUS=y
+CONFIG_TOUCHPANEL_ALGORITHM=y
+CONFIG_TOUCHPANEL_SYNAPTICS=y
+CONFIG_TOUCHPANEL_GOODIX=y
+CONFIG_TOUCHPANEL_SAMSUNG=y
+CONFIG_TOUCHPANEL_SYNAPTICS_TCM_ONCELL=y
+CONFIG_TOUCHPANEL_GOODIX_GT9886=y
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY771=y
+CONFIG_TOUCHPANEL_FOCAL=y
+CONFIG_TOUCHPANEL_FOCAL_FT3518=y
+CONFIG_TOUCHPANEL_NOVA=y
+CONFIG_TOUCHPANEL_NOVA_NT36672C_NOFLASH=y
+CONFIG_TOUCHPANEL_NT_DIGITALNOISE_TEST=y
+CONFIG_TOUCHPANEL_ILITEK=y
+CONFIG_TOUCHPANEL_ILITEK_ILITEK7807S=y
+# CONFIG_SECURE_TOUCH_SYNAPTICS_DSX is not set
CONFIG_TOUCHSCREEN_SYNAPTICS_TCM_REFLASH=y
CONFIG_TOUCHSCREEN_SYNAPTICS_TCM_RECOVERY=y
-CONFIG_TOUCHSCREEN_FTS=y
+CONFIG_TOUCHSCREEN_FTS=n
+CONFIG_TOUCHSCREEN_ST=n
CONFIG_INPUT_MISC=y
CONFIG_INPUT_QPNP_POWER_ON=y
CONFIG_INPUT_UINPUT=y
@@ -356,6 +402,7 @@ CONFIG_INPUT_UINPUT=y
# CONFIG_LEGACY_PTYS is not set
# CONFIG_DEVMEM is not set
CONFIG_SERIAL_MSM_GENI=y
+CONFIG_SERIAL_MSM_GENI_CONSOLE=y
CONFIG_SERIAL_MSM_GENI_HALF_SAMPLING=y
CONFIG_TTY_PRINTK=y
CONFIG_HW_RANDOM=y
@@ -379,12 +426,44 @@ CONFIG_POWER_RESET_QCOM=y
CONFIG_POWER_RESET_XGENE=y
CONFIG_POWER_RESET_SYSCON=y
CONFIG_QPNP_SMB5=y
-CONFIG_SMB1390_CHARGE_PUMP_PSY=y
+#ifdef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/06/22 for charger
+CONFIG_OPLUS_SM7250R_CHARGER=y
CONFIG_SMB1355_SLAVE_CHARGER=y
-CONFIG_QPNP_QG=y
-CONFIG_SMB1398_CHARGER=y
+CONFIG_OPLUS_CHIP_SOC_NODE=y
+CONFIG_OPLUS_QPNP_QG=y
+#else
+#CONFIG_SMB1390_CHARGE_PUMP_PSY=y
+#CONFIG_SMB1398_CHARGER=y
+#CONFIG_QPNP_QG=y
+#CONFIG_QPNP_FG_GEN4=y
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_OPLUS_SHORT_HW_CHECK=y
+CONFIG_OPLUS_SHORT_USERSPACE=y
+CONFIG_OPLUS_SHIP_MODE_SUPPORT=y
+CONFIG_OPLUS_SMART_CHARGER_SUPPORT=y
+CONFIG_OPLUS_CHARGER_OPTIGA=y
+CONFIG_OPLUS_SHORT_C_BATT_CHECK=y
+CONFIG_OPLUS_CHECK_CHARGERID_VOLT=y
+CONFIG_OPLUS_SHORT_IC_CHECK=y
+CONFIG_SONY_FF=y
+CONFIG_HID_BETOP_FF=y
+CONFIG_HID_PLAYSTATION=y
+CONFIG_PLAYSTATION_FF=y
+#endif
+#ifndef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/12/22 for charger
+#CONFIG_HL6111R=y
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_INPUT_JOYSTICK=y
+CONFIG_JOYSTICK_XPAD=y
+CONFIG_JOYSTICK_XPAD_FF=y
+CONFIG_JOYSTICK_XPAD_LEDS=y
+#endif /* OPLUS_FEATURE_CHG_BASIC */
CONFIG_THERMAL=y
-CONFIG_THERMAL_STATISTICS=y
+#ifndef OPLUS_FEATURE_THERMAL_STATISTICS
+#CONFIG_THERMAL_STATISTICS=y
+#endif
CONFIG_THERMAL_WRITABLE_TRIPS=y
CONFIG_THERMAL_GOV_USER_SPACE=y
CONFIG_THERMAL_GOV_LOW_LIMITS=y
@@ -395,6 +474,9 @@ CONFIG_THERMAL_TSENS=y
CONFIG_QTI_ADC_TM=y
CONFIG_QTI_VIRTUAL_SENSOR=y
CONFIG_QTI_QMI_SENSOR=y
+CONFIG_SSC_INTERACTIVE=y
+CONFIG_OPLUS_SENSOR_FB_QC=y
+CONFIG_SENSORS_SSC=y
CONFIG_QTI_BCL_PMIC5=y
CONFIG_QTI_BCL_SOC_DRIVER=y
CONFIG_QTI_QMI_COOLING_DEVICE=y
@@ -417,12 +499,16 @@ CONFIG_REGULATOR_REFGEN=y
CONFIG_REGULATOR_RPMH=y
CONFIG_REGULATOR_STUB=y
CONFIG_REGULATOR_PM8008=y
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_REGULATOR_TPS65132=y
+CONFIG_REGULATOR_TPS65132_FOR_20267=y
+#endif /* OPLUS_BUG_STABILITY */
CONFIG_MEDIA_SUPPORT=y
CONFIG_MEDIA_CAMERA_SUPPORT=y
CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
CONFIG_MEDIA_CONTROLLER=y
CONFIG_VIDEO_V4L2_SUBDEV_API=y
-CONFIG_VIDEO_ADV_DEBUG=y
+#CONFIG_VIDEO_ADV_DEBUG=y
CONFIG_VIDEO_FIXED_MINOR_RANGES=y
CONFIG_V4L_PLATFORM_DRIVERS=y
CONFIG_MSM_NPU=y
@@ -431,6 +517,10 @@ CONFIG_DVB_MPQ_DEMUX=m
CONFIG_DVB_MPQ_SW=y
CONFIG_VIDEO_V4L2_VIDEOBUF2_CORE=y
CONFIG_DRM=y
+#ifdef VENDOR_EDIT
+CONFIG_DRM_MSM=y
+#endif /* VENDOR_EDIT */
+CONFIG_DRM_LONTIUM_LT9611UXC=y
CONFIG_BACKLIGHT_LCD_SUPPORT=y
CONFIG_BACKLIGHT_CLASS_DEVICE=y
CONFIG_BACKLIGHT_QCOM_SPMI_WLED=y
@@ -661,6 +751,15 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+CONFIG_OPLUS_FEATURE_EROFS=y
+CONFIG_EROFS_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
+#ifdef OPLUS_FEATURE_EMMC_SDCARD_OPTIMIZE
+CONFIG_EMMC_SDCARD_OPTIMIZE=y
+#endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_ECRYPT_FS=y
@@ -694,7 +793,7 @@ CONFIG_SCHEDSTATS=y
# CONFIG_DEBUG_PREEMPT is not set
CONFIG_DEBUG_LIST=y
CONFIG_IPC_LOGGING=y
-CONFIG_DEBUG_ALIGN_RODATA=y
+#CONFIG_DEBUG_ALIGN_RODATA=y
CONFIG_ARM64_STRICT_BREAK_BEFORE_MAKE=y
CONFIG_CORESIGHT=y
CONFIG_CORESIGHT_LINK_AND_SINK_TMC=y
@@ -708,3 +807,262 @@ CONFIG_CORESIGHT_HWEVENT=y
CONFIG_CORESIGHT_DUMMY=y
CONFIG_CORESIGHT_REMOTE_ETM=y
CONFIG_CORESIGHT_TGU=y
+#ifdef OPLUS_SYSTEM_KERNEL
+#/*Add for oplus project*/
+CONFIG_OPLUS_COMMON_SOFT=y
+CONFIG_OPLUS_DEVICE_IFNO=y
+CONFIG_OPLUS_RF_CABLE_MONITOR=y
+CONFIG_RECORD_MDMRST=y
+#endif
+#ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+CONFIG_OPLUS_WAKELOCK_PROFILER=y
+#endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+# ifdef VENDOR_EDIT
+CONFIG_CS_F61_NDT=y
+# endif /* VENDOR_EDIT */
+
+
+#ifdef OPLUS_SYSTEM_KERNEL
+#all system oplus feature writer here
+CONFIG_OPLUS_FEATURE_UBOOT_LOG=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE=y
+CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=60
+CONFIG_OPLUS_FEATURE_FEEDBACK=y
+CONFIG_OPLUS_FEATURE_OPROJECT=y
+CONFIG_OPLUS_FEATURE_CMDLINE=y
+CONFIG_OPLUS_FEATURE_PROJECTINFO=y
+CONFIG_OPLUS_FEATURE_PHOENIX=y
+CONFIG_OPLUS_FEATURE_PHOENIX_REBOOT_SPEED=y
+CONFIG_OPLUS_FEATURE_KMSG_WB=y
+CONFIG_OPLUS_FEATURE_SHUTDOWN_SPEED=y
+CONFIG_OPLUS_FEATURE_OLC=y
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
+CONFIG_OPLUS_FEATURE_FDLEAK_CHECK=y
+#add for qcom minidump customized
+CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE=y
+#Add for shutdown detect
+CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT=y
+#add slabtrace function
+# CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG is not set
+#enable oplus misc feature
+#CONFIG_OPLUS_FEATURE_MISC is not set
+#endif
+#ifdef OPLUS_FEATURE_QCOM_PMICWD
+# Add for qcom pmic watchdog
+CONFIG_OPLUS_FEATURE_QCOM_PMICWD=y
+#endif
+#ifdef OPLUS_FEATURE_FINGERPRINT
+CONFIG_OPLUS_FINGERPRINT=y
+CONFIG_OPLUS_FINGERPRINT_QCOM=y
+CONFIG_OPLUS_FINGERPRINT_GOODIX_OPTICAL=y
+CONFIG_OPLUS_FINGERPRINT_JIIOV_OPTICAL=y
+CONFIG_OPLUS_FINGERPRINT_SILEAD=y
+#endif
+CONFIG_OPLUS_FINGERPRINT_GKI_DISABLE=y
+
+#ifdef OPLUS_FEATURE_SECURITY_COMMON
+CONFIG_OPLUS_SECURE=y
+CONFIG_OPLUS_SECURE_QCOM=y
+CONFIG_OPLUS_SECURE_COMMON=y
+#endif /* OPLUS_FEATURE_SECURITY_COMMON */
+
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+CONFIG_OPLUS_HANS=y
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
+#ifdef VENDOR_EDIT//Qingjun.Wang@BSP.Haptic,add 2020/03/17 for vib aw8697
+CONFIG_AW8697_HAPTIC=y
+#endif
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_MEM_MONITOR=y
+CONFIG_FG_TASK_UID=y
+CONFIG_OPLUS_HEALTHINFO=y
+CONFIG_SLUB_DEBUG=y
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_JANK_INFO=y
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
+#ifdef OPLUS_FEATURE_ZRAM_OPT
+CONFIG_OPLUS_ZRAM_OPT=y
+CONFIG_CRYPTO_LZ4=y
+CONFIG_PGTABLE_MAPPING=y
+CONFIG_CRYPTO_ZSTD=y
+#endif
+#ifdef OPLUS_FEATURE_MULTI_KSWAPD
+CONFIG_OPLUS_MULTI_KSWAPD=y
+CONFIG_KSWAPD_UNBIND_MAX_CPU=y
+#endif
+#ifdef VENDOR_EDIT
+CONFIG_REGULATOR_PM8008=y
+#ifdef OPLUS_FEATURE_DUMPDEVICE
+#Add for dump device info
+CONFIG_PSTORE=y
+CONFIG_PSTORE_CONSOLE=y
+CONFIG_PSTORE_PMSG=y
+CONFIG_PSTORE_RAM=y
+#endif
+#ifdef OPLUS_FEATURE_IOMONITOR
+#CONFIG_IOMONITOR=y
+#CONFIG_IOMONITOR_WITH_F2FS=n
+#endif /*OPLUS_FEATURE_IOMONITOR*/
+CONFIG_OPLUS_FEATURE_PMIC_MONITOR=y
+CONFIG_OPLUS_FEATURE_OF2FS=y
+CONFIG_OPLUS_FEATURE_PANIC_FLUSH=y
+CONFIG_OPLUS_FEATURE_OEXT4=y
+CONFIG_F2FS_BD_STAT=y
+#CONFIG_F2FS_GRADING_SSR is not set
+
+#ifdef OPLUS_FEATURE_LOWMEM_DBG
+CONFIG_OPLUS_FEATURE_LOWMEM_DBG=y
+#endif /* OPLUS_FEATURE_LOWMEM_DBG */
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+CONFIG_BLK_WBT_SQ=y
+CONFIG_BLK_WBT=y
+CONFIG_OPLUS_FEATURE_UXIO_FIRST=y
+#endif /*OPLUS_FEATURE_SCHED_ASSIST*/
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_KMALLOC_DEBUG=y
+CONFIG_VMALLOC_DEBUG=y
+CONFIG_DUMP_TASKS_MEM=y
+#endif /*OPLUS_FEATURE_MEMLEAK_DETECT*/
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_SVELTE=y
+#endif
+#ifdef VEDOR_EDIT
+CONFIG_OPLUS_FEATURE_RECORD_MDMRST=y
+#endif
+#ifdef OPLUS_ARCH_EXTENDS
+CONFIG_OPLUS_FEATURE_MM_FEEDBACK=y
+#endif
+
+#ifdef OPLUS_FEATURE_MIDAS
+CONFIG_OPLUS_FEATURE_MIDAS=y
+#endif
+
+#ifdef CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE
+CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE=y
+#endif
+
+#ifdef OPLUS_FEATURE_ACM
+CONFIG_OPLUS_FEATURE_ACM=y
+CONFIG_OPLUS_FEATURE_ACM_LOGGING=y
+#endif /* OPLUS_FEATURE_ACM */
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_HARDEN_BRANCH_PREDICTOR=y
+#endif
+CONFIG_OPLUS_FEATURE_THEIA=y
+##endif /* OPLUS_FEATURE_THEIA */
+
+#ifdef OPLUS_FEATURE_SAUPWK
+CONFIG_OPLUS_FEATURE_SAUPWK=y
+#endif /* OPLUS_FEATURE_SAUPWK */
+
+#ifdef OPLUS_FEATURE_DUMP_DEVICE_INFO
+CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO=y
+#endif /* OPLUS_FEATURE_DUMP_DEVICE_INFO */
+
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_UNMAP_KERNEL_AT_EL0=y
+#endif
+
+#ifdef OPLUS_FEATURE_GPIO_NC
+CONFIG_OPLUS_GPIO_NC=y
+#endif
+
+#ifdef OPLUS_FEATURE_BOOTLOADER_LOG
+CONFIG_BOOTLOADER_LOG=y
+#endif
+#ifdef OPLUS_FEATURE_PARAM
+CONFIG_PARAM_READ_WRITE=y
+#endif
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_SIM_DETECT=y
+#endif
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_OPLUS_FW_UPDATE=y
+#endif /*OPLUS_FEATURE_TP_BASIC*/
+
+#ifdef OPLUS_FEATURE_ION_BOOSTPOOL
+#CONFIG_OPLUS_ION_BOOSTPOOL=y ,Add for disable boost pool ,fill generic ION POOL
+#endif /* OPLUS_FEATURE_ION_BOOSTPOOL */
+
+#ifdef OPLUS_FEATURE_WIFI_SLA
+#todo: need to change to m when GKI
+CONFIG_OPLUS_FEATURE_WIFI_SLA=y
+#endif /* OPLUS_FEATURE_WIFI_SLA */
+
+#ifdef OPLUS_FEATURE_WIFI_ROUTERBOOST
+CONFIG_OPLUS_FEATURE_WIFI_ROUTERBOOST=m
+#endif /* OPLUS_FEATURE_WIFI_ROUTERBOOST */
+
+#ifdef OPLUS_FEATURE_DATA_EVAL
+CONFIG_OPLUS_FEATURE_DATA_EVAL=y
+#endif /* OPLUS_FEATURE_DATA_VAL */
+
+#ifdef OPLUS_FEATURE_DATA_LIMIT
+CONFIG_IFB=y
+CONFIG_NET_SCH_MULTIQ=y
+CONFIG_NET_SCH_NETEM=y
+CONFIG_CLS_U32_MARK=y
+CONFIG_NET_CLS_FLOW=y
+CONFIG_NET_EMATCH_CMP=y
+CONFIG_NET_EMATCH_NBYTE=y
+CONFIG_NET_EMATCH_META=y
+CONFIG_NET_EMATCH_TEXT=y
+CONFIG_NET_ACT_GACT=y
+CONFIG_NET_ACT_MIRRED=y
+CONFIG_NET_ACT_SKBEDIT=y
+#endif /* OPLUS_FEATURE_DATA_LIMIT */
+
+#CONFIG_DEBUG_SPINLOCK=y
+
+#CONFIG_NANDSWAP=y
+#CONFIG_NANDSWAP_DEBUG=y
+#ifdef OPLUS_FEATURE_IM
+#ted.lin@optimization add for im module
+CONFIG_OPLUS_FEATURE_IM=y
+#endif /* OPLUS_FEATURE_IM */
+
+CONFIG_FRAME_WARN=4096
+
+CONFIG_DYNAMIC_TUNNING_SWAPPINESS=y
+
+#ifdef OPLUS_FEATURE_HYBRIDSWAP
+CONFIG_HYBRIDSWAP=y
+CONFIG_HYBRIDSWAP_SWAPD=y
+CONFIG_HYBRIDSWAP_CORE=y
+#endif
+
+#ifdef OPLUS_FEATURE_UID_PERF
+CONFIG_OPLUS_FEATURE_UID_PERF=y
+#endif
+
+#ifdef OPLUS_FEATURE_ESIM
+CONFIG_OPLUS_GPIO=y
+#endif /* OPLUS_FEATURE_ESIM */
+
+#ifdef OPLUS_FEATURE_TPD
+CONFIG_OPLUS_FEATURE_TPD=y
+#endif
+
+#ifdef OPLUS_FEATURE_DNS_HOOK
+CONFIG_OPLUS_FEATURE_DNS_HOOK=y
+#endif /* OPLUS_FEATURE_DNS_HOOK */
+
+#ifdef OPLUS_FEATURE_STATS_CALC
+CONFIG_OPLUS_FEATURE_STATS_CALC=y
+#endif /* OPLUS_FEATURE_STATS_CALC */
+CONFIG_OPLUS_BINDER_STRATEGY=n
+
+#ifdef OPLUS_FEATURE_MDMFEATURE
+CONFIG_OPLUS_FEATURE_MDMFEATURE=y
+#endif
+
+#ifdef OPLUS_FEATURE_GAME_OPT
+CONFIG_OPLUS_FEATURE_GAME_OPT=y
+#endif
+CONFIG_OPLUS_FEATURE_CPU_JANKINFO=y
diff --git a/arch/arm64/configs/vendor/lito_defconfig b/arch/arm64/configs/vendor/lito_defconfig
index f8d3d3081b0c..095e5d50c6ad 100644
--- a/arch/arm64/configs/vendor/lito_defconfig
+++ b/arch/arm64/configs/vendor/lito_defconfig
@@ -5,6 +5,7 @@ CONFIG_HIGH_RES_TIMERS=y
CONFIG_PREEMPT=y
CONFIG_IRQ_TIME_ACCOUNTING=y
CONFIG_SCHED_WALT=y
+CONFIG_MMAP_LOCK_OPT=y
CONFIG_TASKSTATS=y
CONFIG_TASK_XACCT=y
CONFIG_TASK_IO_ACCOUNTING=y
@@ -23,6 +24,10 @@ CONFIG_BLK_CGROUP=y
CONFIG_DEBUG_BLK_CGROUP=y
CONFIG_CGROUP_FREEZER=y
CONFIG_CPUSETS=y
+#ifdef OPLUS_FEATURE_TASK_CPUSTATS
+CONFIG_OPLUS_SCHED=y
+CONFIG_OPLUS_CTP=y
+#endif /* OPLUS_FEATURE_TASK_CPUSTATS */
CONFIG_CGROUP_CPUACCT=y
CONFIG_CGROUP_BPF=y
CONFIG_CGROUP_DEBUG=y
@@ -64,7 +69,7 @@ CONFIG_ARM64_SW_TTBR0_PAN=y
CONFIG_RANDOMIZE_BASE=y
CONFIG_CMDLINE="cgroup_disable=pressure"
CONFIG_CMDLINE_EXTEND=y
-CONFIG_BUILD_ARM64_UNCOMPRESSED_KERNEL=y
+CONFIG_BUILD_ARM64_KERNEL_COMPRESSION_GZIP=y
CONFIG_COMPAT=y
CONFIG_PM_WAKELOCKS=y
CONFIG_PM_WAKELOCKS_LIMIT=0
@@ -81,6 +86,9 @@ CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
CONFIG_CPU_BOOST=y
CONFIG_CPU_FREQ_GOV_SCHEDUTIL=y
+#ifdef VENDOR_EDIT
+CONFIG_CPU_FREQ_STAT=y
+#endif
CONFIG_ARM_QCOM_CPUFREQ_HW=y
CONFIG_ARM_QCOM_CPUFREQ_HW_DEBUG=y
CONFIG_MSM_TZ_LOG=y
@@ -108,7 +116,10 @@ CONFIG_CFQ_GROUP_IOSCHED=y
CONFIG_IOSCHED_BFQ=y
CONFIG_BFQ_GROUP_IOSCHED=y
# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
-CONFIG_MEMORY_HOTPLUG=y
+#ifdef OPLUS_DEBUG_STABILITY
+##CONFIG_MEMORY_HOTPLUG=y
+# CONFIG_MEMORY_HOTPLUG is not set
+# endif
CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=y
CONFIG_MEMORY_HOTPLUG_MOVABLE_NODE=y
CONFIG_MEMORY_HOTREMOVE=y
@@ -277,6 +288,11 @@ CONFIG_CFG80211=y
CONFIG_CFG80211_INTERNAL_REGDB=y
CONFIG_RFKILL=y
CONFIG_NFC_NQ=y
+#ifdef OPLUS_NFC_BRINGUP
+#Add for the kernel Macro for NXP PN557 NFC kernel
+CONFIG_NFC_PN553_DEVICES=y
+CONFIG_NXP_P73_DEVICES=y
+#endif /*OPLUS_NFC_BRINGUP*/
CONFIG_FW_LOADER_USER_HELPER=y
CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
# CONFIG_FW_CACHE is not set
@@ -285,7 +301,7 @@ CONFIG_REGMAP_ALLOW_WRITE_DEBUGFS=y
CONFIG_DMA_CMA=y
CONFIG_MHI_BUS=y
CONFIG_ZRAM=y
-CONFIG_ZRAM_DEDUP=y
+#CONFIG_ZRAM_DEDUP=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_LOOP_MIN_COUNT=16
CONFIG_BLK_DEV_RAM=y
@@ -305,6 +321,15 @@ CONFIG_SCSI_UFSHCD=y
CONFIG_SCSI_UFSHCD_PLATFORM=y
CONFIG_SCSI_UFS_QCOM=y
CONFIG_SCSI_UFSHCD_CMD_LOGGING=y
+#ifdef OPLUS_FEATURE_UFSPLUS
+CONFIG_UFSFEATURE=y
+# CONFIG_UFSHPB is not set
+CONFIG_UFSTW=y
+# CONFIG_HPB_SUP_ONLY_4 is not set
+# CONFIG_HPB_SUP_8_TO_32 is not set
+# CONFIG_HPB_SUP_OVER_36 is not set
+CONFIG_UFSTW_IGNORE_GUARANTEE_BIT=y
+#endif /*OPLUS_FEATURE_UFSPLUS*/
CONFIG_SCSI_UFS_CRYPTO=y
CONFIG_SCSI_UFS_CRYPTO_QTI=y
CONFIG_MD=y
@@ -351,10 +376,29 @@ CONFIG_TABLET_USB_GTCO=y
CONFIG_TABLET_USB_HANWANG=y
CONFIG_TABLET_USB_KBTAB=y
CONFIG_INPUT_TOUCHSCREEN=y
-CONFIG_SECURE_TOUCH_SYNAPTICS_DSX=y
+CONFIG_OPLUS_TRI_STATE_KEY=y
+CONFIG_TOUCHIRQ_UPDATE_QOS=y
+CONFIG_TOUCHPANEL_NEW_SET_IRQ_WAKE=y
+CONFIG_TOUCHPANEL_OPLUS=y
+CONFIG_TOUCHPANEL_ALGORITHM=y
+CONFIG_TOUCHPANEL_SYNAPTICS=y
+CONFIG_TOUCHPANEL_GOODIX=y
+CONFIG_TOUCHPANEL_SAMSUNG=y
+CONFIG_TOUCHPANEL_SYNAPTICS_TCM_ONCELL=y
+CONFIG_TOUCHPANEL_GOODIX_GT9886=y
+CONFIG_TOUCHPANEL_SAMSUNG_S6SY771=y
+CONFIG_TOUCHPANEL_FOCAL=y
+CONFIG_TOUCHPANEL_FOCAL_FT3518=y
+CONFIG_TOUCHPANEL_NOVA=y
+CONFIG_TOUCHPANEL_NOVA_NT36672C_NOFLASH=y
+CONFIG_TOUCHPANEL_NT_DIGITALNOISE_TEST=y
+CONFIG_TOUCHPANEL_ILITEK=y
+CONFIG_TOUCHPANEL_ILITEK_ILITEK7807S=y
+# CONFIG_SECURE_TOUCH_SYNAPTICS_DSX is not set
CONFIG_TOUCHSCREEN_SYNAPTICS_TCM_REFLASH=y
CONFIG_TOUCHSCREEN_SYNAPTICS_TCM_RECOVERY=y
-CONFIG_TOUCHSCREEN_FTS=y
+CONFIG_TOUCHSCREEN_FTS=n
+CONFIG_TOUCHSCREEN_ST=n
CONFIG_INPUT_MISC=y
CONFIG_INPUT_QPNP_POWER_ON=y
CONFIG_INPUT_UINPUT=y
@@ -387,12 +431,46 @@ CONFIG_POWER_RESET_QCOM=y
CONFIG_POWER_RESET_XGENE=y
CONFIG_POWER_RESET_SYSCON=y
CONFIG_QPNP_SMB5=y
-CONFIG_SMB1390_CHARGE_PUMP_PSY=y
+#ifdef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/06/22 for charger
+CONFIG_OPLUS_SM7250R_CHARGER=y
CONFIG_SMB1355_SLAVE_CHARGER=y
-CONFIG_QPNP_QG=y
-CONFIG_SMB1398_CHARGER=y
+CONFIG_OPLUS_CHIP_SOC_NODE=y
+CONFIG_OPLUS_QPNP_QG=y
+#else
+#CONFIG_SMB1390_CHARGE_PUMP_PSY=y
+#CONFIG_SMB1398_CHARGER=y
+#CONFIG_QPNP_QG=y
+#CONFIG_QPNP_FG_GEN4=y
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_OPLUS_SHORT_HW_CHECK=y
+CONFIG_OPLUS_SHORT_USERSPACE=y
+CONFIG_OPLUS_SHIP_MODE_SUPPORT=y
+CONFIG_OPLUS_SMART_CHARGER_SUPPORT=y
+CONFIG_OPLUS_CHARGER_OPTIGA=y
+CONFIG_OPLUS_SHORT_C_BATT_CHECK=y
+CONFIG_OPLUS_CHECK_CHARGERID_VOLT=y
+CONFIG_OPLUS_SHORT_IC_CHECK=y
+CONFIG_SONY_FF=y
+CONFIG_HID_BETOP_FF=y
+CONFIG_HID_PLAYSTATION=y
+CONFIG_PLAYSTATION_FF=y
+#endif
+#ifndef OPLUS_FEATURE_CHG_BASIC//tongfeng.Huang@ProDrv.CHG,add 2019/12/22 for charger
+#CONFIG_HL6111R=y
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+CONFIG_INPUT_JOYSTICK=y
+CONFIG_JOYSTICK_XPAD=y
+CONFIG_JOYSTICK_XPAD_FF=y
+CONFIG_JOYSTICK_XPAD_LEDS=y
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
CONFIG_THERMAL=y
-CONFIG_THERMAL_STATISTICS=y
+#ifndef OPLUS_FEATURE_THERMAL_STATISTICS
+#CONFIG_THERMAL_STATISTICS=y
+#endif
CONFIG_THERMAL_WRITABLE_TRIPS=y
CONFIG_THERMAL_GOV_USER_SPACE=y
CONFIG_THERMAL_GOV_LOW_LIMITS=y
@@ -403,6 +481,9 @@ CONFIG_THERMAL_TSENS=y
CONFIG_QTI_ADC_TM=y
CONFIG_QTI_VIRTUAL_SENSOR=y
CONFIG_QTI_QMI_SENSOR=y
+CONFIG_SSC_INTERACTIVE=y
+CONFIG_OPLUS_SENSOR_FB_QC=y
+CONFIG_SENSORS_SSC=y
CONFIG_QTI_BCL_PMIC5=y
CONFIG_QTI_BCL_SOC_DRIVER=y
CONFIG_QTI_QMI_COOLING_DEVICE=y
@@ -425,6 +506,10 @@ CONFIG_REGULATOR_REFGEN=y
CONFIG_REGULATOR_RPMH=y
CONFIG_REGULATOR_STUB=y
CONFIG_REGULATOR_PM8008=y
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_REGULATOR_TPS65132=y
+CONFIG_REGULATOR_TPS65132_FOR_20267=y
+#endif /* OPLUS_BUG_STABILITY */
CONFIG_MEDIA_SUPPORT=y
CONFIG_MEDIA_CAMERA_SUPPORT=y
CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
@@ -439,6 +524,10 @@ CONFIG_DVB_MPQ_DEMUX=m
CONFIG_DVB_MPQ_SW=y
CONFIG_VIDEO_V4L2_VIDEOBUF2_CORE=y
CONFIG_DRM=y
+#ifdef VENDOR_EDIT
+CONFIG_DRM_MSM=y
+#endif /* VENDOR_EDIT */
+CONFIG_DRM_LONTIUM_LT9611UXC=y
CONFIG_BACKLIGHT_LCD_SUPPORT=y
CONFIG_BACKLIGHT_CLASS_DEVICE=y
CONFIG_BACKLIGHT_QCOM_SPMI_WLED=y
@@ -544,6 +633,7 @@ CONFIG_IPA_UT=y
CONFIG_USB_BAM=y
CONFIG_QCOM_GENI_SE=y
# CONFIG_QCOM_A53PLL is not set
+# CONFIG_IPA3_REGDUMP is not set
CONFIG_QCOM_CLK_RPMH=y
CONFIG_SPMI_PMIC_CLKDIV=y
CONFIG_MSM_CLK_AOP_QMP=y
@@ -560,6 +650,7 @@ CONFIG_SDM_DISPCC_LAGOON=y
CONFIG_SDM_GPUCC_LAGOON=y
CONFIG_SDM_NPUCC_LAGOON=y
CONFIG_SDM_VIDEOCC_LAGOON=y
+
CONFIG_HWSPINLOCK=y
CONFIG_HWSPINLOCK_QCOM=y
CONFIG_MAILBOX=y
@@ -682,6 +773,15 @@ CONFIG_OVERLAY_FS=y
CONFIG_INCREMENTAL_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
+CONFIG_OPLUS_FEATURE_EROFS=y
+CONFIG_EROFS_FS=y
+#ifdef OPLUS_FEATURE_EXFAT_SUPPORT
+CONFIG_NLS_UTF8=y
+CONFIG_EXFAT_FS=y
+# endif
+#ifdef OPLUS_FEATURE_EMMC_SDCARD_OPTIMIZE
+CONFIG_EMMC_SDCARD_OPTIMIZE=y
+#endif
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_EFIVAR_FS=y
@@ -708,7 +808,7 @@ CONFIG_CRYPTO_DEV_QCEDEV=y
CONFIG_XZ_DEC=y
CONFIG_PRINTK_TIME=y
CONFIG_DYNAMIC_DEBUG=y
-CONFIG_DEBUG_CONSOLE_UNHASHED_POINTERS=y
+# CONFIG_DEBUG_CONSOLE_UNHASHED_POINTERS is not set
CONFIG_DEBUG_MODULE_LOAD_INFO=y
CONFIG_DEBUG_INFO=y
CONFIG_PAGE_OWNER=y
@@ -722,15 +822,20 @@ CONFIG_DEBUG_PANIC_ON_OOM=y
CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y
CONFIG_PAGE_POISONING=y
CONFIG_PAGE_POISONING_ENABLE_DEFAULT=y
-CONFIG_SLUB_DEBUG_ON=y
-CONFIG_DEBUG_KMEMLEAK=y
+#ifndef VENDOR_EDIT
+#CONFIG_SLUB_DEBUG_ON=y
+#CONFIG_DEBUG_KMEMLEAK=y
+#else
+CONFIG_DEBUG_KMEMLEAK=n
+CONFIG_HAVE_DEBUG_KMEMLEAK=n
+#endif//VENDOR_EDIT
CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=4000
CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=y
CONFIG_DEBUG_STACK_USAGE=y
CONFIG_DEBUG_MEMORY_INIT=y
CONFIG_SOFTLOCKUP_DETECTOR=y
CONFIG_WQ_WATCHDOG=y
-CONFIG_PANIC_TIMEOUT=5
+CONFIG_PANIC_TIMEOUT=-1
CONFIG_PANIC_ON_SCHED_BUG=y
CONFIG_PANIC_ON_RT_THROTTLING=y
CONFIG_SCHEDSTATS=y
@@ -752,8 +857,9 @@ CONFIG_IPC_LOGGING=y
CONFIG_QCOM_RTB=y
CONFIG_QCOM_RTB_SEPARATE_CPUS=y
CONFIG_FUNCTION_TRACER=y
-CONFIG_PREEMPTIRQ_EVENTS=y
-CONFIG_IRQSOFF_TRACER=y
+#ifndef VENDOR_EDIT
+#CONFIG_PREEMPTIRQ_EVENTS=y
+#endif//VENDOR_EDITCONFIG_IRQSOFF_TRACER=y
CONFIG_PREEMPT_TRACER=y
CONFIG_BLK_DEV_IO_TRACE=y
CONFIG_LKDTM=m
@@ -775,3 +881,269 @@ CONFIG_CORESIGHT_HWEVENT=y
CONFIG_CORESIGHT_DUMMY=y
CONFIG_CORESIGHT_REMOTE_ETM=y
CONFIG_CORESIGHT_TGU=y
+#ifdef OPLUS_SYSTEM_KERNEL
+#/*Add for oplus project*/
+CONFIG_OPLUS_COMMON_SOFT=y
+CONFIG_OPLUS_DEVICE_IFNO=y
+CONFIG_OPLUS_RF_CABLE_MONITOR=y
+CONFIG_RECORD_MDMRST=y
+#endif
+#ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+CONFIG_OPLUS_WAKELOCK_PROFILER=y
+#endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+# ifdef VENDOR_EDIT
+CONFIG_CS_F61_NDT=y
+# endif /* VENDOR_EDIT */
+
+#ifdef OPLUS_SYSTEM_KERNEL
+#all system oplus feature writer here
+CONFIG_OPLUS_FEATURE_UBOOT_LOG=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_OPLUS_FEATURE_HUNG_TASK_ENHANCE=y
+CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=60
+CONFIG_OPLUS_FEATURE_FEEDBACK=y
+CONFIG_OPLUS_FEATURE_OPROJECT=y
+CONFIG_OPLUS_FEATURE_CMDLINE=y
+CONFIG_OPLUS_FEATURE_PROJECTINFO=y
+CONFIG_OPLUS_FEATURE_PHOENIX=y
+CONFIG_OPLUS_FEATURE_PHOENIX_REBOOT_SPEED=y
+CONFIG_OPLUS_FEATURE_KMSG_WB=y
+CONFIG_OPLUS_FEATURE_SHUTDOWN_SPEED=y
+CONFIG_OPLUS_FEATURE_OLC=y
+CONFIG_OPLUS_FEATURE_FDLEAK_CHECK=y
+#add for qcom minidump customized
+CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE=y
+#Add for shutdown detect
+CONFIG_OPLUS_FEATURE_SHUTDOWN_DETECT=y
+#add slabtrace function
+CONFIG_OPLUS_FEATURE_SLABTRACE_DEBUG=y
+#enable oplus misc feature
+#CONFIG_OPLUS_FEATURE_MISC is not set
+#endif
+#ifdef OPLUS_FEATURE_QCOM_PMICWD
+#Add for qcom pmic watchdog
+CONFIG_OPLUS_FEATURE_QCOM_PMICWD=y
+#endif
+#ifdef OPLUS_FEATURE_FINGERPRINT
+CONFIG_OPLUS_FINGERPRINT=y
+CONFIG_OPLUS_FINGERPRINT_QCOM=y
+CONFIG_OPLUS_FINGERPRINT_GOODIX_OPTICAL=y
+CONFIG_OPLUS_FINGERPRINT_JIIOV_OPTICAL=y
+CONFIG_OPLUS_FINGERPRINT_SILEAD=y
+CONFIG_OPLUS_FINGERPRINT_GOODIX=y
+#endif
+CONFIG_OPLUS_FINGERPRINT_GKI_DISABLE=y
+
+#ifdef OPLUS_FEATURE_SECURITY_COMMON
+CONFIG_OPLUS_SECURE=y
+CONFIG_OPLUS_SECURE_QCOM=y
+CONFIG_OPLUS_SECURE_COMMON=y
+#endif /* OPLUS_FEATURE_SECURITY_COMMON */
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+CONFIG_OPLUS_HANS=y
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
+#ifdef VENDOR_EDIT//Qingjun.Wang@BSP.Haptic,add 2020/03/17 for vib aw8697
+CONFIG_AW8697_HAPTIC=y
+#endif
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_MEM_MONITOR=y
+CONFIG_FG_TASK_UID=y
+CONFIG_OPLUS_HEALTHINFO=y
+CONFIG_SLUB_DEBUG=y
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+#ifdef OPLUS_FEATURE_HEALTHINFO
+CONFIG_OPLUS_JANK_INFO=y
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
+#ifdef OPLUS_FEATURE_ZRAM_OPT
+CONFIG_OPLUS_ZRAM_OPT=y
+CONFIG_CRYPTO_LZ4=y
+CONFIG_PGTABLE_MAPPING=y
+CONFIG_CRYPTO_ZSTD=y
+#endif
+
+#ifdef OPLUS_FEATURE_MULTI_KSWAPD
+CONFIG_OPLUS_MULTI_KSWAPD=y
+CONFIG_KSWAPD_UNBIND_MAX_CPU=y
+#endif
+
+#ifdef VENDOR_EDIT
+CONFIG_REGULATOR_PM8008=y
+
+#ifdef OPLUS_FEATURE_DUMPDEVICE
+CONFIG_PSTORE=y
+CONFIG_PSTORE_CONSOLE=y
+CONFIG_PSTORE_PMSG=y
+CONFIG_PSTORE_RAM=y
+#endif
+
+#ifdef OPLUS_FEATURE_IOMONITOR
+CONFIG_IOMONITOR=y
+#CONFIG_IOMONITOR_WITH_F2FS=n
+#endif /*OPLUS_FEATURE_IOMONITOR*/
+
+CONFIG_OPLUS_FEATURE_PMIC_MONITOR=y
+
+CONFIG_OPLUS_FEATURE_OF2FS=y
+CONFIG_OPLUS_FEATURE_PANIC_FLUSH=y
+CONFIG_OPLUS_FEATURE_OEXT4=y
+CONFIG_F2FS_BD_STAT=y
+#CONFIG_F2FS_GRADING_SSR is not set
+
+#ifdef OPLUS_FEATURE_LOWMEM_DBG
+CONFIG_OPLUS_FEATURE_LOWMEM_DBG=y
+#endif /* OPLUS_FEATURE_LOWMEM_DBG */
+
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+CONFIG_BLK_WBT_SQ=y
+CONFIG_BLK_WBT=y
+CONFIG_OPLUS_FEATURE_UXIO_FIRST=y
+#endif /*OPLUS_FEATURE_SCHED_ASSIST*/
+
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_KMALLOC_DEBUG=y
+CONFIG_VMALLOC_DEBUG=y
+CONFIG_DUMP_TASKS_MEM=y
+#endif /*OPLUS_FEATURE_MEMLEAK_DETECT*/
+
+#ifdef OPLUS_FEATURE_MEMLEAK_DETECT
+CONFIG_SVELTE=y
+#endif
+
+#ifdef VEDOR_EDIT
+CONFIG_OPLUS_FEATURE_RECORD_MDMRST=y
+#endif
+#ifdef OPLUS_ARCH_EXTENDS
+CONFIG_OPLUS_FEATURE_MM_FEEDBACK=y
+#endif
+
+#ifdef OPLUS_FEATURE_MIDAS
+CONFIG_OPLUS_FEATURE_MIDAS=y
+#endif
+
+#ifdef CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE
+CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE=y
+#endif
+
+#ifdef OPLUS_FEATURE_ACM
+CONFIG_OPLUS_FEATURE_ACM=y
+CONFIG_OPLUS_FEATURE_ACM_LOGGING=y
+#endif /* OPLUS_FEATURE_ACM */
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_HARDEN_BRANCH_PREDICTOR=y
+#endif
+CONFIG_OPLUS_FEATURE_THEIA=y
+##endif /* OPLUS_FEATURE_THEIA */
+
+#ifdef OPLUS_FEATURE_SAUPWK
+CONFIG_OPLUS_FEATURE_SAUPWK=y
+#endif /* OPLUS_FEATURE_SAUPWK */
+
+#ifdef OPLUS_FEATURE_DUMP_DEVICE_INFO
+CONFIG_OPLUS_FEATURE_DUMP_DEVICE_INFO=y
+#endif /* OPLUS_FEATURE_DUMP_DEVICE_INFO */
+
+#ifdef OPLUS_BUG_STABILITY
+CONFIG_UNMAP_KERNEL_AT_EL0=y
+#endif
+
+#ifdef OPLUS_FEATURE_GPIO_NC
+CONFIG_OPLUS_GPIO_NC=y
+#endif
+
+#ifdef OPLUS_FEATURE_BOOTLOADER_LOG
+CONFIG_BOOTLOADER_LOG=y
+#endif
+#ifdef OPLUS_FEATURE_PARAM
+CONFIG_PARAM_READ_WRITE=y
+#endif
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_SIM_DETECT=y
+#endif
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+CONFIG_OPLUS_FW_UPDATE=y
+#endif /*OPLUS_FEATURE_TP_BASIC*/
+
+#ifdef OPLUS_FEATURE_ION_BOOSTPOOL
+#CONFIG_OPLUS_ION_BOOSTPOOL=y ,Add for disable boost pool ,fill generic ION POOL
+#endif /* OPLUS_FEATURE_ION_BOOSTPOOL */
+
+#ifdef OPLUS_FEATURE_WIFI_SLA
+#todo: need to change to m when GKI
+CONFIG_OPLUS_FEATURE_WIFI_SLA=y
+#endif /* OPLUS_FEATURE_WIFI_SLA */
+
+#ifdef OPLUS_FEATURE_WIFI_ROUTERBOOST
+CONFIG_OPLUS_FEATURE_WIFI_ROUTERBOOST=m
+#endif /* OPLUS_FEATURE_WIFI_ROUTERBOOST */
+
+#ifdef OPLUS_FEATURE_DATA_EVAL
+CONFIG_OPLUS_FEATURE_DATA_EVAL=y
+#endif /* OPLUS_FEATURE_DATA_VAL */
+
+#ifdef OPLUS_FEATURE_DATA_LIMIT
+CONFIG_IFB=y
+CONFIG_NET_SCH_MULTIQ=y
+CONFIG_NET_SCH_NETEM=y
+CONFIG_CLS_U32_MARK=y
+CONFIG_NET_CLS_FLOW=y
+CONFIG_NET_EMATCH_CMP=y
+CONFIG_NET_EMATCH_NBYTE=y
+CONFIG_NET_EMATCH_META=y
+CONFIG_NET_EMATCH_TEXT=y
+CONFIG_NET_ACT_GACT=y
+CONFIG_NET_ACT_MIRRED=y
+CONFIG_NET_ACT_SKBEDIT=y
+#endif /* OPLUS_FEATURE_DATA_LIMIT */
+
+CONFIG_DEBUG_SPINLOCK=y
+
+#CONFIG_NANDSWAP=y
+#CONFIG_NANDSWAP_DEBUG=y
+#ifdef OPLUS_FEATURE_IM
+#ted.lin@optimization add for im module
+CONFIG_OPLUS_FEATURE_IM=y
+#endif /* OPLUS_FEATURE_IM */
+
+CONFIG_FRAME_WARN=4096
+
+CONFIG_DYNAMIC_TUNNING_SWAPPINESS=y
+
+#ifdef OPLUS_FEATURE_HYBRIDSWAP
+CONFIG_HYBRIDSWAP=y
+CONFIG_HYBRIDSWAP_SWAPD=y
+CONFIG_HYBRIDSWAP_CORE=y
+#endif
+
+#ifdef OPLUS_FEATURE_UID_PERF
+CONFIG_OPLUS_FEATURE_UID_PERF=y
+#endif
+
+#ifdef OPLUS_FEATURE_ESIM
+CONFIG_OPLUS_GPIO=y
+#endif /* OPLUS_FEATURE_ESIM */
+
+#ifdef OPLUS_FEATURE_DNS_HOOK
+CONFIG_OPLUS_FEATURE_DNS_HOOK=y
+#endif /* OPLUS_FEATURE_DNS_HOOK */
+
+#ifdef OPLUS_FEATURE_STATS_CALC
+CONFIG_OPLUS_FEATURE_STATS_CALC=y
+#endif /* OPLUS_FEATURE_STATS_CALC */
+
+#ifdef OPLUS_FEATURE_TPD
+CONFIG_OPLUS_FEATURE_TPD=y
+#endif
+
+#ifdef OPLUS_FEATURE_MDMFEATURE
+CONFIG_OPLUS_FEATURE_MDMFEATURE=y
+#endif
+
+#ifdef OPLUS_FEATURE_GAME_OPT
+CONFIG_OPLUS_FEATURE_GAME_OPT=y
+#endif
+CONFIG_OPLUS_BINDER_STRATEGY=n
+
+CONFIG_OPLUS_FEATURE_CPU_JANKINFO=y
diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h
index 3f8a615bfc82..87aa95b97955 100644
--- a/arch/arm64/include/asm/cacheflush.h
+++ b/arch/arm64/include/asm/cacheflush.h
@@ -200,5 +200,4 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
}
int set_memory_valid(unsigned long addr, int numpages, int enable);
-
#endif
diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index c5bd9a724319..57432c316c61 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -571,6 +571,20 @@ enum mitigation_state arm64_get_spectre_bhb_state(void);
bool is_spectre_bhb_affected(const struct arm64_cpu_capabilities *entry, int scope);
u8 spectre_bhb_loop_affected(int scope);
void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *__unused);
+
+/* Check whether hardware update of the Access flag is supported */
+static inline bool cpu_has_hw_af(void)
+{
+ u64 mmfr1;
+
+ if (!IS_ENABLED(CONFIG_ARM64_HW_AFDBM))
+ return false;
+
+ mmfr1 = read_cpuid(ID_AA64MMFR1_EL1);
+ return cpuid_feature_extract_unsigned_field(mmfr1,
+ ID_AA64MMFR1_HADBS_SHIFT);
+}
+
#endif /* __ASSEMBLY__ */
#endif
diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index 3b21bcd2c1cd..d7c1263282d8 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -115,9 +115,20 @@ static inline u64 __raw_readq_no_log(const volatile void __iomem *addr)
LOG_BARRIER; \
})
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define __raw_write_logged_oplus_vooc(v, a, _t) ({ \
+ volatile void __iomem *_a = (a); \
+ __raw_write##_t##_no_log((v), _a); \
+ })
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
#define __raw_writeb(v, a) __raw_write_logged((v), a, b)
#define __raw_writew(v, a) __raw_write_logged((v), a, w)
#define __raw_writel(v, a) __raw_write_logged((v), a, l)
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define __raw_writel_oplus_vooc(v, a) __raw_write_logged_oplus_vooc((v), a, l)
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
#define __raw_writeq(v, a) __raw_write_logged((v), a, q)
#define __raw_read_logged(a, _l, _t) ({ \
@@ -132,9 +143,20 @@ static inline u64 __raw_readq_no_log(const volatile void __iomem *addr)
__a; \
})
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define __raw_read_logged_oplus_vooc(a, _l, _t) ({ \
+ _t __a; \
+ const volatile void __iomem *_a = (const volatile void __iomem *)(a); \
+ __a = __raw_read##_l##_no_log(_a); \
+ })
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
#define __raw_readb(a) __raw_read_logged((a), b, u8)
#define __raw_readw(a) __raw_read_logged((a), w, u16)
#define __raw_readl(a) __raw_read_logged((a), l, u32)
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define __raw_readl_oplus_vooc(a) __raw_read_logged_oplus_vooc((a), l, u32)
+#endif /* OPLUS_FEATURE_CHG_BASIC */
#define __raw_readq(a) __raw_read_logged((a), q, u64)
/* IO barriers */
@@ -167,11 +189,18 @@ static inline u64 __raw_readq_no_log(const volatile void __iomem *addr)
#define readb_relaxed(c) ({ u8 __r = __raw_readb(c); __r; })
#define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; })
#define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; })
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define readl_relaxed_oplus_vooc(c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl_oplus_vooc(c)); __r; })
+#endif /* OPLUS_FEATURE_CHG_BASIC */
#define readq_relaxed(c) ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; })
#define writeb_relaxed(v,c) ((void)__raw_writeb((v),(c)))
#define writew_relaxed(v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
#define writel_relaxed(v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define writel_relaxed_oplus_vooc(v,c) ((void)__raw_writel_oplus_vooc((__force u32)cpu_to_le32(v),(c)))
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
#define writeq_relaxed(v,c) ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c)))
#define readb_relaxed_no_log(c) ({ u8 __v = __raw_readb_no_log(c); __v; })
@@ -198,11 +227,17 @@ static inline u64 __raw_readq_no_log(const volatile void __iomem *addr)
#define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(__v); __v; })
#define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(__v); __v; })
#define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(__v); __v; })
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define readl_oplus_vooc(c) ({ u32 __v = readl_relaxed_oplus_vooc(c); __v; })
+#endif /* OPLUS_FEATURE_CHG_BASIC */
#define readq(c) ({ u64 __v = readq_relaxed(c); __iormb(__v); __v; })
#define writeb(v,c) ({ __iowmb(); writeb_relaxed((v),(c)); })
#define writew(v,c) ({ __iowmb(); writew_relaxed((v),(c)); })
#define writel(v,c) ({ __iowmb(); writel_relaxed((v),(c)); })
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define writel_oplus_vooc(v,c) ({ writel_relaxed_oplus_vooc((v),(c)); })
+#endif /* OPLUS_FEATURE_CHG_BASIC */
#define writeq(v,c) ({ __iowmb(); writeq_relaxed((v),(c)); })
#define readb_no_log(c) \
diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h
index af547be1779b..c42d954b89db 100644
--- a/arch/arm64/include/asm/pgtable-prot.h
+++ b/arch/arm64/include/asm/pgtable-prot.h
@@ -32,6 +32,7 @@
#ifndef __ASSEMBLY__
+#include
#include
#define _PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 10c1ff13b992..14183ed6057e 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -782,6 +782,8 @@ extern pgd_t tramp_pg_dir[PTRS_PER_PGD];
extern int kern_addr_valid(unsigned long addr);
+#define arch_has_hw_pte_young cpu_has_hw_af
+
#include
void pgd_cache_init(void);
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index f0d7f22fae63..7fc27fba97c4 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -73,3 +73,7 @@ extra-y += $(head-y) vmlinux.lds
ifeq ($(CONFIG_DEBUG_EFI),y)
AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\""
endif
+
+#ifdef CONFIG_OPLUS_SECURE_GUARD
+obj-$(CONFIG_OPLUS_SECURE_GUARD) += rootguard/
+#endif /* CONFIG_OPLUS_SECURE_GUARD */
\ No newline at end of file
diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index b8f83cfe43f3..cd4153f72c3f 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -180,6 +180,21 @@ int main(void)
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
DEFINE(TRAMP_VALIAS, TRAMP_VALIAS);
#endif
+
+#ifdef CONFIG_OPLUS_SECURE_GUARD
+#ifdef CONFIG_OPLUS_ROOT_CHECK
+ DEFINE(PROOT_TSK_CRED, offsetof(struct task_struct, cred));
+ DEFINE(PROOT_CRED_UID, offsetof(struct cred, uid));
+ DEFINE(PROOT_CRED_EUID, offsetof(struct cred, euid));
+ DEFINE(PROOT_CRED_FSUID, offsetof(struct cred, fsuid));
+#ifdef CONFIG_THREAD_INFO_IN_TASK
+ DEFINE(PROOT_THREAD_ADDR_LIMIT, offsetof(struct task_struct, thread_info.addr_limit));
+#else
+ DEFINE(PROOT_THREAD_TSK, offsetof(struct thread_info,task));
+ DEFINE(PROOT_THREAD_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
+#endif
+#endif /* CONFIG_OPLUS_ROOT_CHECK */
+#endif /* CONFIG_OPLUS_SECURE_GUARD */
#ifdef CONFIG_ARM_SDE_INTERFACE
DEFINE(SDEI_EVENT_INTREGS, offsetof(struct sdei_registered_event, interrupted_regs));
DEFINE(SDEI_EVENT_PRIORITY, offsetof(struct sdei_registered_event, priority));
diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c
index 92bb53460401..8507e89bd4d3 100644
--- a/arch/arm64/kernel/kaslr.c
+++ b/arch/arm64/kernel/kaslr.c
@@ -35,6 +35,13 @@ static __init u64 get_kaslr_seed(void *fdt)
if (node < 0)
return 0;
+#ifdef OPLUS_BUG_STABILITY
+/* Aging/kasan version disable kaslr, easier to analysis problem */
+#ifdef CONFIG_KASAN
+ return 0;
+#endif
+#endif
+
prop = fdt_getprop_w(fdt, node, "kaslr-seed", &len);
if (!prop || len != sizeof(u64))
return 0;
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 152514428ac8..dcd55c0b54c4 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -68,6 +68,8 @@ unsigned long __stack_chk_guard __ro_after_init;
EXPORT_SYMBOL(__stack_chk_guard);
#endif
+#ifndef CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE
+
/*
* Function pointers to optional machine specific functions
*/
@@ -77,6 +79,19 @@ EXPORT_SYMBOL_GPL(pm_power_off);
void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
EXPORT_SYMBOL_GPL(arm_pm_restart);
+#else
+
+#include
+
+/*
+ * Function pointers to optional machine specific functions
+ */
+void (*pm_power_off)(void) = do_poweroff_early;
+EXPORT_SYMBOL_GPL(pm_power_off);
+void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd) = do_restart_early;
+
+#endif /* CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE */
+
/*
* This is our default idle handler.
*/
@@ -289,13 +304,18 @@ void __show_regs(struct pt_regs *regs)
sp = regs->sp;
top_reg = 29;
}
-
+
show_regs_print_info(KERN_DEFAULT);
print_pstate(regs);
if (!user_mode(regs)) {
printk("pc : %pS\n", (void *)regs->pc);
printk("lr : %pS\n", (void *)lr);
+#ifdef CONFIG_OPLUS_FEATURE_QCOM_MINIDUMP_ENHANCE
+ printk("pc : %016llx\n", regs->pc);
+ printk("lr : %016llx\n", lr);
+#endif
+
} else {
printk("pc : %016llx\n", regs->pc);
printk("lr : %016llx\n", lr);
diff --git a/arch/arm64/kernel/rootguard b/arch/arm64/kernel/rootguard
new file mode 120000
index 000000000000..87d3ea33cfb5
--- /dev/null
+++ b/arch/arm64/kernel/rootguard
@@ -0,0 +1 @@
+../../../../../vendor/oplus/kernel/secureguard/rootguard
\ No newline at end of file
diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
index f2d2dbbbfca2..223ba6f9fec1 100644
--- a/arch/arm64/kernel/syscall.c
+++ b/arch/arm64/kernel/syscall.c
@@ -17,6 +17,11 @@
long compat_arm_syscall(struct pt_regs *regs, int scno);
long sys_ni_syscall(void);
+#ifdef CONFIG_OPLUS_SECURE_GUARD
+extern void oplus_invoke_syscall(struct pt_regs *regs, unsigned int scno,
+ unsigned int sc_nr,
+ const syscall_fn_t syscall_table[]);
+#else
static long do_ni_syscall(struct pt_regs *regs, int scno)
{
#ifdef CONFIG_COMPAT
@@ -41,7 +46,6 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno,
const syscall_fn_t syscall_table[])
{
long ret;
-
if (scno < sc_nr) {
syscall_fn_t syscall_fn;
syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)];
@@ -55,6 +59,7 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno,
regs->regs[0] = ret;
}
+#endif /* CONFIG_OPLUS_SECURE_GUARD */
static inline bool has_syscall_work(unsigned long flags)
{
@@ -113,9 +118,11 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
if (scno == NO_SYSCALL)
goto trace_exit;
}
-
+#ifdef CONFIG_OPLUS_SECURE_GUARD
+ oplus_invoke_syscall(regs, scno, sc_nr, syscall_table);
+#else
invoke_syscall(regs, scno, sc_nr, syscall_table);
-
+#endif /* CONFIG_OPLUS_SECURE_GUARD */
/*
* The tracing status may have changed under our feet, so we have to
* check again. However, if we were tracing entry, then we always trace
diff --git a/arch/arm64/mm/arch_mmap.h b/arch/arm64/mm/arch_mmap.h
new file mode 120000
index 000000000000..226371c1811c
--- /dev/null
+++ b/arch/arm64/mm/arch_mmap.h
@@ -0,0 +1 @@
+../../../../../vendor/oplus/kernel/oplus_performance/gloom_new/arch_mmap.h
\ No newline at end of file
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 5e9df5bd73df..40badc1ad228 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -48,6 +48,9 @@
#include
#include
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+#include
+#endif /*OPLUS_FEATURE_IOMONITOR*/
struct fault_info {
int (*fn)(unsigned long addr, unsigned int esr,
@@ -567,6 +570,9 @@ done:
*/
if (major) {
tsk->maj_flt++;
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ iomonitor_update_fs_stats(FS_MAJOR_FAULT, 1);
+#endif /*OPLUS_FEATURE_IOMONITOR*/
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs,
addr);
} else {
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c
index 157f2caa1351..9d35b52e3108 100644
--- a/arch/arm64/mm/mmap.c
+++ b/arch/arm64/mm/mmap.c
@@ -30,6 +30,9 @@
#include
#include
+#if defined(OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY) && defined(CONFIG_VIRTUAL_RESERVE_MEMORY)
+#include "arch_mmap.h"
+#endif
/*
* Leave enough space between the mmap area and the stack to honour ulimit in
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index a12dc211399f..2912ef832881 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -62,6 +62,7 @@ config X86
select ARCH_HAS_PMEM_API if X86_64
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_REFCOUNT
+ select ARCH_HAS_NONLEAF_PMD_YOUNG
select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
select ARCH_HAS_UACCESS_MCSAFE if X86_64 && X86_MCE
select ARCH_HAS_SET_MEMORY
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 7de459cf36b5..f3ca6a3e2644 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -826,7 +826,8 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)
static inline int pmd_bad(pmd_t pmd)
{
- return (pmd_flags(pmd) & ~_PAGE_USER) != _KERNPG_TABLE;
+ return (pmd_flags(pmd) & ~(_PAGE_USER | _PAGE_ACCESSED)) !=
+ (_KERNPG_TABLE & ~_PAGE_ACCESSED);
}
static inline unsigned long pages_to_mb(unsigned long npg)
@@ -1442,6 +1443,12 @@ static inline bool arch_has_pfn_modify_check(void)
return boot_cpu_has_bug(X86_BUG_L1TF);
}
+#define arch_has_hw_pte_young arch_has_hw_pte_young
+static inline bool arch_has_hw_pte_young(void)
+{
+ return true;
+}
+
#include
#endif /* __ASSEMBLY__ */
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index c0e9c00402ac..71b8d760bc3a 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -560,7 +560,7 @@ int ptep_test_and_clear_young(struct vm_area_struct *vma,
return ret;
}
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
int pmdp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmdp)
{
@@ -572,6 +572,9 @@ int pmdp_test_and_clear_young(struct vm_area_struct *vma,
return ret;
}
+#endif
+
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
int pudp_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pud_t *pudp)
{
diff --git a/block/Kconfig b/block/Kconfig
index d4f96c78862e..4a0e44ef7b36 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -36,7 +36,7 @@ config LBDAF
This option is required to support the full capacity of large
(2TB+) block devices, including RAID, disk, Network Block Device,
Logical Volume Manager (LVM) and loopback.
-
+
This option also enables support for single files larger than
2TB.
@@ -246,3 +246,7 @@ config BLK_MQ_RDMA
default y
source block/Kconfig.iosched
+
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+source block/uxio_first/Kconfig
+#endif
diff --git a/block/Makefile b/block/Makefile
index a2e05332682f..ab08e77d657f 100644
--- a/block/Makefile
+++ b/block/Makefile
@@ -39,4 +39,7 @@ obj-$(CONFIG_BLK_DEBUG_FS_ZONED)+= blk-mq-debugfs-zoned.o
obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o
obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += keyslot-manager.o bio-crypt-ctx.o \
blk-crypto.o
-obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o
\ No newline at end of file
+obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+obj-$(CONFIG_OPLUS_FEATURE_UXIO_FIRST) += uxio_first/
+#endif /*OPLUS_FEATURE_SCHED_ASSIST*/
diff --git a/block/blk-core.c b/block/blk-core.c
index d3a6da3012a4..cf73c525be8f 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -46,6 +46,14 @@
#include "blk-mq-sched.h"
#include "blk-rq-qos.h"
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+#include
+#endif /*OPLUS_FEATURE_IOMONITOR*/
+
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+#include "uxio_first/uxio_first_opt.h"
+#endif
+
#ifdef CONFIG_DEBUG_FS
struct dentry *blk_debugfs_root;
#endif
@@ -190,6 +198,9 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
memset(rq, 0, sizeof(*rq));
INIT_LIST_HEAD(&rq->queuelist);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ INIT_LIST_HEAD(&rq->ux_fg_bg_list);
+#endif
INIT_LIST_HEAD(&rq->timeout_list);
rq->cpu = -1;
rq->q = q;
@@ -1016,6 +1027,11 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id,
return NULL;
INIT_LIST_HEAD(&q->queue_head);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ INIT_LIST_HEAD(&q->ux_head);
+ INIT_LIST_HEAD(&q->fg_head);
+ INIT_LIST_HEAD(&q->bg_head);
+#endif
q->last_merge = NULL;
q->end_sector = 0;
q->boundary_rq = NULL;
@@ -1476,7 +1492,9 @@ out:
*/
if (ioc_batching(q, ioc))
ioc->nr_batch_requests--;
-
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ iomonitor_init_reqstats(rq);
+#endif /*OPLUS_FEATURE_IOMONITOR*/
trace_block_getrq(q, bio, op);
return rq;
@@ -1774,8 +1792,11 @@ void __blk_put_request(struct request_queue *q, struct request *req)
/* this is a bio leak */
WARN_ON(req->bio != NULL);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ rq_qos_done(q, req, (bool)((req->cmd_flags & REQ_FG)||(req->cmd_flags & REQ_UX)));
+#else
rq_qos_done(q, req);
-
+#endif
/*
* Request may not have originated from ll_rw_blk. if not,
* it didn't come out of our reserved rq pools
@@ -1986,9 +2007,14 @@ out:
void blk_init_request_from_bio(struct request *req, struct bio *bio)
{
struct io_context *ioc = rq_ioc(bio);
-
if (bio->bi_opf & REQ_RAHEAD)
req->cmd_flags |= REQ_FAILFAST_MASK;
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ if (bio->bi_opf & REQ_UX)
+ req->cmd_flags |= REQ_UX;
+ else if (bio->bi_opf & REQ_FG)
+ req->cmd_flags |= REQ_FG;
+#endif
req->__sector = bio->bi_iter.bi_sector;
if (ioprio_valid(bio_prio(bio)))
@@ -2570,11 +2596,17 @@ blk_qc_t submit_bio(struct bio *bio)
if (op_is_write(bio_op(bio))) {
count_vm_events(PGPGOUT, count);
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ iomonitor_update_vm_stats(PGPGOUT, count);
+#endif /*OPLUS_FEATURE_IOMONITOR*/
} else {
if (bio_flagged(bio, BIO_WORKINGSET))
workingset_read = true;
task_io_account_read(bio->bi_iter.bi_size);
count_vm_events(PGPGIN, count);
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ iomonitor_update_vm_stats(PGPGIN, count);
+#endif /*OPLUS_FEATURE_IOMONITOR*/
}
if (unlikely(block_dump)) {
@@ -2586,7 +2618,12 @@ blk_qc_t submit_bio(struct bio *bio)
bio_devname(bio, b), count);
}
}
-
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ if (test_task_ux(current))
+ bio->bi_opf |= REQ_UX;
+ else if (high_prio_for_task(current))
+ bio->bi_opf |= REQ_FG;
+#endif
/*
* If we're reading data that is part of the userspace
* workingset, count submission time as memory stall. When the
@@ -2793,7 +2830,11 @@ void blk_account_io_done(struct request *req, u64 now)
* Don't process normal requests when queue is suspended
* or in the process of suspending/resuming
*/
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+bool blk_pm_allow_request(struct request *rq)
+#else
static bool blk_pm_allow_request(struct request *rq)
+#endif
{
switch (rq->q->rpm_status) {
case RPM_RESUMING:
@@ -2806,7 +2847,11 @@ static bool blk_pm_allow_request(struct request *rq)
}
}
#else
+ #if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ bool blk_pm_allow_request(struct request *rq)
+ #else
static bool blk_pm_allow_request(struct request *rq)
+#endif
{
return true;
}
@@ -2856,14 +2901,24 @@ static struct request *elv_next_request(struct request_queue *q)
WARN_ON_ONCE(q->mq_ops);
while (1) {
- list_for_each_entry(rq, &q->queue_head, queuelist) {
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ if (likely(sysctl_uxio_io_opt)){
+ rq = smart_peek_request(q);
+ if (rq)
+ return rq;
+ } else
+ {
+#endif
+ list_for_each_entry(rq, &q->queue_head, queuelist) {
if (blk_pm_allow_request(rq))
return rq;
if (rq->rq_flags & RQF_SOFTBARRIER)
break;
}
-
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ }
+#endif
/*
* Flush request is running and flush request isn't queueable
* in the drive, we can hold the queue till flush request is
@@ -2927,6 +2982,10 @@ struct request *blk_peek_request(struct request_queue *q)
* not be passed by new incoming requests
*/
rq->rq_flags |= RQF_STARTED;
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ rq->req_td = ktime_get();
+#endif /*OPLUS_FEATURE_IOMONITOR*/
+
trace_block_rq_issue(q, rq);
}
@@ -2986,7 +3045,9 @@ struct request *blk_peek_request(struct request_queue *q)
break;
}
}
-
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ iomonitor_record_io_history(rq);
+#endif /*OPLUS_FEATURE_IOMONITOR*/
return rq;
}
EXPORT_SYMBOL(blk_peek_request);
@@ -2999,14 +3060,27 @@ static void blk_dequeue_request(struct request *rq)
BUG_ON(ELV_ON_HASH(rq));
list_del_init(&rq->queuelist);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ list_del_init(&rq->ux_fg_bg_list);
+#endif
/*
* the time frame between a request being removed from the lists
* and to it is freed is accounted as io that is in progress at
* the driver side.
*/
- if (blk_account_rq(rq))
- q->in_flight[rq_is_sync(rq)]++;
+#ifdef OPLUS_FEATURE_HEALTHINFO
+// Add for ioqueue
+#ifdef CONFIG_OPLUS_HEALTHINFO
+ if (blk_account_rq(rq)) {
+ q->in_flight[rq_is_sync(rq)]++;
+ ohm_ioqueue_add_inflight(q, rq);
+ }
+#else
+ if (blk_account_rq(rq))
+ q->in_flight[rq_is_sync(rq)]++;
+#endif
+#endif
}
/**
@@ -3117,6 +3191,9 @@ bool blk_update_request(struct request *req, blk_status_t error,
int total_bytes;
trace_block_rq_complete(req, blk_status_to_errno(error), nr_bytes);
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ iomonitor_record_reqstats(req, nr_bytes);
+#endif /*OPLUS_FEATURE_IOMONITOR*/
if (!req->bio)
return false;
@@ -3254,7 +3331,11 @@ void blk_finish_request(struct request *req, blk_status_t error)
blk_account_io_done(req, now);
if (req->end_io) {
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ rq_qos_done(q, req, (bool)((req->cmd_flags & REQ_FG)||(req->cmd_flags & REQ_UX)));
+#else
rq_qos_done(q, req);
+#endif
req->end_io(req, error);
} else {
if (blk_bidi_rq(req))
diff --git a/block/blk-flush.c b/block/blk-flush.c
index dc71da0e6b0e..961b37f06b43 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -76,6 +76,10 @@
#include "blk-mq-tag.h"
#include "blk-mq-sched.h"
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+#include "uxio_first/uxio_first_opt.h"
+#endif
+
/* PREFLUSH/FUA sequences */
enum {
REQ_FSEQ_PREFLUSH = (1 << 0), /* pre-flushing in progress */
@@ -142,6 +146,9 @@ static bool blk_flush_queue_rq(struct request *rq, bool add_front)
list_add(&rq->queuelist, &rq->q->queue_head);
else
list_add_tail(&rq->queuelist, &rq->q->queue_head);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ queue_throtl_add_request(rq->q, rq, add_front);
+#endif /*OPLUS_FEATURE_SCHED_ASSIST*/
return true;
}
}
@@ -499,7 +506,14 @@ void blk_insert_flush(struct request *rq)
if (q->mq_ops)
blk_mq_request_bypass_insert(rq, false);
else
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ {
list_add_tail(&rq->queuelist, &q->queue_head);
+ queue_throtl_add_request(q, rq, false);
+ }
+#else
+ list_add_tail(&rq->queuelist, &q->queue_head);
+#endif
return;
}
diff --git a/block/blk-mq.c b/block/blk-mq.c
index ae70b4809bec..6c1e973a8c11 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -505,8 +505,11 @@ void blk_mq_free_request(struct request *rq)
if (unlikely(laptop_mode && !blk_rq_is_passthrough(rq)))
laptop_io_completion(q->backing_dev_info);
-
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ rq_qos_done(q, rq,(bool)((rq->cmd_flags & REQ_FG)||(rq->cmd_flags & REQ_UX)));
+#else
rq_qos_done(q, rq);
+#endif
if (blk_rq_rl(rq))
blk_put_rl(blk_rq_rl(rq));
@@ -529,7 +532,11 @@ inline void __blk_mq_end_request(struct request *rq, blk_status_t error)
blk_account_io_done(rq, now);
if (rq->end_io) {
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ rq_qos_done(rq->q, rq,(bool)((rq->cmd_flags & REQ_FG)||(rq->cmd_flags & REQ_UX)));
+#else
rq_qos_done(rq->q, rq);
+#endif
rq->end_io(rq, error);
} else {
if (unlikely(blk_bidi_rq(rq)))
diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index 43bcd4e7a7f9..9dcc3ab6806d 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -36,7 +36,17 @@ void rq_qos_cleanup(struct request_queue *q, struct bio *bio)
rqos->ops->cleanup(rqos, bio);
}
}
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+void rq_qos_done(struct request_queue *q, struct request *rq, bool fgux)
+{
+ struct rq_qos *rqos;
+ for (rqos = q->rq_qos; rqos; rqos = rqos->next) {
+ if (rqos->ops->done)
+ rqos->ops->done(rqos, rq, fgux);
+ }
+}
+#else
void rq_qos_done(struct request_queue *q, struct request *rq)
{
struct rq_qos *rqos;
@@ -46,7 +56,7 @@ void rq_qos_done(struct request_queue *q, struct request *rq)
rqos->ops->done(rqos, rq);
}
}
-
+#endif
void rq_qos_issue(struct request_queue *q, struct request *rq)
{
struct rq_qos *rqos;
diff --git a/block/blk-rq-qos.h b/block/blk-rq-qos.h
index 98caba3e962e..8e6b865434f7 100644
--- a/block/blk-rq-qos.h
+++ b/block/blk-rq-qos.h
@@ -29,7 +29,11 @@ struct rq_qos_ops {
void (*track)(struct rq_qos *, struct request *, struct bio *);
void (*issue)(struct rq_qos *, struct request *);
void (*requeue)(struct rq_qos *, struct request *);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ void (*done)(struct rq_qos *, struct request *, bool);
+#else
void (*done)(struct rq_qos *, struct request *);
+#endif
void (*done_bio)(struct rq_qos *, struct bio *);
void (*cleanup)(struct rq_qos *, struct bio *);
void (*exit)(struct rq_qos *);
@@ -96,7 +100,11 @@ bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
bool rq_depth_calc_max_depth(struct rq_depth *rqd);
void rq_qos_cleanup(struct request_queue *, struct bio *);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+void rq_qos_done(struct request_queue *, struct request *, bool);
+#else
void rq_qos_done(struct request_queue *, struct request *);
+#endif
void rq_qos_issue(struct request_queue *, struct request *);
void rq_qos_requeue(struct request_queue *, struct request *);
void rq_qos_done_bio(struct request_queue *q, struct bio *bio);
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 50cd3fbb0b8e..8bdc3c61ed75 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -393,6 +393,61 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page,
return count;
}
+#ifdef OPLUS_FEATURE_HEALTHINFO
+// Add for ioqueue
+#ifdef CONFIG_OPLUS_HEALTHINFO
+static ssize_t queue_show_ohm_inflight(struct request_queue *q, char *page)
+{
+ ssize_t ret;
+
+ ret = sprintf(page, "async:%d\n", q->in_flight[0]);
+ ret += sprintf(page + ret, "sync:%d\n", q->in_flight[1]);
+ ret += sprintf(page + ret, "ux:%d\n", q->in_flight[2]);
+ ret += sprintf(page + ret, "fg:%d\n", q->in_flight[3]);
+ ret += sprintf(page + ret, "bg:%d\n", q->in_flight[4]);
+ return ret;
+}
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+static ssize_t queue_bg_max_depth_show(struct request_queue *q, char *page)
+{
+ ssize_t ret;
+
+ if (!q->queue_tags)
+ return -EINVAL;
+
+ ret = sprintf(page, "%d\n", q->queue_tags->bg_max_depth);
+
+ return ret;
+}
+
+static ssize_t queue_bg_max_depth_store(struct request_queue *q,
+ const char *page, size_t count)
+{
+ unsigned long val;
+ int ret;
+
+ if (!q->queue_tags)
+ return -EINVAL;
+
+ ret = queue_var_store(&val, page, count);
+ if (ret < 0)
+ return ret;
+
+ if (val > q->queue_tags->max_depth)
+ return -EINVAL;
+
+ q->queue_tags->bg_max_depth = val;
+ return (ssize_t)count;
+}
+
+static struct queue_sysfs_entry queue_bg_max_depth_entry = {
+ .attr = {.name = "bg_max_depth", .mode = S_IRUGO | S_IWUSR },
+ .show = queue_bg_max_depth_show,
+ .store = queue_bg_max_depth_store,
+};
+#endif
static ssize_t queue_poll_show(struct request_queue *q, char *page)
{
@@ -527,7 +582,6 @@ static struct queue_sysfs_entry queue_ra_entry = {
.show = queue_ra_show,
.store = queue_ra_store,
};
-
static struct queue_sysfs_entry queue_max_sectors_entry = {
.attr = {.name = "max_sectors_kb", .mode = 0644 },
.show = queue_max_sectors_show,
@@ -654,6 +708,15 @@ static struct queue_sysfs_entry queue_iostats_entry = {
.show = queue_show_iostats,
.store = queue_store_iostats,
};
+#ifdef OPLUS_FEATURE_HEALTHINFO
+// Add for ioqueue
+#ifdef CONFIG_OPLUS_HEALTHINFO
+static struct queue_sysfs_entry queue_ohm_inflight_entry = {
+ .attr = {.name = "ohm_inflight", .mode = S_IRUGO },
+ .show = queue_show_ohm_inflight,
+};
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
static struct queue_sysfs_entry queue_random_entry = {
.attr = {.name = "add_random", .mode = 0644 },
@@ -730,6 +793,14 @@ static struct attribute *default_attrs[] = {
&queue_nomerges_entry.attr,
&queue_rq_affinity_entry.attr,
&queue_iostats_entry.attr,
+#if defined OPLUS_FEATURE_HEALTHINFO && defined CONFIG_OPLUS_HEALTHINFO
+// Add for ioqueue
+ &queue_ohm_inflight_entry.attr,
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ &queue_bg_max_depth_entry.attr,
+#endif
&queue_random_entry.attr,
&queue_poll_entry.attr,
&queue_wc_entry.attr,
diff --git a/block/blk-tag.c b/block/blk-tag.c
index fbc153aef166..492a6516f63f 100644
--- a/block/blk-tag.c
+++ b/block/blk-tag.c
@@ -10,6 +10,10 @@
#include "blk.h"
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+#include "uxio_first/uxio_first_opt.h"
+#endif
+
/**
* blk_queue_find_tag - find a request by its tag and queue
* @q: The request queue for the device
@@ -110,6 +114,9 @@ init_tag_map(struct request_queue *q, struct blk_queue_tag *tags, int depth)
tags->real_max_depth = depth;
tags->max_depth = depth;
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ tags->bg_max_depth = BLK_MAX_BG_DEPTH;
+#endif
tags->tag_index = tag_index;
tags->tag_map = tag_map;
diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 880a41adde8f..33241effaac7 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -30,6 +30,9 @@
#define CREATE_TRACE_POINTS
#include
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+extern bool sysctl_wbt_enable;
+#endif
static inline void wbt_clear_state(struct request *rq)
{
rq->wbt_flags = 0;
@@ -76,8 +79,14 @@ enum {
static inline bool rwb_enabled(struct rq_wb *rwb)
{
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ return sysctl_wbt_enable && rwb &&
+ rwb->enable_state != WBT_STATE_OFF_DEFAULT &&
+ rwb->wb_normal != 0;
+#else
return rwb && rwb->enable_state != WBT_STATE_OFF_DEFAULT &&
rwb->wb_normal != 0;
+#endif
}
static void wb_timestamp(struct rq_wb *rwb, unsigned long *var)
@@ -182,7 +191,11 @@ static void __wbt_done(struct rq_qos *rqos, enum wbt_flags wb_acct)
* Called on completion of a request. Note that it's also called when
* a request is merged, when the request gets freed.
*/
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+static void wbt_done(struct rq_qos *rqos, struct request *rq, bool fgux)
+#else
static void wbt_done(struct rq_qos *rqos, struct request *rq)
+#endif
{
struct rq_wb *rwb = RQWB(rqos);
@@ -192,7 +205,11 @@ static void wbt_done(struct rq_qos *rqos, struct request *rq)
rwb->sync_cookie = NULL;
}
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ if (wbt_is_read(rq) || fgux)
+#else
if (wbt_is_read(rq))
+#endif
wb_timestamp(rwb, &rwb->last_comp);
} else {
WARN_ON_ONCE(rq == rwb->sync_cookie);
diff --git a/block/elevator.c b/block/elevator.c
index 9909aa54a802..d0ae32cfcd4f 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -42,6 +42,9 @@
#include "blk.h"
#include "blk-mq-sched.h"
#include "blk-wbt.h"
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+#include "uxio_first/uxio_first_opt.h"
+#endif
static DEFINE_SPINLOCK(elv_list_lock);
static LIST_HEAD(elv_list);
@@ -394,6 +397,9 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
}
list_add(&rq->queuelist, entry);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ queue_throtl_add_request(q, rq, false);
+#endif
}
EXPORT_SYMBOL(elv_dispatch_sort);
@@ -414,6 +420,9 @@ void elv_dispatch_add_tail(struct request_queue *q, struct request *rq)
q->end_sector = rq_end_sector(rq);
q->boundary_rq = rq;
list_add_tail(&rq->queuelist, &q->queue_head);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ queue_throtl_add_request(q, rq, false);
+#endif
}
EXPORT_SYMBOL(elv_dispatch_add_tail);
@@ -593,6 +602,12 @@ void elv_requeue_request(struct request_queue *q, struct request *rq)
*/
if (blk_account_rq(rq)) {
q->in_flight[rq_is_sync(rq)]--;
+#ifdef OPLUS_FEATURE_HEALTHINFO
+// Add for ioqueue
+#ifdef CONFIG_OPLUS_HEALTHINFO
+ ohm_ioqueue_dec_inflight(q, rq);
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
if (rq->rq_flags & RQF_SORTED)
elv_deactivate_rq(q, rq);
}
@@ -625,6 +640,10 @@ void elv_drain_elevator(struct request_queue *q)
void __elv_add_request(struct request_queue *q, struct request *rq, int where)
{
+#if defined(OPLUS_FEATURE_IOMONITOR) && defined(CONFIG_IOMONITOR)
+ rq->req_ti = ktime_get();
+#endif /*OPLUS_FEATURE_IOMONITOR*/
+
trace_block_rq_insert(q, rq);
blk_pm_add_request(q, rq);
@@ -647,12 +666,18 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
case ELEVATOR_INSERT_FRONT:
rq->rq_flags |= RQF_SOFTBARRIER;
list_add(&rq->queuelist, &q->queue_head);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ queue_throtl_add_request(q, rq, true);
+#endif
break;
case ELEVATOR_INSERT_BACK:
rq->rq_flags |= RQF_SOFTBARRIER;
elv_drain_elevator(q);
list_add_tail(&rq->queuelist, &q->queue_head);
+#if defined(OPLUS_FEATURE_SCHED_ASSIST) && defined(CONFIG_OPLUS_FEATURE_UXIO_FIRST)
+ queue_throtl_add_request(q, rq, false);
+#endif
/*
* We kick the queue here for the following reasons.
* - The elevator might have returned NULL previously
@@ -787,6 +812,12 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
*/
if (blk_account_rq(rq)) {
q->in_flight[rq_is_sync(rq)]--;
+#ifdef OPLUS_FEATURE_HEALTHINFO
+// Add for ioqueue
+#ifdef CONFIG_OPLUS_HEALTHINFO
+ ohm_ioqueue_dec_inflight(q, rq);
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
if ((rq->rq_flags & RQF_SORTED) &&
e->type->ops.sq.elevator_completed_req_fn)
e->type->ops.sq.elevator_completed_req_fn(q, rq);
diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 39f70d968754..b6aa14f5d167 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -689,6 +689,36 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
* 1 if successful
*
*/
+
+struct replace_partition_tbl {
+ char *old_name;
+ char *new_name;
+};
+static struct replace_partition_tbl tbl[] = {
+ {"oplus_sec", "oplus_sec"},
+ {"oppodycnvbk","oplusdycnvbk"},
+ {"oppostanvbk", "oplusstanvbk"},
+ {"opporeserve1", "oplusreserve1"},
+ {"opporeserve2", "oplusreserve2"},
+ {"opporeserve3", "oplusreserve3"},
+ {"opporeserve4", "oplusreserve4"},
+ {"opporeserve5", "oplusreserve5"},
+};
+
+static void oplus_replace_partition_name(char *name)
+{
+ int part_idx = 0;
+
+ for (part_idx = 0; part_idx < ARRAY_SIZE(tbl); part_idx++) {
+ if (!strncmp(name, tbl[part_idx].old_name, strlen(tbl[part_idx].old_name))) {
+ pr_warn("rename partition name: %s->%s\n", name, tbl[part_idx].new_name);
+ memset(name, 0, strlen(tbl[part_idx].old_name));
+ strcpy(name, tbl[part_idx].new_name);
+ return;
+ }
+ }
+}
+
int efi_partition(struct parsed_partitions *state)
{
gpt_header *gpt = NULL;
@@ -736,6 +766,7 @@ int efi_partition(struct parsed_partitions *state)
label_count++;
}
state->parts[i + 1].has_info = true;
+ oplus_replace_partition_name(&info->volname[0]);
}
kfree(ptes);
kfree(gpt);
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 533f4aee8567..58996837997a 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -205,6 +205,12 @@ static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
__set_bit(GPCMD_LOAD_UNLOAD, filter->write_ok);
__set_bit(GPCMD_SET_STREAMING, filter->write_ok);
__set_bit(GPCMD_SET_READ_AHEAD, filter->write_ok);
+#ifdef OPLUS_FEATURE_STORAGE_TOOL
+// add write buffer command for common user
+// add vendor command for common user
+ __set_bit(WRITE_BUFFER, filter->write_ok);
+ __set_bit(VENDOR_SPECIFIC_CDB, filter->write_ok);
+#endif
}
int blk_verify_command(unsigned char *cmd, fmode_t mode)
@@ -424,6 +430,11 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
int err;
unsigned int in_len, out_len, bytes, opcode, cmdlen;
char *buffer = NULL;
+#ifdef OPLUS_FEATURE_STORAGE_TOOL
+// vendor cmd len is 16 and not 10 in spec.
+// in current application ,only samsung health will use this cmd.
+ struct scsi_device *sdev = NULL;
+#endif
if (!sic)
return -EINVAL;
@@ -456,6 +467,16 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
req = scsi_req(rq);
cmdlen = COMMAND_SIZE(opcode);
+#ifdef OPLUS_FEATURE_STORAGE_TOOL
+// vendor cmd len is 16 and not 10 in spec.
+// in current application ,only samsung health will use this cmd.
+ sdev = (struct scsi_device*)(q->queuedata);
+ if ((VENDOR_SPECIFIC_CDB == opcode)
+ &&(0 == strncmp(sdev->vendor, "SAMSUNG ", 8))
+ ){
+ cmdlen = 16;
+ }
+#endif
/*
* get command and data to send to device, if any
diff --git a/block/uxio_first b/block/uxio_first
new file mode 120000
index 000000000000..e83c1411361b
--- /dev/null
+++ b/block/uxio_first
@@ -0,0 +1 @@
+../../../vendor/oplus/kernel/oplus_performance/uxio_first
\ No newline at end of file
diff --git a/crypto/zstd.c b/crypto/zstd.c
index 9a76b3ed8b8b..f6f5de75b7cd 100644
--- a/crypto/zstd.c
+++ b/crypto/zstd.c
@@ -23,7 +23,7 @@
#include
-#define ZSTD_DEF_LEVEL 3
+#define ZSTD_DEF_LEVEL 1
struct zstd_ctx {
ZSTD_CCtx *cctx;
@@ -248,6 +248,7 @@ static int __init zstd_mod_init(void)
if (ret)
crypto_unregister_alg(&alg);
+ pr_warn("ZSTD_DEF_LEVEL val %d\n", ZSTD_DEF_LEVEL);
return ret;
}
diff --git a/drivers/Kconfig b/drivers/Kconfig
index e0866eda8bbd..c182112c6f15 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -232,4 +232,10 @@ source "drivers/sensors/Kconfig"
source "drivers/gpu/msm/Kconfig"
source "drivers/energy_model/Kconfig"
+
+#ifdef OPLUS_NFC_BRINGUP
+#Add for the kernel Macro for NXP PN557 NFC kernel
+source "drivers/nfc/pn553-i2c/Kconfig"
+source "drivers/nfc/p73-spi/Kconfig"
+#endif /*OPLUS_NFC_BRINGUP*/
endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index 9a258f18ec6f..1266025ada2f 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -192,3 +192,4 @@ obj-$(CONFIG_UNISYS_VISORBUS) += visorbus/
obj-$(CONFIG_SIOX) += siox/
obj-$(CONFIG_GNSS) += gnss/
obj-$(CONFIG_SENSORS_SSC) += sensors/
+obj-$(CONFIG_SENSORS_SIMULATED_HALL) += sensors/
diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig
index 6fdf2abe4598..123a5050fd2c 100644
--- a/drivers/android/Kconfig
+++ b/drivers/android/Kconfig
@@ -54,6 +54,11 @@ config ANDROID_BINDER_IPC_SELFTEST
exhaustively with combinations of various buffer sizes and
alignments.
+config OPLUS_BINDER_STRATEGY
+ default n
+ bool "config binder control"
+ help
+ it helps to reduce anr by restricting background app binder behavior.
endif # if ANDROID
endmenu
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 41222500e1a3..d74050487e6e 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -81,6 +81,21 @@
#include "binder_internal.h"
#include "binder_trace.h"
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+#include
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+#include
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
+
+#ifdef CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4
+#include
+#endif /* CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4 */
+
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+#include
+#endif
+
static HLIST_HEAD(binder_deferred_list);
static DEFINE_MUTEX(binder_deferred_lock);
@@ -136,6 +151,40 @@ module_param_named(devices, binder_devices_param, charp, 0444);
static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
static int binder_stop_on_user_error;
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+
+#include
+#ifndef CONFIG_OPLUS_FEATURE_CPU_JANKINFO
+#define OPLUS_MAX_SERVICE_NAME_LEN 32
+#endif
+#define OPLUS_MAGIC_SERVICE_NAME_OFFSET 76
+
+struct binder_notify {
+ struct task_struct *caller_task;
+ struct task_struct *binder_task;
+ char service_name[OPLUS_MAX_SERVICE_NAME_LEN];
+ bool pending_async;
+};
+
+static ATOMIC_NOTIFIER_HEAD(binderevent_notif_chain);
+
+int register_binderevent_notifier(struct notifier_block *nb) {
+ return atomic_notifier_chain_register(&binderevent_notif_chain, nb);
+}
+EXPORT_SYMBOL_GPL(register_binderevent_notifier);
+
+int unregister_binderevent_notifier(struct notifier_block *nb) {
+ return atomic_notifier_chain_unregister(&binderevent_notif_chain, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_binderevent_notifier);
+
+int call_binderevent_notifiers(unsigned long val, void *v) {
+ return atomic_notifier_call_chain(&binderevent_notif_chain, val, v);
+}
+EXPORT_SYMBOL_GPL(call_binderevent_notifiers);
+
+#endif // #if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+
static int binder_set_stop_on_user_error(const char *val,
const struct kernel_param *kp)
{
@@ -174,6 +223,7 @@ module_param_call(stop_on_user_error, binder_set_stop_on_user_error,
#define to_binder_fd_array_object(hdr) \
container_of(hdr, struct binder_fd_array_object, hdr)
+#ifndef CONFIG_OPLUS_FEATURE_CPU_JANKINFO
enum binder_stat_types {
BINDER_STAT_PROC,
BINDER_STAT_THREAD,
@@ -191,6 +241,7 @@ struct binder_stats {
atomic_t obj_created[BINDER_STAT_COUNT];
atomic_t obj_deleted[BINDER_STAT_COUNT];
};
+#endif
static struct binder_stats binder_stats;
@@ -227,6 +278,7 @@ static struct binder_transaction_log_entry *binder_transaction_log_add(
return e;
}
+#ifndef CONFIG_OPLUS_FEATURE_CPU_JANKINFO
/**
* struct binder_work - work enqueued on a worklist
* @entry: node enqueued on list
@@ -246,6 +298,9 @@ struct binder_work {
BINDER_WORK_DEAD_BINDER_AND_CLEAR,
BINDER_WORK_CLEAR_DEATH_NOTIFICATION,
} type;
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ u64 ob_begin;
+#endif
};
struct binder_error {
@@ -354,6 +409,9 @@ struct binder_node {
};
bool has_async_transaction;
struct list_head async_todo;
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ char service_name[OPLUS_MAX_SERVICE_NAME_LEN];
+#endif
};
struct binder_ref_death {
@@ -513,6 +571,9 @@ struct binder_proc {
struct hlist_node deferred_work_node;
int deferred_work;
bool is_dead;
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ int proc_type;
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
struct list_head todo;
struct binder_stats stats;
@@ -537,6 +598,9 @@ enum {
BINDER_LOOPER_STATE_INVALID = 0x08,
BINDER_LOOPER_STATE_WAITING = 0x10,
BINDER_LOOPER_STATE_POLL = 0x20,
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ BINDER_LOOPER_STATE_BACKGROUND = 0x40,
+#endif
};
/**
@@ -594,6 +658,7 @@ struct binder_thread {
bool is_dead;
struct task_struct *task;
};
+#endif
struct binder_transaction {
int debug_id;
@@ -643,6 +708,58 @@ struct binder_object {
};
};
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+
+static void oplus_parse_service_name(struct binder_transaction_data *tr,
+ struct binder_proc *proc,
+ char *name) {
+ unsigned int i, len = 0;
+ char *tmp;
+ char c;
+ char sname[OPLUS_MAX_SERVICE_NAME_LEN];
+
+ if (NULL != tr && tr->target.handle == 0 && NULL != proc && NULL != proc->context) {
+ if (!strcmp(proc->context->name, "hwbinder")) {
+ strcpy(sname, "hwbinderService");
+ } else {
+ for (i = 0; (2 * i) < tr->data_size; i++) {
+ if ((2 * i) < OPLUS_MAGIC_SERVICE_NAME_OFFSET) {
+ continue;
+ }
+ if (len >= (OPLUS_MAX_SERVICE_NAME_LEN - 1))
+ break;
+ tmp = (char *)(uintptr_t)(tr->data.ptr.buffer + (2*i));
+ get_user(c, tmp);
+ if (c >= 32 && c <= 126) { // visible character range [32, 126]
+ if (len < OPLUS_MAX_SERVICE_NAME_LEN - 1)
+ len += sprintf(sname + len, "%c", c);
+ else
+ break;
+ }
+ if ('\0' == c) {
+ break;
+ }
+ }
+ sname[len] = '\0';
+ }
+ pr_info("context.name[%s] tr.size:%lu service:%s\n",
+ proc->context->name, (unsigned long)tr->data_size, sname);
+ } else {
+ if (NULL != tr && 0 != tr->target.handle) {
+ sprintf(sname, "AnonymousCallback");
+ } else {
+ sprintf(sname, "unknown");
+ }
+ }
+
+ if (NULL != name){
+ strncpy(name, sname, OPLUS_MAX_SERVICE_NAME_LEN);
+ name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0';
+ }
+}
+
+#endif // #if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+
/**
* binder_proc_lock() - Acquire outer lock for given binder_proc
* @proc: struct binder_proc to acquire
@@ -967,13 +1084,25 @@ err:
return retval;
}
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+bool obthread_has_work(struct binder_thread *thread);
+static struct binder_thread *
+binder_select_thread_ilocked(struct binder_proc *proc);
+#endif
static bool binder_has_work_ilocked(struct binder_thread *thread,
bool do_proc_work)
{
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ return thread->process_todo ||
+ thread->looper_need_return || (do_proc_work && obthread_has_work(thread)) ||
+ (do_proc_work &&
+ !binder_worklist_empty_ilocked(&thread->proc->todo));
+#else
return thread->process_todo ||
thread->looper_need_return ||
(do_proc_work &&
!binder_worklist_empty_ilocked(&thread->proc->todo));
+#endif
}
static bool binder_has_work(struct binder_thread *thread, bool do_proc_work)
@@ -987,6 +1116,290 @@ static bool binder_has_work(struct binder_thread *thread, bool do_proc_work)
return has_work;
}
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+#include
+
+
+#define BINDER_LOOPER_STATE_BACKGROUND 0x40
+#define OBPROC_CHECK_CYCLE_NS 100000000
+#define OBWORK_TIMEOUT_NS 800000000
+#define BG_THREAD (2)
+#define SA_CGROUP_BACKGROUND (3)
+
+struct ob_struct ob_target;
+pid_t ob_pid;
+int ob_err;
+int sysctl_ob_control_enable = 1;
+noinline void ob_tracing_mark_write(const char *buf)
+{
+ trace_printk(buf);
+}
+
+void ob_sysctrace_c(struct binder_proc *proc, struct binder_thread *thread)
+{
+ char buf[256];
+
+ snprintf(buf, sizeof(buf), "C|%d|oplus_bt%s|%d", proc->pid, thread->task->comm, 1);
+ ob_tracing_mark_write(buf);
+}
+
+int get_task_cgroup_id(struct task_struct *task)
+{
+ struct cgroup_subsys_state *css = task_css(task, schedtune_cgrp_id);
+ return css ? css->id : -1;
+}
+
+bool test_task_bg(struct task_struct *task)
+{
+ return (SA_CGROUP_BACKGROUND == get_task_cgroup_id(task)) ? 1 : 0;
+}
+
+bool obtrans_is_from_background(struct binder_transaction *t)
+{
+ return test_task_bg(t->from->task);
+}
+
+bool obtrans_is_from_third_party(struct binder_transaction *t)
+{
+ return (from_kuid(current_user_ns(), t->sender_euid) % 100000) >= 10000;
+}
+
+bool obtrans_is_from_main(struct binder_transaction *t)
+{
+ return t->from->proc->pid == t->from->pid;
+}
+
+static char *obs_blacklist[] = {
+ "rocess.contacts"
+};
+
+bool obs_black_list(struct binder_transaction *t)
+{
+ int i = 0;
+
+ if (!t->from->proc->tsk)
+ return false;
+ for (i = 0; i < ARRAY_SIZE(obs_blacklist); i++) {
+ if (strstr(t->from->proc->tsk->comm, obs_blacklist[i])) {
+ pr_debug("%s is obs blacklist, don't limit it!!!",obs_blacklist[i]);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool obwork_is_restrict(struct binder_transaction *t)
+{
+ if ((!t->from) || (!t->from->proc))
+ return false;
+ if (obs_black_list(t))
+ return false;
+ return (obtrans_is_from_background(t)) && obtrans_is_from_third_party(t) &&
+ (!obtrans_is_from_main(t)) && (!test_task_ux(t->from->task));
+}
+
+void obwork_check_restrict_off(struct binder_proc *proc)
+{
+ struct binder_work *w = NULL;
+ struct binder_work *tmp = NULL;
+ struct binder_transaction *t = NULL;
+ u64 now = sched_clock();
+
+ if (proc != ob_target.ob_proc || binder_worklist_empty_ilocked(&ob_target.ob_list) || (now - ob_target.ob_check_ts) < OBPROC_CHECK_CYCLE_NS)
+ return;
+ list_for_each_entry_safe(w, tmp, &ob_target.ob_list, entry) {
+ if (!w)
+ continue;
+ t = container_of(w, struct binder_transaction, work);
+ if (now - w->ob_begin < OBWORK_TIMEOUT_NS)
+ break;
+ list_del_init(&w->entry);
+ //pr_info("%s timeoutinfo:t->from:%d,t->start:%llu now:%llu",__func__,t->from->pid,w->ob_begin,now);
+ binder_enqueue_work_ilocked(w, &proc->todo);
+ }
+ ob_target.ob_check_ts = sched_clock();
+}
+
+void obtrans_restrict_start(struct binder_proc *proc, struct binder_transaction *t)
+{
+ if (!sysctl_ob_control_enable)
+ return;
+ if (obwork_is_restrict(t)) {
+ t->work.ob_begin = sched_clock();
+ }
+ obwork_check_restrict_off(proc);
+}
+
+void oblist_dequeue_all(void)
+{
+ struct binder_work *w;
+ struct binder_work *w_tmp;
+ if (ob_target.ob_proc == NULL)
+ return;
+ binder_inner_proc_lock(ob_target.ob_proc);
+ if (binder_worklist_empty_ilocked(&ob_target.ob_list)) {
+ binder_inner_proc_unlock(ob_target.ob_proc);
+ return;
+ }
+ list_for_each_entry_safe(w, w_tmp, &ob_target.ob_list, entry) {
+ if (!w)
+ continue;
+ list_del_init(&w->entry);
+ binder_enqueue_work_ilocked(w, &ob_target.ob_proc->todo);
+ }
+ binder_inner_proc_unlock(ob_target.ob_proc);
+ return;
+}
+
+void oblist_dequeue_topapp_change(uid_t topuid)
+{
+ struct binder_work *w;
+ struct binder_work *w_tmp;
+ struct binder_transaction *t;
+ if (ob_target.ob_proc == NULL)
+ return;
+ binder_inner_proc_lock(ob_target.ob_proc);
+ if (!binder_worklist_empty_ilocked(&ob_target.ob_list)) {
+ list_for_each_entry_safe(w, w_tmp, &ob_target.ob_list, entry) {
+ if (!w)
+ continue;
+ t = container_of(w, struct binder_transaction, work);
+ if (from_kuid(current_user_ns(), t->sender_euid) != topuid)
+ continue;
+ list_del_init(&w->entry);
+ binder_enqueue_work_ilocked(w, &ob_target.ob_proc->todo);
+ }
+ }
+ binder_inner_proc_unlock(ob_target.ob_proc);
+ return;
+}
+
+void obwork_restrict(struct binder_proc *proc, struct binder_transaction *t)
+{
+ if (!sysctl_ob_control_enable || (proc != ob_target.ob_proc) || !obwork_is_restrict(t))
+ binder_enqueue_work_ilocked(&t->work, &proc->todo);
+ else
+ binder_enqueue_work_ilocked(&t->work, &ob_target.ob_list);
+}
+
+void obtarget_init(struct binder_proc *proc)
+{
+ if (!proc->tsk || !proc->context || !proc->context->name)
+ return;
+ if (ob_target.init)
+ return;
+ if ((!strncmp(proc->tsk->comm, "system_server", TASK_COMM_LEN)) && !strcmp(proc->context->name, "binder")) {
+ ob_target.ob_proc = proc;
+ ob_target.ob_check_ts = sched_clock();
+ INIT_LIST_HEAD(&ob_target.ob_list);
+ ob_target.init = true;
+ //pr_info("%s: ob_target->pid:%d ob_target->name:%s\n", __func__, proc->tsk->pid,proc->tsk->comm);
+ }
+}
+
+void obthread_init(struct binder_proc *proc, struct binder_thread *thread)
+{
+ if (proc != ob_target.ob_proc)
+ return;
+ if (proc->requested_threads_started == BG_THREAD) {
+ thread->looper |= BINDER_LOOPER_STATE_BACKGROUND;
+ ob_pid = thread->task->pid;
+ //pr_info("%s :bg thread->name:%s thread->pid:%d", __func__,thread->task->comm,thread->task->pid);
+ }
+}
+
+bool obthread_has_work(struct binder_thread *thread)
+{
+ if (!sysctl_ob_control_enable || !(thread->looper & BINDER_LOOPER_STATE_BACKGROUND) || (thread->proc != ob_target.ob_proc))
+ return false;
+ return !binder_worklist_empty_ilocked(&ob_target.ob_list);
+}
+
+bool obproc_has_work(struct binder_proc *proc)
+{
+ if (!sysctl_ob_control_enable || ob_target.ob_proc != proc)
+ return false;
+ if (!binder_worklist_empty_ilocked(&ob_target.ob_list))
+ return true;
+ else
+ return false;
+}
+
+void obthread_wakeup(struct binder_proc *proc)
+{
+ struct binder_thread *thread = NULL;
+
+ list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node) {
+ if (thread && (thread->looper & BINDER_LOOPER_STATE_BACKGROUND)) {
+ list_del_init(&thread->waiting_thread_node);
+ wake_up_interruptible(&thread->wait);
+ }
+ }
+ return;
+}
+
+void obproc_free(struct binder_proc *proc)
+{
+ if (proc == ob_target.ob_proc) {
+ BUG_ON(!list_empty(&ob_target.ob_list));
+ ob_target.ob_check_ts = 0;
+ ob_target.ob_proc = NULL;
+ }
+}
+
+void obprint_oblist(void)
+{
+ struct binder_work *w;
+ struct binder_work *w_tmp;
+ struct binder_transaction *t;
+ if (!sysctl_ob_control_enable)
+ return;
+ if (ob_target.ob_proc == NULL)
+ return;
+ if (binder_worklist_empty_ilocked(&ob_target.ob_list))
+ return;
+ list_for_each_entry_safe(w, w_tmp, &ob_target.ob_list, entry) {
+ if (!w)
+ continue;
+ t = container_of(w, struct binder_transaction, work);
+ if (!obwork_is_restrict(t))
+ ob_err++;
+ }
+}
+
+struct binder_thread *obthread_get(struct binder_proc *proc, struct binder_transaction *t, bool oneway)
+{
+ struct binder_thread *thread = NULL;
+ if (sysctl_ob_control_enable && (proc == ob_target.ob_proc) && obwork_is_restrict(t) && !oneway) {
+ list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node)
+ if (thread && (thread->looper & BINDER_LOOPER_STATE_BACKGROUND)) {
+ list_del_init(&thread->waiting_thread_node);
+ pr_info("%s :bg thread->name:%s thread->pid:%d", __func__, thread->task->comm, thread->task->pid);
+ return thread;
+ }
+ return NULL;
+ }
+ return binder_select_thread_ilocked(proc);
+}
+
+int sysctl_ob_control_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+ int ret;
+
+ if (write && *ppos)
+ *ppos = 0;
+ ret = proc_dointvec(table, write, buffer, lenp, ppos);
+ if (!write)
+ goto out;
+ if (!sysctl_ob_control_enable) {
+ pr_info("_%s dequeue all bg work", __func__);
+ oblist_dequeue_all();
+ }
+out:
+ return ret;
+}
+#endif
+
static bool binder_available_for_proc_work_ilocked(struct binder_thread *thread)
{
return !thread->transaction_stack &&
@@ -1212,10 +1625,17 @@ static void binder_restore_priority(struct task_struct *task,
binder_do_set_priority(task, desired, /* verify = */ false);
}
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+static void binder_transaction_priority(struct binder_thread *thread, struct task_struct *task,
+ struct binder_transaction *t,
+ struct binder_priority node_prio,
+ bool inherit_rt)
+#else
static void binder_transaction_priority(struct task_struct *task,
struct binder_transaction *t,
struct binder_priority node_prio,
bool inherit_rt)
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
{
struct binder_priority desired_prio = t->priority;
@@ -1226,6 +1646,13 @@ static void binder_transaction_priority(struct task_struct *task,
t->saved_priority.sched_policy = task->policy;
t->saved_priority.prio = task->normal_prio;
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ //NOTE: if task is main thread, and doesn't join pool as a binder thread,
+ //DON'T actually change priority in binder transaction.
+ if ((task->tgid == task->pid) && !(thread->looper & BINDER_LOOPER_STATE_ENTERED)) {
+ return;
+ }
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
if (!inherit_rt && is_rt_policy(desired_prio.sched_policy)) {
desired_prio.prio = NICE_TO_PRIO(0);
desired_prio.sched_policy = SCHED_NORMAL;
@@ -2528,9 +2955,16 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
}
}
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+static int binder_translate_binder(struct binder_transaction_data *tr,
+ struct flat_binder_object *fp,
+ struct binder_transaction *t,
+ struct binder_thread *thread)
+#else
static int binder_translate_binder(struct flat_binder_object *fp,
struct binder_transaction *t,
struct binder_thread *thread)
+#endif
{
struct binder_node *node;
struct binder_proc *proc = thread->proc;
@@ -2543,6 +2977,9 @@ static int binder_translate_binder(struct flat_binder_object *fp,
node = binder_new_node(proc, fp);
if (!node)
return -ENOMEM;
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ oplus_parse_service_name(tr, proc, node->service_name);
+#endif
}
if (fp->cookie != node->cookie) {
binder_user_error("%d:%d sending u%016llx node %d, cookie mismatch %016llx != %016llx\n",
@@ -2833,6 +3270,13 @@ static int binder_fixup_parent(struct binder_transaction *t,
return 0;
}
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+static inline bool is_binder_proc_sf(struct binder_proc *proc)
+{
+ return proc && proc->tsk && strstr(proc->tsk->comm, "surfaceflinger")
+ && (task_uid(proc->tsk).val == 1000);
+}
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
/**
* binder_proc_transaction() - sends a transaction to a process and wakes it up
* @t: transaction to send
@@ -2850,6 +3294,9 @@ static int binder_fixup_parent(struct binder_transaction *t,
* Return: true if the transactions was successfully queued
* false if the target process or thread is dead
*/
+#if defined(OPLUS_FEATURE_SCHED_ASSIST)
+extern bool is_sf(struct task_struct *p);
+#endif
static bool binder_proc_transaction(struct binder_transaction *t,
struct binder_proc *proc,
struct binder_thread *thread)
@@ -2858,7 +3305,13 @@ static bool binder_proc_transaction(struct binder_transaction *t,
struct binder_priority node_prio;
bool oneway = !!(t->flags & TF_ONE_WAY);
bool pending_async = false;
-
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ struct binder_notify binder_notify_obj;
+#endif
+#if defined(OPLUS_FEATURE_SCHED_ASSIST)
+ struct task_struct *grp_leader = NULL;
+ struct task_struct *curr = current;
+#endif
BUG_ON(!node);
binder_node_lock(node);
node_prio.prio = node->min_priority;
@@ -2880,22 +3333,84 @@ static bool binder_proc_transaction(struct binder_transaction *t,
binder_node_unlock(node);
return false;
}
-
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ obtrans_restrict_start(proc, t);
+ if (!thread && !pending_async) {
+ thread = obthread_get(proc, t, oneway);
+ }
+#else
if (!thread && !pending_async)
thread = binder_select_thread_ilocked(proc);
+#endif
+
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ if (NULL != node && NULL != proc->tsk) {
+ binder_notify_obj.caller_task = current;
+ strncpy(binder_notify_obj.service_name, node->service_name, OPLUS_MAX_SERVICE_NAME_LEN);
+ binder_notify_obj.service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0';
+ binder_notify_obj.pending_async = pending_async;
+ }
+#endif
if (thread) {
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ if (NULL != thread && NULL != thread->task) {
+ binder_notify_obj.binder_task = thread->task;
+ call_binderevent_notifiers(0, (void *)&binder_notify_obj);
+ }
+#endif
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ binder_transaction_priority(thread, thread->task, t, node_prio,
+ node->inherit_rt);
+#else
binder_transaction_priority(thread->task, t, node_prio,
node->inherit_rt);
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
binder_enqueue_thread_work_ilocked(thread, &t->work);
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ if (sysctl_sched_assist_enabled) {
+ if (!oneway || proc->proc_type)
+ binder_set_inherit_ux(thread->task, current);
+ }
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
+#ifdef CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4
+ if (t->from) {
+ binder_thread_set_fbg(thread->task, t->from->task, oneway);
+ }
+#endif /* CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4 */
} else if (!pending_async) {
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ if (NULL != proc && NULL != proc->tsk) {
+ binder_notify_obj.binder_task = proc->tsk;
+ call_binderevent_notifiers(0, (void *)&binder_notify_obj);
+ }
+#endif
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ obwork_restrict(proc, t);
+#else
binder_enqueue_work_ilocked(&t->work, &proc->todo);
+#endif
} else {
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ if (NULL != proc && NULL != proc->tsk) {
+ binder_notify_obj.binder_task = proc->tsk;
+ call_binderevent_notifiers(0, (void *)&binder_notify_obj);
+ }
+#endif
binder_enqueue_work_ilocked(&t->work, &node->async_todo);
}
- if (!pending_async)
+ if (!pending_async) {
+#if defined(OPLUS_FEATURE_SCHED_ASSIST)
+ if (thread && thread->task) {
+ grp_leader = thread->task->group_leader;
+ if (grp_leader && is_sf(curr) && test_task_ux(thread->task->group_leader) && oneway) {
+ set_once_ux(thread->task);
+ }
+ }
+#endif
binder_wakeup_thread_ilocked(proc, thread, !oneway /* sync */);
+ }
binder_inner_proc_unlock(proc);
binder_node_unlock(node);
@@ -2972,6 +3487,13 @@ static void binder_transaction(struct binder_proc *proc,
int t_debug_id = atomic_inc_return(&binder_last_id);
char *secctx = NULL;
u32 secctx_sz = 0;
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+ char buf_data[INTERFACETOKEN_BUFF_SIZE];
+ size_t buf_data_size;
+ char buf[INTERFACETOKEN_BUFF_SIZE] = {0};
+ int i = 0;
+ int j = 0;
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
e = binder_transaction_log_add(&binder_transaction_log);
e->debug_id = t_debug_id;
@@ -3087,6 +3609,26 @@ static void binder_transaction(struct binder_proc *proc,
return_error_line = __LINE__;
goto err_dead_binder;
}
+
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+ if (!(tr->flags & TF_ONE_WAY) //report sync binder call
+ && target_proc
+ && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID)
+ && (proc->pid != target_proc->pid)
+ && is_frozen_tg(target_proc->tsk)) {
+ hans_report(SYNC_BINDER, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER", -1);
+ }
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
+
+#if defined(CONFIG_CFS_BANDWIDTH)
+ if (!(tr->flags & TF_ONE_WAY) //report sync binder call
+ && target_proc
+ && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID || task_uid(target_proc->tsk).val == HANS_SYSTEM_UID) //uid >10000
+ && is_belong_cpugrp(target_proc->tsk)) {
+ hans_report(SYNC_BINDER_CPUCTL, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER_CPUCTL", -1);
+ }
+#endif
+
e->to_node = target_node->debug_id;
if (security_binder_transaction(proc->cred,
target_proc->cred) < 0) {
@@ -3319,6 +3861,31 @@ static void binder_transaction(struct binder_proc *proc,
return_error_line = __LINE__;
goto err_bad_offset;
}
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+ if ((tr->flags & TF_ONE_WAY) //report async binder call
+ && target_proc
+ && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID)
+ && (proc->pid != target_proc->pid)
+ && is_frozen_tg(target_proc->tsk)) {
+ buf_data_size = tr->data_size>INTERFACETOKEN_BUFF_SIZE ?INTERFACETOKEN_BUFF_SIZE:tr->data_size;
+ if (!copy_from_user(buf_data, (char*)tr->data.ptr.buffer, buf_data_size)) {
+ //1.skip first PARCEL_OFFSET bytes (useless data)
+ //2.make sure the invalid address issue is not occuring(j =PARCEL_OFFSET+1, j+=2)
+ //3.java layer uses 2 bytes char. And only the first bytes has the data.(p+=2)
+ if (buf_data_size > PARCEL_OFFSET) {
+ char *p = (char *)(buf_data) + PARCEL_OFFSET;
+ j = PARCEL_OFFSET + 1;
+ while (i < INTERFACETOKEN_BUFF_SIZE && j < buf_data_size && *p != '\0') {
+ buf[i++] = *p;
+ j += 2;
+ p += 2;
+ }
+ if (i == INTERFACETOKEN_BUFF_SIZE) buf[i-1] = '\0';
+ }
+ hans_report(ASYNC_BINDER, task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, buf, tr->code);
+ }
+ }
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
off_start_offset = ALIGN(tr->data_size, sizeof(void *));
buffer_offset = off_start_offset;
off_end_offset = off_start_offset + tr->offsets_size;
@@ -3360,7 +3927,11 @@ static void binder_transaction(struct binder_proc *proc,
struct flat_binder_object *fp;
fp = to_flat_binder_object(hdr);
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ ret = binder_translate_binder(tr, fp, t, thread);
+#else
ret = binder_translate_binder(fp, t, thread);
+#endif
if (ret < 0) {
return_error = BR_FAILED_REPLY;
return_error_param = ret;
@@ -3516,6 +4087,9 @@ static void binder_transaction(struct binder_proc *proc,
t->work.type = BINDER_WORK_TRANSACTION;
if (reply) {
+#ifdef CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4
+ bool oneway = !!(t->flags & TF_ONE_WAY);
+#endif /* CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4 */
binder_enqueue_thread_work(thread, tcomplete);
binder_inner_proc_lock(target_proc);
if (target_thread->is_dead) {
@@ -3528,6 +4102,19 @@ static void binder_transaction(struct binder_proc *proc,
binder_inner_proc_unlock(target_proc);
wake_up_interruptible_sync(&target_thread->wait);
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ if (sysctl_sched_assist_enabled && !proc->proc_type) {
+ binder_unset_inherit_ux(thread->task);
+ }
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
+#ifdef CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4
+ binder_thread_remove_fbg(thread->task, oneway);
+#endif /* CONFIG_OPLUS_FEATURE_INPUT_BOOST_V4 */
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ binder_inner_proc_lock(proc);
+ obwork_check_restrict_off(proc);
+ binder_inner_proc_unlock(proc);
+#endif
binder_restore_priority(current, in_reply_to->saved_priority);
binder_free_transaction(in_reply_to);
} else if (!(t->flags & TF_ONE_WAY)) {
@@ -3911,6 +4498,9 @@ static int binder_thread_write(struct binder_proc *proc,
proc->requested_threads_started++;
}
thread->looper |= BINDER_LOOPER_STATE_REGISTERED;
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ obthread_init(proc, thread);
+#endif
binder_inner_proc_unlock(proc);
break;
case BC_ENTER_LOOPER:
@@ -4170,11 +4760,36 @@ static int binder_wait_for_work(struct binder_thread *thread,
prepare_to_wait(&thread->wait, &wait, TASK_INTERRUPTIBLE);
if (binder_has_work_ilocked(thread, do_proc_work))
break;
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ if (do_proc_work) {
+ list_add(&thread->waiting_thread_node,
+ &proc->waiting_threads);
+
+ if (sysctl_sched_assist_enabled) {
+ binder_unset_inherit_ux(thread->task);
+ }
+ }
+#else /* OPLUS_FEATURE_SCHED_ASSIST */
if (do_proc_work)
list_add(&thread->waiting_thread_node,
&proc->waiting_threads);
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+ android_vh_binder_wait_for_work_hanlder(NULL,
+ do_proc_work, thread, proc);
+#endif
binder_inner_proc_unlock(proc);
+#ifdef OPLUS_FEATURE_HEALTHINFO
+#ifdef CONFIG_OPLUS_JANK_INFO
+ current->in_binder = 1;
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
schedule();
+#ifdef OPLUS_FEATURE_HEALTHINFO
+#ifdef CONFIG_OPLUS_JANK_INFO
+ current->in_binder = 0;
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
binder_inner_proc_lock(proc);
list_del_init(&thread->waiting_thread_node);
if (signal_pending(current)) {
@@ -4253,6 +4868,11 @@ retry:
binder_inner_proc_lock(proc);
if (!binder_worklist_empty_ilocked(&thread->todo))
list = &thread->todo;
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ else if (obthread_has_work(thread) && wait_for_proc_work) {
+ list = &ob_target.ob_list;
+ }
+#endif
else if (!binder_worklist_empty_ilocked(&proc->todo) &&
wait_for_proc_work)
list = &proc->todo;
@@ -4448,8 +5068,13 @@ retry:
trd->cookie = target_node->cookie;
node_prio.sched_policy = target_node->sched_policy;
node_prio.prio = target_node->min_priority;
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ binder_transaction_priority(thread, current, t, node_prio,
+ target_node->inherit_rt);
+#else
binder_transaction_priority(current, t, node_prio,
target_node->inherit_rt);
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
cmd = BR_TRANSACTION;
} else {
trd->target.ptr = 0;
@@ -4467,6 +5092,11 @@ retry:
trd->sender_pid =
task_tgid_nr_ns(sender,
task_active_pid_ns(current));
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ if (sysctl_sched_assist_enabled) {
+ binder_set_inherit_ux(thread->task, t_from->task);
+ }
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
} else {
trd->sender_pid = 0;
}
@@ -4686,6 +5316,9 @@ static void binder_free_proc(struct binder_proc *proc)
BUG_ON(!list_empty(&proc->todo));
BUG_ON(!list_empty(&proc->delivered_death));
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ obproc_free(proc);
+#endif
device = container_of(proc->context, struct binder_device, context);
if (refcount_dec_and_test(&device->ref)) {
kfree(proc->context->name);
@@ -4861,6 +5494,10 @@ static int binder_ioctl_write_read(struct file *filp,
binder_inner_proc_lock(proc);
if (!binder_worklist_empty_ilocked(&proc->todo))
binder_wakeup_proc_ilocked(proc);
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ if (obproc_has_work(proc))
+ obthread_wakeup(proc);
+#endif
binder_inner_proc_unlock(proc);
if (ret < 0) {
if (copy_to_user(ubuf, &bwr, sizeof(bwr)))
@@ -4922,6 +5559,15 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp,
new_node->has_strong_ref = 1;
new_node->has_weak_ref = 1;
context->binder_context_mgr_node = new_node;
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ if (NULL != context->binder_context_mgr_node &&
+ NULL != context->binder_context_mgr_node->proc &&
+ NULL != context->binder_context_mgr_node->proc->tsk) {
+ snprintf(context->binder_context_mgr_node->service_name, OPLUS_MAX_SERVICE_NAME_LEN,
+ "%s", context->binder_context_mgr_node->proc->tsk->comm);
+ context->binder_context_mgr_node->service_name[OPLUS_MAX_SERVICE_NAME_LEN-1] = '\0';
+ }
+#endif
binder_node_unlock(new_node);
binder_put_node(new_node);
out:
@@ -5219,6 +5865,9 @@ static int binder_open(struct inode *nodp, struct file *filp)
spin_lock_init(&proc->outer_lock);
get_task_struct(current->group_leader);
proc->tsk = current->group_leader;
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ proc->proc_type = is_binder_proc_sf(proc) ? 1 : 0;
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
mutex_init(&proc->files_lock);
proc->cred = get_cred(filp->f_cred);
INIT_LIST_HEAD(&proc->todo);
@@ -5248,6 +5897,9 @@ static int binder_open(struct inode *nodp, struct file *filp)
INIT_LIST_HEAD(&proc->delivered_death);
INIT_LIST_HEAD(&proc->waiting_threads);
filp->private_data = proc;
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ obtarget_init(proc);
+#endif
mutex_lock(&binder_procs_lock);
hlist_add_head(&proc->proc_node, &binder_procs);
@@ -5491,6 +6143,10 @@ static void binder_deferred_release(struct binder_proc *proc)
binder_release_work(proc, &proc->todo);
binder_release_work(proc, &proc->delivered_death);
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ if (proc == ob_target.ob_proc)
+ binder_release_work(proc, &ob_target.ob_list);
+#endif
binder_debug(BINDER_DEBUG_OPEN_CLOSE,
"%s: %d threads %d, nodes %d (ref %d), refs %d, active transactions %d\n",
@@ -5989,6 +6645,71 @@ int binder_state_show(struct seq_file *m, void *unused)
return 0;
}
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+static void hans_check_uid_proc_status(struct binder_proc *proc, enum message_type type)
+{
+ struct rb_node *n = NULL;
+ struct binder_thread *thread = NULL;
+ int uid = -1;
+ struct binder_transaction *btrans = NULL;
+ bool empty = true;
+
+ /* check binder_thread/transaction_stack/binder_proc ongoing transaction */
+ binder_inner_proc_lock(proc);
+ for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) {
+ thread = rb_entry(n, struct binder_thread, rb_node);
+ empty = binder_worklist_empty_ilocked(&thread->todo);
+
+ if (thread->task != NULL) {
+ /* has "todo" binder thread in worklist? */
+ uid = task_uid(thread->task).val;
+ if (!empty) {
+ binder_inner_proc_unlock(proc);
+ hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_THREAD", 1);
+ return;
+ }
+
+ /* has transcation in transaction_stack? */
+ btrans = thread->transaction_stack;
+ if (btrans) {
+ spin_lock(&btrans->lock);
+ if (btrans->to_thread == thread) {
+ /* only report incoming binder call */
+ spin_unlock(&btrans->lock);
+ binder_inner_proc_unlock(proc);
+ hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_STACK", 1);
+ return;
+ }
+ spin_unlock(&btrans->lock);
+ }
+ }
+ }
+
+ /* has "todo" binder proc in worklist */
+ empty = binder_worklist_empty_ilocked(&proc->todo);
+ if (proc->tsk != NULL && !empty) {
+ uid = task_uid(proc->tsk).val;
+ binder_inner_proc_unlock(proc);
+ hans_report(type, -1, -1, -1, uid, "FROZEN_TRANS_PROC", 1);
+ return;
+ }
+ binder_inner_proc_unlock(proc);
+}
+
+void hans_check_frozen_transcation(uid_t uid, enum message_type type)
+{
+ struct binder_proc *proc;
+
+ mutex_lock(&binder_procs_lock);
+ hlist_for_each_entry(proc, &binder_procs, proc_node) {
+ if (proc != NULL && (task_uid(proc->tsk).val == uid)) {
+ hans_check_uid_proc_status(proc, type);
+ }
+ }
+ mutex_unlock(&binder_procs_lock);
+}
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
+
int binder_stats_show(struct seq_file *m, void *unused)
{
struct binder_proc *proc;
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 59ffccbcca3c..34340f9c3f96 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -33,6 +33,9 @@
#include
#include "binder_alloc.h"
#include "binder_trace.h"
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+#include
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
struct list_lru binder_alloc_lru;
@@ -400,6 +403,9 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
void __user *end_page_addr;
size_t size, data_offsets_size;
int ret;
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+ struct task_struct *p = NULL;
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
if (!binder_alloc_get_vma(alloc)) {
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
@@ -424,6 +430,18 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
alloc->pid, extra_buffers_size);
return ERR_PTR(-EINVAL);
}
+#ifdef OPLUS_FEATURE_HANS_FREEZE
+ if (is_async
+ && (alloc->free_async_space < 3 * (size + sizeof(struct binder_buffer))
+ || (alloc->free_async_space < ((alloc->buffer_size / 2) * 9 / 10)))) {
+ rcu_read_lock();
+ p = find_task_by_vpid(alloc->pid);
+ rcu_read_unlock();
+ if (p != NULL && is_frozen_tg(p)) {
+ hans_report(ASYNC_BINDER, task_tgid_nr(current), task_uid(current).val, task_tgid_nr(p), task_uid(p).val, "free_buffer_full", -1);
+ }
+ }
+#endif /*OPLUS_FEATURE_HANS_FREEZE*/
if (is_async &&
alloc->free_async_space < size + sizeof(struct binder_buffer)) {
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
@@ -548,6 +566,15 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
debug_low_async_space_locked(alloc, pid);
}
}
+
+ #ifdef OPLUS_BUG_STABILITY
+ if (size > 2000000 /*2MB*/){
+ binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
+ "%d: binder_alloc_buf size %zd successed, but it seems too large.\n",
+ alloc->pid, size);
+ }
+ #endif /*OPLUS_BUG_STABILITY*/
+
return buffer;
err_alloc_buf_struct_failed:
diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h
index 8d0bffcc9e27..e30ccc1ef8b4 100644
--- a/drivers/android/binder_internal.h
+++ b/drivers/android/binder_internal.h
@@ -12,6 +12,10 @@
#include
#include
#include
+#ifdef CONFIG_OPLUS_FEATURE_CPU_JANKINFO
+#include "binder_alloc.h"
+#endif
+
struct binder_context {
struct binder_node *binder_context_mgr_node;
@@ -141,6 +145,406 @@ struct binder_transaction_log {
struct binder_transaction_log_entry entry[32];
};
+#ifdef CONFIG_OPLUS_FEATURE_CPU_JANKINFO
+#define OPLUS_MAX_SERVICE_NAME_LEN 32
+enum binder_stat_types {
+ BINDER_STAT_PROC,
+ BINDER_STAT_THREAD,
+ BINDER_STAT_NODE,
+ BINDER_STAT_REF,
+ BINDER_STAT_DEATH,
+ BINDER_STAT_TRANSACTION,
+ BINDER_STAT_TRANSACTION_COMPLETE,
+ BINDER_STAT_COUNT
+};
+
+struct binder_stats {
+ atomic_t br[_IOC_NR(BR_FAILED_REPLY) + 1];
+ atomic_t bc[_IOC_NR(BC_REPLY_SG) + 1];
+ atomic_t obj_created[BINDER_STAT_COUNT];
+ atomic_t obj_deleted[BINDER_STAT_COUNT];
+};
+/**
+ * struct binder_work - work enqueued on a worklist
+ * @entry: node enqueued on list
+ * @type: type of work to be performed
+ *
+ * There are separate work lists for proc, thread, and node (async).
+ */
+struct binder_work {
+ struct list_head entry;
+
+ enum binder_work_type {
+ BINDER_WORK_TRANSACTION = 1,
+ BINDER_WORK_TRANSACTION_COMPLETE,
+ BINDER_WORK_RETURN_ERROR,
+ BINDER_WORK_NODE,
+ BINDER_WORK_DEAD_BINDER,
+ BINDER_WORK_DEAD_BINDER_AND_CLEAR,
+ BINDER_WORK_CLEAR_DEATH_NOTIFICATION,
+ } type;
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ u64 ob_begin;
+#endif
+};
+
+struct binder_error {
+ struct binder_work work;
+ uint32_t cmd;
+};
+/**
+ * struct binder_node - binder node bookkeeping
+ * @debug_id: unique ID for debugging
+ * (invariant after initialized)
+ * @lock: lock for node fields
+ * @work: worklist element for node work
+ * (protected by @proc->inner_lock)
+ * @rb_node: element for proc->nodes tree
+ * (protected by @proc->inner_lock)
+ * @dead_node: element for binder_dead_nodes list
+ * (protected by binder_dead_nodes_lock)
+ * @proc: binder_proc that owns this node
+ * (invariant after initialized)
+ * @refs: list of references on this node
+ * (protected by @lock)
+ * @internal_strong_refs: used to take strong references when
+ * initiating a transaction
+ * (protected by @proc->inner_lock if @proc
+ * and by @lock)
+ * @local_weak_refs: weak user refs from local process
+ * (protected by @proc->inner_lock if @proc
+ * and by @lock)
+ * @local_strong_refs: strong user refs from local process
+ * (protected by @proc->inner_lock if @proc
+ * and by @lock)
+ * @tmp_refs: temporary kernel refs
+ * (protected by @proc->inner_lock while @proc
+ * is valid, and by binder_dead_nodes_lock
+ * if @proc is NULL. During inc/dec and node release
+ * it is also protected by @lock to provide safety
+ * as the node dies and @proc becomes NULL)
+ * @ptr: userspace pointer for node
+ * (invariant, no lock needed)
+ * @cookie: userspace cookie for node
+ * (invariant, no lock needed)
+ * @has_strong_ref: userspace notified of strong ref
+ * (protected by @proc->inner_lock if @proc
+ * and by @lock)
+ * @pending_strong_ref: userspace has acked notification of strong ref
+ * (protected by @proc->inner_lock if @proc
+ * and by @lock)
+ * @has_weak_ref: userspace notified of weak ref
+ * (protected by @proc->inner_lock if @proc
+ * and by @lock)
+ * @pending_weak_ref: userspace has acked notification of weak ref
+ * (protected by @proc->inner_lock if @proc
+ * and by @lock)
+ * @has_async_transaction: async transaction to node in progress
+ * (protected by @lock)
+ * @sched_policy: minimum scheduling policy for node
+ * (invariant after initialized)
+ * @accept_fds: file descriptor operations supported for node
+ * (invariant after initialized)
+ * @min_priority: minimum scheduling priority
+ * (invariant after initialized)
+ * @inherit_rt: inherit RT scheduling policy from caller
+ * @txn_security_ctx: require sender's security context
+ * (invariant after initialized)
+ * @async_todo: list of async work items
+ * (protected by @proc->inner_lock)
+ *
+ * Bookkeeping structure for binder nodes.
+ */
+struct binder_node {
+ int debug_id;
+ spinlock_t lock;
+ struct binder_work work;
+ union {
+ struct rb_node rb_node;
+ struct hlist_node dead_node;
+ };
+ struct binder_proc *proc;
+ struct hlist_head refs;
+ int internal_strong_refs;
+ int local_weak_refs;
+ int local_strong_refs;
+ int tmp_refs;
+ binder_uintptr_t ptr;
+ binder_uintptr_t cookie;
+ struct {
+ /*
+ * bitfield elements protected by
+ * proc inner_lock
+ */
+ u8 has_strong_ref:1;
+ u8 pending_strong_ref:1;
+ u8 has_weak_ref:1;
+ u8 pending_weak_ref:1;
+ };
+ struct {
+ /*
+ * invariant after initialization
+ */
+ u8 sched_policy:2;
+ u8 inherit_rt:1;
+ u8 accept_fds:1;
+ u8 txn_security_ctx:1;
+ u8 min_priority;
+ };
+ bool has_async_transaction;
+ struct list_head async_todo;
+#if defined(CONFIG_OPLUS_FEATURE_BINDER_STATS_ENABLE)
+ char service_name[OPLUS_MAX_SERVICE_NAME_LEN];
+#endif
+};
+
+struct binder_ref_death {
+ /**
+ * @work: worklist element for death notifications
+ * (protected by inner_lock of the proc that
+ * this ref belongs to)
+ */
+ struct binder_work work;
+ binder_uintptr_t cookie;
+};
+
+/**
+ * struct binder_ref_data - binder_ref counts and id
+ * @debug_id: unique ID for the ref
+ * @desc: unique userspace handle for ref
+ * @strong: strong ref count (debugging only if not locked)
+ * @weak: weak ref count (debugging only if not locked)
+ *
+ * Structure to hold ref count and ref id information. Since
+ * the actual ref can only be accessed with a lock, this structure
+ * is used to return information about the ref to callers of
+ * ref inc/dec functions.
+ */
+struct binder_ref_data {
+ int debug_id;
+ uint32_t desc;
+ int strong;
+ int weak;
+};
+
+/**
+ * struct binder_ref - struct to track references on nodes
+ * @data: binder_ref_data containing id, handle, and current refcounts
+ * @rb_node_desc: node for lookup by @data.desc in proc's rb_tree
+ * @rb_node_node: node for lookup by @node in proc's rb_tree
+ * @node_entry: list entry for node->refs list in target node
+ * (protected by @node->lock)
+ * @proc: binder_proc containing ref
+ * @node: binder_node of target node. When cleaning up a
+ * ref for deletion in binder_cleanup_ref, a non-NULL
+ * @node indicates the node must be freed
+ * @death: pointer to death notification (ref_death) if requested
+ * (protected by @node->lock)
+ *
+ * Structure to track references from procA to target node (on procB). This
+ * structure is unsafe to access without holding @proc->outer_lock.
+ */
+struct binder_ref {
+ /* Lookups needed: */
+ /* node + proc => ref (transaction) */
+ /* desc + proc => ref (transaction, inc/dec ref) */
+ /* node => refs + procs (proc exit) */
+ struct binder_ref_data data;
+ struct rb_node rb_node_desc;
+ struct rb_node rb_node_node;
+ struct hlist_node node_entry;
+ struct binder_proc *proc;
+ struct binder_node *node;
+ struct binder_ref_death *death;
+};
+
+enum binder_deferred_state {
+ BINDER_DEFERRED_PUT_FILES = 0x01,
+ BINDER_DEFERRED_FLUSH = 0x02,
+ BINDER_DEFERRED_RELEASE = 0x04,
+};
+
+/**
+ * struct binder_priority - scheduler policy and priority
+ * @sched_policy scheduler policy
+ * @prio [100..139] for SCHED_NORMAL, [0..99] for FIFO/RT
+ *
+ * The binder driver supports inheriting the following scheduler policies:
+ * SCHED_NORMAL
+ * SCHED_BATCH
+ * SCHED_FIFO
+ * SCHED_RR
+ */
+struct binder_priority {
+ unsigned int sched_policy;
+ int prio;
+};
+
+/**
+ * struct binder_proc - binder process bookkeeping
+ * @proc_node: element for binder_procs list
+ * @threads: rbtree of binder_threads in this proc
+ * (protected by @inner_lock)
+ * @nodes: rbtree of binder nodes associated with
+ * this proc ordered by node->ptr
+ * (protected by @inner_lock)
+ * @refs_by_desc: rbtree of refs ordered by ref->desc
+ * (protected by @outer_lock)
+ * @refs_by_node: rbtree of refs ordered by ref->node
+ * (protected by @outer_lock)
+ * @waiting_threads: threads currently waiting for proc work
+ * (protected by @inner_lock)
+ * @pid PID of group_leader of process
+ * (invariant after initialized)
+ * @tsk task_struct for group_leader of process
+ * (invariant after initialized)
+ * @files files_struct for process
+ * (protected by @files_lock)
+ * @files_lock mutex to protect @files
+ * @cred struct cred associated with the `struct file`
+ * in binder_open()
+ * (invariant after initialized)
+ * @deferred_work_node: element for binder_deferred_list
+ * (protected by binder_deferred_lock)
+ * @deferred_work: bitmap of deferred work to perform
+ * (protected by binder_deferred_lock)
+ * @is_dead: process is dead and awaiting free
+ * when outstanding transactions are cleaned up
+ * (protected by @inner_lock)
+ * @todo: list of work for this process
+ * (protected by @inner_lock)
+ * @stats: per-process binder statistics
+ * (atomics, no lock needed)
+ * @delivered_death: list of delivered death notification
+ * (protected by @inner_lock)
+ * @max_threads: cap on number of binder threads
+ * (protected by @inner_lock)
+ * @requested_threads: number of binder threads requested but not
+ * yet started. In current implementation, can
+ * only be 0 or 1.
+ * (protected by @inner_lock)
+ * @requested_threads_started: number binder threads started
+ * (protected by @inner_lock)
+ * @tmp_ref: temporary reference to indicate proc is in use
+ * (protected by @inner_lock)
+ * @default_priority: default scheduler priority
+ * (invariant after initialized)
+ * @debugfs_entry: debugfs node
+ * @alloc: binder allocator bookkeeping
+ * @context: binder_context for this proc
+ * (invariant after initialized)
+ * @inner_lock: can nest under outer_lock and/or node lock
+ * @outer_lock: no nesting under innor or node lock
+ * Lock order: 1) outer, 2) node, 3) inner
+ * @binderfs_entry: process-specific binderfs log file
+ *
+ * Bookkeeping structure for binder processes
+ */
+struct binder_proc {
+ struct hlist_node proc_node;
+ struct rb_root threads;
+ struct rb_root nodes;
+ struct rb_root refs_by_desc;
+ struct rb_root refs_by_node;
+ struct list_head waiting_threads;
+ int pid;
+ struct task_struct *tsk;
+ struct files_struct *files;
+ struct mutex files_lock;
+ const struct cred *cred;
+ struct hlist_node deferred_work_node;
+ int deferred_work;
+ bool is_dead;
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ int proc_type;
+#endif /* OPLUS_FEATURE_SCHED_ASSIST */
+
+ struct list_head todo;
+ struct binder_stats stats;
+ struct list_head delivered_death;
+ int max_threads;
+ int requested_threads;
+ int requested_threads_started;
+ int tmp_ref;
+ struct binder_priority default_priority;
+ struct dentry *debugfs_entry;
+ struct binder_alloc alloc;
+ struct binder_context *context;
+ spinlock_t inner_lock;
+ spinlock_t outer_lock;
+ struct dentry *binderfs_entry;
+};
+
+enum {
+ BINDER_LOOPER_STATE_REGISTERED = 0x01,
+ BINDER_LOOPER_STATE_ENTERED = 0x02,
+ BINDER_LOOPER_STATE_EXITED = 0x04,
+ BINDER_LOOPER_STATE_INVALID = 0x08,
+ BINDER_LOOPER_STATE_WAITING = 0x10,
+ BINDER_LOOPER_STATE_POLL = 0x20,
+#ifdef CONFIG_OPLUS_BINDER_STRATEGY
+ BINDER_LOOPER_STATE_BACKGROUND = 0x40,
+#endif
+};
+
+/**
+ * struct binder_thread - binder thread bookkeeping
+ * @proc: binder process for this thread
+ * (invariant after initialization)
+ * @rb_node: element for proc->threads rbtree
+ * (protected by @proc->inner_lock)
+ * @waiting_thread_node: element for @proc->waiting_threads list
+ * (protected by @proc->inner_lock)
+ * @pid: PID for this thread
+ * (invariant after initialization)
+ * @looper: bitmap of looping state
+ * (only accessed by this thread)
+ * @looper_needs_return: looping thread needs to exit driver
+ * (no lock needed)
+ * @transaction_stack: stack of in-progress transactions for this thread
+ * (protected by @proc->inner_lock)
+ * @todo: list of work to do for this thread
+ * (protected by @proc->inner_lock)
+ * @process_todo: whether work in @todo should be processed
+ * (protected by @proc->inner_lock)
+ * @return_error: transaction errors reported by this thread
+ * (only accessed by this thread)
+ * @reply_error: transaction errors reported by target thread
+ * (protected by @proc->inner_lock)
+ * @wait: wait queue for thread work
+ * @stats: per-thread statistics
+ * (atomics, no lock needed)
+ * @tmp_ref: temporary reference to indicate thread is in use
+ * (atomic since @proc->inner_lock cannot
+ * always be acquired)
+ * @is_dead: thread is dead and awaiting free
+ * when outstanding transactions are cleaned up
+ * (protected by @proc->inner_lock)
+ * @task: struct task_struct for this thread
+ *
+ * Bookkeeping structure for binder threads.
+ */
+struct binder_thread {
+ struct binder_proc *proc;
+ struct rb_node rb_node;
+ struct list_head waiting_thread_node;
+ int pid;
+ int looper; /* only modified by this thread */
+ bool looper_need_return; /* can be written by other thread */
+ struct binder_transaction *transaction_stack;
+ struct list_head todo;
+ bool process_todo;
+ struct binder_error return_error;
+ struct binder_error reply_error;
+ wait_queue_head_t wait;
+ struct binder_stats stats;
+ atomic_t tmp_ref;
+ bool is_dead;
+ struct task_struct *task;
+};
+
+#endif
+
extern struct binder_transaction_log binder_transaction_log;
extern struct binder_transaction_log binder_transaction_log_failed;
#endif /* _LINUX_BINDER_INTERNAL_H */
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index d85275a7e0da..df1089f03414 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -156,6 +156,10 @@ config DEBUG_TEST_DRIVER_REMOVE
source "drivers/base/test/Kconfig"
+#ifdef OPLUS_FEATURE_TP_BASIC
+source "drivers/base/kernelFwUpdate/Kconfig"
+#endif /*OPLUS_FEATURE_TP_BASIC*/
+
config SYS_HYPERVISOR
bool
default n
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 704f44295810..e8226ec70749 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -28,3 +28,6 @@ obj-y += test/
ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
+#ifdef OPLUS_FEATURE_TP_BASIC
+obj-$(CONFIG_OPLUS_FW_UPDATE) += kernelFwUpdate/
+#endif /*OPLUS_FEATURE_TP_BASIC*/
diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
index 821e27bda4ca..8a1bbfb346b7 100644
--- a/drivers/base/firmware_loader/fallback.c
+++ b/drivers/base/firmware_loader/fallback.c
@@ -544,6 +544,10 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs,
struct device *f_dev = &fw_sysfs->dev;
struct fw_priv *fw_priv = fw_sysfs->fw_priv;
+#ifdef OPLUS_FEATURE_TP_BSPFWUPDATE
+ char *envp[2]={"FwUp=compare", NULL};
+#endif/*OPLUS_FEATURE_TP_BSPFWUPDATE*/
+
/* fall back on userspace loading */
if (!fw_priv->data)
fw_priv->is_paged_buf = true;
@@ -569,7 +573,15 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs,
fw_priv->need_uevent = true;
dev_set_uevent_suppress(f_dev, false);
dev_dbg(f_dev, "firmware: requesting %s\n", fw_priv->fw_name);
+#ifdef OPLUS_FEATURE_TP_BSPFWUPDATE
+ if (opt_flags & FW_OPT_COMPARE) {
+ kobject_uevent_env(&fw_sysfs->dev.kobj, KOBJ_CHANGE,envp);
+ } else {
+ kobject_uevent(&fw_sysfs->dev.kobj, KOBJ_ADD);
+ }
+#else
kobject_uevent(&fw_sysfs->dev.kobj, KOBJ_ADD);
+#endif/*OPLUS_FEATURE_TP_BSPFWUPDATE*/
} else {
timeout = MAX_JIFFY_OFFSET;
}
diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h
index e2000b4ad09b..ef05a791b5af 100644
--- a/drivers/base/firmware_loader/firmware.h
+++ b/drivers/base/firmware_loader/firmware.h
@@ -37,6 +37,9 @@ enum fw_opt {
FW_OPT_NO_WARN = BIT(3),
FW_OPT_NOCACHE = BIT(4),
FW_OPT_NOFALLBACK = BIT(5),
+#ifdef OPLUS_FEATURE_TP_BSPFWUPDATE
+ FW_OPT_COMPARE = BIT(6),
+#endif/*OPLUS_FEATURE_TP_BSPFWUPDATE*/
};
enum fw_status {
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index 8b716933fe89..7c676ed56cf7 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -283,6 +283,10 @@ static void free_fw_priv(struct fw_priv *fw_priv)
/* direct firmware loading support */
static char fw_path_para[256];
static const char * const fw_path[] = {
+ //#ifdef OPLUS_FEATURE_WIFI_RUSUPGRADE
+ //add for: support auto update function, include mtk fw, mtk wifi.cfg, qcom fw, qcom bdf, qcom ini
+ "/data/misc/firmware/active",
+ //#endif /* OPLUS_FEATURE_WIFI_RUSUPGRADE */
fw_path_para,
"/lib/firmware/updates/" UTS_RELEASE,
"/lib/firmware/updates",
@@ -298,8 +302,14 @@ static const char * const fw_path[] = {
module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
+#ifdef OPLUS_FEATURE_TP_BSPFWUPDATE
+static int fw_get_filesystem_firmware(struct device *device,
+ struct fw_priv *fw_priv,
+ enum fw_opt opt_flags)
+#else
static int
fw_get_filesystem_firmware(struct device *device, struct fw_priv *fw_priv)
+#endif /*OPLUS_FEATURE_TP_BSPFWUPDATE*/
{
loff_t size;
int i, len;
@@ -308,6 +318,13 @@ fw_get_filesystem_firmware(struct device *device, struct fw_priv *fw_priv)
enum kernel_read_file_id id = READING_FIRMWARE;
size_t msize = INT_MAX;
+#ifdef OPLUS_FEATURE_TP_BSPFWUPDATE
+ if(opt_flags & FW_OPT_COMPARE) {
+ pr_err("%s opt_flags get FW_OPT_COMPARE!\n", __func__);
+ return rc;
+ }
+#endif/*OPLUS_FEATURE_TP_BSPFWUPDATE*/
+
/* Already populated data member means we're loading into a buffer */
if (fw_priv->data) {
id = READING_FIRMWARE_PREALLOC_BUFFER;
@@ -330,6 +347,24 @@ fw_get_filesystem_firmware(struct device *device, struct fw_priv *fw_priv)
break;
}
+#if defined(OPLUS_FEATURE_CAMERA_OIS)
+ if (strstr(fw_path[i], "/lib/firmware/") != NULL) {
+ if (strstr(fw_priv->fw_name, "ois_") != NULL) {
+ snprintf(path, PATH_MAX, "%s/%s", "/odm/vendor/firmware", fw_priv->fw_name);
+ }
+ }
+#endif /*OPLUS_FEATURE_CAMERA_OIS*/
+#if defined(OPLUS_FEATURE_PXLW_IRIS5)
+ if (!strcmp(fw_priv->fw_name, "iris5.fw")
+ || !strcmp(fw_priv->fw_name, "iris5_ccf1.fw")
+ || !strcmp(fw_priv->fw_name, "iris5_ccf2.fw")) {
+ snprintf(path, PATH_MAX, "%s/%s", "/odm/vendor/firmware", fw_priv->fw_name);
+ }
+ if (!strcmp(fw_priv->fw_name, "iris5_ccf1b.fw")
+ || !strcmp(fw_priv->fw_name, "iris5_ccf2b.fw")) {
+ snprintf(path, PATH_MAX, "%s/%s", "/data/vendor/display", fw_priv->fw_name);
+ }
+#endif /*OPLUS_FEATURE_PXLW_IRIS5*/
fw_priv->size = 0;
rc = kernel_read_file_from_path(path, &fw_priv->data, &size,
msize, id);
@@ -592,7 +627,11 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
if (ret <= 0) /* error or already assigned */
goto out;
+#ifdef OPLUS_FEATURE_TP_BSPFWUPDATE
+ ret = fw_get_filesystem_firmware(device, fw->priv, opt_flags);
+#else
ret = fw_get_filesystem_firmware(device, fw->priv);
+#endif/*OPLUS_FEATURE_TP_BSPFWUPDATE*/
if (ret) {
if (!(opt_flags & FW_OPT_NO_WARN))
dev_dbg(device,
@@ -648,6 +687,25 @@ request_firmware(const struct firmware **firmware_p, const char *name,
}
EXPORT_SYMBOL(request_firmware);
+
+#ifdef VENDOR_EDIT
+//Add for: reload wlan bdf without using cache
+int
+request_firmware_no_cache(const struct firmware **firmware_p, const char *name,
+ struct device *device)
+{
+ int ret;
+
+ /* Need to pin this module until return */
+ __module_get(THIS_MODULE);
+ ret = _request_firmware(firmware_p, name, device, NULL, 0,
+ FW_OPT_UEVENT | FW_OPT_NOCACHE);
+ module_put(THIS_MODULE);
+ return ret;
+}
+EXPORT_SYMBOL(request_firmware_no_cache);
+#endif /* VENDOR_EDIT */
+
/**
* firmware_request_nowarn() - request for an optional fw module
* @firmware: pointer to firmware image
diff --git a/drivers/base/kernelFwUpdate b/drivers/base/kernelFwUpdate
new file mode 120000
index 000000000000..e1d84774ab42
--- /dev/null
+++ b/drivers/base/kernelFwUpdate
@@ -0,0 +1 @@
+../../../../vendor/oplus/kernel/touchpanel/kernelFwUpdate/
\ No newline at end of file
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 25090f9284f7..d0d6b212dd97 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -25,7 +25,9 @@
#include
#include
-
+#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION)
+#include
+#endif
static DEFINE_MUTEX(mem_sysfs_mutex);
#define MEMORY_CLASS_NAME "memory"
@@ -447,12 +449,32 @@ static DEVICE_ATTR(valid_zones, 0444, show_valid_zones, NULL);
#ifdef CONFIG_MEMORY_HOTPLUG
static int count_num_free_block_pages(struct zone *zone, int bid)
{
+#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION)
+ int order, type, flc;
+#else
int order, type;
+#endif
unsigned long freecount = 0;
unsigned long flags;
spin_lock_irqsave(&zone->lock, flags);
for (type = 0; type < MIGRATE_TYPES; type++) {
+#if defined(OPLUS_FEATURE_MULTI_FREEAREA) && defined(CONFIG_PHYSICAL_ANTI_FRAGMENTATION)
+ for (flc = 0; flc < FREE_AREA_COUNTS; flc++) {
+ struct free_area *area;
+ struct page *page;
+ for (order = 0; order < MAX_ORDER; ++order) {
+ area = &(zone->free_area[flc][order]);
+ list_for_each_entry(page, &area->free_list[type], lru) {
+ unsigned long pfn = page_to_pfn(page);
+ int section_nr = pfn_to_section_nr(pfn);
+
+ if (bid == base_memory_block_id(section_nr))
+ freecount += (1 << order);
+ }
+ }
+ }
+#else
for (order = 0; order < MAX_ORDER; ++order) {
struct free_area *area;
struct page *page;
@@ -467,6 +489,7 @@ static int count_num_free_block_pages(struct zone *zone, int bid)
}
}
+#endif
}
spin_unlock_irqrestore(&zone->lock, flags);
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index f72608d1be4b..9af5d826c66c 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -19,12 +19,22 @@
#include
#include
#include
+#ifdef OPLUS_FEATURE_LOGKIT
+#include
+#include
+#endif /* OPLUS_FEATURE_LOGKIT */
#include
#include
#include
+#ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+#include
+#endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+
#include "power.h"
+#include
+
#ifndef CONFIG_SUSPEND
suspend_state_t pm_suspend_target_state;
#define pm_suspend_target_state (PM_SUSPEND_ON)
@@ -545,6 +555,10 @@ static void wakeup_source_activate(struct wakeup_source *ws)
"unregistered wakeup source\n"))
return;
+ #ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+ wakeup_get_start_time();
+ #endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+
ws->active = true;
ws->active_count++;
ws->last_time = ktime_get();
@@ -686,8 +700,12 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
trace_wakeup_source_deactivate(ws->name, cec);
split_counters(&cnt, &inpr);
- if (!inpr && waitqueue_active(&wakeup_count_wait_queue))
+ if (!inpr && waitqueue_active(&wakeup_count_wait_queue)) {
+ #ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+ wakeup_get_end_hold_time();
+ #endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
wake_up(&wakeup_count_wait_queue);
+ }
}
/**
@@ -861,7 +879,11 @@ void pm_print_active_wakeup_sources(void)
srcuidx = srcu_read_lock(&wakeup_srcu);
list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
if (ws->active) {
+ #ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+ pr_info("active wakeup source: %s\n", ws->name);
+ #else
pr_debug("active wakeup source: %s\n", ws->name);
+ #endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
active = 1;
} else if (!active &&
(!last_activity_ws ||
@@ -871,13 +893,46 @@ void pm_print_active_wakeup_sources(void)
}
}
- if (!active && last_activity_ws)
+ if (!active && last_activity_ws) {
+ #ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+ pr_info("last active wakeup source: %s\n",
+ last_activity_ws->name);
+ #else
pr_debug("last active wakeup source: %s\n",
last_activity_ws->name);
+ #endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+ }
srcu_read_unlock(&wakeup_srcu, srcuidx);
}
EXPORT_SYMBOL_GPL(pm_print_active_wakeup_sources);
+#ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+void get_ws_listhead(struct list_head **ws)
+{
+ if (ws)
+ *ws = &wakeup_sources;
+}
+
+void wakeup_srcu_read_lock(int *srcuidx)
+{
+ *srcuidx = srcu_read_lock(&wakeup_srcu);
+}
+
+void wakeup_srcu_read_unlock(int srcuidx)
+{
+ srcu_read_unlock(&wakeup_srcu, srcuidx);
+}
+
+bool ws_all_release(void)
+{
+ unsigned int cnt, inpr;
+
+ pr_info("Enter: %s\n", __func__);
+ split_counters(&cnt, &inpr);
+ return (!inpr) ? true : false;
+}
+#endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+
/**
* pm_wakeup_pending - Check if power transition in progress should be aborted.
*
@@ -903,6 +958,12 @@ bool pm_wakeup_pending(void)
raw_spin_unlock_irqrestore(&events_lock, flags);
if (ret) {
+ #ifndef OPLUS_FEATURE_POWERINFO_STANDBY
+ pr_debug("PM: Wakeup pending, aborting suspend\n");
+ #else
+ pr_info("PM: Wakeup pending, aborting suspend\n");
+ wakeup_reasons_statics(IRQ_NAME_ABORT, WS_CNT_ABORT);
+ #endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
pm_get_active_wakeup_sources(suspend_abort,
MAX_SUSPEND_ABORT_LEN);
log_suspend_abort_reason(suspend_abort);
@@ -946,6 +1007,11 @@ void pm_system_irq_wakeup(unsigned int irq_number)
log_irq_wakeup_reason(irq_number);
pr_warn("%s: %d triggered %s\n", __func__, irq_number, name);
+ #ifdef OPLUS_FEATURE_POWERINFO_STANDBY
+ pr_info("%s: resume caused by irq=%d, name=%s\n", __func__, irq_number, name);
+ wakeup_reasons_statics(name, WS_CNT_POWERKEY|WS_CNT_RTCALARM);
+ #endif /* OPLUS_FEATURE_POWERINFO_STANDBY */
+
pm_wakeup_irq = irq_number;
pm_system_wakeup();
}
@@ -1169,12 +1235,22 @@ static const struct file_operations wakeup_sources_stats_fops = {
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
+#ifdef OPLUS_FEATURE_LOGKIT
+ .write = watchdog_write,
+#endif /* OPLUS_FEATURE_LOGKIT */
};
static int __init wakeup_sources_debugfs_init(void)
{
+ #ifndef OPLUS_FEATURE_LOGKIT
wakeup_sources_stats_dentry = debugfs_create_file("wakeup_sources",
S_IRUGO, NULL, NULL, &wakeup_sources_stats_fops);
+ #else /* OPLUS_FEATURE_LOGKIT */
+ wakeup_sources_stats_dentry = debugfs_create_file("wakeup_sources",
+ S_IRUGO| S_IWUGO, NULL, NULL, &wakeup_sources_stats_fops);
+ #endif /* OPLUS_FEATURE_LOGKIT */
+
+ proc_create_data("wakeup_sources", 0444, NULL, &wakeup_sources_stats_fops, NULL);
return 0;
}
diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig
index c8aab3115733..3c69e370cf7c 100644
--- a/drivers/block/zram/Kconfig
+++ b/drivers/block/zram/Kconfig
@@ -53,3 +53,55 @@ config ZRAM_MEMORY_TRACKING
/sys/kernel/debug/zram/zramX/block_state.
See Documentation/blockdev/zram.txt for more information.
+
+#ifdef OPLUS_FEATURE_ZRAM_OPT
+config OPLUS_ZRAM_OPT
+ bool "oplus zram optimization"
+ depends on ZRAM
+ default y
+ help
+ oplus zram optimization
+#endif /*OPLUS_FEATURE_ZRAM_OPT*/
+
+#ifdef OPLUS_FEATURE_ZRAM_WRITEBACK
+source "drivers/block/zram/zwb_handle/Kconfig"
+#endif /* OPLUS_FEATURE_ZRAM_WRITEBACK */
+
+config HYBRIDSWAP
+ bool "Enable Hybridswap"
+ depends on MEMCG && ZRAM && !ZRAM_DEDUP && !ZRAM_WRITEBACK && !ZWB_HANDLE
+ default n
+ help
+ Hybridswap is a intelligent memory management solution.
+
+config HYBRIDSWAP_SWAPD
+ bool "Enable hybridswap swapd thread to reclaim anon pages in background"
+ default n
+ depends on HYBRIDSWAP
+ help
+ swapd is a kernel thread that reclaim anonymous pages in the
+ background. When the use of swap pages reaches the watermark
+ and the refault of anonymous pages is high, the content of
+ zram will exchanged to eswap by a certain percentage.
+
+# Selected when system need hybridswap container
+config HYBRIDSWAP_CORE
+ bool "Hybridswap container device support"
+ depends on ZRAM && HYBRIDSWAP
+ default n
+ help
+ Say Y here if you want to use the hybridswap
+ as the backend device in ZRAM.
+ If unsure, say N here.
+ This module can't be compiled as a module,
+ the module is as one part of the ZRAM driver.
+
+config HYBRIDSWAP_ASYNC_COMPRESS
+ bool "hypbridswap support asynchronous compress anon pages"
+ depends on ZRAM && HYBRIDSWAP
+ default n
+ help
+ Say Y here if you want to create asynchronous thread
+ for compress anon pages.
+ If unsure, say N here.
+ This feature will reduce the kswapd cpu load.
diff --git a/drivers/block/zram/Makefile b/drivers/block/zram/Makefile
index d7204ef6ee53..f08cdabb26ac 100644
--- a/drivers/block/zram/Makefile
+++ b/drivers/block/zram/Makefile
@@ -1,4 +1,14 @@
-zram-y := zcomp.o zram_drv.o
+# SPDX-License-Identifier: GPL-2.0-only
+zram-y := zcomp.o zram_drv.o
zram-$(CONFIG_ZRAM_DEDUP) += zram_dedup.o
obj-$(CONFIG_ZRAM) += zram.o
+
+#ifdef OPLUS_FEATURE_ZRAM_WRITEBACK
+obj-$(CONFIG_ZWB_HANDLE) += zwb_handle/
+#endif /* OPLUS_FEATURE_ZRAM_WRITEBACK */
+
+zram-$(CONFIG_HYBRIDSWAP) += hybridswap/hybridswap_main.o
+zram-$(CONFIG_HYBRIDSWAP_SWAPD) += hybridswap/hybridswap_swapd.o
+zram-$(CONFIG_HYBRIDSWAP_ASYNC_COMPRESS) += hybridswap/hybridswap_akcompress.o
+zram-$(CONFIG_HYBRIDSWAP_CORE) += hybridswap/hybridswap_eswap.o
diff --git a/drivers/block/zram/hybridswap/hybridswap.h b/drivers/block/zram/hybridswap/hybridswap.h
new file mode 100644
index 000000000000..13b3bea215fd
--- /dev/null
+++ b/drivers/block/zram/hybridswap/hybridswap.h
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020-2022 Oplus. All rights reserved.
+ */
+
+#ifndef HYBRIDSWAP_H
+#define HYBRIDSWAP_H
+extern int __init hybridswap_pre_init(void);
+extern ssize_t hybridswap_vmstat_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_loglevel_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_loglevel_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_enable_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_enable_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+#ifdef CONFIG_HYBRIDSWAP_CORE
+extern void hybridswap_record(struct zram *zram, u32 index, struct mem_cgroup *memcg);
+extern void hybridswap_untrack(struct zram *zram, u32 index);
+extern int hybridswap_page_fault(struct zram *zram, u32 index);
+extern bool hybridswap_delete(struct zram *zram, u32 index);
+
+extern ssize_t hybridswap_report_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_stat_snap_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_meminfo_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_core_enable_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_core_enable_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_loop_device_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_loop_device_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_dev_life_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_dev_life_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_quota_day_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_quota_day_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern ssize_t hybridswap_zram_increase_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_zram_increase_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+/* 63---48,47--32,31-0 : cgroup id, thread_index, index*/
+#define ZRAM_INDEX_SHIFT 32
+#define CACHE_INDEX_SHIFT 32
+#define CACHE_INDEX_MASK ((1llu << CACHE_INDEX_SHIFT) - 1)
+#define ZRAM_INDEX_MASK ((1llu << ZRAM_INDEX_SHIFT) - 1)
+
+#define cache_index_val(index) (((unsigned long)index & CACHE_INDEX_MASK) << ZRAM_INDEX_SHIFT)
+#define zram_index_val(id) ((unsigned long)id & ZRAM_INDEX_MASK)
+#define mk_page_val(cache_index, index) (cache_index_val(cache_index) | zram_index_val(index))
+
+#define fetch_cache_id(page) ((page->private >> 32) & CACHE_INDEX_MASK)
+#define fetch_zram_index(page) (page->private & ZRAM_INDEX_MASK)
+
+#define zram_set_page(zram, index, page) (zram->table[index].page = page)
+#define zram_fetch_page(zram, index) (zram->table[index].page)
+
+extern void del_page_from_cache(struct page *page);
+extern int add_anon_page2cache(struct zram * zram, u32 index,
+ struct page *page);
+extern ssize_t hybridswap_akcompress_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_akcompress_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+extern void put_free_page(struct page *page);
+extern void put_anon_pages(struct page *page);
+extern int akcompress_cache_page_fault(struct zram *zram,
+ struct page *page, u32 index);
+extern void destroy_akcompressd_task(struct zram *zram);
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+extern ssize_t hybridswap_swapd_pause_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len);
+extern ssize_t hybridswap_swapd_pause_show(struct device *dev,
+ struct device_attribute *attr, char *buf);
+#endif
+static inline bool current_is_swapd(void)
+{
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ return (strncmp(current->comm, "hybridswapd:", sizeof("hybridswapd:") - 1) == 0);
+#else
+ return false;
+#endif
+}
+#endif /* HYBRIDSWAP_H */
diff --git a/drivers/block/zram/hybridswap/hybridswap_akcompress.c b/drivers/block/zram/hybridswap/hybridswap_akcompress.c
new file mode 100644
index 000000000000..3548f042cf2e
--- /dev/null
+++ b/drivers/block/zram/hybridswap/hybridswap_akcompress.c
@@ -0,0 +1,575 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020-2022 Oplus. All rights reserved.
+ */
+
+#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt
+
+#include
+#include
+#include
+#include
+#include
+
+#include "../zram_drv.h"
+#include "../zram_drv_internal.h"
+#include "hybridswap_internal.h"
+#include "hybridswap.h"
+
+struct compress_info_s {
+ struct list_head free_page_head;
+ spinlock_t free_lock;
+ unsigned int free_cnt;
+
+ unsigned int max_cnt;
+} compress_info;
+
+#define MAX_AKCOMPRESSD_THREADS 4
+#define DEFAULT_CACHE_SIZE_MB 64
+#define DEFAULT_COMPRESS_BATCH_MB 1
+#define DEFAULT_CACHE_COUNT ((DEFAULT_CACHE_SIZE_MB << 20) >> PAGE_SHIFT)
+#define WAKEUP_AKCOMPRESSD_WATERMARK ((DEFAULT_COMPRESS_BATCH_MB << 20) >> PAGE_SHIFT)
+
+static wait_queue_head_t akcompressd_wait;
+static struct task_struct *akc_task[MAX_AKCOMPRESSD_THREADS];
+static atomic64_t akc_cnt[MAX_AKCOMPRESSD_THREADS];
+static int akcompressd_threads = 0;
+static atomic64_t cached_cnt;
+static struct zram *zram_info;
+static DEFINE_MUTEX(akcompress_init_lock);
+
+struct idr cached_idr = IDR_INIT(cached_idr);
+DEFINE_SPINLOCK(cached_idr_lock);
+
+static void wake_all_akcompressd(void);
+
+void clear_page_memcg(struct cgroup_cache_page *cache)
+{
+ struct list_head *pos;
+ struct page *page;
+
+ spin_lock(&cache->lock);
+ if (list_empty(&cache->head))
+ goto out;
+
+ list_for_each(pos, &cache->head) {
+ page = list_entry(pos, struct page, lru);
+ if (!page->mem_cgroup)
+ BUG();
+ page->mem_cgroup = NULL;
+ }
+
+out:
+ cache->dead = 1;
+ spin_unlock(&cache->lock);
+}
+
+static inline struct page * fetch_free_page(void)
+{
+ struct page *page = NULL;
+
+ spin_lock(&compress_info.free_lock);
+ if (compress_info.free_cnt > 0) {
+ if (list_empty(&compress_info.free_page_head))
+ BUG();
+ page = lru_to_page(&compress_info.free_page_head);
+ list_del(&page->lru);
+ compress_info.free_cnt--;
+ }
+ spin_unlock(&compress_info.free_lock);
+
+ return page;
+}
+
+void put_free_page(struct page *page)
+{
+ set_page_private(page, 0);
+ spin_lock(&compress_info.free_lock);
+ list_add_tail(&page->lru, &compress_info.free_page_head);
+ compress_info.free_cnt++;
+ spin_unlock(&compress_info.free_lock);
+}
+
+static inline struct cgroup_cache_page *find_and_fetch_memcg_cache(int cache_id)
+{
+ struct cgroup_cache_page *cache;
+
+ spin_lock(&cached_idr_lock);
+ cache = (struct cgroup_cache_page *)idr_find(&cached_idr, cache_id);
+ if (unlikely(!cache)) {
+ spin_unlock(&cached_idr_lock);
+ pr_err("cache_id %d cache not find.\n", cache_id);
+
+ return NULL;
+ }
+ fetch_memcg_cache(container_of(cache, memcg_hybs_t, cache));
+ spin_unlock(&cached_idr_lock);
+
+ return cache;
+}
+
+void del_page_from_cache(struct page *page)
+{
+ int cache_id;
+ struct cgroup_cache_page *cache;
+
+ if (!page)
+ return;
+
+ cache_id = fetch_cache_id(page);
+ if (unlikely(cache_id < 0 || cache_id > MEM_CGROUP_ID_MAX)) {
+ hybp(HYB_ERR, "page %p cache_id %d index %u is invalid.\n",
+ page, cache_id, fetch_zram_index(page));
+ return;
+ }
+
+ cache = find_and_fetch_memcg_cache(cache_id);
+ if (!cache)
+ return;
+
+ spin_lock(&cache->lock);
+ list_del(&page->lru);
+ cache->cnt--;
+ spin_unlock(&cache->lock);
+ put_memcg_cache(container_of(cache, memcg_hybs_t, cache));
+ atomic64_dec(&cached_cnt);
+}
+
+void del_page_from_cache_with_cache(struct page *page,
+ struct cgroup_cache_page *cache)
+{
+ spin_lock(&cache->lock);
+ list_del(&page->lru);
+ cache->cnt--;
+ spin_unlock(&cache->lock);
+ atomic64_dec(&cached_cnt);
+}
+
+void put_anon_pages(struct page *page)
+{
+ memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(page->mem_cgroup);
+
+ spin_lock(&hybs->cache.lock);
+ list_add(&page->lru, &hybs->cache.head);
+ hybs->cache.cnt++;
+ spin_unlock(&hybs->cache.lock);
+}
+
+static inline bool can_stop_working(struct cgroup_cache_page *cache, int index)
+{
+ spin_lock(&cache->lock);
+ if (unlikely(!list_empty(&cache->head))) {
+ spin_unlock(&cache->lock);
+ return false;
+ }
+ spin_unlock(&cache->lock);
+ return 1;
+}
+
+static int check_cache_state(struct cgroup_cache_page *cache)
+{
+ if (cache->cnt == 0 || cache->compressing == 1)
+ return 0;
+
+ spin_lock(&cache->lock);
+ if (cache->cnt == 0 || cache->compressing) {
+ spin_unlock(&cache->lock);
+ return 0;
+ }
+ cache->compressing = 1;
+ spin_unlock(&cache->lock);
+ fetch_memcg_cache(container_of(cache, memcg_hybs_t, cache));
+ return 1;
+}
+
+struct cgroup_cache_page *fetch_one_cache(void)
+{
+ struct cgroup_cache_page *cache = NULL;
+ int id;
+
+ spin_lock(&cached_idr_lock);
+ idr_for_each_entry(&cached_idr, cache, id) {
+ if (check_cache_state(cache))
+ break;
+ }
+ spin_unlock(&cached_idr_lock);
+
+ return cache;
+}
+
+void mark_compressing_stop(struct cgroup_cache_page *cache)
+{
+ spin_lock(&cache->lock);
+ if (cache->dead)
+ hybp(HYB_WARN, "stop compressing, may be cgroup is delelted\n");
+ cache->compressing = 0;
+ spin_unlock(&cache->lock);
+ put_memcg_cache(container_of(cache, memcg_hybs_t, cache));
+}
+
+static inline struct page *fetch_anon_page(struct zram *zram,
+ struct cgroup_cache_page *cache)
+{
+ struct page *page, *prev_page;
+ int index;
+
+ if (compress_info.free_cnt == 0)
+ return NULL;
+
+ prev_page = NULL;
+try_again:
+ page = NULL;
+
+ spin_lock(&cache->lock);
+ if (!list_empty(&cache->head)) {
+ page = lru_to_page(&cache->head);
+ index = fetch_zram_index(page);
+ }
+ spin_unlock(&cache->lock);
+
+ if (page) {
+ if (prev_page && (page == prev_page)) {
+ hybp(HYB_ERR, "zram %p index %d page %p\n",
+ zram, index, page);
+ BUG();
+ }
+
+ zram_slot_lock(zram, index);
+ if (!zram_test_flag(zram, index, ZRAM_CACHED)) {
+ zram_slot_unlock(zram, index);
+ prev_page = page;
+ goto try_again;
+ }
+
+ prev_page = NULL;
+ zram_clear_flag(zram, index, ZRAM_CACHED);
+ del_page_from_cache_with_cache(page, cache);
+ zram_set_flag(zram, index, ZRAM_CACHED_COMPRESS);
+ zram_slot_unlock(zram, index);
+ }
+
+ return page;
+}
+
+int add_anon_page2cache(struct zram * zram, u32 index, struct page *page)
+{
+ struct page *dst_page;
+ void *src, *dst;
+ struct mem_cgroup *memcg;
+ struct cgroup_cache_page *cache;
+ memcg_hybs_t *hybs;
+
+ if (akcompressd_threads == 0)
+ return 0;
+
+ memcg = page->mem_cgroup;
+ if (!memcg || !MEMCGRP_ITEM_DATA(memcg))
+ return 0;
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ cache = &hybs->cache;
+ if (find_and_fetch_memcg_cache(cache->id) != cache)
+ return 0;
+
+ spin_lock(&cache->lock);
+ if (cache->dead == 1) {
+ spin_unlock(&cache->lock);
+ return 0;
+ }
+ spin_unlock(&cache->lock);
+
+ dst_page = fetch_free_page();
+ if (!dst_page)
+ return 0;
+
+ src = kmap_atomic(page);
+ dst = kmap_atomic(dst_page);
+ memcpy(dst, src, PAGE_SIZE);
+ kunmap_atomic(src);
+ kunmap_atomic(dst);
+
+ dst_page->mem_cgroup = memcg;
+ set_page_private(dst_page, mk_page_val(cache->id, index));
+ update_zram_index(zram, index, (unsigned long)dst_page);
+ atomic64_inc(&cached_cnt);
+ wake_all_akcompressd();
+ hybp(HYB_DEBUG, "add_anon_page2cache index %u page %p passed\n",
+ index, dst_page);
+ return 1;
+}
+
+static inline void akcompressd_try_to_sleep(wait_queue_head_t *waitq)
+{
+ DEFINE_WAIT(wait);
+
+ prepare_to_wait(waitq, &wait, TASK_INTERRUPTIBLE);
+ freezable_schedule();
+ finish_wait(waitq, &wait);
+}
+
+static int akcompressd_func(void *data)
+{
+ struct page *page;
+ int ret, thread_index;
+ struct list_head compress_fail_list;
+ struct cgroup_cache_page *cache = NULL;
+
+ thread_index = (int)data;
+ if (thread_index < 0 || thread_index >= MAX_AKCOMPRESSD_THREADS) {
+ hybp(HYB_ERR, "akcompress task index %d is invalid.\n", thread_index);
+ return -EINVAL;
+ }
+
+ set_freezable();
+ while (!kthread_should_stop()) {
+ akcompressd_try_to_sleep(&akcompressd_wait);
+ count_swapd_event(AKCOMPRESSD_WAKEUP);
+
+ cache = fetch_one_cache();
+ if (!cache)
+ continue;
+
+finish_last_jobs:
+ INIT_LIST_HEAD(&compress_fail_list);
+ page = fetch_anon_page(zram_info, cache);
+ while (page) {
+ ret = async_compress_page(zram_info, page);
+ put_memcg_cache(container_of(cache, memcg_hybs_t, cache));
+
+ if (ret)
+ list_add(&page->lru, &compress_fail_list);
+ else {
+ atomic64_inc(&akc_cnt[thread_index]);
+ page->mem_cgroup = NULL;
+ put_free_page(page);
+ }
+ page = fetch_anon_page(zram_info, cache);
+ }
+
+ if (!list_empty(&compress_fail_list))
+ hybp(HYB_ERR, "have some compress failed pages.\n");
+
+ if (kthread_should_stop()) {
+ if (!can_stop_working(cache, thread_index))
+ goto finish_last_jobs;
+ }
+ mark_compressing_stop(cache);
+ }
+
+ return 0;
+}
+
+static int update_akcompressd_threads(int thread_count, struct zram *zram)
+{
+ int drop, increase;
+ int last_index, start_index, hid;
+ static DEFINE_MUTEX(update_lock);
+
+ if (thread_count < 0 || thread_count > MAX_AKCOMPRESSD_THREADS) {
+ hybp(HYB_ERR, "thread_count %d is invalid\n", thread_count);
+ return -EINVAL;
+ }
+
+ mutex_lock(&update_lock);
+ if (!zram_info || zram_info != zram)
+ zram_info = zram;
+
+ if (thread_count == akcompressd_threads) {
+ mutex_unlock(&update_lock);
+ return thread_count;
+ }
+
+ last_index = akcompressd_threads - 1;
+ if (thread_count < akcompressd_threads) {
+ drop = akcompressd_threads - thread_count;
+ for (hid = last_index; hid > (last_index - drop); hid--) {
+ if (akc_task[hid]) {
+ kthread_stop(akc_task[hid]);
+ akc_task[hid] = NULL;
+ }
+ }
+ } else {
+ increase = thread_count - akcompressd_threads;
+ start_index = last_index + 1;
+ for (hid = start_index; hid < (start_index + increase); hid++) {
+ if (unlikely(akc_task[hid]))
+ BUG();
+ akc_task[hid]= kthread_run(akcompressd_func,
+ (void*)(unsigned long)hid, "akcompressd:%d", hid);
+ if (IS_ERR(akc_task[hid])) {
+ pr_err("Failed to start akcompressd%d\n", hid);
+ akc_task[hid] = NULL;
+ break;
+ }
+ }
+ }
+
+ hybp(HYB_INFO, "akcompressd_threads count changed, old:%d new:%d\n",
+ akcompressd_threads, thread_count);
+ akcompressd_threads = thread_count;
+ mutex_unlock(&update_lock);
+
+ return thread_count;
+}
+
+static void wake_all_akcompressd(void)
+{
+ if (atomic64_read(&cached_cnt) < WAKEUP_AKCOMPRESSD_WATERMARK)
+ return;
+
+ if (!waitqueue_active(&akcompressd_wait))
+ return;
+
+ wake_up_interruptible(&akcompressd_wait);
+}
+
+int create_akcompressd_task(struct zram *zram)
+{
+ return update_akcompressd_threads(1, zram) != 1;
+}
+
+void destroy_akcompressd_task(struct zram *zram)
+{
+ (void)update_akcompressd_threads(0, zram);
+}
+
+ssize_t hybridswap_akcompress_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ int ret;
+ unsigned long val;
+ struct zram *zram = dev_to_zram(dev);
+
+ ret = kstrtoul(buf, 0, &val);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "val is error!\n");
+ return -EINVAL;
+ }
+
+ ret = update_akcompressd_threads(val, zram);
+ if (ret < 0) {
+ hybp(HYB_ERR, "create task failed, val %d\n", val);
+ return ret;
+ }
+
+ return len;
+}
+
+ssize_t hybridswap_akcompress_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int len = 0, id, i;
+ struct cgroup_cache_page *cache = NULL;
+ unsigned long cnt = atomic64_read(&cached_cnt);
+ memcg_hybs_t *hybs;
+
+ len += sprintf(buf + len, "akcompressd_threads: %d\n", akcompressd_threads);
+ len += sprintf(buf + len, "cached page cnt: %lu\n", cnt);
+ len += sprintf(buf + len, "free page cnt: %u\n", compress_info.free_cnt);
+
+ for (i = 0; i < MAX_AKCOMPRESSD_THREADS; i++)
+ len += sprintf(buf + len, "%-d %-d\n", i, atomic64_read(&akc_cnt[i]));
+
+ if (cnt == 0)
+ return len;
+
+ spin_lock(&cached_idr_lock);
+ idr_for_each_entry(&cached_idr, cache, id) {
+ hybs = container_of(cache, memcg_hybs_t, cache);
+ if (cache->cnt == 0)
+ continue;
+
+ len += scnprintf(buf + len, PAGE_SIZE - len, "%s %d\n",
+ hybs->name, cache->cnt);
+
+ if (len >= PAGE_SIZE)
+ break;
+ }
+ spin_unlock(&cached_idr_lock);
+
+ return len;
+}
+
+void __init akcompressd_pre_init(void)
+{
+ int i;
+ struct page *page;
+
+ mutex_lock(&akcompress_init_lock);
+ INIT_LIST_HEAD(&compress_info.free_page_head);
+ spin_lock_init(&compress_info.free_lock);
+ compress_info.free_cnt = 0;
+
+ init_waitqueue_head(&akcompressd_wait);
+
+ atomic64_set(&cached_cnt, 0);
+ for (i = 0; i < MAX_AKCOMPRESSD_THREADS; i++)
+ atomic64_set(&akc_cnt[i], 0);
+
+ for (i = 0; i < DEFAULT_CACHE_COUNT; i ++) {
+ page = alloc_page(GFP_KERNEL);
+
+ if (page) {
+ list_add_tail(&page->lru, &compress_info.free_page_head);
+ } else
+ break;
+ }
+ compress_info.free_cnt = i;
+ mutex_unlock(&akcompress_init_lock);
+}
+
+void __exit akcompressd_pre_deinit(void)
+{
+ int i;
+ struct page *page, *tmp;
+
+ mutex_lock(&akcompress_init_lock);
+ if (list_empty(&compress_info.free_page_head))
+ goto out;
+ list_for_each_entry_safe(page, tmp, &compress_info.free_page_head , lru) {
+ list_del(&page->lru);
+ free_page(page);
+ }
+
+out:
+ compress_info.free_cnt = 0;
+ mutex_unlock(&akcompress_init_lock);
+}
+
+int akcompress_cache_page_fault(struct zram *zram,
+ struct page *page, u32 index)
+{
+ void *src, *dst;
+
+ if (zram_test_flag(zram, index, ZRAM_CACHED)) {
+ struct page *src_page = (struct page *)zram_fetch_page(zram, index);
+
+ src = kmap_atomic(src_page);
+ dst = kmap_atomic(page);
+ memcpy(dst, src, PAGE_SIZE);
+ kunmap_atomic(src);
+ kunmap_atomic(dst);
+ zram_slot_unlock(zram, index);
+
+ hybp(HYB_DEBUG, "read_anon_page_from_cache index %u page %p passed, ZRAM_CACHED\n",
+ index, src_page);
+ return 1;
+ }
+
+ if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) {
+ struct page *src_page = (struct page *)zram_fetch_page(zram, index);
+
+ src = kmap_atomic(src_page);
+ dst = kmap_atomic(page);
+ memcpy(dst, src, PAGE_SIZE);
+ kunmap_atomic(src);
+ kunmap_atomic(dst);
+ zram_slot_unlock(zram, index);
+
+ hybp(HYB_DEBUG, "read_anon_page_from_cache index %u page %p passed, ZRAM_CACHED_COMPRESS\n",
+ index, src_page);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/drivers/block/zram/hybridswap/hybridswap_eswap.c b/drivers/block/zram/hybridswap/hybridswap_eswap.c
new file mode 100644
index 000000000000..9073bf1b621c
--- /dev/null
+++ b/drivers/block/zram/hybridswap/hybridswap_eswap.c
@@ -0,0 +1,5476 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020-2022 Oplus. All rights reserved.
+ */
+
+#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#ifdef CONFIG_FG_TASK_UID
+#include
+#endif
+
+#include "../zram_drv.h"
+#include "../zram_drv_internal.h"
+#include "hybridswap_internal.h"
+#include "hybridswap.h"
+
+#define PRE_EOL_INFO_OVER_VAL 2
+#define LIFE_TIME_EST_OVER_VAL 8
+#define DEFAULT_STORED_WM_RATIO 90
+#define DEVICE_NAME_LEN 64
+#define MIN_RECLAIM_ZRAM_SZ (1024 * 1024)
+#define esentry_extid(e) ((e) >> ESWAP_SHIFT)
+#define esentry_pgid(e) (((e) & ((1 << ESWAP_SHIFT) - 1)) >> PAGE_SHIFT)
+#define esentry_pgoff(e) ((e) & (PAGE_SIZE - 1))
+#define DUMP_BUF_LEN 512
+#define HYBRIDSWAP_KEY_INDEX 0
+#define HYBRIDSWAP_KEY_SIZE 64
+#define HYBRIDSWAP_KEY_INDEX_SHIFT 3
+#define HYBRIDSWAP_MAX_INFILGHT_NUM 256
+#define HYBRIDSWAP_SECTOR_SHIFT 9
+#define HYBRIDSWAP_PAGE_SIZE_SECTOR (PAGE_SIZE >> HYBRIDSWAP_SECTOR_SHIFT)
+#define HYBRIDSWAP_READ_TIME 10
+#define HYBRIDSWAP_WRITE_TIME 100
+#define HYB_FAULT_OUT_TIME 10
+#define CLASS_NAME_LEN 32
+#define MBYTE_SHIFT 20
+#define ENTRY_PTR_SHIFT 23
+#define ENTRY_MCG_SHIFT_HALF 8
+#define ENTRY_LOCK_BIT ENTRY_MCG_SHIFT_HALF
+#define ENTRY_DATA_BIT (ENTRY_PTR_SHIFT + ENTRY_MCG_SHIFT_HALF + \
+ ENTRY_MCG_SHIFT_HALF + 1)
+
+struct zs_eswap_para {
+ struct hybridswap_page_pool *pool;
+ size_t alloc_size;
+ bool fast;
+ bool nofail;
+};
+
+struct hybridswap_cfg {
+ atomic_t enable;
+ atomic_t out_to_eswap_enable;
+ struct hybstatus *stat;
+ struct workqueue_struct *reclaim_wq;
+ struct zram *zram;
+
+ atomic_t dev_life;
+ unsigned long quota_day;
+ struct timer_list lpc_timer;
+ struct work_struct lpc_work;
+};
+
+struct async_req {
+ struct mem_cgroup *mcg;
+ unsigned long size;
+ unsigned long out_size;
+ unsigned long reclaimined_sz;
+ struct work_struct work;
+ int nice;
+ bool preload;
+};
+
+struct io_priv {
+ struct zram *zram;
+ enum hybridswap_class class;
+ struct hybridswap_page_pool page_pool;
+};
+
+struct io_work_arg {
+ void *iohandle;
+ struct hybridswap_entry *ioentry;
+ struct hybridswap_buffer io_buf;
+ struct io_priv data;
+ struct hybridswap_key_point_record record;
+};
+
+struct hyb_sgm_time {
+ ktime_t submit_bio;
+ ktime_t end_io;
+};
+
+struct hyb_sgm {
+ struct work_struct stopio_work;
+ struct hyb_sgm_time time;
+ struct hybridswap_io_req *req;
+ struct hybridswap_entry *io_entries_fifo[BIO_MAX_PAGES];
+ struct list_head io_entries;
+ sector_t segment_sector;
+ int eswap_cnt;
+ u32 bio_result;
+ int page_cnt;
+};
+
+struct hyb_info {
+ unsigned long size;
+ int total_objects;
+ int nr_es;
+ int memcg_num;
+
+ unsigned long *bitmask;
+ atomic_t last_alloc_bit;
+
+ struct hyb_entries_table *eswap_table;
+ struct hyb_entries_head *eswap;
+
+ struct hyb_entries_table *objects;
+ struct hyb_entries_head *maps;
+ struct hyb_entries_head *lru;
+
+ atomic_t stored_exts;
+ atomic_t *eswap_stored_pages;
+
+ unsigned int memcgid_cnt[MEM_CGROUP_ID_MAX + 1];
+};
+
+struct hyb_entries_head {
+ unsigned int mcg_left : 8;
+ unsigned int lock : 1;
+ unsigned int prev : 23;
+ unsigned int mcg_right : 8;
+ unsigned int data : 1;
+ unsigned int next : 23;
+};
+
+struct hyb_entries_table {
+ struct hyb_entries_head *(*fetch_node)(int, void *);
+ void *private;
+};
+
+#define index_node(index, tab) ((tab)->fetch_node((index), (tab)->private))
+#define next_index(index, tab) (index_node((index), (tab))->next)
+#define prev_index(index, tab) (index_node((index), (tab))->prev)
+#define is_last_index(index, hindex, tab) (next_index(index, tab) == (hindex))
+#define is_first_index(index, hindex, tab) (prev_index(index, tab) == (hindex))
+#define hyb_entries_for_each_entry(index, hindex, tab) \
+ for ((index) = next_index((hindex), (tab)); \
+ (index) != (hindex); (index) = next_index((index), (tab)))
+#define hyb_entries_for_each_entry_safe(index, tmp, hindex, tab) \
+ for ((index) = next_index((hindex), (tab)), (tmp) = next_index((index), (tab)); \
+ (index) != (hindex); (index) = (tmp), (tmp) = next_index((index), (tab)))
+#define hyb_entries_for_each_entry_reverse(index, hindex, tab) \
+ for ((index) = prev_index((hindex), (tab)); \
+ (index) != (hindex); (index) = prev_index((index), (tab)))
+#define hyb_entries_for_each_entry_reverse_safe(index, tmp, hindex, tab) \
+ for ((index) = prev_index((hindex), (tab)), (tmp) = prev_index((index), (tab)); \
+ (index) != (hindex); (index) = (tmp), (tmp) = prev_index((index), (tab)))
+
+static unsigned long warn_level[HYB_CLASS_BUTT] = {
+ 0, 200, 500, 0
+};
+
+const char *key_point_name[HYB_KYE_POINT_BUTT] = {
+ "START",
+ "INIT",
+ "IOENTRY_ALLOC",
+ "FIND_ESWAP",
+ "IO_ESWAP",
+ "SEGMENT_ALLOC",
+ "BIO_ALLOC",
+ "SUBMIT_BIO",
+ "END_IO",
+ "SCHED_WORK",
+ "END_WORK",
+ "CALL_BACK",
+ "WAKE_UP",
+ "ZRAM_LOCK",
+ "DONE"
+};
+
+static const char class_name[HYB_CLASS_BUTT][CLASS_NAME_LEN] = {
+ "out_to_eswap",
+ "page_fault",
+ "batches",
+ "readahead"
+};
+
+static const char *fg_bg[2] = {"BG", "FG"};
+
+bool hyb_io_work_begin_flag;
+struct hybridswap_cfg global_settings;
+
+static u8 hybridswap_io_key[HYBRIDSWAP_KEY_SIZE];
+static struct workqueue_struct *hybridswap_proc_read_workqueue;
+static struct workqueue_struct *hybridswap_proc_write_workqueue;
+static char loop_device[DEVICE_NAME_LEN];
+
+struct mem_cgroup *find_memcg_by_id(unsigned short memcgid);
+int obj_index(struct hyb_info *infos, int index);
+int eswap_index(struct hyb_info *infos, int index);
+int memcgindex(struct hyb_info *infos, int index);
+void free_hyb_info(struct hyb_info *infos);
+struct hyb_info *alloc_hyb_info(unsigned long ori_size, unsigned long comp_size);
+void hybridswap_check_infos_eswap(struct hyb_info *infos);
+void hybridswap_free_eswap(struct hyb_info *infos, int eswapid);
+int hybridswap_alloc_eswap(struct hyb_info *infos, struct mem_cgroup *mcg);
+int fetch_eswap(struct hyb_info *infos, int eswapid);
+void put_eswap(struct hyb_info *infos, int eswapid);
+int fetch_memcg_eswap(struct hyb_info *infos, struct mem_cgroup *mcg);
+int fetch_memcg_zram_entry(struct hyb_info *infos, struct mem_cgroup *mcg);
+int fetch_eswap_zram_entry(struct hyb_info *infos, int eswapid);
+struct hyb_entries_table *alloc_table(struct hyb_entries_head *(*fetch_node)(int, void *),
+ void *private, gfp_t gfp);
+void hyb_lock_with_idx(int index, struct hyb_entries_table *table);
+void hyb_unlock_with_idx(int index, struct hyb_entries_table *table);
+void hyb_entries_init(int index, struct hyb_entries_table *table);
+void hyb_entries_add_nolock(int index, int hindex, struct hyb_entries_table *table);
+void hyb_entries_add_tail_nolock(int index, int hindex, struct hyb_entries_table *table);
+void hyb_entries_del_nolock(int index, int hindex, struct hyb_entries_table *table);
+void hyb_entries_add(int index, int hindex, struct hyb_entries_table *table);
+void hyb_entries_add_tail(int index, int hindex, struct hyb_entries_table *table);
+void hyb_entries_del(int index, int hindex, struct hyb_entries_table *table);
+unsigned short hyb_entries_fetch_memcgid(int index, struct hyb_entries_table *table);
+void hyb_entries_set_memcgid(int index, struct hyb_entries_table *table, int memcgid);
+bool hyb_entries_set_priv(int index, struct hyb_entries_table *table);
+bool hyb_entries_clear_priv(int index, struct hyb_entries_table *table);
+bool hyb_entries_test_priv(int index, struct hyb_entries_table *table);
+bool hyb_entries_empty(int hindex, struct hyb_entries_table *table);
+void zram_set_mcg(struct zram *zram, u32 index, int memcgid);
+struct mem_cgroup *zram_fetch_mcg(struct zram *zram, u32 index);
+int zram_fetch_mcg_last_index(struct hyb_info *infos,
+ struct mem_cgroup *mcg,
+ int *index, int max_cnt);
+int swap_maps_fetch_eswap_index(struct hyb_info *infos,
+ int eswapid, int *index);
+void swap_sorted_list_add(struct zram *zram, u32 index, struct mem_cgroup *memcg);
+void swap_sorted_list_add_tail(struct zram *zram, u32 index, struct mem_cgroup *mcg);
+void swap_sorted_list_del(struct zram *zram, u32 index);
+void swap_maps_insert(struct zram *zram, u32 index);
+void swap_maps_destroy(struct zram *zram, u32 index);
+
+static void hybridswapiowrkshow(struct seq_file *m, struct hybstatus *stat)
+{
+ int i;
+
+ for (i = 0; i < HYB_CLASS_BUTT; ++i) {
+ seq_printf(m, "hybridswap_%s_total_lat: %lld\n",
+ class_name[i],
+ atomic64_read(&stat->lat[i].total_lat));
+ seq_printf(m, "hybridswap_%s_max_lat: %lld\n",
+ class_name[i],
+ atomic64_read(&stat->lat[i].max_lat));
+ seq_printf(m, "hybridswap_%s_timeout_cnt: %lld\n",
+ class_name[i],
+ atomic64_read(&stat->lat[i].timeout_cnt));
+ }
+
+ for (i = 0; i < 2; i++) {
+ seq_printf(m, "page_fault_timeout_100ms_cnt(%s): %lld\n",
+ fg_bg[i],
+ atomic64_read(&stat->fault_stat[i].timeout_100ms_cnt));
+ seq_printf(m, "page_fault_timeout_500ms_cnt(%s): %lld\n",
+ fg_bg[i],
+ atomic64_read(&stat->fault_stat[i].timeout_500ms_cnt));
+ }
+}
+
+static void hybstatuss_show(struct seq_file *m,
+ struct hybstatus *stat)
+{
+ seq_printf(m, "hybridswap_out_times: %lld\n",
+ atomic64_read(&stat->reclaimin_cnt));
+ seq_printf(m, "hybridswap_out_comp_size: %lld MB\n",
+ atomic64_read(&stat->reclaimin_bytes) >> MBYTE_SHIFT);
+ if (PAGE_SHIFT < MBYTE_SHIFT)
+ seq_printf(m, "hybridswap_out_ori_size: %lld MB\n",
+ atomic64_read(&stat->reclaimin_pages) >>
+ (MBYTE_SHIFT - PAGE_SHIFT));
+ seq_printf(m, "hybridswap_in_times: %lld\n",
+ atomic64_read(&stat->batchout_cnt));
+ seq_printf(m, "hybridswap_in_comp_size: %lld MB\n",
+ atomic64_read(&stat->batchout_bytes) >> MBYTE_SHIFT);
+ if (PAGE_SHIFT < MBYTE_SHIFT)
+ seq_printf(m, "hybridswap_in_ori_size: %lld MB\n",
+ atomic64_read(&stat->batchout_pages) >>
+ (MBYTE_SHIFT - PAGE_SHIFT));
+ seq_printf(m, "hybridswap_all_fault: %lld\n",
+ atomic64_read(&stat->fault_cnt));
+ seq_printf(m, "hybridswap_fault: %lld\n",
+ atomic64_read(&stat->hybridswap_fault_cnt));
+}
+
+static void hyb_info_info_show(struct seq_file *m,
+ struct hybstatus *stat)
+{
+ seq_printf(m, "hybridswap_reout_ori_size: %lld MB\n",
+ atomic64_read(&stat->reout_pages) >>
+ (MBYTE_SHIFT - PAGE_SHIFT));
+ seq_printf(m, "hybridswap_reout_comp_size: %lld MB\n",
+ atomic64_read(&stat->reout_bytes) >> MBYTE_SHIFT);
+ seq_printf(m, "hybridswap_store_comp_size: %lld MB\n",
+ atomic64_read(&stat->stored_size) >> MBYTE_SHIFT);
+ seq_printf(m, "hybridswap_store_ori_size: %lld MB\n",
+ atomic64_read(&stat->stored_pages) >>
+ (MBYTE_SHIFT - PAGE_SHIFT));
+ seq_printf(m, "hybridswap_notify_free_size: %lld MB\n",
+ atomic64_read(&stat->notify_free) >>
+ (MBYTE_SHIFT - ESWAP_SHIFT));
+ seq_printf(m, "hybridswap_store_memcg_cnt: %lld\n",
+ atomic64_read(&stat->mcg_cnt));
+ seq_printf(m, "hybridswap_store_eswap_cnt: %lld\n",
+ atomic64_read(&stat->eswap_cnt));
+ seq_printf(m, "hybridswap_store_frag_info_cnt: %lld\n",
+ atomic64_read(&stat->frag_cnt));
+}
+
+static void hybridswap_fail_show(struct seq_file *m,
+ struct hybstatus *stat)
+{
+ int i;
+
+ for (i = 0; i < HYB_CLASS_BUTT; ++i) {
+ seq_printf(m, "hybridswap_%s_io_fail_cnt: %lld\n",
+ class_name[i],
+ atomic64_read(&stat->io_fail_cnt[i]));
+ seq_printf(m, "hybridswap_%s_alloc_fail_cnt: %lld\n",
+ class_name[i],
+ atomic64_read(&stat->alloc_fail_cnt[i]));
+ }
+}
+
+int hybridswap_psi_show(struct seq_file *m, void *v)
+{
+ struct hybstatus *stat = NULL;
+
+ if (!hybridswap_core_enabled())
+ return -EINVAL;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_ERR, "can't fetch stat obj!\n");
+ return -EINVAL;
+ }
+
+ hybstatuss_show(m, stat);
+ hyb_info_info_show(m, stat);
+ hybridswapiowrkshow(m, stat);
+ hybridswap_fail_show(m, stat);
+
+ return 0;
+}
+
+unsigned long long hybridswap_fetch_zram_pagefault(void)
+{
+ struct hybstatus *stat = NULL;
+
+ if (!hybridswap_core_enabled())
+ return 0;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_ERR, "can't fetch stat obj!\n");
+
+ return 0;
+ }
+
+ return atomic64_read(&stat->fault_cnt);
+}
+
+bool hybridswap_reclaim_work_running(void)
+{
+ struct hybstatus *stat = NULL;
+
+ if (!hybridswap_core_enabled())
+ return false;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_ERR, "can't fetch stat obj!\n");
+
+ return 0;
+ }
+
+ return atomic64_read(&stat->reclaimin_infight) ? true : false;
+}
+
+unsigned long long hybridswap_read_mcg_stats(struct mem_cgroup *mcg,
+ enum hybridswap_mcg_member mcg_member)
+{
+ struct mem_cgroup_hybridswap *mcg_hybs;
+
+ unsigned long long val = 0;
+ int extcnt;
+
+ if (!hybridswap_core_enabled())
+ return 0;
+
+ mcg_hybs = MEMCGRP_ITEM_DATA(mcg);
+ if (!mcg_hybs) {
+ hybp(HYB_DEBUG, "NULL mcg_hybs\n");
+ return 0;
+ }
+
+ switch (mcg_member) {
+ case MCG_ZRAM_STORED_SZ:
+ val = atomic64_read(&mcg_hybs->zram_stored_size);
+ break;
+ case MCG_ZRAM_STORED_PG_SZ:
+ val = atomic64_read(&mcg_hybs->zram_page_size);
+ break;
+ case MCG_DISK_STORED_SZ:
+ val = atomic64_read(&mcg_hybs->hybridswap_stored_size);
+ break;
+ case MCG_DISK_STORED_PG_SZ:
+ val = atomic64_read(&mcg_hybs->hybridswap_stored_pages);
+ break;
+ case MCG_ANON_FAULT_CNT:
+ val = atomic64_read(&mcg_hybs->hybridswap_allfaultcnt);
+ break;
+ case MCG_DISK_FAULT_CNT:
+ val = atomic64_read(&mcg_hybs->hybridswap_faultcnt);
+ break;
+ case MCG_ESWAPOUT_CNT:
+ val = atomic64_read(&mcg_hybs->hybridswap_outcnt);
+ break;
+ case MCG_ESWAPOUT_SZ:
+ val = atomic64_read(&mcg_hybs->hybridswap_outextcnt) << ESWAP_SHIFT;
+ break;
+ case MCG_ESWAPIN_CNT:
+ val = atomic64_read(&mcg_hybs->hybridswap_incnt);
+ break;
+ case MCG_ESWAPIN_SZ:
+ val = atomic64_read(&mcg_hybs->hybridswap_inextcnt) << ESWAP_SHIFT;
+ break;
+ case MCG_DISK_SPACE:
+ extcnt = atomic_read(&mcg_hybs->hybridswap_extcnt);
+ if (extcnt < 0)
+ extcnt = 0;
+ val = ((unsigned long long) extcnt) << ESWAP_SHIFT;
+ break;
+ case MCG_DISK_SPACE_PEAK:
+ extcnt = atomic_read(&mcg_hybs->hybridswap_peakextcnt);
+ if (extcnt < 0)
+ extcnt = 0;
+ val = ((unsigned long long) extcnt) << ESWAP_SHIFT;
+ break;
+ default:
+ break;
+ }
+
+ return val;
+}
+
+void hybridswap_fail_record(enum hybridswap_fail_point point,
+ u32 index, int eswapid, unsigned char *task_comm)
+{
+ struct hybstatus *stat = NULL;
+ unsigned long flags;
+ unsigned int copylen = strlen(task_comm) + 1;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_ERR, "can't fetch stat obj!\n");
+ return;
+ }
+
+ if (copylen > TASK_COMM_LEN) {
+ hybp(HYB_ERR, "task_comm len %d is err\n", copylen);
+ return;
+ }
+
+ spin_lock_irqsave(&stat->record.lock, flags);
+ if (stat->record.num < MAX_FAIL_RECORD_NUM) {
+ stat->record.record[stat->record.num].point = point;
+ stat->record.record[stat->record.num].index = index;
+ stat->record.record[stat->record.num].eswapid = eswapid;
+ stat->record.record[stat->record.num].time = ktime_get();
+ memcpy(stat->record.record[stat->record.num].task_comm,
+ task_comm, copylen);
+ stat->record.num++;
+ }
+ spin_unlock_irqrestore(&stat->record.lock, flags);
+}
+
+static void hybridswap_fail_record_fetch(
+ struct hybridswap_fail_record_info *record_info)
+{
+ struct hybstatus *stat = NULL;
+ unsigned long flags;
+
+ if (!hybridswap_core_enabled())
+ return;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_ERR, "can't fetch stat obj!\n");
+ return;
+ }
+
+ spin_lock_irqsave(&stat->record.lock, flags);
+ memcpy(record_info, &stat->record,
+ sizeof(struct hybridswap_fail_record_info));
+ stat->record.num = 0;
+ spin_unlock_irqrestore(&stat->record.lock, flags);
+}
+
+static ssize_t hybridswap_fail_record_show(char *buf)
+{
+ int i;
+ ssize_t size = 0;
+ struct hybridswap_fail_record_info record_info = { 0 };
+
+ hybridswap_fail_record_fetch(&record_info);
+
+ size += scnprintf(buf + size, PAGE_SIZE,
+ "hybridswap_fail_record_num: %d\n", record_info.num);
+ for (i = 0; i < record_info.num; ++i)
+ size += scnprintf(buf + size, PAGE_SIZE - size,
+ "point[%u]time[%lld]taskname[%s]index[%u]eswapid[%d]\n",
+ record_info.record[i].point,
+ ktime_us_delta(ktime_get(),
+ record_info.record[i].time),
+ record_info.record[i].task_comm,
+ record_info.record[i].index,
+ record_info.record[i].eswapid);
+
+ return size;
+}
+
+ssize_t hybridswap_report_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ return hybridswap_fail_record_show(buf);
+}
+
+static inline meminfo_show(struct hybstatus *stat, char *buf, ssize_t len)
+{
+ unsigned long eswap_total_pages = 0, eswap_compressed_pages = 0;
+ unsigned long eswap_used_pages = 0;
+ unsigned long zram_total_pags, zram_used_pages, zram_compressed;
+ ssize_t size = 0;
+
+ if (!stat || !buf || !len)
+ return 0;
+
+ (void)hybridswap_stored_info(&eswap_total_pages, &eswap_compressed_pages);
+ eswap_used_pages = atomic64_read(&stat->stored_pages);
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ zram_total_pags = fetch_nr_zram_total();
+#else
+ zram_total_pags = 0;
+#endif
+ zram_compressed = atomic64_read(&stat->zram_stored_size);
+ zram_used_pages = atomic64_read(&stat->zram_stored_pages);
+
+ size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n",
+ "EST:", eswap_total_pages << (PAGE_SHIFT - 10));
+ size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n",
+ "ESU_C:", eswap_compressed_pages << (PAGE_SHIFT - 10));
+ size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n",
+ "ESU_O:", eswap_used_pages << (PAGE_SHIFT - 10));
+ size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n",
+ "ZST:", zram_total_pags << (PAGE_SHIFT - 10));
+ size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n",
+ "ZSU_C:", zram_compressed >> 10);
+ size += scnprintf(buf + size, len - size, "%-32s %12llu KB\n",
+ "ZSU_O:", zram_used_pages << (PAGE_SHIFT - 10));
+
+ return size;
+}
+
+ssize_t hybridswap_stat_snap_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ ssize_t size = 0;
+ struct hybstatus *stat = NULL;
+
+ if (!hybridswap_core_enabled())
+ return 0;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_INFO, "can't fetch stat obj!\n");
+ return 0;
+ }
+
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "reclaimin_cnt:", atomic64_read(&stat->reclaimin_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "reclaimin_bytes:", atomic64_read(&stat->reclaimin_bytes) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "reclaimin_real_load:", atomic64_read(&stat->reclaimin_real_load) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "reclaimin_bytes_daily:", atomic64_read(&stat->reclaimin_bytes_daily) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "reclaimin_pages:", atomic64_read(&stat->reclaimin_pages) * PAGE_SIZE / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "reclaimin_infight:", atomic64_read(&stat->reclaimin_infight));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "batchout_cnt:", atomic64_read(&stat->batchout_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "batchout_bytes:", atomic64_read(&stat->batchout_bytes) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "batchout_real_load:", atomic64_read(&stat->batchout_real_load) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "batchout_pages:", atomic64_read(&stat->batchout_pages) * PAGE_SIZE / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "batchout_inflight:", atomic64_read(&stat->batchout_inflight));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "fault_cnt:", atomic64_read(&stat->fault_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "hybridswap_fault_cnt:", atomic64_read(&stat->hybridswap_fault_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "reout_pages:", atomic64_read(&stat->reout_pages) * PAGE_SIZE / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "reout_bytes:", atomic64_read(&stat->reout_bytes) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "zram_stored_pages:", atomic64_read(&stat->zram_stored_pages) * PAGE_SIZE / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "zram_stored_size:", atomic64_read(&stat->zram_stored_size) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "stored_pages:", atomic64_read(&stat->stored_pages) * PAGE_SIZE / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "stored_size:", atomic64_read(&stat->stored_size) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu KB\n",
+ "reclain-batchout:", (atomic64_read(&stat->reclaimin_real_load) -
+ atomic64_read(&stat->batchout_real_load)) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12lld KB\n",
+ "reclain-batchout-stored:",
+ (atomic64_read(&stat->reclaimin_real_load) -
+ atomic64_read(&stat->batchout_real_load) -
+ atomic64_read(&stat->stored_size)) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12lld KB\n",
+ "dropped_eswap_size:", atomic64_read(&stat->dropped_eswap_size) / SZ_1K);
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "notify_free:", atomic64_read(&stat->notify_free));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "frag_cnt:", atomic64_read(&stat->frag_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "mcg_cnt:", atomic64_read(&stat->mcg_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "ext_cnt:", atomic64_read(&stat->eswap_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "miss_free:", atomic64_read(&stat->miss_free));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "memcgid_clear:", atomic64_read(&stat->memcgid_clear));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "skip_track_cnt:", atomic64_read(&stat->skip_track_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "null_memcg_skip_track_cnt:",
+ atomic64_read(&stat->null_memcg_skip_track_cnt));
+ size += scnprintf(buf + size, PAGE_SIZE - size, "%-32s %12llu\n",
+ "used_swap_pages:", atomic64_read(&stat->used_swap_pages) * PAGE_SIZE / SZ_1K);
+ size += meminfo_show(stat, buf + size, PAGE_SIZE - size);
+
+ return size;
+}
+
+ssize_t hybridswap_meminfo_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct hybstatus *stat = NULL;
+
+ if (!hybridswap_core_enabled())
+ return 0;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_INFO, "can't fetch stat obj!\n");
+ return 0;
+ }
+
+ return meminfo_show(stat, buf, PAGE_SIZE);
+}
+
+static void hybridswap_iostatus_bytes(struct hybridswap_io_req *req)
+{
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat || !req->page_cnt)
+ return;
+
+ if (req->io_para.class == HYB_RECLAIM_IN) {
+ atomic64_add(req->page_cnt * PAGE_SIZE, &stat->reclaimin_bytes);
+ atomic64_add(req->page_cnt * PAGE_SIZE, &stat->reclaimin_bytes_daily);
+ atomic64_add(atomic64_read(&req->real_load), &stat->reclaimin_real_load);
+ atomic64_inc(&stat->reclaimin_cnt);
+ } else {
+ atomic64_add(req->page_cnt * PAGE_SIZE, &stat->batchout_bytes);
+ atomic64_inc(&stat->batchout_cnt);
+ }
+}
+
+static void hybridswap_key_init(void)
+{
+ get_random_bytes(hybridswap_io_key, HYBRIDSWAP_KEY_SIZE);
+}
+
+static void hybridswap_io_req_release(struct kref *ref)
+{
+ struct hybridswap_io_req *req =
+ container_of(ref, struct hybridswap_io_req, refcount);
+
+ if (req->io_para.complete_notify && req->io_para.private)
+ req->io_para.complete_notify(req->io_para.private);
+
+ kfree(req);
+}
+
+static void hyb_sgm_free(struct hybridswap_io_req *req,
+ struct hyb_sgm *segment)
+{
+ int i;
+
+ for (i = 0; i < segment->eswap_cnt; ++i) {
+ INIT_LIST_HEAD(&segment->io_entries_fifo[i]->list);
+ req->io_para.done_callback(segment->io_entries_fifo[i], -EIO, req);
+ }
+ kfree(segment);
+}
+
+static void hybridswap_limit_doing(struct hybridswap_io_req *req)
+{
+ int ret;
+
+ if (!req->limit_doing_flag)
+ return;
+
+ if (atomic_read(&req->eswap_doing) >= HYBRIDSWAP_MAX_INFILGHT_NUM) {
+ do {
+ hybp(HYB_DEBUG, "wait doing start\n");
+ ret = wait_event_timeout(req->io_wait,
+ atomic_read(&req->eswap_doing) <
+ HYBRIDSWAP_MAX_INFILGHT_NUM,
+ msecs_to_jiffies(100));
+ } while (!ret);
+ }
+}
+
+static void hybridswap_wait_io_finish(struct hybridswap_io_req *req)
+{
+ int ret;
+ unsigned int wait_time;
+
+ if (!req->wait_io_finish_flag || !req->page_cnt)
+ return;
+
+ if (req->io_para.class == HYB_FAULT_OUT) {
+ hybp(HYB_DEBUG, "fault out wait finish start\n");
+ wait_for_completion_io_timeout(&req->io_end_flag,
+ MAX_SCHEDULE_TIMEOUT);
+
+ return;
+ }
+
+ wait_time = (req->io_para.class == HYB_RECLAIM_IN) ?
+ HYBRIDSWAP_WRITE_TIME : HYBRIDSWAP_READ_TIME;
+
+ do {
+ hybp(HYB_DEBUG, "wait finish start\n");
+ ret = wait_event_timeout(req->io_wait,
+ (!atomic_read(&req->eswap_doing)),
+ msecs_to_jiffies(wait_time));
+ } while (!ret);
+}
+
+static void hybridswap_doing_inc(struct hyb_sgm *segment)
+{
+ mutex_lock(&segment->req->refmutex);
+ kref_get(&segment->req->refcount);
+ mutex_unlock(&segment->req->refmutex);
+ atomic_add(segment->page_cnt, &segment->req->eswap_doing);
+}
+
+static void hybridswap_doing_dec(struct hybridswap_io_req *req,
+ int num)
+{
+ if ((atomic_sub_return(num, &req->eswap_doing) <
+ HYBRIDSWAP_MAX_INFILGHT_NUM) && req->limit_doing_flag &&
+ wq_has_sleeper(&req->io_wait))
+ wake_up(&req->io_wait);
+}
+
+static void hybridswap_io_end_wake_up(struct hybridswap_io_req *req)
+{
+ if (req->io_para.class == HYB_FAULT_OUT) {
+ complete(&req->io_end_flag);
+ return;
+ }
+
+ if (wq_has_sleeper(&req->io_wait))
+ wake_up(&req->io_wait);
+}
+
+static void hybridswap_ioentry_proc(struct hyb_sgm *segment)
+{
+ int i;
+ struct hybridswap_io_req *req = segment->req;
+ struct hybridswap_key_point_record *record = req->io_para.record;
+ int page_num;
+ ktime_t callback_start;
+ unsigned long long callback_start_ravg_sum;
+
+ for (i = 0; i < segment->eswap_cnt; ++i) {
+ INIT_LIST_HEAD(&segment->io_entries_fifo[i]->list);
+ page_num = segment->io_entries_fifo[i]->pages_sz;
+ hybp(HYB_DEBUG, "eswap_id[%d] %d page_num %d\n",
+ i, segment->io_entries_fifo[i]->eswapid, page_num);
+ callback_start = ktime_get();
+ callback_start_ravg_sum = hybridswap_fetch_ravg_sum();
+ if (req->io_para.done_callback)
+ req->io_para.done_callback(segment->io_entries_fifo[i],
+ 0, req);
+ hybperf_async_perf(record, HYB_CALL_BACK,
+ callback_start, callback_start_ravg_sum);
+ hybridswap_doing_dec(req, page_num);
+ }
+}
+
+static void hybridswap_errio_record(enum hybridswap_fail_point point,
+ struct hybridswap_io_req *req, int eswapid)
+{
+ if (req->io_para.class == HYB_FAULT_OUT)
+ hybridswap_fail_record(point, 0, eswapid,
+ req->io_para.record->task_comm);
+}
+
+static void hybridswap_iostatus_fail(enum hybridswap_class class)
+{
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat || (class >= HYB_CLASS_BUTT))
+ return;
+
+ atomic64_inc(&stat->io_fail_cnt[class]);
+}
+
+static void hybridswap_errio_proc(struct hybridswap_io_req *req,
+ struct hyb_sgm *segment)
+{
+ hybp(HYB_ERR, "segment sector 0x%llx, eswap_cnt %d\n",
+ segment->segment_sector, segment->eswap_cnt);
+ hybp(HYB_ERR, "class %u, bio_result %u\n",
+ req->io_para.class, segment->bio_result);
+ hybridswap_iostatus_fail(req->io_para.class);
+ hybridswap_errio_record(HYB_FAULT_OUT_IO_FAIL, req,
+ segment->io_entries_fifo[0]->eswapid);
+ hybridswap_doing_dec(req, segment->page_cnt);
+ hybridswap_io_end_wake_up(req);
+ hyb_sgm_free(req, segment);
+ kref_put_mutex(&req->refcount, hybridswap_io_req_release,
+ &req->refmutex);
+}
+
+static void hybridswap_io_end_work(struct work_struct *work)
+{
+ struct hyb_sgm *segment =
+ container_of(work, struct hyb_sgm, stopio_work);
+ struct hybridswap_io_req *req = segment->req;
+ struct hybridswap_key_point_record *record = req->io_para.record;
+ int old_nice = task_nice(current);
+ ktime_t work_start;
+ unsigned long long work_start_ravg_sum;
+
+ if (unlikely(segment->bio_result)) {
+ hybridswap_errio_proc(req, segment);
+ return;
+ }
+
+ hybp(HYB_DEBUG, "segment sector 0x%llx, eswap_cnt %d passed\n",
+ segment->segment_sector, segment->eswap_cnt);
+ hybp(HYB_DEBUG, "class %u, bio_result %u passed\n",
+ req->io_para.class, segment->bio_result);
+
+ set_user_nice(current, req->nice);
+
+ hybperf_async_perf(record, HYB_SCHED_WORK,
+ segment->time.end_io, 0);
+ work_start = ktime_get();
+ work_start_ravg_sum = hybridswap_fetch_ravg_sum();
+
+ hybridswap_ioentry_proc(segment);
+
+ hybperf_async_perf(record, HYB_END_WORK, work_start,
+ work_start_ravg_sum);
+
+ hybridswap_io_end_wake_up(req);
+
+ kref_put_mutex(&req->refcount, hybridswap_io_req_release,
+ &req->refmutex);
+ kfree(segment);
+
+ set_user_nice(current, old_nice);
+}
+
+static void hybridswap_end_io(struct bio *bio)
+{
+ struct hyb_sgm *segment = bio->bi_private;
+ struct hybridswap_io_req *req = NULL;
+ struct workqueue_struct *workqueue = NULL;
+ struct hybridswap_key_point_record *record = NULL;
+
+ if (unlikely(!segment || !(segment->req))) {
+ hybp(HYB_ERR, "segment or req null\n");
+ bio_put(bio);
+
+ return;
+ }
+
+ req = segment->req;
+ record = req->io_para.record;
+
+ hybperf_async_perf(record, HYB_END_IO,
+ segment->time.submit_bio, 0);
+
+ workqueue = (req->io_para.class == HYB_RECLAIM_IN) ?
+ hybridswap_proc_write_workqueue : hybridswap_proc_read_workqueue;
+ segment->time.end_io = ktime_get();
+ segment->bio_result = bio->bi_status;
+
+ queue_work(workqueue, &segment->stopio_work);
+ bio_put(bio);
+}
+
+static bool hybridswap_eswap_merge_back(
+ struct hyb_sgm *segment,
+ struct hybridswap_entry *ioentry)
+{
+ struct hybridswap_entry *tail_ioentry =
+ list_last_entry(&segment->io_entries,
+ struct hybridswap_entry, list);
+
+ return ((tail_ioentry->addr +
+ tail_ioentry->pages_sz * HYBRIDSWAP_PAGE_SIZE_SECTOR) ==
+ ioentry->addr);
+}
+
+static bool hybridswap_eswap_merge_front(
+ struct hyb_sgm *segment,
+ struct hybridswap_entry *ioentry)
+{
+ struct hybridswap_entry *head_ioentry =
+ list_first_entry(&segment->io_entries,
+ struct hybridswap_entry, list);
+
+ return (head_ioentry->addr ==
+ (ioentry->addr +
+ ioentry->pages_sz * HYBRIDSWAP_PAGE_SIZE_SECTOR));
+}
+
+static bool hybridswap_eswap_merge(struct hybridswap_io_req *req,
+ struct hybridswap_entry *ioentry)
+{
+ struct hyb_sgm *segment = req->segment;
+
+ if (segment == NULL)
+ return false;
+
+ if ((segment->page_cnt + ioentry->pages_sz) > BIO_MAX_PAGES)
+ return false;
+
+ if (hybridswap_eswap_merge_front(segment, ioentry)) {
+ list_add(&ioentry->list, &segment->io_entries);
+ segment->io_entries_fifo[segment->eswap_cnt++] = ioentry;
+ segment->segment_sector = ioentry->addr;
+ segment->page_cnt += ioentry->pages_sz;
+ return true;
+ }
+
+ if (hybridswap_eswap_merge_back(segment, ioentry)) {
+ list_add_tail(&ioentry->list, &segment->io_entries);
+ segment->io_entries_fifo[segment->eswap_cnt++] = ioentry;
+ segment->page_cnt += ioentry->pages_sz;
+ return true;
+ }
+
+ return false;
+}
+
+static struct bio *hybridswap_bio_alloc(enum hybridswap_class class)
+{
+ gfp_t gfp = (class != HYB_RECLAIM_IN) ? GFP_ATOMIC : GFP_NOIO;
+ struct bio *bio = bio_alloc(gfp, BIO_MAX_PAGES);
+
+ if (!bio && (class == HYB_FAULT_OUT))
+ bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
+
+ return bio;
+}
+
+static int hybridswap_bio_add_page(struct bio *bio,
+ struct hyb_sgm *segment)
+{
+ int i;
+ int k = 0;
+ struct hybridswap_entry *ioentry = NULL;
+ struct hybridswap_entry *tmp = NULL;
+
+ list_for_each_entry_safe(ioentry, tmp, &segment->io_entries, list) {
+ for (i = 0; i < ioentry->pages_sz; i++) {
+ ioentry->dest_pages[i]->index =
+ bio->bi_iter.bi_sector + k;
+ if (unlikely(!bio_add_page(bio,
+ ioentry->dest_pages[i], PAGE_SIZE, 0))) {
+ return -EIO;
+ }
+ k += HYBRIDSWAP_PAGE_SIZE_SECTOR;
+ }
+ }
+
+ return 0;
+}
+
+static void hybridswap_set_bio_opf(struct bio *bio,
+ struct hyb_sgm *segment)
+{
+ if (segment->req->io_para.class == HYB_RECLAIM_IN) {
+ bio->bi_opf |= REQ_BACKGROUND;
+ return;
+ }
+
+ bio->bi_opf |= REQ_SYNC;
+}
+
+int hybridswap_submit_bio(struct hyb_sgm *segment)
+{
+ unsigned int op =
+ (segment->req->io_para.class == HYB_RECLAIM_IN) ?
+ REQ_OP_WRITE : REQ_OP_READ;
+ struct hybridswap_entry *head_ioentry =
+ list_first_entry(&segment->io_entries,
+ struct hybridswap_entry, list);
+ struct hybridswap_key_point_record *record =
+ segment->req->io_para.record;
+ struct bio *bio = NULL;
+
+ hybperfiowrkstart(record, HYB_BIO_ALLOC);
+ bio = hybridswap_bio_alloc(segment->req->io_para.class);
+ hybperfiowrkend(record, HYB_BIO_ALLOC);
+ if (unlikely(!bio)) {
+ hybp(HYB_ERR, "bio is null.\n");
+ hybridswap_errio_record(HYB_FAULT_OUT_BIO_ALLOC_FAIL,
+ segment->req, segment->io_entries_fifo[0]->eswapid);
+
+ return -ENOMEM;
+ }
+
+ bio->bi_iter.bi_sector = segment->segment_sector;
+ bio_set_dev(bio, segment->req->io_para.bdev);
+ bio->bi_private = segment;
+ bio_set_op_attrs(bio, op, 0);
+ bio->bi_end_io = hybridswap_end_io;
+ hybridswap_set_bio_opf(bio, segment);
+
+ if (unlikely(hybridswap_bio_add_page(bio, segment))) {
+ bio_put(bio);
+ hybp(HYB_ERR, "bio_add_page fail\n");
+ hybridswap_errio_record(HYB_FAULT_OUT_BIO_ADD_FAIL,
+ segment->req, segment->io_entries_fifo[0]->eswapid);
+
+ return -EIO;
+ }
+
+ hybridswap_doing_inc(segment);
+ hybp(HYB_DEBUG, "submit bio sector %llu eswapid %d\n",
+ segment->segment_sector, head_ioentry->eswapid);
+ hybp(HYB_DEBUG, "eswap_cnt %d class %u\n",
+ segment->eswap_cnt, segment->req->io_para.class);
+
+ segment->req->page_cnt += segment->page_cnt;
+ segment->req->segment_cnt++;
+ segment->time.submit_bio = ktime_get();
+
+ hybperfiowrkstart(record, HYB_SUBMIT_BIO);
+ submit_bio(bio);
+ hybperfiowrkend(record, HYB_SUBMIT_BIO);
+
+ return 0;
+}
+
+static int hybridswap_new_segment_init(struct hybridswap_io_req *req,
+ struct hybridswap_entry *ioentry)
+{
+ gfp_t gfp = (req->io_para.class != HYB_RECLAIM_IN) ?
+ GFP_ATOMIC : GFP_NOIO;
+ struct hyb_sgm *segment = NULL;
+ struct hybridswap_key_point_record *record = req->io_para.record;
+
+ hybperfiowrkstart(record, HYB_SEGMENT_ALLOC);
+ segment = kzalloc(sizeof(struct hyb_sgm), gfp);
+ if (!segment && (req->io_para.class == HYB_FAULT_OUT))
+ segment = kzalloc(sizeof(struct hyb_sgm), GFP_NOIO);
+ hybperfiowrkend(record, HYB_SEGMENT_ALLOC);
+ if (unlikely(!segment)) {
+ hybridswap_errio_record(HYB_FAULT_OUT_SEGMENT_ALLOC_FAIL,
+ req, ioentry->eswapid);
+
+ return -ENOMEM;
+ }
+
+ segment->req = req;
+ INIT_LIST_HEAD(&segment->io_entries);
+ list_add_tail(&ioentry->list, &segment->io_entries);
+ segment->io_entries_fifo[segment->eswap_cnt++] = ioentry;
+ segment->page_cnt = ioentry->pages_sz;
+ INIT_WORK(&segment->stopio_work, hybridswap_io_end_work);
+ segment->segment_sector = ioentry->addr;
+ req->segment = segment;
+
+ return 0;
+}
+
+static int hybridswap_io_submit(struct hybridswap_io_req *req,
+ bool merge_flag)
+{
+ int ret;
+ struct hyb_sgm *segment = req->segment;
+
+ if (!segment || ((merge_flag) && (segment->page_cnt < BIO_MAX_PAGES)))
+ return 0;
+
+ hybridswap_limit_doing(req);
+
+ ret = hybridswap_submit_bio(segment);
+ if (unlikely(ret)) {
+ hybp(HYB_WARN, "submit bio failed, ret %d\n", ret);
+ hyb_sgm_free(req, segment);
+ }
+ req->segment = NULL;
+
+ return ret;
+}
+
+static bool hybridswap_check_io_para_err(struct hybridswap_io *io_para)
+{
+ if (unlikely(!io_para)) {
+ hybp(HYB_ERR, "io_para null\n");
+
+ return true;
+ }
+
+ if (unlikely(!io_para->bdev ||
+ (io_para->class >= HYB_CLASS_BUTT))) {
+ hybp(HYB_ERR, "io_para err, class %u\n",
+ io_para->class);
+
+ return true;
+ }
+
+ if (unlikely(!io_para->done_callback)) {
+ hybp(HYB_ERR, "done_callback err\n");
+
+ return true;
+ }
+
+ return false;
+}
+
+static bool hybridswap_check_entry_err(
+ struct hybridswap_entry *ioentry)
+{
+ int i;
+
+ if (unlikely(!ioentry)) {
+ hybp(HYB_ERR, "ioentry null\n");
+
+ return true;
+ }
+
+ if (unlikely((!ioentry->dest_pages) ||
+ (ioentry->eswapid < 0) ||
+ (ioentry->pages_sz > BIO_MAX_PAGES) ||
+ (ioentry->pages_sz <= 0))) {
+ hybp(HYB_ERR, "eswapid %d, page_sz %d\n", ioentry->eswapid,
+ ioentry->pages_sz);
+
+ return true;
+ }
+
+ for (i = 0; i < ioentry->pages_sz; ++i) {
+ if (!ioentry->dest_pages[i]) {
+ hybp(HYB_ERR, "dest_pages[%d] is null\n", i);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static int hybridswap_io_eswapent(void *iohandle,
+ struct hybridswap_entry *ioentry)
+{
+ int ret;
+ struct hybridswap_io_req *req = (struct hybridswap_io_req *)iohandle;
+
+ if (unlikely(hybridswap_check_entry_err(ioentry))) {
+ hybridswap_errio_record(HYB_FAULT_OUT_IO_ENTRY_PARA_FAIL,
+ req, ioentry ? ioentry->eswapid : -EINVAL);
+ req->io_para.done_callback(ioentry, -EIO, req);
+
+ return -EFAULT;
+ }
+
+ hybp(HYB_DEBUG, "eswap id %d, pages_sz %d, addr %llx\n",
+ ioentry->eswapid, ioentry->pages_sz,
+ ioentry->addr);
+
+ if (hybridswap_eswap_merge(req, ioentry))
+ return hybridswap_io_submit(req, true);
+
+ ret = hybridswap_io_submit(req, false);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "submit fail %d\n", ret);
+ req->io_para.done_callback(ioentry, -EIO, req);
+
+ return ret;
+ }
+
+ ret = hybridswap_new_segment_init(req, ioentry);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "hybridswap_new_segment_init fail %d\n", ret);
+ req->io_para.done_callback(ioentry, -EIO, req);
+
+ return ret;
+ }
+
+ return 0;
+}
+
+int hyb_io_work_begin(void)
+{
+ if (hyb_io_work_begin_flag)
+ return 0;
+
+ hybridswap_proc_read_workqueue = alloc_workqueue("proc_hybridswap_read",
+ WQ_HIGHPRI | WQ_UNBOUND, 0);
+ if (unlikely(!hybridswap_proc_read_workqueue))
+ return -EFAULT;
+
+ hybridswap_proc_write_workqueue = alloc_workqueue("proc_hybridswap_write",
+ WQ_CPU_INTENSIVE, 0);
+ if (unlikely(!hybridswap_proc_write_workqueue)) {
+ destroy_workqueue(hybridswap_proc_read_workqueue);
+
+ return -EFAULT;
+ }
+
+ hybridswap_key_init();
+
+ hyb_io_work_begin_flag = true;
+
+ return 0;
+}
+
+void *hybridswap_plug_start(struct hybridswap_io *io_para)
+{
+ gfp_t gfp;
+ struct hybridswap_io_req *req = NULL;
+
+ if (unlikely(hybridswap_check_io_para_err(io_para)))
+ return NULL;
+
+ gfp = (io_para->class != HYB_RECLAIM_IN) ?
+ GFP_ATOMIC : GFP_NOIO;
+ req = kzalloc(sizeof(struct hybridswap_io_req), gfp);
+ if (!req && (io_para->class == HYB_FAULT_OUT))
+ req = kzalloc(sizeof(struct hybridswap_io_req), GFP_NOIO);
+
+ if (unlikely(!req)) {
+ hybp(HYB_ERR, "io_req null\n");
+
+ return NULL;
+ }
+
+ kref_init(&req->refcount);
+ mutex_init(&req->refmutex);
+ atomic_set(&req->eswap_doing, 0);
+ init_waitqueue_head(&req->io_wait);
+ req->io_para.bdev = io_para->bdev;
+ req->io_para.class = io_para->class;
+ req->io_para.done_callback = io_para->done_callback;
+ req->io_para.complete_notify = io_para->complete_notify;
+ req->io_para.private = io_para->private;
+ req->io_para.record = io_para->record;
+ req->limit_doing_flag =
+ (io_para->class == HYB_RECLAIM_IN) ||
+ (io_para->class == HYB_PRE_OUT);
+ req->wait_io_finish_flag =
+ (io_para->class == HYB_RECLAIM_IN) ||
+ (io_para->class == HYB_FAULT_OUT);
+ req->nice = task_nice(current);
+ init_completion(&req->io_end_flag);
+
+ return (void *)req;
+}
+
+int hybridswap_read_eswap(void *iohandle,
+ struct hybridswap_entry *ioentry)
+{
+ return hybridswap_io_eswapent(iohandle, ioentry);
+}
+
+int hybridswap_write_eswap(void *iohandle,
+ struct hybridswap_entry *ioentry)
+{
+ return hybridswap_io_eswapent(iohandle, ioentry);
+}
+
+int hybridswap_plug_finish(void *iohandle)
+{
+ int ret;
+ struct hybridswap_io_req *req = (struct hybridswap_io_req *)iohandle;
+
+ hybperfiowrkstart(req->io_para.record, HYB_IO_ESWAP);
+ ret = hybridswap_io_submit(req, false);
+ if (unlikely(ret))
+ hybp(HYB_ERR, "submit fail %d\n", ret);
+
+ hybperfiowrkend(req->io_para.record, HYB_IO_ESWAP);
+ hybridswap_wait_io_finish(req);
+ hybperfiowrkpoint(req->io_para.record, HYB_WAKE_UP);
+
+ hybridswap_iostatus_bytes(req);
+ hybperf_io_stat(req->io_para.record, req->page_cnt,
+ req->segment_cnt);
+
+ kref_put_mutex(&req->refcount, hybridswap_io_req_release,
+ &req->refmutex);
+
+ hybp(HYB_DEBUG, "io schedule finish succ\n");
+
+ return ret;
+}
+
+static void hybridswap_dump_point_lat(
+ struct hybridswap_key_point_record *record, ktime_t start)
+{
+ int i;
+
+ for (i = 0; i < HYB_KYE_POINT_BUTT; ++i) {
+ if (!record->key_point[i].record_cnt)
+ continue;
+
+ hybp(HYB_ERR,
+ "%s diff %lld cnt %u end %u lat %lld ravg_sum %llu\n",
+ key_point_name[i],
+ ktime_us_delta(record->key_point[i].first_time, start),
+ record->key_point[i].record_cnt,
+ record->key_point[i].end_cnt,
+ record->key_point[i].proc_total_time,
+ record->key_point[i].proc_ravg_sum);
+ }
+}
+
+static void hybridswap_dump_no_record_point(
+ struct hybridswap_key_point_record *record, char *log,
+ unsigned int *count)
+{
+ int i;
+ unsigned int point = 0;
+
+ for (i = 0; i < HYB_KYE_POINT_BUTT; ++i)
+ if (record->key_point[i].record_cnt)
+ point = i;
+
+ point++;
+ if (point < HYB_KYE_POINT_BUTT)
+ *count += snprintf(log + *count,
+ (size_t)(DUMP_BUF_LEN - *count),
+ " no_record_point %s", key_point_name[point]);
+ else
+ *count += snprintf(log + *count,
+ (size_t)(DUMP_BUF_LEN - *count), " all_point_record");
+}
+
+static long long hybridswap_calc_speed(s64 page_cnt, s64 time)
+{
+ s64 size;
+
+ if (!page_cnt)
+ return 0;
+
+ size = page_cnt * PAGE_SIZE * BITS_PER_BYTE;
+ if (time)
+ return size * USEC_PER_SEC / time;
+ else
+ return S64_MAX;
+}
+
+static void hybridswap_dump_lat(
+ struct hybridswap_key_point_record *record, ktime_t curr_time,
+ bool perf_end_flag)
+{
+ char log[DUMP_BUF_LEN] = { 0 };
+ unsigned int count = 0;
+ ktime_t start;
+ s64 total_time;
+
+ start = record->key_point[HYB_START].first_time;
+ total_time = ktime_us_delta(curr_time, start);
+ count += snprintf(log + count,
+ (size_t)(DUMP_BUF_LEN - count),
+ "totaltime(us) %lld class %u task %s nice %d",
+ total_time, record->class, record->task_comm, record->nice);
+
+ if (perf_end_flag)
+ count += snprintf(log + count, (size_t)(DUMP_BUF_LEN - count),
+ " page %d segment %d speed(bps) %lld level %llu",
+ record->page_cnt, record->segment_cnt,
+ hybridswap_calc_speed(record->page_cnt, total_time),
+ record->warn_level);
+ else
+ count += snprintf(log + count, (size_t)(DUMP_BUF_LEN - count),
+ " state %c", task_state_to_char(record->task));
+
+ hybridswap_dump_no_record_point(record, log, &count);
+
+ hybp(HYB_ERR, "perf end flag %u %s\n", perf_end_flag, log);
+ hybridswap_dump_point_lat(record, start);
+ dump_stack();
+}
+
+static unsigned long hybperf_warn_level(
+ enum hybridswap_class class)
+{
+ if (unlikely(class >= HYB_CLASS_BUTT))
+ return 0;
+
+ return warn_level[class];
+}
+
+void hybperf_warning(struct timer_list *t)
+{
+ struct hybridswap_key_point_record *record =
+ from_timer(record, t, lat_monitor);
+ static unsigned long last_dumpiowrkjiffies = 0;
+
+ if (!record->warn_level)
+ return;
+
+ if (jiffies_to_msecs(jiffies - last_dumpiowrkjiffies) <= 60000)
+ return;
+
+ hybridswap_dump_lat(record, ktime_get(), false);
+
+ if (likely(record->task))
+ sched_show_task(record->task);
+ last_dumpiowrkjiffies = jiffies;
+ record->warn_level <<= 2;
+ record->timeout_flag = true;
+ mod_timer(&record->lat_monitor,
+ jiffies + msecs_to_jiffies(record->warn_level));
+}
+
+static void hybperf_init_monitor(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_class class)
+{
+ record->warn_level = hybperf_warn_level(class);
+
+ if (!record->warn_level)
+ return;
+
+ record->task = current;
+ get_task_struct(record->task);
+ timer_setup(&record->lat_monitor, hybperf_warning, 0);
+ mod_timer(&record->lat_monitor,
+ jiffies + msecs_to_jiffies(record->warn_level));
+}
+
+static void hybperf_stop_monitor(
+ struct hybridswap_key_point_record *record)
+{
+ if (!record->warn_level)
+ return;
+
+ del_timer_sync(&record->lat_monitor);
+ put_task_struct(record->task);
+}
+
+static void hybperf_init(struct hybridswap_key_point_record *record,
+ enum hybridswap_class class)
+{
+ int i;
+
+ for (i = 0; i < HYB_KYE_POINT_BUTT; ++i)
+ spin_lock_init(&record->key_point[i].time_lock);
+
+ record->nice = task_nice(current);
+ record->class = class;
+ get_task_comm(record->task_comm, current);
+ hybperf_init_monitor(record, class);
+}
+
+void hybperf_start_proc(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type, ktime_t curr_time,
+ unsigned long long current_ravg_sum)
+{
+ struct hybridswap_key_point_info *key_point =
+ &record->key_point[type];
+
+ if (!key_point->record_cnt)
+ key_point->first_time = curr_time;
+
+ key_point->record_cnt++;
+ key_point->last_time = curr_time;
+ key_point->last_ravg_sum = current_ravg_sum;
+}
+
+void hybperf_end_proc(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type, ktime_t curr_time,
+ unsigned long long current_ravg_sum)
+{
+ struct hybridswap_key_point_info *key_point =
+ &record->key_point[type];
+ s64 diff_time = ktime_us_delta(curr_time, key_point->last_time);
+
+ key_point->proc_total_time += diff_time;
+ if (diff_time > key_point->proc_max_time)
+ key_point->proc_max_time = diff_time;
+
+ key_point->proc_ravg_sum += current_ravg_sum -
+ key_point->last_ravg_sum;
+ key_point->end_cnt++;
+ key_point->last_time = curr_time;
+ key_point->last_ravg_sum = current_ravg_sum;
+}
+
+void hybperf_async_perf(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type, ktime_t start,
+ unsigned long long start_ravg_sum)
+{
+ unsigned long long current_ravg_sum = ((type == HYB_CALL_BACK) ||
+ (type == HYB_END_WORK)) ? hybridswap_fetch_ravg_sum() : 0;
+ unsigned long flags;
+
+ spin_lock_irqsave(&record->key_point[type].time_lock, flags);
+ hybperf_start_proc(record, type, start, start_ravg_sum);
+ hybperf_end_proc(record, type, ktime_get(),
+ current_ravg_sum);
+ spin_unlock_irqrestore(&record->key_point[type].time_lock, flags);
+}
+
+void hybperfiowrkpoint(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type)
+{
+ hybperf_start_proc(record, type, ktime_get(),
+ hybridswap_fetch_ravg_sum());
+ record->key_point[type].end_cnt++;
+}
+
+void hybperf_start(
+ struct hybridswap_key_point_record *record,
+ ktime_t stsrt, unsigned long long start_ravg_sum,
+ enum hybridswap_class class)
+{
+ hybperf_init(record, class);
+ hybperf_start_proc(record, HYB_START, stsrt,
+ start_ravg_sum);
+ record->key_point[HYB_START].end_cnt++;
+}
+
+void hybperfiowrkstat(
+ struct hybridswap_key_point_record *record)
+{
+ int task_is_fg = 0;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+ s64 curr_lat;
+ s64 timeout_value[HYB_CLASS_BUTT] = {
+ 2000000, 100000, 500000, 2000000
+ };
+
+ if (!stat || (record->class >= HYB_CLASS_BUTT))
+ return;
+
+ curr_lat = ktime_us_delta(record->key_point[HYB_DONE].first_time,
+ record->key_point[HYB_START].first_time);
+ atomic64_add(curr_lat, &stat->lat[record->class].total_lat);
+ if (curr_lat > atomic64_read(&stat->lat[record->class].max_lat))
+ atomic64_set(&stat->lat[record->class].max_lat, curr_lat);
+ if (curr_lat > timeout_value[record->class])
+ atomic64_inc(&stat->lat[record->class].timeout_cnt);
+ if (record->class == HYB_FAULT_OUT) {
+ if (curr_lat <= timeout_value[HYB_FAULT_OUT])
+ return;
+#ifdef CONFIG_FG_TASK_UID
+ task_is_fg = current_is_fg() ? 1 : 0;
+#endif
+ if (curr_lat > 500000)
+ atomic64_inc(&stat->fault_stat[task_is_fg].timeout_500ms_cnt);
+ else if (curr_lat > 100000)
+ atomic64_inc(&stat->fault_stat[task_is_fg].timeout_100ms_cnt);
+ hybp(HYB_INFO, "task %s:%d fault out timeout us %llu fg %d\n",
+ current->comm, current->pid, curr_lat, task_is_fg);
+ }
+}
+
+void hybperf_end(struct hybridswap_key_point_record *record)
+{
+ int loglevel;
+
+ hybperf_stop_monitor(record);
+ hybperfiowrkpoint(record, HYB_DONE);
+ hybperfiowrkstat(record);
+
+ loglevel = record->timeout_flag ? HYB_ERR : HYB_DEBUG;
+ if (loglevel > hybridswap_loglevel())
+ return;
+
+ hybridswap_dump_lat(record,
+ record->key_point[HYB_DONE].first_time, true);
+}
+
+void hybperfiowrkstart(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type)
+{
+ hybperf_start_proc(record, type, ktime_get(),
+ hybridswap_fetch_ravg_sum());
+}
+
+void hybperfiowrkend(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type)
+{
+ hybperf_end_proc(record, type, ktime_get(),
+ hybridswap_fetch_ravg_sum());
+}
+
+void hybperf_io_stat(
+ struct hybridswap_key_point_record *record, int page_cnt,
+ int segment_cnt)
+{
+ record->page_cnt = page_cnt;
+ record->segment_cnt = segment_cnt;
+}
+
+static struct io_eswapent *alloc_io_eswapent(struct hybridswap_page_pool *pool,
+ bool fast, bool nofail)
+{
+ int i;
+ struct io_eswapent *io_eswap = hybridswap_malloc(sizeof(struct io_eswapent),
+ fast, nofail);
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "alloc io_eswap failed\n");
+ return NULL;
+ }
+
+ io_eswap->eswapid = -EINVAL;
+ io_eswap->pool = pool;
+ for (i = 0; i < (int)ESWAP_PG_CNT; i++) {
+ io_eswap->pages[i] = hybridswap_alloc_page(pool, GFP_ATOMIC,
+ fast, nofail);
+ if (!io_eswap->pages[i]) {
+ hybp(HYB_ERR, "alloc page[%d] failed\n", i);
+ goto page_free;
+ }
+ }
+ return io_eswap;
+page_free:
+ for (i = 0; i < (int)ESWAP_PG_CNT; i++)
+ if (io_eswap->pages[i])
+ hybridswap_page_recycle(io_eswap->pages[i], pool);
+ hybridswap_free(io_eswap);
+
+ return NULL;
+}
+
+static void discard_io_eswapent(struct io_eswapent *io_eswap, unsigned int op)
+{
+ struct zram *zram = NULL;
+ int i;
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ return;
+ }
+ if (!io_eswap->mcg)
+ zram = io_eswap->zram;
+ else
+ zram = MEMCGRP_ITEM(io_eswap->mcg, zram);
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ goto out;
+ }
+ for (i = 0; i < (int)ESWAP_PG_CNT; i++)
+ if (io_eswap->pages[i])
+ hybridswap_page_recycle(io_eswap->pages[i], io_eswap->pool);
+ if (io_eswap->eswapid < 0)
+ goto out;
+ hybp(HYB_DEBUG, "eswap = %d, op = %d\n", io_eswap->eswapid, op);
+ if (op == REQ_OP_READ) {
+ put_eswap(zram->infos, io_eswap->eswapid);
+ goto out;
+ }
+ for (i = 0; i < io_eswap->cnt; i++) {
+ u32 index = io_eswap->index[i];
+
+ zram_slot_lock(zram, index);
+ if (io_eswap->mcg)
+ swap_sorted_list_add_tail(zram, index, io_eswap->mcg);
+ zram_clear_flag(zram, index, ZRAM_UNDER_WB);
+ zram_slot_unlock(zram, index);
+ }
+ hybridswap_free_eswap(zram->infos, io_eswap->eswapid);
+out:
+ hybridswap_free(io_eswap);
+}
+
+static void copy_to_pages(u8 *src, struct page *pages[],
+ unsigned long eswpentry, int size)
+{
+ u8 *dst = NULL;
+ int pg_id = esentry_pgid(eswpentry);
+ int offset = esentry_pgoff(eswpentry);
+
+ if (!src) {
+ hybp(HYB_ERR, "NULL src\n");
+ return;
+ }
+ if (!pages) {
+ hybp(HYB_ERR, "NULL pages\n");
+ return;
+ }
+ if (size < 0 || size > (int)PAGE_SIZE) {
+ hybp(HYB_ERR, "size = %d invalid\n", size);
+ return;
+ }
+ dst = page_to_virt(pages[pg_id]);
+ if (offset + size <= (int)PAGE_SIZE) {
+ memcpy(dst + offset, src, size);
+ return;
+ }
+ if (pg_id == ESWAP_PG_CNT - 1) {
+ hybp(HYB_ERR, "eswap overflow, addr = %lx, size = %d\n",
+ eswpentry, size);
+ return;
+ }
+ memcpy(dst + offset, src, PAGE_SIZE - offset);
+ dst = page_to_virt(pages[pg_id + 1]);
+ memcpy(dst, src + PAGE_SIZE - offset, offset + size - PAGE_SIZE);
+}
+
+static void copy_from_pages(u8 *dst, struct page *pages[],
+ unsigned long eswpentry, int size)
+{
+ u8 *src = NULL;
+ int pg_id = esentry_pgid(eswpentry);
+ int offset = esentry_pgoff(eswpentry);
+
+ if (!dst) {
+ hybp(HYB_ERR, "NULL dst\n");
+ return;
+ }
+ if (!pages) {
+ hybp(HYB_ERR, "NULL pages\n");
+ return;
+ }
+ if (size < 0 || size > (int)PAGE_SIZE) {
+ hybp(HYB_ERR, "size = %d invalid\n", size);
+ return;
+ }
+
+ src = page_to_virt(pages[pg_id]);
+ if (offset + size <= (int)PAGE_SIZE) {
+ memcpy(dst, src + offset, size);
+ return;
+ }
+ if (pg_id == ESWAP_PG_CNT - 1) {
+ hybp(HYB_ERR, "eswap overflow, addr = %lx, size = %d\n",
+ eswpentry, size);
+ return;
+ }
+ memcpy(dst, src + offset, PAGE_SIZE - offset);
+ src = page_to_virt(pages[pg_id + 1]);
+ memcpy(dst + PAGE_SIZE - offset, src, offset + size - PAGE_SIZE);
+}
+
+static bool zram_test_skip(struct zram *zram, u32 index, struct mem_cgroup *mcg)
+{
+ if (zram_test_flag(zram, index, ZRAM_WB))
+ return true;
+ if (zram_test_flag(zram, index, ZRAM_UNDER_WB))
+ return true;
+ if (zram_test_flag(zram, index, ZRAM_BATCHING_OUT))
+ return true;
+ if (zram_test_flag(zram, index, ZRAM_SAME))
+ return true;
+ if (mcg != zram_fetch_mcg(zram, index))
+ return true;
+ if (!zram_get_obj_size(zram, index))
+ return true;
+
+ return false;
+}
+
+static bool zram_test_overwrite(struct zram *zram, u32 index, int eswapid)
+{
+ if (!zram_test_flag(zram, index, ZRAM_WB))
+ return true;
+ if (eswapid != esentry_extid(zram_get_handle(zram, index)))
+ return true;
+
+ return false;
+}
+
+static void update_size_info(struct zram *zram, u32 index)
+{
+ struct hybstatus *stat;
+ int size = zram_get_obj_size(zram, index);
+ struct mem_cgroup *mcg;
+ memcg_hybs_t *hybs;
+ int eswapid;
+
+ if (!zram_test_flag(zram, index, ZRAM_IN_BD))
+ return;
+
+ eswapid = esentry_extid(zram_get_handle(zram, index));
+ hybp(HYB_INFO, "eswapid %d index %d\n", eswapid, index);
+
+ if (eswapid >= 0 && eswapid < zram->infos->nr_es)
+ atomic_dec(&zram->infos->eswap_stored_pages[eswapid]);
+ else {
+ hybp(HYB_ERR, "eswap = %d invalid\n", eswapid);
+ eswapid = -1;
+ }
+
+ stat = hybridswap_fetch_stat_obj();
+ if (stat) {
+ atomic64_add(size, &stat->dropped_eswap_size);
+ atomic64_sub(size, &stat->stored_size);
+ atomic64_dec(&stat->stored_pages);
+ } else
+ hybp(HYB_ERR, "NULL stat\n");
+
+ mcg = zram_fetch_mcg(zram, index);
+ if (mcg) {
+ hybs = MEMCGRP_ITEM_DATA(mcg);
+
+ if (hybs) {
+ atomic64_sub(size, &hybs->hybridswap_stored_size);
+ atomic64_dec(&hybs->hybridswap_stored_pages);
+ } else
+ hybp(HYB_ERR, "NULL hybs\n");
+ } else
+ hybp(HYB_ERR, "NULL mcg\n");
+ zram_clear_flag(zram, index, ZRAM_IN_BD);
+}
+
+static void move_to_hybridswap(struct zram *zram, u32 index,
+ unsigned long eswpentry, struct mem_cgroup *mcg)
+{
+ int size;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ return;
+ }
+
+ size = zram_get_obj_size(zram, index);
+
+ zram_clear_flag(zram, index, ZRAM_UNDER_WB);
+
+ zs_free(zram->mem_pool, zram_get_handle(zram, index));
+ atomic64_sub(size, &zram->stats.compr_data_size);
+ atomic64_dec(&zram->stats.pages_stored);
+
+ zram_set_mcg(zram, index, mcg->id.id);
+ zram_set_flag(zram, index, ZRAM_IN_BD);
+ zram_set_flag(zram, index, ZRAM_WB);
+ zram_set_obj_size(zram, index, size);
+ if (size == PAGE_SIZE)
+ zram_set_flag(zram, index, ZRAM_HUGE);
+ zram_set_handle(zram, index, eswpentry);
+ swap_maps_insert(zram, index);
+
+ atomic64_add(size, &stat->stored_size);
+ atomic64_add(size, &MEMCGRP_ITEM(mcg, hybridswap_stored_size));
+ atomic64_inc(&stat->stored_pages);
+ atomic_inc(&zram->infos->eswap_stored_pages[esentry_extid(eswpentry)]);
+ atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_stored_pages));
+}
+
+static void __move_to_zram(struct zram *zram, u32 index, unsigned long handle,
+ struct io_eswapent *io_eswap)
+{
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+ struct mem_cgroup *mcg = io_eswap->mcg;
+ int size = zram_get_obj_size(zram, index);
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+
+ zram_slot_lock(zram, index);
+ if (zram_test_overwrite(zram, index, io_eswap->eswapid)) {
+ zram_slot_unlock(zram, index);
+ zs_free(zram->mem_pool, handle);
+ return;
+ }
+ swap_maps_destroy(zram, index);
+ zram_set_handle(zram, index, handle);
+ zram_clear_flag(zram, index, ZRAM_WB);
+ if (mcg)
+ swap_sorted_list_add_tail(zram, index, mcg);
+ zram_set_flag(zram, index, ZRAM_FROM_HYBRIDSWAP);
+ atomic64_add(size, &zram->stats.compr_data_size);
+ atomic64_inc(&zram->stats.pages_stored);
+ zram_clear_flag(zram, index, ZRAM_IN_BD);
+ zram_slot_unlock(zram, index);
+
+ atomic64_inc(&stat->batchout_pages);
+ atomic64_sub(size, &stat->stored_size);
+ atomic64_dec(&stat->stored_pages);
+ atomic64_add(size, &stat->batchout_real_load);
+ atomic_dec(&zram->infos->eswap_stored_pages[io_eswap->eswapid]);
+ if (mcg) {
+ atomic64_sub(size, &MEMCGRP_ITEM(mcg, hybridswap_stored_size));
+ atomic64_dec(&MEMCGRP_ITEM(mcg, hybridswap_stored_pages));
+ }
+}
+
+static int move_to_zram(struct zram *zram, u32 index, struct io_eswapent *io_eswap)
+{
+ unsigned long handle, eswpentry;
+ struct mem_cgroup *mcg = NULL;
+ int size, i;
+ u8 *dst = NULL;
+
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return -EINVAL;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return -EINVAL;
+ }
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ return -EINVAL;
+ }
+
+ mcg = io_eswap->mcg;
+ zram_slot_lock(zram, index);
+ eswpentry = zram_get_handle(zram, index);
+ if (zram_test_overwrite(zram, index, io_eswap->eswapid)) {
+ zram_slot_unlock(zram, index);
+ return 0;
+ }
+ size = zram_get_obj_size(zram, index);
+ zram_slot_unlock(zram, index);
+
+ for (i = esentry_pgid(eswpentry) - 1; i >= 0 && io_eswap->pages[i]; i--) {
+ hybridswap_page_recycle(io_eswap->pages[i], io_eswap->pool);
+ io_eswap->pages[i] = NULL;
+ }
+ handle = hybridswap_zsmalloc(zram->mem_pool, size, io_eswap->pool);
+ if (!handle) {
+ hybp(HYB_ERR, "alloc handle failed, size = %d\n", size);
+ return -ENOMEM;
+ }
+ dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO);
+ copy_from_pages(dst, io_eswap->pages, eswpentry, size);
+ zs_unmap_object(zram->mem_pool, handle);
+ __move_to_zram(zram, index, handle, io_eswap);
+
+ return 0;
+}
+
+static int eswap_unlock(struct io_eswapent *io_eswap)
+{
+ int eswapid;
+ struct mem_cgroup *mcg = NULL;
+ struct zram *zram = NULL;
+ int k;
+ unsigned long eswpentry;
+ int real_load = 0, size;
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ goto out;
+ }
+
+ mcg = io_eswap->mcg;
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ goto out;
+ }
+ zram = MEMCGRP_ITEM(mcg, zram);
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ goto out;
+ }
+ eswapid = io_eswap->eswapid;
+ if (eswapid < 0)
+ goto out;
+
+ eswapid = io_eswap->eswapid;
+ if (MEMCGRP_ITEM(mcg, in_swapin))
+ goto out;
+ hybp(HYB_DEBUG, "add eswapid = %d, cnt = %d.\n",
+ eswapid, io_eswap->cnt);
+ eswpentry = ((unsigned long)eswapid) << ESWAP_SHIFT;
+ for (k = 0; k < io_eswap->cnt; k++)
+ zram_slot_lock(zram, io_eswap->index[k]);
+ for (k = 0; k < io_eswap->cnt; k++) {
+ move_to_hybridswap(zram, io_eswap->index[k], eswpentry, mcg);
+ size = zram_get_obj_size(zram, io_eswap->index[k]);
+ eswpentry += size;
+ real_load += size;
+ }
+ put_eswap(zram->infos, eswapid);
+ io_eswap->eswapid = -EINVAL;
+ for (k = 0; k < io_eswap->cnt; k++)
+ zram_slot_unlock(zram, io_eswap->index[k]);
+ hybp(HYB_DEBUG, "add eswap OK.\n");
+out:
+ discard_io_eswapent(io_eswap, REQ_OP_WRITE);
+ if (mcg)
+ css_put(&mcg->css);
+
+ return real_load;
+}
+
+static void eswap_add(struct io_eswapent *io_eswap,
+ enum hybridswap_class class)
+{
+ struct mem_cgroup *mcg = NULL;
+ struct zram *zram = NULL;
+ int eswapid;
+ int k;
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ return;
+ }
+
+ mcg = io_eswap->mcg;
+ if (!mcg)
+ zram = io_eswap->zram;
+ else
+ zram = MEMCGRP_ITEM(mcg, zram);
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ goto out;
+ }
+
+ eswapid = io_eswap->eswapid;
+ if (eswapid < 0)
+ goto out;
+
+ io_eswap->cnt = swap_maps_fetch_eswap_index(zram->infos,
+ eswapid,
+ io_eswap->index);
+ hybp(HYB_DEBUG, "eswapid = %d, cnt = %d.\n", eswapid, io_eswap->cnt);
+ for (k = 0; k < io_eswap->cnt; k++) {
+ int ret = move_to_zram(zram, io_eswap->index[k], io_eswap);
+
+ if (ret < 0)
+ goto out;
+ }
+ hybp(HYB_DEBUG, "eswap add OK, free eswapid = %d.\n", eswapid);
+ hybridswap_free_eswap(zram->infos, io_eswap->eswapid);
+ io_eswap->eswapid = -EINVAL;
+ if (mcg) {
+ atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_inextcnt));
+ atomic_dec(&MEMCGRP_ITEM(mcg, hybridswap_extcnt));
+ }
+out:
+ discard_io_eswapent(io_eswap, REQ_OP_READ);
+ if (mcg)
+ css_put(&mcg->css);
+}
+
+static void eswap_clear(struct zram *zram, int eswapid)
+{
+ int *index = NULL;
+ int cnt;
+ int k;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+
+ index = kzalloc(sizeof(int) * ESWAP_MAX_OBJ_CNT, GFP_NOIO);
+ if (!index)
+ index = kzalloc(sizeof(int) * ESWAP_MAX_OBJ_CNT,
+ GFP_NOIO | __GFP_NOFAIL);
+
+ cnt = swap_maps_fetch_eswap_index(zram->infos, eswapid, index);
+
+ for (k = 0; k < cnt; k++) {
+ zram_slot_lock(zram, index[k]);
+ if (zram_test_overwrite(zram, index[k], eswapid)) {
+ zram_slot_unlock(zram, index[k]);
+ continue;
+ }
+ zram_set_mcg(zram, index[k], 0);
+ zram_set_flag(zram, index[k], ZRAM_MCGID_CLEAR);
+ atomic64_inc(&stat->memcgid_clear);
+ zram_slot_unlock(zram, index[k]);
+ }
+
+ kfree(index);
+}
+
+static int shrink_entry(struct zram *zram, u32 index, struct io_eswapent *io_eswap,
+ unsigned long eswap_off)
+{
+ unsigned long handle;
+ int size;
+ u8 *src = NULL;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return -EINVAL;
+ }
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return -EINVAL;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return -EINVAL;
+ }
+
+ zram_slot_lock(zram, index);
+ handle = zram_get_handle(zram, index);
+ if (!handle || zram_test_skip(zram, index, io_eswap->mcg)) {
+ zram_slot_unlock(zram, index);
+ return 0;
+ }
+ size = zram_get_obj_size(zram, index);
+ if (eswap_off + size > ESWAP_SIZE) {
+ zram_slot_unlock(zram, index);
+ return -ENOSPC;
+ }
+
+ src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
+ copy_to_pages(src, io_eswap->pages, eswap_off, size);
+ zs_unmap_object(zram->mem_pool, handle);
+ io_eswap->index[io_eswap->cnt++] = index;
+
+ swap_sorted_list_del(zram, index);
+ zram_set_flag(zram, index, ZRAM_UNDER_WB);
+ if (zram_test_flag(zram, index, ZRAM_FROM_HYBRIDSWAP)) {
+ atomic64_inc(&stat->reout_pages);
+ atomic64_add(size, &stat->reout_bytes);
+ }
+ zram_slot_unlock(zram, index);
+ atomic64_inc(&stat->reclaimin_pages);
+
+ return size;
+}
+
+static int shrink_entry_list(struct io_eswapent *io_eswap)
+{
+ struct mem_cgroup *mcg = NULL;
+ struct zram *zram = NULL;
+ unsigned long stored_size;
+ int *swap_index = NULL;
+ int swap_cnt, k;
+ int swap_size = 0;
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ return -EINVAL;
+ }
+
+ mcg = io_eswap->mcg;
+ zram = MEMCGRP_ITEM(mcg, zram);
+ hybp(HYB_DEBUG, "mcg = %d\n", mcg->id.id);
+ stored_size = atomic64_read(&MEMCGRP_ITEM(mcg, zram_stored_size));
+ hybp(HYB_DEBUG, "zram_stored_size = %ld\n", stored_size);
+ if (stored_size < ESWAP_SIZE) {
+ hybp(HYB_INFO, "%lu is smaller than ESWAP_SIZE\n", stored_size);
+ return -ENOENT;
+ }
+
+ swap_index = kzalloc(sizeof(int) * ESWAP_MAX_OBJ_CNT, GFP_NOIO);
+ if (!swap_index)
+ return -ENOMEM;
+ io_eswap->eswapid = hybridswap_alloc_eswap(zram->infos, mcg);
+ if (io_eswap->eswapid < 0) {
+ kfree(swap_index);
+ return io_eswap->eswapid;
+ }
+ swap_cnt = zram_fetch_mcg_last_index(zram->infos, mcg, swap_index,
+ ESWAP_MAX_OBJ_CNT);
+ io_eswap->cnt = 0;
+ for (k = 0; k < swap_cnt && swap_size < (int)ESWAP_SIZE; k++) {
+ int size = shrink_entry(zram, swap_index[k], io_eswap, swap_size);
+
+ if (size < 0)
+ break;
+ swap_size += size;
+ }
+ kfree(swap_index);
+ hybp(HYB_DEBUG, "fill eswap = %d, cnt = %d, overhead = %ld.\n",
+ io_eswap->eswapid, io_eswap->cnt, ESWAP_SIZE - swap_size);
+ if (swap_size == 0) {
+ hybp(HYB_ERR, "swap_size = 0, free eswapid = %d.\n",
+ io_eswap->eswapid);
+ hybridswap_free_eswap(zram->infos, io_eswap->eswapid);
+ io_eswap->eswapid = -EINVAL;
+ return -ENOENT;
+ }
+
+ return swap_size;
+}
+
+void hybridswap_manager_deinit(struct zram *zram)
+{
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+
+ free_hyb_info(zram->infos);
+ zram->infos = NULL;
+}
+
+int hybridswap_manager_init(struct zram *zram)
+{
+ int ret;
+
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ zram->infos = alloc_hyb_info(zram->disksize,
+ zram->nr_pages << PAGE_SHIFT);
+ if (!zram->infos) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ return 0;
+out:
+ hybridswap_manager_deinit(zram);
+
+ return ret;
+}
+
+void hybridswap_manager_memcg_init(struct zram *zram,
+ struct mem_cgroup *memcg)
+{
+ memcg_hybs_t *hybs;
+
+ if (!memcg || !zram || !zram->infos) {
+ hybp(HYB_ERR, "invalid zram or mcg_hyb\n");
+ return;
+ }
+
+ hyb_entries_init(memcgindex(zram->infos, memcg->id.id), zram->infos->objects);
+ hyb_entries_init(memcgindex(zram->infos, memcg->id.id), zram->infos->eswap_table);
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ hybs->in_swapin = false;
+ atomic64_set(&hybs->zram_stored_size, 0);
+ atomic64_set(&hybs->zram_page_size, 0);
+ atomic64_set(&hybs->hybridswap_stored_pages, 0);
+ atomic64_set(&hybs->hybridswap_stored_size, 0);
+ atomic64_set(&hybs->hybridswap_allfaultcnt, 0);
+ atomic64_set(&hybs->hybridswap_outcnt, 0);
+ atomic64_set(&hybs->hybridswap_incnt, 0);
+ atomic64_set(&hybs->hybridswap_faultcnt, 0);
+ atomic64_set(&hybs->hybridswap_outextcnt, 0);
+ atomic64_set(&hybs->hybridswap_inextcnt, 0);
+ atomic_set(&hybs->hybridswap_extcnt, 0);
+ atomic_set(&hybs->hybridswap_peakextcnt, 0);
+ mutex_init(&hybs->swap_lock);
+
+ smp_wmb();
+ hybs->zram = zram;
+ hybp(HYB_DEBUG, "new memcg in zram, id = %d.\n", memcg->id.id);
+}
+
+void hybridswap_manager_memcg_deinit(struct mem_cgroup *mcg)
+{
+ struct zram *zram = NULL;
+ struct hyb_info *infos = NULL;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+ int last_index = -1;
+ memcg_hybs_t *hybs;
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+
+ hybs = MEMCGRP_ITEM_DATA(mcg);
+ if (!hybs->zram)
+ return;
+
+ zram = hybs->zram;
+ if (!zram->infos) {
+ hybp(HYB_WARN, "mcg %p name %s id %d zram %p infos is NULL\n",
+ mcg, hybs->name, mcg->id.id, zram);
+ return;
+ }
+
+ hybp(HYB_DEBUG, "deinit mcg %d %s\n", mcg->id.id, hybs->name);
+ if (mcg->id.id == 0)
+ return;
+
+ infos = zram->infos;
+ while (1) {
+ int index = fetch_memcg_zram_entry(infos, mcg);
+
+ if (index == -ENOENT)
+ break;
+
+ if (index < 0) {
+ hybp(HYB_ERR, "invalid index\n");
+ return;
+ }
+
+ if (last_index == index) {
+ hybp(HYB_ERR, "dup index %d\n", index);
+ dump_stack();
+ }
+
+ zram_slot_lock(zram, index);
+ if (index == last_index || mcg == zram_fetch_mcg(zram, index)) {
+ hyb_entries_del(obj_index(zram->infos, index),
+ memcgindex(zram->infos, mcg->id.id),
+ zram->infos->objects);
+ zram_set_mcg(zram, index, 0);
+ zram_set_flag(zram, index, ZRAM_MCGID_CLEAR);
+ atomic64_inc(&stat->memcgid_clear);
+ }
+ zram_slot_unlock(zram, index);
+ last_index = index;
+ }
+
+ hybp(HYB_DEBUG, "deinit mcg %d %s, entry done\n", mcg->id.id, hybs->name);
+ while (1) {
+ int eswapid = fetch_memcg_eswap(infos, mcg);
+
+ if (eswapid == -ENOENT)
+ break;
+
+ eswap_clear(zram, eswapid);
+ hyb_entries_set_memcgid(eswap_index(infos, eswapid), infos->eswap_table, 0);
+ put_eswap(infos, eswapid);
+ }
+ hybp(HYB_DEBUG, "deinit mcg %d %s, eswap done\n", mcg->id.id, hybs->name);
+ hybs->zram = NULL;
+}
+void hybridswap_swap_sorted_list_add(struct zram *zram,
+ u32 index, struct mem_cgroup *memcg)
+{
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+
+ swap_sorted_list_add(zram, index, memcg);
+}
+
+void hybridswap_swap_sorted_list_del(struct zram *zram, u32 index)
+{
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+
+ zram_clear_flag(zram, index, ZRAM_FROM_HYBRIDSWAP);
+ if (zram_test_flag(zram, index, ZRAM_MCGID_CLEAR)) {
+ zram_clear_flag(zram, index, ZRAM_MCGID_CLEAR);
+ atomic64_dec(&stat->memcgid_clear);
+ }
+
+ if (zram_test_flag(zram, index, ZRAM_WB)) {
+ update_size_info(zram, index);
+ swap_maps_destroy(zram, index);
+ zram_clear_flag(zram, index, ZRAM_WB);
+ zram_set_mcg(zram, index, 0);
+ zram_set_handle(zram, index, 0);
+ } else {
+ swap_sorted_list_del(zram, index);
+ }
+}
+
+unsigned long hybridswap_eswap_create(struct mem_cgroup *mcg,
+ int *eswapid,
+ struct hybridswap_buffer *buf,
+ void **private)
+{
+ struct io_eswapent *io_eswap = NULL;
+ int reclaim_size;
+
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ return 0;
+ }
+ if (!eswapid) {
+ hybp(HYB_ERR, "NULL eswapid\n");
+ return 0;
+ }
+ (*eswapid) = -EINVAL;
+ if (!buf) {
+ hybp(HYB_ERR, "NULL buf\n");
+ return 0;
+ }
+ if (!private) {
+ hybp(HYB_ERR, "NULL private\n");
+ return 0;
+ }
+
+ io_eswap = alloc_io_eswapent(buf->pool, false, true);
+ if (!io_eswap)
+ return 0;
+ io_eswap->mcg = mcg;
+ reclaim_size = shrink_entry_list(io_eswap);
+ if (reclaim_size < 0) {
+ discard_io_eswapent(io_eswap, REQ_OP_WRITE);
+ (*eswapid) = reclaim_size;
+ return 0;
+ }
+ io_eswap->real_load = reclaim_size;
+ css_get(&mcg->css);
+ (*eswapid) = io_eswap->eswapid;
+ buf->dest_pages = io_eswap->pages;
+ (*private) = io_eswap;
+ hybp(HYB_DEBUG, "mcg = %d, eswapid = %d\n", mcg->id.id, io_eswap->eswapid);
+
+ return reclaim_size;
+}
+
+void hybridswap_eswap_register(void *private, struct hybridswap_io_req *req)
+{
+ struct io_eswapent *io_eswap = private;
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ return;
+ }
+ hybp(HYB_DEBUG, "eswapid = %d\n", io_eswap->eswapid);
+ atomic64_add(eswap_unlock(io_eswap), &req->real_load);
+}
+
+void hybridswap_eswap_objs_del(struct zram *zram, u32 index)
+{
+ int eswapid;
+ struct mem_cgroup *mcg = NULL;
+ unsigned long eswpentry;
+ int size;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+ if (!zram || !zram->infos) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+ if (!zram_test_flag(zram, index, ZRAM_WB)) {
+ hybp(HYB_ERR, "not WB object\n");
+ return;
+ }
+
+ eswpentry = zram_get_handle(zram, index);
+ size = zram_get_obj_size(zram, index);
+ atomic64_sub(size, &stat->stored_size);
+ atomic64_dec(&stat->stored_pages);
+ atomic64_add(size, &stat->dropped_eswap_size);
+ mcg = zram_fetch_mcg(zram, index);
+ if (mcg) {
+ atomic64_sub(size, &MEMCGRP_ITEM(mcg, hybridswap_stored_size));
+ atomic64_dec(&MEMCGRP_ITEM(mcg, hybridswap_stored_pages));
+ }
+
+ zram_clear_flag(zram, index, ZRAM_IN_BD);
+ if (!atomic_dec_and_test(
+ &zram->infos->eswap_stored_pages[esentry_extid(eswpentry)]))
+ return;
+ eswapid = fetch_eswap(zram->infos, esentry_extid(eswpentry));
+ if (eswapid < 0)
+ return;
+
+ atomic64_inc(&stat->notify_free);
+ if (mcg)
+ atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_eswap_notify_free));
+ hybp(HYB_DEBUG, "free eswapid = %d\n", eswapid);
+ hybridswap_free_eswap(zram->infos, eswapid);
+}
+
+int hybridswap_find_eswap_by_index(unsigned long eswpentry,
+ struct hybridswap_buffer *buf,
+ void **private)
+{
+ int eswapid;
+ struct io_eswapent *io_eswap = NULL;
+ struct zram *zram = NULL;
+
+ if (!buf) {
+ hybp(HYB_ERR, "NULL buf\n");
+ return -EINVAL;
+ }
+ if (!private) {
+ hybp(HYB_ERR, "NULL private\n");
+ return -EINVAL;
+ }
+
+ zram = buf->zram;
+ eswapid = fetch_eswap(zram->infos, esentry_extid(eswpentry));
+ if (eswapid < 0)
+ return eswapid;
+ io_eswap = alloc_io_eswapent(buf->pool, true, true);
+ if (!io_eswap) {
+ hybp(HYB_ERR, "io_eswap alloc failed\n");
+ put_eswap(zram->infos, eswapid);
+ return -ENOMEM;
+ }
+
+ io_eswap->eswapid = eswapid;
+ io_eswap->zram = zram;
+ io_eswap->mcg = find_memcg_by_id(
+ hyb_entries_fetch_memcgid(eswap_index(zram->infos, eswapid),
+ zram->infos->eswap_table));
+ if (io_eswap->mcg)
+ css_get(&io_eswap->mcg->css);
+ buf->dest_pages = io_eswap->pages;
+ (*private) = io_eswap;
+ hybp(HYB_DEBUG, "fetch entry = %lx eswap = %d\n", eswpentry, eswapid);
+
+ return eswapid;
+}
+
+int hybridswap_find_eswap_by_memcg(struct mem_cgroup *mcg,
+ struct hybridswap_buffer *buf,
+ void **private)
+{
+ int eswapid;
+ struct io_eswapent *io_eswap = NULL;
+
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ return -EINVAL;
+ }
+ if (!buf) {
+ hybp(HYB_ERR, "NULL buf\n");
+ return -EINVAL;
+ }
+ if (!private) {
+ hybp(HYB_ERR, "NULL private\n");
+ return -EINVAL;
+ }
+
+ eswapid = fetch_memcg_eswap(MEMCGRP_ITEM(mcg, zram)->infos, mcg);
+ if (eswapid < 0)
+ return eswapid;
+ io_eswap = alloc_io_eswapent(buf->pool, true, false);
+ if (!io_eswap) {
+ hybp(HYB_ERR, "io_eswap alloc failed\n");
+ put_eswap(MEMCGRP_ITEM(mcg, zram)->infos, eswapid);
+ return -ENOMEM;
+ }
+ io_eswap->eswapid = eswapid;
+ io_eswap->mcg = mcg;
+ css_get(&mcg->css);
+ buf->dest_pages = io_eswap->pages;
+ (*private) = io_eswap;
+ hybp(HYB_DEBUG, "fetch mcg = %d, eswap = %d\n", mcg->id.id, eswapid);
+
+ return eswapid;
+}
+
+void hybridswap_eswap_destroy(void *private, enum hybridswap_class class)
+{
+ struct io_eswapent *io_eswap = private;
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ return;
+ }
+
+ hybp(HYB_DEBUG, "eswapid = %d\n", io_eswap->eswapid);
+ eswap_add(io_eswap, class);
+}
+
+void hybridswap_eswap_exception(enum hybridswap_class class,
+ void *private)
+{
+ struct io_eswapent *io_eswap = private;
+ struct mem_cgroup *mcg = NULL;
+ unsigned int op = (class == HYB_RECLAIM_IN) ?
+ REQ_OP_WRITE : REQ_OP_READ;
+
+ if (!io_eswap) {
+ hybp(HYB_ERR, "NULL io_eswap\n");
+ return;
+ }
+
+ hybp(HYB_DEBUG, "eswapid = %d, op = %d\n", io_eswap->eswapid, op);
+ mcg = io_eswap->mcg;
+ discard_io_eswapent(io_eswap, op);
+ if (mcg)
+ css_put(&mcg->css);
+}
+
+struct mem_cgroup *hybridswap_zram_fetch_mcg(struct zram *zram, u32 index)
+{
+ return zram_fetch_mcg(zram, index);
+}
+
+void zram_set_mcg(struct zram *zram, u32 index, int memcgid)
+{
+ hyb_entries_set_memcgid(obj_index(zram->infos, index),
+ zram->infos->objects, memcgid);
+}
+
+struct mem_cgroup *zram_fetch_mcg(struct zram *zram, u32 index)
+{
+ unsigned short memcgid;
+
+ memcgid = hyb_entries_fetch_memcgid(obj_index(zram->infos, index),
+ zram->infos->objects);
+
+ return find_memcg_by_id(memcgid);
+}
+
+int zram_fetch_mcg_last_index(struct hyb_info *infos,
+ struct mem_cgroup *mcg,
+ int *index, int max_cnt)
+{
+ int cnt = 0;
+ u32 i, tmp;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return 0;
+ }
+ if (!infos->objects) {
+ hybp(HYB_ERR, "NULL table\n");
+ return 0;
+ }
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ return 0;
+ }
+ if (!index) {
+ hybp(HYB_ERR, "NULL index\n");
+ return 0;
+ }
+
+ hyb_lock_with_idx(memcgindex(infos, mcg->id.id), infos->objects);
+ hyb_entries_for_each_entry_reverse_safe(i, tmp,
+ memcgindex(infos, mcg->id.id), infos->objects) {
+ if (i >= (u32)infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", i);
+ continue;
+ }
+ index[cnt++] = i;
+ if (cnt >= max_cnt)
+ break;
+ }
+ hyb_unlock_with_idx(memcgindex(infos, mcg->id.id), infos->objects);
+
+ return cnt;
+}
+
+int swap_maps_fetch_eswap_index(struct hyb_info *infos,
+ int eswapid, int *index)
+{
+ int cnt = 0;
+ u32 i;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return 0;
+ }
+ if (!infos->objects) {
+ hybp(HYB_ERR, "NULL table\n");
+ return 0;
+ }
+ if (!index) {
+ hybp(HYB_ERR, "NULL index\n");
+ return 0;
+ }
+ if (eswapid < 0 || eswapid >= infos->nr_es) {
+ hybp(HYB_ERR, "eswap = %d invalid\n", eswapid);
+ return 0;
+ }
+
+ hyb_lock_with_idx(eswap_index(infos, eswapid), infos->objects);
+ hyb_entries_for_each_entry(i, eswap_index(infos, eswapid), infos->objects) {
+ if (cnt >= (int)ESWAP_MAX_OBJ_CNT) {
+ WARN_ON_ONCE(1);
+ break;
+ }
+ index[cnt++] = i;
+ }
+ hyb_unlock_with_idx(eswap_index(infos, eswapid), infos->objects);
+
+ return cnt;
+}
+
+void swap_sorted_list_add(struct zram *zram, u32 index, struct mem_cgroup *memcg)
+{
+ unsigned long size;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+ if (zram_test_flag(zram, index, ZRAM_WB)) {
+ hybp(HYB_ERR, "WB object, index = %d\n", index);
+ return;
+ }
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ if (zram_test_flag(zram, index, ZRAM_CACHED)) {
+ hybp(HYB_ERR, "CACHED object, index = %d\n", index);
+ return;
+ }
+ if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) {
+ hybp(HYB_ERR, "CACHED_COMPRESS object, index = %d\n", index);
+ return;
+ }
+#endif
+ if (zram_test_flag(zram, index, ZRAM_SAME))
+ return;
+
+ zram_set_mcg(zram, index, memcg->id.id);
+ hyb_entries_add(obj_index(zram->infos, index),
+ memcgindex(zram->infos, memcg->id.id),
+ zram->infos->objects);
+
+ size = zram_get_obj_size(zram, index);
+
+ atomic64_add(size, &MEMCGRP_ITEM(memcg, zram_stored_size));
+ atomic64_inc(&MEMCGRP_ITEM(memcg, zram_page_size));
+ atomic64_add(size, &stat->zram_stored_size);
+ atomic64_inc(&stat->zram_stored_pages);
+}
+
+void swap_sorted_list_add_tail(struct zram *zram, u32 index, struct mem_cgroup *mcg)
+{
+ unsigned long size;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (!mcg || !MEMCGRP_ITEM(mcg, zram) || !MEMCGRP_ITEM(mcg, zram)->infos) {
+ hybp(HYB_ERR, "invalid mcg\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+ if (zram_test_flag(zram, index, ZRAM_WB)) {
+ hybp(HYB_ERR, "WB object, index = %d\n", index);
+ return;
+ }
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ if (zram_test_flag(zram, index, ZRAM_CACHED)) {
+ hybp(HYB_ERR, "CACHED object, index = %d\n", index);
+ return;
+ }
+ if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) {
+ hybp(HYB_ERR, "CACHED_COMPRESS object, index = %d\n", index);
+ return;
+ }
+#endif
+ if (zram_test_flag(zram, index, ZRAM_SAME))
+ return;
+
+ zram_set_mcg(zram, index, mcg->id.id);
+ hyb_entries_add_tail(obj_index(zram->infos, index),
+ memcgindex(zram->infos, mcg->id.id),
+ zram->infos->objects);
+
+ size = zram_get_obj_size(zram, index);
+
+ atomic64_add(size, &MEMCGRP_ITEM(mcg, zram_stored_size));
+ atomic64_inc(&MEMCGRP_ITEM(mcg, zram_page_size));
+ atomic64_add(size, &stat->zram_stored_size);
+ atomic64_inc(&stat->zram_stored_pages);
+}
+
+void swap_sorted_list_del(struct zram *zram, u32 index)
+{
+ struct mem_cgroup *mcg = NULL;
+ unsigned long size;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+ if (!zram || !zram->infos) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+ if (zram_test_flag(zram, index, ZRAM_WB)) {
+ hybp(HYB_ERR, "WB object, index = %d\n", index);
+ return;
+ }
+
+ mcg = zram_fetch_mcg(zram, index);
+ if (!mcg || !MEMCGRP_ITEM(mcg, zram) || !MEMCGRP_ITEM(mcg, zram)->infos)
+ return;
+ if (zram_test_flag(zram, index, ZRAM_SAME))
+ return;
+
+ size = zram_get_obj_size(zram, index);
+ hyb_entries_del(obj_index(zram->infos, index),
+ memcgindex(zram->infos, mcg->id.id),
+ zram->infos->objects);
+ zram_set_mcg(zram, index, 0);
+
+ atomic64_sub(size, &MEMCGRP_ITEM(mcg, zram_stored_size));
+ atomic64_dec(&MEMCGRP_ITEM(mcg, zram_page_size));
+ atomic64_sub(size, &stat->zram_stored_size);
+ atomic64_dec(&stat->zram_stored_pages);
+}
+
+void swap_maps_insert(struct zram *zram, u32 index)
+{
+ unsigned long eswpentry;
+ u32 eswapid;
+
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+
+ eswpentry = zram_get_handle(zram, index);
+ eswapid = esentry_extid(eswpentry);
+ hyb_entries_add_tail(obj_index(zram->infos, index),
+ eswap_index(zram->infos, eswapid),
+ zram->infos->objects);
+}
+
+void swap_maps_destroy(struct zram *zram, u32 index)
+{
+ unsigned long eswpentry;
+ u32 eswapid;
+
+ if (!zram) {
+ hybp(HYB_ERR, "NULL zram\n");
+ return;
+ }
+ if (index >= (u32)zram->infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return;
+ }
+
+ eswpentry = zram_get_handle(zram, index);
+ eswapid = esentry_extid(eswpentry);
+ hyb_entries_del(obj_index(zram->infos, index),
+ eswap_index(zram->infos, eswapid),
+ zram->infos->objects);
+}
+
+static struct hyb_entries_head *fetch_node_default(int index, void *private)
+{
+ struct hyb_entries_head *table = private;
+
+ return &table[index];
+}
+
+struct hyb_entries_table *alloc_table(struct hyb_entries_head *(*fetch_node)(int, void *),
+ void *private, gfp_t gfp)
+{
+ struct hyb_entries_table *table =
+ kmalloc(sizeof(struct hyb_entries_table), gfp);
+
+ if (!table)
+ return NULL;
+ table->fetch_node = fetch_node ? fetch_node : fetch_node_default;
+ table->private = private;
+
+ return table;
+}
+
+void hyb_lock_with_idx(int index, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pK\n", index, table);
+ return;
+ }
+ bit_spin_lock(ENTRY_LOCK_BIT, (unsigned long *)node);
+}
+
+void hyb_unlock_with_idx(int index, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pK\n", index, table);
+ return;
+ }
+ bit_spin_unlock(ENTRY_LOCK_BIT, (unsigned long *)node);
+}
+
+bool hyb_entries_empty(int hindex, struct hyb_entries_table *table)
+{
+ bool ret = false;
+
+ hyb_lock_with_idx(hindex, table);
+ ret = (prev_index(hindex, table) == hindex) && (next_index(hindex, table) == hindex);
+ hyb_unlock_with_idx(hindex, table);
+
+ return ret;
+}
+
+void hyb_entries_init(int index, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pS func %pS\n",
+ index, table, table->fetch_node);
+ return;
+ }
+ memset(node, 0, sizeof(struct hyb_entries_head));
+ node->prev = index;
+ node->next = index;
+}
+
+void hyb_entries_add_nolock(int index, int hindex, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = NULL;
+ struct hyb_entries_head *head = NULL;
+ struct hyb_entries_head *next = NULL;
+ int nindex;
+
+ node = index_node(index, table);
+ if (!node) {
+ hybp(HYB_ERR,
+ "NULL node, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+ head = index_node(hindex, table);
+ if (!head) {
+ hybp(HYB_ERR,
+ "NULL head, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+ next = index_node(head->next, table);
+ if (!next) {
+ hybp(HYB_ERR,
+ "NULL next, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+
+ nindex = head->next;
+ if (index != hindex)
+ hyb_lock_with_idx(index, table);
+ node->prev = hindex;
+ node->next = nindex;
+ if (index != hindex)
+ hyb_unlock_with_idx(index, table);
+ head->next = index;
+ if (nindex != hindex)
+ hyb_lock_with_idx(nindex, table);
+ next->prev = index;
+ if (nindex != hindex)
+ hyb_unlock_with_idx(nindex, table);
+}
+
+void hyb_entries_add_tail_nolock(int index, int hindex, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = NULL;
+ struct hyb_entries_head *head = NULL;
+ struct hyb_entries_head *tail = NULL;
+ int tindex;
+
+ node = index_node(index, table);
+ if (!node) {
+ hybp(HYB_ERR,
+ "NULL node, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+ head = index_node(hindex, table);
+ if (!head) {
+ hybp(HYB_ERR,
+ "NULL head, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+ tail = index_node(head->prev, table);
+ if (!tail) {
+ hybp(HYB_ERR,
+ "NULL tail, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+
+ tindex = head->prev;
+ if (index != hindex)
+ hyb_lock_with_idx(index, table);
+ node->prev = tindex;
+ node->next = hindex;
+ if (index != hindex)
+ hyb_unlock_with_idx(index, table);
+ head->prev = index;
+ if (tindex != hindex)
+ hyb_lock_with_idx(tindex, table);
+ tail->next = index;
+ if (tindex != hindex)
+ hyb_unlock_with_idx(tindex, table);
+}
+
+void hyb_entries_del_nolock(int index, int hindex, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = NULL;
+ struct hyb_entries_head *prev = NULL;
+ struct hyb_entries_head *next = NULL;
+ int pindex, nindex;
+
+ node = index_node(index, table);
+ if (!node) {
+ hybp(HYB_ERR,
+ "NULL node, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+ prev = index_node(node->prev, table);
+ if (!prev) {
+ hybp(HYB_ERR,
+ "NULL prev, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+ next = index_node(node->next, table);
+ if (!next) {
+ hybp(HYB_ERR,
+ "NULL next, index = %d, hindex = %d, table = %pK\n",
+ index, hindex, table);
+ return;
+ }
+
+ if (index != hindex)
+ hyb_lock_with_idx(index, table);
+ pindex = node->prev;
+ nindex = node->next;
+ node->prev = index;
+ node->next = index;
+ if (index != hindex)
+ hyb_unlock_with_idx(index, table);
+ if (pindex != hindex)
+ hyb_lock_with_idx(pindex, table);
+ prev->next = nindex;
+ if (pindex != hindex)
+ hyb_unlock_with_idx(pindex, table);
+ if (nindex != hindex)
+ hyb_lock_with_idx(nindex, table);
+ next->prev = pindex;
+ if (nindex != hindex)
+ hyb_unlock_with_idx(nindex, table);
+}
+
+void hyb_entries_add(int index, int hindex, struct hyb_entries_table *table)
+{
+ hyb_lock_with_idx(hindex, table);
+ hyb_entries_add_nolock(index, hindex, table);
+ hyb_unlock_with_idx(hindex, table);
+}
+
+void hyb_entries_add_tail(int index, int hindex, struct hyb_entries_table *table)
+{
+ hyb_lock_with_idx(hindex, table);
+ hyb_entries_add_tail_nolock(index, hindex, table);
+ hyb_unlock_with_idx(hindex, table);
+}
+
+void hyb_entries_del(int index, int hindex, struct hyb_entries_table *table)
+{
+ hyb_lock_with_idx(hindex, table);
+ hyb_entries_del_nolock(index, hindex, table);
+ hyb_unlock_with_idx(hindex, table);
+}
+
+unsigned short hyb_entries_fetch_memcgid(int index, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+ int memcgid;
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pK\n", index, table);
+ return 0;
+ }
+
+ hyb_lock_with_idx(index, table);
+ memcgid = (node->mcg_left << ENTRY_MCG_SHIFT_HALF) | node->mcg_right;
+ hyb_unlock_with_idx(index, table);
+
+ return memcgid;
+}
+
+void hyb_entries_set_memcgid(int index, struct hyb_entries_table *table, int memcgid)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pK, mcg = %d\n",
+ index, table, memcgid);
+ return;
+ }
+
+ hyb_lock_with_idx(index, table);
+ node->mcg_left = (u32)memcgid >> ENTRY_MCG_SHIFT_HALF;
+ node->mcg_right = (u32)memcgid & ((1 << ENTRY_MCG_SHIFT_HALF) - 1);
+ hyb_unlock_with_idx(index, table);
+}
+
+bool hyb_entries_set_priv(int index, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+ bool ret = false;
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pK\n", index, table);
+ return false;
+ }
+ hyb_lock_with_idx(index, table);
+ ret = !test_and_set_bit(ENTRY_DATA_BIT, (unsigned long *)node);
+ hyb_unlock_with_idx(index, table);
+
+ return ret;
+}
+
+bool hyb_entries_test_priv(int index, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+ bool ret = false;
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pK\n", index, table);
+ return false;
+ }
+ hyb_lock_with_idx(index, table);
+ ret = test_bit(ENTRY_DATA_BIT, (unsigned long *)node);
+ hyb_unlock_with_idx(index, table);
+
+ return ret;
+}
+
+bool hyb_entries_clear_priv(int index, struct hyb_entries_table *table)
+{
+ struct hyb_entries_head *node = index_node(index, table);
+ bool ret = false;
+
+ if (!node) {
+ hybp(HYB_ERR, "index = %d, table = %pK\n", index, table);
+ return false;
+ }
+
+ hyb_lock_with_idx(index, table);
+ ret = test_and_clear_bit(ENTRY_DATA_BIT, (unsigned long *)node);
+ hyb_unlock_with_idx(index, table);
+
+ return ret;
+}
+
+struct mem_cgroup *find_memcg_by_id(unsigned short memcgid)
+{
+ struct mem_cgroup *mcg = NULL;
+
+ rcu_read_lock();
+ mcg = mem_cgroup_from_id(memcgid);
+ rcu_read_unlock();
+
+ return mcg;
+}
+
+static bool frag_info_dec(bool prev_flag, bool next_flag,
+ struct hybstatus *stat)
+{
+ if (prev_flag && next_flag) {
+ atomic64_inc(&stat->frag_cnt);
+ return false;
+ }
+
+ if (prev_flag || next_flag)
+ return false;
+
+ return true;
+}
+
+static bool frag_info_inc(bool prev_flag, bool next_flag,
+ struct hybstatus *stat)
+{
+ if (prev_flag && next_flag) {
+ atomic64_dec(&stat->frag_cnt);
+ return false;
+ }
+
+ if (prev_flag || next_flag)
+ return false;
+
+ return true;
+}
+
+static bool pre_is_conted(struct hyb_info *infos, int eswapid, int memcgid)
+{
+ int prev;
+
+ if (is_first_index(eswap_index(infos, eswapid), memcgindex(infos, memcgid),
+ infos->eswap_table))
+ return false;
+ prev = prev_index(eswap_index(infos, eswapid), infos->eswap_table);
+
+ return (prev >= 0) && (eswap_index(infos, eswapid) == prev + 1);
+}
+
+static bool ne_is_conted(struct hyb_info *infos, int eswapid, int memcgid)
+{
+ int next;
+
+ if (is_last_index(eswap_index(infos, eswapid), memcgindex(infos, memcgid),
+ infos->eswap_table))
+ return false;
+ next = next_index(eswap_index(infos, eswapid), infos->eswap_table);
+
+ return (next >= 0) && (eswap_index(infos, eswapid) + 1 == next);
+}
+
+static void eswap_frag_info_sub(struct hyb_info *infos, int eswapid)
+{
+ bool prev_flag = false;
+ bool next_flag = false;
+ int memcgid;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+
+ if (!infos->eswap_table) {
+ hybp(HYB_ERR, "NULL table\n");
+ return;
+ }
+ if (eswapid < 0 || eswapid >= infos->nr_es) {
+ hybp(HYB_ERR, "eswap = %d invalid\n", eswapid);
+ return;
+ }
+
+ memcgid = hyb_entries_fetch_memcgid(eswap_index(infos, eswapid), infos->eswap_table);
+ if (memcgid <= 0 || memcgid >= infos->memcg_num) {
+ hybp(HYB_ERR, "memcgid = %d invalid\n", memcgid);
+ return;
+ }
+
+ atomic64_dec(&stat->eswap_cnt);
+ infos->memcgid_cnt[memcgid]--;
+ if (infos->memcgid_cnt[memcgid] == 0) {
+ atomic64_dec(&stat->mcg_cnt);
+ atomic64_dec(&stat->frag_cnt);
+ return;
+ }
+
+ prev_flag = pre_is_conted(infos, eswapid, memcgid);
+ next_flag = ne_is_conted(infos, eswapid, memcgid);
+
+ if (frag_info_dec(prev_flag, next_flag, stat))
+ atomic64_dec(&stat->frag_cnt);
+}
+
+static void eswap_frag_info_add(struct hyb_info *infos, int eswapid)
+{
+ bool prev_flag = false;
+ bool next_flag = false;
+ int memcgid;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat) {
+ hybp(HYB_ERR, "NULL stat\n");
+ return;
+ }
+
+ if (!infos->eswap_table) {
+ hybp(HYB_ERR, "NULL table\n");
+ return;
+ }
+ if (eswapid < 0 || eswapid >= infos->nr_es) {
+ hybp(HYB_ERR, "eswap = %d invalid\n", eswapid);
+ return;
+ }
+
+ memcgid = hyb_entries_fetch_memcgid(eswap_index(infos, eswapid), infos->eswap_table);
+ if (memcgid <= 0 || memcgid >= infos->memcg_num) {
+ hybp(HYB_ERR, "memcgid = %d invalid\n", memcgid);
+ return;
+ }
+
+ atomic64_inc(&stat->eswap_cnt);
+ if (infos->memcgid_cnt[memcgid] == 0) {
+ infos->memcgid_cnt[memcgid]++;
+ atomic64_inc(&stat->frag_cnt);
+ atomic64_inc(&stat->mcg_cnt);
+ return;
+ }
+ infos->memcgid_cnt[memcgid]++;
+
+ prev_flag = pre_is_conted(infos, eswapid, memcgid);
+ next_flag = ne_is_conted(infos, eswapid, memcgid);
+
+ if (frag_info_inc(prev_flag, next_flag, stat))
+ atomic64_inc(&stat->frag_cnt);
+}
+
+static int eswap_bit2id(struct hyb_info *infos, int bit)
+{
+ if (bit < 0 || bit >= infos->nr_es) {
+ hybp(HYB_ERR, "bit = %d invalid\n", bit);
+ return -EINVAL;
+ }
+
+ return infos->nr_es - bit - 1;
+}
+
+static int eswap_id2bit(struct hyb_info *infos, int id)
+{
+ if (id < 0 || id >= infos->nr_es) {
+ hybp(HYB_ERR, "id = %d invalid\n", id);
+ return -EINVAL;
+ }
+
+ return infos->nr_es - id - 1;
+}
+
+int obj_index(struct hyb_info *infos, int index)
+{
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (index < 0 || index >= infos->total_objects) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return -EINVAL;
+ }
+
+ return index;
+}
+
+int eswap_index(struct hyb_info *infos, int index)
+{
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (index < 0 || index >= infos->nr_es) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return -EINVAL;
+ }
+
+ return index + infos->total_objects;
+}
+
+int memcgindex(struct hyb_info *infos, int index)
+{
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (index <= 0 || index >= infos->memcg_num) {
+ hybp(HYB_ERR, "index = %d invalid, memcg_num %d\n", index,
+ infos->memcg_num);
+ return -EINVAL;
+ }
+
+ return index + infos->total_objects + infos->nr_es;
+}
+
+static struct hyb_entries_head *fetch_objects_node(int index, void *private)
+{
+ struct hyb_info *infos = private;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return NULL;
+ }
+ if (index < 0) {
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+ return NULL;
+ }
+ if (index < infos->total_objects)
+ return &infos->lru[index];
+ index -= infos->total_objects;
+ if (index < infos->nr_es)
+ return &infos->maps[index];
+ index -= infos->nr_es;
+ if (index > 0 && index < infos->memcg_num) {
+ struct mem_cgroup *mcg = find_memcg_by_id(index);
+
+ if (!mcg)
+ goto err_out;
+ return (struct hyb_entries_head *)(&MEMCGRP_ITEM(mcg, swap_sorted_list));
+ }
+err_out:
+ hybp(HYB_ERR, "index = %d invalid, mcg is NULL\n", index);
+
+ return NULL;
+}
+
+static void free_obj_list_table(struct hyb_info *infos)
+{
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return;
+ }
+
+ if (infos->lru) {
+ vfree(infos->lru);
+ infos->lru = NULL;
+ }
+ if (infos->maps) {
+ vfree(infos->maps);
+ infos->maps = NULL;
+ }
+
+ kfree(infos->objects);
+ infos->objects = NULL;
+}
+
+static int init_obj_list_table(struct hyb_info *infos)
+{
+ int i;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+
+ infos->lru = vzalloc(sizeof(struct hyb_entries_head) * infos->total_objects);
+ if (!infos->lru) {
+ hybp(HYB_ERR, "infos->lru alloc failed\n");
+ goto err_out;
+ }
+ infos->maps = vzalloc(sizeof(struct hyb_entries_head) * infos->nr_es);
+ if (!infos->maps) {
+ hybp(HYB_ERR, "infos->maps alloc failed\n");
+ goto err_out;
+ }
+ infos->objects = alloc_table(fetch_objects_node, infos, GFP_KERNEL);
+ if (!infos->objects) {
+ hybp(HYB_ERR, "infos->objects alloc failed\n");
+ goto err_out;
+ }
+ for (i = 0; i < infos->total_objects; i++)
+ hyb_entries_init(obj_index(infos, i), infos->objects);
+ for (i = 0; i < infos->nr_es; i++)
+ hyb_entries_init(eswap_index(infos, i), infos->objects);
+
+ hybp(HYB_INFO, "hybridswap obj list table init OK.\n");
+ return 0;
+err_out:
+ free_obj_list_table(infos);
+ hybp(HYB_ERR, "hybridswap obj list table init failed.\n");
+
+ return -ENOMEM;
+}
+
+static struct hyb_entries_head *fetch_eswap_table_node(int index, void *private)
+{
+ struct hyb_info *infos = private;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return NULL;
+ }
+
+ if (index < infos->total_objects)
+ goto err_out;
+ index -= infos->total_objects;
+ if (index < infos->nr_es)
+ return &infos->eswap[index];
+ index -= infos->nr_es;
+ if (index > 0 && index < infos->memcg_num) {
+ struct mem_cgroup *mcg = find_memcg_by_id(index);
+
+ if (!mcg)
+ return NULL;
+ return (struct hyb_entries_head *)(&MEMCGRP_ITEM(mcg, eswap_lru));
+ }
+err_out:
+ hybp(HYB_ERR, "index = %d invalid\n", index);
+
+ return NULL;
+}
+
+static void free_eswap_list_table(struct hyb_info *infos)
+{
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return;
+ }
+
+ if (infos->eswap)
+ vfree(infos->eswap);
+
+ kfree(infos->eswap_table);
+}
+
+static int init_eswap_list_table(struct hyb_info *infos)
+{
+ int i;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ infos->eswap = vzalloc(sizeof(struct hyb_entries_head) * infos->nr_es);
+ if (!infos->eswap)
+ goto err_out;
+ infos->eswap_table = alloc_table(fetch_eswap_table_node, infos, GFP_KERNEL);
+ if (!infos->eswap_table)
+ goto err_out;
+ for (i = 0; i < infos->nr_es; i++)
+ hyb_entries_init(eswap_index(infos, i), infos->eswap_table);
+ hybp(HYB_INFO, "hybridswap eswap list table init OK.\n");
+ return 0;
+err_out:
+ free_eswap_list_table(infos);
+ hybp(HYB_ERR, "hybridswap eswap list table init failed.\n");
+
+ return -ENOMEM;
+}
+
+void free_hyb_info(struct hyb_info *infos)
+{
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return;
+ }
+
+ vfree(infos->bitmask);
+ vfree(infos->eswap_stored_pages);
+ free_obj_list_table(infos);
+ free_eswap_list_table(infos);
+ vfree(infos);
+}
+
+struct hyb_info *alloc_hyb_info(unsigned long ori_size,
+ unsigned long comp_size)
+{
+ struct hyb_info *infos = vzalloc(sizeof(struct hyb_info));
+
+ if (!infos) {
+ hybp(HYB_ERR, "infos alloc failed\n");
+ goto err_out;
+ }
+ if (comp_size & (ESWAP_SIZE - 1)) {
+ hybp(HYB_ERR, "disksize = %ld align invalid (32K align needed)\n",
+ comp_size);
+ goto err_out;
+ }
+ infos->size = comp_size;
+ infos->nr_es = comp_size >> ESWAP_SHIFT;
+ infos->memcg_num = MEM_CGROUP_ID_MAX;
+ infos->total_objects = ori_size >> PAGE_SHIFT;
+ infos->bitmask = vzalloc(BITS_TO_LONGS(infos->nr_es) * sizeof(long));
+ if (!infos->bitmask) {
+ hybp(HYB_ERR, "infos->bitmask alloc failed, %lu\n",
+ BITS_TO_LONGS(infos->nr_es) * sizeof(long));
+ goto err_out;
+ }
+ infos->eswap_stored_pages = vzalloc(sizeof(atomic_t) * infos->nr_es);
+ if (!infos->eswap_stored_pages) {
+ hybp(HYB_ERR, "infos->eswap_stored_pages alloc failed\n");
+ goto err_out;
+ }
+ if (init_obj_list_table(infos)) {
+ hybp(HYB_ERR, "init obj list table failed\n");
+ goto err_out;
+ }
+ if (init_eswap_list_table(infos)) {
+ hybp(HYB_ERR, "init eswap list table failed\n");
+ goto err_out;
+ }
+ hybp(HYB_INFO, "infos %p size %lu nr_es %lu memcg_num %lu total_objects %lu\n",
+ infos, infos->size, infos->nr_es, infos->memcg_num,
+ infos->total_objects);
+ hybp(HYB_INFO, "hyb_info init OK.\n");
+ return infos;
+err_out:
+ free_hyb_info(infos);
+ hybp(HYB_ERR, "hyb_info init failed.\n");
+
+ return NULL;
+}
+
+void hybridswap_check_infos_eswap(struct hyb_info *infos)
+{
+ int i;
+
+ if (!infos)
+ return;
+
+ for (i = 0; i < infos->nr_es; i++) {
+ int cnt = atomic_read(&infos->eswap_stored_pages[i]);
+ int eswapid = eswap_index(infos, i);
+ bool data = hyb_entries_test_priv(eswapid, infos->eswap_table);
+ int memcgid = hyb_entries_fetch_memcgid(eswapid, infos->eswap_table);
+
+ if (cnt < 0 || (cnt > 0 && memcgid == 0))
+ hybp(HYB_ERR, "%8d %8d %8d %8d %4d\n", i, cnt, eswapid,
+ memcgid, data);
+ }
+}
+
+void hybridswap_free_eswap(struct hyb_info *infos, int eswapid)
+{
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return;
+ }
+ if (eswapid < 0 || eswapid >= infos->nr_es) {
+ hybp(HYB_ERR, "INVALID eswap %d\n", eswapid);
+ return;
+ }
+ hybp(HYB_DEBUG, "free eswap id = %d.\n", eswapid);
+
+ hyb_entries_set_memcgid(eswap_index(infos, eswapid), infos->eswap_table, 0);
+ if (!test_and_clear_bit(eswap_id2bit(infos, eswapid), infos->bitmask)) {
+ hybp(HYB_ERR, "bit not set, eswap = %d\n", eswapid);
+ WARN_ON_ONCE(1);
+ }
+ atomic_dec(&infos->stored_exts);
+}
+
+static int alloc_bitmask(unsigned long *bitmask, int max, int last_bit)
+{
+ int bit;
+
+ if (!bitmask) {
+ hybp(HYB_ERR, "NULL bitmask.\n");
+ return -EINVAL;
+ }
+retry:
+ bit = find_next_zero_bit(bitmask, max, last_bit);
+ if (bit == max) {
+ if (last_bit == 0) {
+ hybp(HYB_ERR, "alloc bitmask failed.\n");
+ return -ENOSPC;
+ }
+ last_bit = 0;
+ goto retry;
+ }
+ if (test_and_set_bit(bit, bitmask))
+ goto retry;
+
+ return bit;
+}
+
+int hybridswap_alloc_eswap(struct hyb_info *infos, struct mem_cgroup *mcg)
+{
+ int last_bit;
+ int bit;
+ int eswapid;
+ int memcgid;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ return -EINVAL;
+ }
+
+ last_bit = atomic_read(&infos->last_alloc_bit);
+ hybp(HYB_DEBUG, "last_bit = %d.\n", last_bit);
+ bit = alloc_bitmask(infos->bitmask, infos->nr_es, last_bit);
+ if (bit < 0) {
+ hybp(HYB_ERR, "alloc bitmask failed.\n");
+ return bit;
+ }
+ eswapid = eswap_bit2id(infos, bit);
+ memcgid = hyb_entries_fetch_memcgid(eswap_index(infos, eswapid), infos->eswap_table);
+ if (memcgid) {
+ hybp(HYB_ERR, "already has mcg %d, eswap %d\n",
+ memcgid, eswapid);
+ goto err_out;
+ }
+ hyb_entries_set_memcgid(eswap_index(infos, eswapid), infos->eswap_table, mcg->id.id);
+
+ atomic_set(&infos->last_alloc_bit, bit);
+ atomic_inc(&infos->stored_exts);
+ hybp(HYB_DEBUG, "eswap %d init OK.\n", eswapid);
+ hybp(HYB_DEBUG, "memcgid = %d, eswap id = %d\n", mcg->id.id, eswapid);
+
+ return eswapid;
+err_out:
+ clear_bit(bit, infos->bitmask);
+ WARN_ON_ONCE(1);
+ return -EBUSY;
+}
+
+int fetch_eswap(struct hyb_info *infos, int eswapid)
+{
+ int memcgid;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (eswapid < 0 || eswapid >= infos->nr_es) {
+ hybp(HYB_ERR, "eswap = %d invalid\n", eswapid);
+ return -EINVAL;
+ }
+
+ if (!hyb_entries_clear_priv(eswap_index(infos, eswapid), infos->eswap_table))
+ return -EBUSY;
+ memcgid = hyb_entries_fetch_memcgid(eswap_index(infos, eswapid), infos->eswap_table);
+ if (memcgid) {
+ eswap_frag_info_sub(infos, eswapid);
+ hyb_entries_del(eswap_index(infos, eswapid), memcgindex(infos, memcgid),
+ infos->eswap_table);
+ }
+ hybp(HYB_DEBUG, "eswap id = %d\n", eswapid);
+
+ return eswapid;
+}
+
+void put_eswap(struct hyb_info *infos, int eswapid)
+{
+ int memcgid;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return;
+ }
+ if (eswapid < 0 || eswapid >= infos->nr_es) {
+ hybp(HYB_ERR, "eswap = %d invalid\n", eswapid);
+ return;
+ }
+
+ memcgid = hyb_entries_fetch_memcgid(eswap_index(infos, eswapid), infos->eswap_table);
+ if (memcgid) {
+ hyb_lock_with_idx(memcgindex(infos, memcgid), infos->eswap_table);
+ hyb_entries_add_nolock(eswap_index(infos, eswapid), memcgindex(infos, memcgid),
+ infos->eswap_table);
+ eswap_frag_info_add(infos, eswapid);
+ hyb_unlock_with_idx(memcgindex(infos, memcgid), infos->eswap_table);
+ }
+ if (!hyb_entries_set_priv(eswap_index(infos, eswapid), infos->eswap_table)) {
+ hybp(HYB_ERR, "private not set, eswap = %d\n", eswapid);
+ WARN_ON_ONCE(1);
+ return;
+ }
+ hybp(HYB_DEBUG, "put eswap %d.\n", eswapid);
+}
+
+int fetch_memcg_eswap(struct hyb_info *infos, struct mem_cgroup *mcg)
+{
+ int memcgid;
+ int eswapid = -ENOENT;
+ int index;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (!infos->eswap_table) {
+ hybp(HYB_ERR, "NULL table\n");
+ return -EINVAL;
+ }
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ return -EINVAL;
+ }
+
+ memcgid = mcg->id.id;
+ hyb_lock_with_idx(memcgindex(infos, memcgid), infos->eswap_table);
+ hyb_entries_for_each_entry(index, memcgindex(infos, memcgid), infos->eswap_table)
+ if (hyb_entries_clear_priv(index, infos->eswap_table)) {
+ eswapid = index - infos->total_objects;
+ break;
+ }
+ if (eswapid >= 0 && eswapid < infos->nr_es) {
+ eswap_frag_info_sub(infos, eswapid);
+ hyb_entries_del_nolock(index, memcgindex(infos, memcgid), infos->eswap_table);
+ hybp(HYB_DEBUG, "eswap id = %d\n", eswapid);
+ }
+ hyb_unlock_with_idx(memcgindex(infos, memcgid), infos->eswap_table);
+
+ return eswapid;
+}
+
+int fetch_memcg_zram_entry(struct hyb_info *infos, struct mem_cgroup *mcg)
+{
+ int memcgid, idx;
+ int index = -ENOENT;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (!infos->objects) {
+ hybp(HYB_ERR, "NULL table\n");
+ return -EINVAL;
+ }
+ if (!mcg) {
+ hybp(HYB_ERR, "NULL mcg\n");
+ return -EINVAL;
+ }
+
+ memcgid = mcg->id.id;
+ hyb_lock_with_idx(memcgindex(infos, memcgid), infos->objects);
+ hyb_entries_for_each_entry(idx, memcgindex(infos, memcgid), infos->objects) {
+ index = idx;
+ break;
+ }
+ hyb_unlock_with_idx(memcgindex(infos, memcgid), infos->objects);
+
+ return index;
+}
+
+int fetch_eswap_zram_entry(struct hyb_info *infos, int eswapid)
+{
+ int index = -ENOENT;
+ int idx;
+
+ if (!infos) {
+ hybp(HYB_ERR, "NULL infos\n");
+ return -EINVAL;
+ }
+ if (!infos->objects) {
+ hybp(HYB_ERR, "NULL table\n");
+ return -EINVAL;
+ }
+ if (eswapid < 0 || eswapid >= infos->nr_es) {
+ hybp(HYB_ERR, "eswap = %d invalid\n", eswapid);
+ return -EINVAL;
+ }
+
+ hyb_lock_with_idx(eswap_index(infos, eswapid), infos->objects);
+ hyb_entries_for_each_entry(idx, eswap_index(infos, eswapid), infos->objects) {
+ index = idx;
+ break;
+ }
+ hyb_unlock_with_idx(eswap_index(infos, eswapid), infos->objects);
+
+ return index;
+}
+
+void *hybridswap_malloc(size_t size, bool fast, bool nofail)
+{
+ void *mem = NULL;
+
+ if (likely(fast)) {
+ mem = kzalloc(size, GFP_ATOMIC);
+ if (likely(mem || !nofail))
+ return mem;
+ }
+
+ mem = kzalloc(size, GFP_NOIO);
+
+ return mem;
+}
+
+void hybridswap_free(const void *mem)
+{
+ kfree(mem);
+}
+
+struct page *hybridswap_alloc_page_common(void *data, gfp_t gfp)
+{
+ struct page *page = NULL;
+ struct zs_eswap_para *eswap_para = (struct zs_eswap_para *)data;
+
+ if (eswap_para->pool) {
+ spin_lock(&eswap_para->pool->page_pool_lock);
+ if (!list_empty(&eswap_para->pool->page_pool_list)) {
+ page = list_first_entry(
+ &eswap_para->pool->page_pool_list,
+ struct page, lru);
+ list_del(&page->lru);
+ }
+ spin_unlock(&eswap_para->pool->page_pool_lock);
+ }
+
+ if (!page) {
+ if (eswap_para->fast) {
+ page = alloc_page(GFP_ATOMIC);
+ if (likely(page))
+ goto out;
+ }
+ if (eswap_para->nofail)
+ page = alloc_page(GFP_NOIO);
+ else
+ page = alloc_page(gfp);
+ }
+out:
+ return page;
+}
+
+unsigned long hybridswap_zsmalloc(struct zs_pool *zs_pool,
+ size_t size, struct hybridswap_page_pool *pool)
+{
+ gfp_t gfp = __GFP_DIRECT_RECLAIM | __GFP_KSWAPD_RECLAIM |
+ __GFP_NOWARN | __GFP_HIGHMEM | __GFP_MOVABLE;
+ return zs_malloc(zs_pool, size, gfp);
+}
+
+unsigned long zram_zsmalloc(struct zs_pool *zs_pool, size_t size, gfp_t gfp)
+{
+ return zs_malloc(zs_pool, size, gfp);
+}
+
+struct page *hybridswap_alloc_page(struct hybridswap_page_pool *pool,
+ gfp_t gfp, bool fast, bool nofail)
+{
+ struct zs_eswap_para eswap_para;
+
+ eswap_para.pool = pool;
+ eswap_para.fast = fast;
+ eswap_para.nofail = nofail;
+
+ return hybridswap_alloc_page_common((void *)&eswap_para, gfp);
+}
+
+void hybridswap_page_recycle(struct page *page, struct hybridswap_page_pool *pool)
+{
+ if (pool) {
+ spin_lock(&pool->page_pool_lock);
+ list_add(&page->lru, &pool->page_pool_list);
+ spin_unlock(&pool->page_pool_lock);
+ } else {
+ __free_page(page);
+ }
+}
+
+bool hybridswap_out_to_eswap_enable(void)
+{
+ return !!atomic_read(&global_settings.out_to_eswap_enable);
+}
+
+void hybridswap_set_out_to_eswap_disable(void)
+{
+ atomic_set(&global_settings.out_to_eswap_enable, false);
+}
+
+void hybridswap_set_out_to_eswap_enable(bool en)
+{
+ atomic_set(&global_settings.out_to_eswap_enable, en ? 1 : 0);
+}
+
+bool hybridswap_core_enabled(void)
+{
+ return !!atomic_read(&global_settings.enable);
+}
+
+void hybridswap_set_enable(bool en)
+{
+ hybridswap_set_out_to_eswap_enable(en);
+
+ if (!hybridswap_core_enabled())
+ atomic_set(&global_settings.enable, en ? 1 : 0);
+}
+
+struct hybstatus *hybridswap_fetch_stat_obj(void)
+{
+ return global_settings.stat;
+}
+
+bool hybridswap_dev_life(void)
+{
+ return !!atomic_read(&global_settings.dev_life);
+}
+
+void hybridswap_set_dev_life(bool en)
+{
+ atomic_set(&global_settings.dev_life, en ? 1 : 0);
+}
+
+unsigned long hybridswap_quota_day(void)
+{
+ return global_settings.quota_day;
+}
+
+void hybridswap_set_quota_day(unsigned long val)
+{
+ global_settings.quota_day = val;
+}
+
+bool hybridswap_reach_life_protect(void)
+{
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+ unsigned long quota = hybridswap_quota_day();
+
+ if (hybridswap_dev_life())
+ quota /= 10;
+ return atomic64_read(&stat->reclaimin_bytes_daily) > quota;
+}
+
+static void hybridswap_life_protect_ctrl_work(struct work_struct *work)
+{
+ struct tm tm;
+ struct timespec64 ts;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ ktime_get_real_ts64(&ts);
+ time64_to_tm(ts.tv_sec - sys_tz.tz_minuteswest * 60, 0, &tm);
+
+ if (tm.tm_hour > 2)
+ atomic64_set(&stat->reclaimin_bytes_daily, 0);
+}
+
+static void hybridswap_life_protect_ctrl_timer(struct timer_list *t)
+{
+ schedule_work(&global_settings.lpc_work);
+ mod_timer(&global_settings.lpc_timer,
+ jiffies + HYBRIDSWAP_CHECK_GAP * HZ);
+}
+
+void hybridswap_close_bdev(struct block_device *bdev, struct file *backing_dev)
+{
+ if (bdev)
+ blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
+
+ if (backing_dev)
+ filp_close(backing_dev, NULL);
+}
+
+struct file *hybridswap_open_bdev(const char *file_name)
+{
+ struct file *backing_dev = NULL;
+
+ backing_dev = filp_open(file_name, O_RDWR|O_LARGEFILE, 0);
+ if (unlikely(IS_ERR(backing_dev))) {
+ hybp(HYB_ERR, "open the %s failed! eno = %lld\n",
+ file_name, PTR_ERR(backing_dev));
+ backing_dev = NULL;
+ return NULL;
+ }
+
+ if (unlikely(!S_ISBLK(backing_dev->f_mapping->host->i_mode))) {
+ hybp(HYB_ERR, "%s isn't a blk device\n", file_name);
+ hybridswap_close_bdev(NULL, backing_dev);
+ return NULL;
+ }
+
+ return backing_dev;
+}
+
+int hybridswap_bind(struct zram *zram, const char *file_name)
+{
+ struct file *backing_dev = NULL;
+ struct inode *inode = NULL;
+ unsigned long nr_pages;
+ struct block_device *bdev = NULL;
+ int err;
+
+ backing_dev = hybridswap_open_bdev(file_name);
+ if (unlikely(!backing_dev))
+ return -EINVAL;
+
+ inode = backing_dev->f_mapping->host;
+ bdev = blkdev_get_by_dev(inode->i_rdev,
+ FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram);
+ if (IS_ERR(bdev)) {
+ hybp(HYB_ERR, "%s blkdev_fetch failed!\n", file_name);
+ err = PTR_ERR(bdev);
+ bdev = NULL;
+ goto out;
+ }
+
+ nr_pages = (unsigned long)i_size_read(inode) >> PAGE_SHIFT;
+ err = set_blocksize(bdev, PAGE_SIZE);
+ if (unlikely(err)) {
+ hybp(HYB_ERR,
+ "%s set blocksize failed! eno = %d\n", file_name, err);
+ goto out;
+ }
+
+ zram->bdev = bdev;
+ zram->backing_dev = backing_dev;
+ zram->nr_pages = nr_pages;
+ return 0;
+
+out:
+ hybridswap_close_bdev(bdev, backing_dev);
+
+ return err;
+}
+
+static inline unsigned long fetch_original_used_swap(void)
+{
+ struct sysinfo val;
+
+ si_swapinfo(&val);
+
+ return val.totalswap - val.freeswap;
+}
+
+void hybstatus_init(struct hybstatus *stat)
+{
+ int i;
+
+ atomic64_set(&stat->reclaimin_cnt, 0);
+ atomic64_set(&stat->reclaimin_bytes, 0);
+ atomic64_set(&stat->reclaimin_real_load, 0);
+ atomic64_set(&stat->dropped_eswap_size, 0);
+ atomic64_set(&stat->reclaimin_bytes_daily, 0);
+ atomic64_set(&stat->reclaimin_pages, 0);
+ atomic64_set(&stat->reclaimin_infight, 0);
+ atomic64_set(&stat->batchout_cnt, 0);
+ atomic64_set(&stat->batchout_bytes, 0);
+ atomic64_set(&stat->batchout_real_load, 0);
+ atomic64_set(&stat->batchout_pages, 0);
+ atomic64_set(&stat->batchout_inflight, 0);
+ atomic64_set(&stat->fault_cnt, 0);
+ atomic64_set(&stat->hybridswap_fault_cnt, 0);
+ atomic64_set(&stat->reout_pages, 0);
+ atomic64_set(&stat->reout_bytes, 0);
+ atomic64_set(&stat->zram_stored_pages, 0);
+ atomic64_set(&stat->zram_stored_size, 0);
+ atomic64_set(&stat->stored_pages, 0);
+ atomic64_set(&stat->stored_size, 0);
+ atomic64_set(&stat->notify_free, 0);
+ atomic64_set(&stat->frag_cnt, 0);
+ atomic64_set(&stat->mcg_cnt, 0);
+ atomic64_set(&stat->eswap_cnt, 0);
+ atomic64_set(&stat->miss_free, 0);
+ atomic64_set(&stat->memcgid_clear, 0);
+ atomic64_set(&stat->skip_track_cnt, 0);
+ atomic64_set(&stat->null_memcg_skip_track_cnt, 0);
+ atomic64_set(&stat->used_swap_pages, fetch_original_used_swap());
+ atomic64_set(&stat->stored_wm_scale, DEFAULT_STORED_WM_RATIO);
+
+ for (i = 0; i < HYB_CLASS_BUTT; ++i) {
+ atomic64_set(&stat->io_fail_cnt[i], 0);
+ atomic64_set(&stat->alloc_fail_cnt[i], 0);
+ atomic64_set(&stat->lat[i].total_lat, 0);
+ atomic64_set(&stat->lat[i].max_lat, 0);
+ }
+
+ stat->record.num = 0;
+ spin_lock_init(&stat->record.lock);
+}
+
+static bool hybridswap_global_setting_init(struct zram *zram)
+{
+ if (unlikely(global_settings.stat))
+ return false;
+
+ global_settings.zram = zram;
+ hybridswap_set_enable(false);
+ global_settings.stat = hybridswap_malloc(
+ sizeof(struct hybstatus), false, true);
+ if (unlikely(!global_settings.stat)) {
+ hybp(HYB_ERR, "global stat allocation failed!\n");
+ return false;
+ }
+
+ hybstatus_init(global_settings.stat);
+ global_settings.reclaim_wq = alloc_workqueue("hybridswap_reclaim",
+ WQ_CPU_INTENSIVE, 0);
+ if (unlikely(!global_settings.reclaim_wq)) {
+ hybp(HYB_ERR, "reclaim workqueue allocation failed!\n");
+ hybridswap_free(global_settings.stat);
+ global_settings.stat = NULL;
+
+ return false;
+ }
+
+ global_settings.quota_day = HYBRIDSWAP_QUOTA_DAY;
+ INIT_WORK(&global_settings.lpc_work, hybridswap_life_protect_ctrl_work);
+ global_settings.lpc_timer.expires = jiffies + HYBRIDSWAP_CHECK_GAP * HZ;
+ timer_setup(&global_settings.lpc_timer, hybridswap_life_protect_ctrl_timer, 0);
+ add_timer(&global_settings.lpc_timer);
+
+ hybp(HYB_DEBUG, "global settings init success\n");
+ return true;
+}
+
+void hybridswap_global_setting_deinit(void)
+{
+ destroy_workqueue(global_settings.reclaim_wq);
+ hybridswap_free(global_settings.stat);
+ global_settings.stat = NULL;
+ global_settings.zram = NULL;
+ global_settings.reclaim_wq = NULL;
+}
+
+struct workqueue_struct *hybridswap_fetch_reclaim_workqueue(void)
+{
+ return global_settings.reclaim_wq;
+}
+
+static int hybridswap_core_init(struct zram *zram)
+{
+ int ret;
+
+ if (loop_device[0] == '\0') {
+ hybp(HYB_ERR, "please setting loop_device first\n");
+ return -EINVAL;
+ }
+
+ if (!hybridswap_global_setting_init(zram))
+ return -EINVAL;
+
+ ret = hybridswap_bind(zram, loop_device);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "bind storage device failed! %d\n", ret);
+ hybridswap_global_setting_deinit();
+ }
+
+ return 0;
+}
+
+int hybridswap_set_enable_init(bool en)
+{
+ int ret;
+
+ if (hybridswap_core_enabled() || !en)
+ return 0;
+
+ if (!global_settings.stat) {
+ hybp(HYB_ERR, "global_settings.stat is null!\n");
+
+ return -EINVAL;
+ }
+
+ ret = hybridswap_manager_init(global_settings.zram);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "init manager failed! %d\n", ret);
+
+ return -EINVAL;
+ }
+
+ ret = hyb_io_work_begin();
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "init schedule failed! %d\n", ret);
+ hybridswap_manager_deinit(global_settings.zram);
+
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+ssize_t hybridswap_core_enable_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ int ret;
+ unsigned long val;
+
+ ret = kstrtoul(buf, 0, &val);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "val is error!\n");
+
+ return -EINVAL;
+ }
+
+ if (hybridswap_set_enable_init(!!val))
+ return -EINVAL;
+
+ hybridswap_set_enable(!!val);
+
+ return len;
+}
+
+ssize_t hybridswap_core_enable_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int len = snprintf(buf, PAGE_SIZE, "hybridswap %s out_to_eswap %s\n",
+ hybridswap_core_enabled() ? "enable" : "disable",
+ hybridswap_out_to_eswap_enable() ? "enable" : "disable");
+
+ return len;
+}
+
+ssize_t hybridswap_loop_device_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ struct zram *zram;
+ int ret = 0;
+
+ if (len > (DEVICE_NAME_LEN - 1)) {
+ hybp(HYB_ERR, "buf %s len %d is too long\n", buf, len);
+ return -EINVAL;
+ }
+
+ memcpy(loop_device, buf, len);
+ loop_device[len] = '\0';
+ strstrip(loop_device);
+
+ zram = dev_to_zram(dev);
+ down_write(&zram->init_lock);
+ if (zram->disksize == 0) {
+ hybp(HYB_ERR, "disksize is 0\n");
+ goto out;
+ }
+
+ ret = hybridswap_core_init(zram);
+ if (ret)
+ hybp(HYB_ERR, "hybridswap_core_init init failed\n");
+
+out:
+ up_write(&zram->init_lock);
+ return len;
+}
+
+ssize_t hybridswap_loop_device_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int len = 0;
+
+ len = sprintf(buf, "%s\n", loop_device);
+
+ return len;
+}
+
+ssize_t hybridswap_dev_life_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ int ret;
+ unsigned long val;
+
+ ret = kstrtoul(buf, 0, &val);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "val is error!\n");
+
+ return -EINVAL;
+ }
+
+ hybridswap_set_dev_life(!!val);
+
+ return len;
+}
+
+ssize_t hybridswap_dev_life_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int len = 0;
+
+ len = sprintf(buf, "%s\n",
+ hybridswap_dev_life() ? "enable" : "disable");
+
+ return len;
+}
+
+ssize_t hybridswap_quota_day_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ int ret;
+ unsigned long val;
+
+ ret = kstrtoul(buf, 0, &val);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "val is error!\n");
+
+ return -EINVAL;
+ }
+
+ hybridswap_set_quota_day(val);
+
+ return len;
+}
+
+ssize_t hybridswap_quota_day_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int len = 0;
+
+ len = sprintf(buf, "%llu\n", hybridswap_quota_day());
+
+ return len;
+}
+
+ssize_t hybridswap_zram_increase_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ char *type_buf = NULL;
+ unsigned long val;
+ struct zram *zram = dev_to_zram(dev);
+
+ type_buf = strstrip((char *)buf);
+ if (kstrtoul(type_buf, 0, &val))
+ return -EINVAL;
+
+ zram->increase_nr_pages = (val << 8);
+ return len;
+}
+
+ssize_t hybridswap_zram_increase_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ ssize_t size = 0;
+ struct zram *zram = dev_to_zram(dev);
+
+ size += scnprintf(buf + size, PAGE_SIZE - size,
+ "%lu\n", zram->increase_nr_pages >> 8);
+
+ return size;
+}
+
+int mem_cgroup_stored_wm_scale_write(
+ struct cgroup_subsys_state *css, struct cftype *cft, s64 val)
+{
+ if (val > MAX_RATIO || val < MIN_RATIO)
+ return -EINVAL;
+
+ if (!global_settings.stat)
+ return -EINVAL;
+
+ atomic64_set(&global_settings.stat->stored_wm_scale, val);
+
+ return 0;
+}
+
+s64 mem_cgroup_stored_wm_scale_read(
+ struct cgroup_subsys_state *css, struct cftype *cft)
+{
+ if (!global_settings.stat)
+ return -EINVAL;
+
+ return atomic64_read(&global_settings.stat->stored_wm_scale);
+}
+
+int hybridswap_stored_info(unsigned long *total, unsigned long *used)
+{
+ if (!total || !used)
+ return -EINVAL;
+
+ if (!global_settings.stat || !global_settings.zram) {
+ *total = 0;
+ *used = 0;
+ return 0;
+ }
+
+ *used = atomic64_read(&global_settings.stat->eswap_cnt) * ESWAP_PG_CNT;
+ *total = global_settings.zram->nr_pages;
+
+ return 0;
+}
+
+bool hybridswap_stored_wm_ok(void)
+{
+ unsigned long scale, stored_pages, total_pages, wm_scale;
+ int ret;
+
+ if (!hybridswap_core_enabled())
+ return false;
+
+ ret = hybridswap_stored_info(&total_pages, &stored_pages);
+ if (ret)
+ return false;
+
+ scale = (stored_pages * 100) / (total_pages + 1);
+ wm_scale = atomic64_read(&global_settings.stat->stored_wm_scale);
+
+ return scale <= wm_scale;
+}
+
+int hybridswap_core_enable(void)
+{
+ int ret;
+
+ ret = hybridswap_set_enable_init(true);
+ if (ret) {
+ hybp(HYB_ERR, "set true failed, ret=%d\n", ret);
+ return ret;
+ }
+
+ hybridswap_set_enable(true);
+ return 0;
+}
+
+void hybridswap_core_disable(void)
+{
+ (void)hybridswap_set_enable_init(false);
+ hybridswap_set_enable(false);
+}
+
+static void hybridswap_memcg_iter(
+ int (*iter)(struct mem_cgroup *, void *), void *data)
+{
+ struct mem_cgroup *mcg = fetch_next_memcg(NULL);
+ int ret;
+
+ while (mcg) {
+ ret = iter(mcg, data);
+ hybp(HYB_DEBUG, "%pS mcg %d %s %s, ret %d\n",
+ iter, mcg->id.id,
+ MEMCGRP_ITEM(mcg, name),
+ ret ? "failed" : "pass",
+ ret);
+ if (ret) {
+ fetch_next_memcg_break(mcg);
+ return;
+ }
+ mcg = fetch_next_memcg(mcg);
+ }
+}
+
+void hybridswap_record(struct zram *zram, u32 index,
+ struct mem_cgroup *memcg)
+{
+ memcg_hybs_t *hybs;
+ struct hybstatus *stat;
+
+ if (!hybridswap_core_enabled())
+ return;
+
+ if (!memcg || !memcg->id.id) {
+ stat = hybridswap_fetch_stat_obj();
+ if (stat)
+ atomic64_inc(&stat->null_memcg_skip_track_cnt);
+ return;
+ }
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ if (!hybs) {
+ hybs = hybridswap_cache_alloc(memcg, false);
+ if (!hybs) {
+ stat = hybridswap_fetch_stat_obj();
+ if (stat)
+ atomic64_inc(&stat->skip_track_cnt);
+ return;
+ }
+ }
+
+ if (unlikely(!hybs->zram)) {
+ spin_lock(&hybs->zram_init_lock);
+ if (!hybs->zram)
+ hybridswap_manager_memcg_init(zram, memcg);
+ spin_unlock(&hybs->zram_init_lock);
+ }
+
+ hybridswap_swap_sorted_list_add(zram, index, memcg);
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ zram_slot_unlock(zram, index);
+ if (!zram_watermark_ok())
+ wake_all_swapd();
+ zram_slot_lock(zram, index);
+#endif
+}
+
+void hybridswap_untrack(struct zram *zram, u32 index)
+{
+ if (!hybridswap_core_enabled())
+ return;
+
+ while (zram_test_flag(zram, index, ZRAM_UNDER_WB) ||
+ zram_test_flag(zram, index, ZRAM_BATCHING_OUT)) {
+ zram_slot_unlock(zram, index);
+ udelay(50);
+ zram_slot_lock(zram, index);
+ }
+
+ hybridswap_swap_sorted_list_del(zram, index);
+}
+
+static unsigned long memcg_reclaim_size(struct mem_cgroup *memcg)
+{
+ memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg);
+ unsigned long zram_size, cur_size, new_size;
+
+ if (!hybs)
+ return 0;
+
+ zram_size = atomic64_read(&hybs->zram_stored_size);
+ if (hybs->force_swapout) {
+ hybs->can_eswaped = zram_size;
+ return zram_size;
+ }
+
+ cur_size = atomic64_read(&hybs->hybridswap_stored_size);
+ new_size = (zram_size + cur_size) *
+ atomic_read(&hybs->zram2ufs_scale) / 100;
+
+ hybs->can_eswaped = (new_size > cur_size) ? (new_size - cur_size) : 0;
+ return hybs->can_eswaped;
+}
+
+static int hybridswap_permcg_sz(struct mem_cgroup *memcg, void *data)
+{
+ unsigned long *out_size = (unsigned long *)data;
+
+ *out_size += memcg_reclaim_size(memcg);
+ return 0;
+}
+
+static void hybridswap_flush_cb(enum hybridswap_class class,
+ void *pri, struct hybridswap_io_req *req)
+{
+ switch (class) {
+ case HYB_FAULT_OUT:
+ case HYB_PRE_OUT:
+ case HYB_BATCH_OUT:
+ hybridswap_eswap_destroy(pri, class);
+ break;
+ case HYB_RECLAIM_IN:
+ hybridswap_eswap_register(pri, req);
+ break;
+ default:
+ break;
+ }
+}
+
+static void hybridswap_flush_done(struct hybridswap_entry *ioentry,
+ int err, struct hybridswap_io_req *req)
+{
+ struct io_priv *data;
+
+ if (unlikely(!ioentry))
+ return;
+
+ data = (struct io_priv *)(ioentry->private);
+ if (likely(!err)) {
+ hybridswap_flush_cb(data->class,
+ ioentry->manager_private, req);
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ if (!zram_watermark_ok())
+ wake_all_swapd();
+#endif
+ } else {
+ hybridswap_eswap_exception(data->class,
+ ioentry->manager_private);
+ }
+ hybridswap_free(ioentry);
+}
+
+static void hybridswap_free_pagepool(struct io_work_arg *iowork)
+{
+ struct page *free_page = NULL;
+
+ spin_lock(&iowork->data.page_pool.page_pool_lock);
+ while (!list_empty(&iowork->data.page_pool.page_pool_list)) {
+ free_page = list_first_entry(
+ &iowork->data.page_pool.page_pool_list,
+ struct page, lru);
+ list_del_init(&free_page->lru);
+ __free_page(free_page);
+ }
+ spin_unlock(&iowork->data.page_pool.page_pool_lock);
+}
+
+static void hybridswap_plug_complete(void *data)
+{
+ struct io_work_arg *iowork = (struct io_work_arg *)data;
+
+ hybridswap_free_pagepool(iowork);
+
+ hybperf_end(&iowork->record);
+
+ hybridswap_free(iowork);
+}
+
+static void *hybridswap_init_plug(struct zram *zram,
+ enum hybridswap_class class,
+ struct io_work_arg *iowork)
+{
+ struct hybridswap_io io_para;
+
+ io_para.bdev = zram->bdev;
+ io_para.class = class;
+ io_para.private = (void *)iowork;
+ io_para.record = &iowork->record;
+ INIT_LIST_HEAD(&iowork->data.page_pool.page_pool_list);
+ spin_lock_init(&iowork->data.page_pool.page_pool_lock);
+ io_para.done_callback = hybridswap_flush_done;
+ switch (io_para.class) {
+ case HYB_RECLAIM_IN:
+ io_para.complete_notify = hybridswap_plug_complete;
+ iowork->io_buf.pool = NULL;
+ break;
+ case HYB_BATCH_OUT:
+ case HYB_PRE_OUT:
+ io_para.complete_notify = hybridswap_plug_complete;
+ iowork->io_buf.pool = &iowork->data.page_pool;
+ break;
+ case HYB_FAULT_OUT:
+ io_para.complete_notify = NULL;
+ iowork->io_buf.pool = NULL;
+ break;
+ default:
+ break;
+ }
+ iowork->io_buf.zram = zram;
+ iowork->data.zram = zram;
+ iowork->data.class = io_para.class;
+ return hybridswap_plug_start(&io_para);
+}
+
+static void hybridswap_fill_entry(struct hybridswap_entry *ioentry,
+ struct hybridswap_buffer *io_buf,
+ void *private)
+{
+ ioentry->addr = ioentry->eswapid * ESWAP_SECTOR_SIZE;
+ ioentry->dest_pages = io_buf->dest_pages;
+ ioentry->pages_sz = ESWAP_PG_CNT;
+ ioentry->private = private;
+}
+
+static int hybridswap_reclaim_check(struct mem_cgroup *memcg,
+ unsigned long *require_size)
+{
+ memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg);
+
+ if (unlikely(!hybs) || unlikely(!hybs->zram))
+ return -EAGAIN;
+ if (unlikely(hybs->in_swapin))
+ return -EAGAIN;
+ if (!hybs->force_swapout && *require_size < MIN_RECLAIM_ZRAM_SZ)
+ return -EAGAIN;
+
+ return 0;
+}
+
+static int hybridswap_update_reclaim_sz(unsigned long *require_size,
+ unsigned long *mcg_reclaimed_sz,
+ unsigned long reclaim_size)
+{
+ *mcg_reclaimed_sz += reclaim_size;
+
+ if (*require_size > reclaim_size)
+ *require_size -= reclaim_size;
+ else
+ *require_size = 0;
+
+ return 0;
+}
+
+static void hybstatus_alloc_fail(enum hybridswap_class class,
+ int err)
+{
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (!stat || (err != -ENOMEM) || (class >= HYB_CLASS_BUTT))
+ return;
+
+ atomic64_inc(&stat->alloc_fail_cnt[class]);
+}
+
+static int hybridswap_reclaim_eswap(struct mem_cgroup *memcg,
+ struct io_work_arg *iowork,
+ unsigned long *require_size,
+ unsigned long *mcg_reclaimed_sz,
+ int *errio)
+{
+ int ret;
+ unsigned long reclaim_size;
+
+ hybperfiowrkstart(&iowork->record, HYB_IOENTRY_ALLOC);
+ iowork->ioentry = hybridswap_malloc(
+ sizeof(struct hybridswap_entry), false, true);
+ hybperfiowrkend(&iowork->record, HYB_IOENTRY_ALLOC);
+ if (unlikely(!iowork->ioentry)) {
+ hybp(HYB_ERR, "alloc io entry failed!\n");
+ *require_size = 0;
+ *errio = -ENOMEM;
+ hybstatus_alloc_fail(HYB_RECLAIM_IN, -ENOMEM);
+
+ return *errio;
+ }
+
+ hybperfiowrkstart(&iowork->record, HYB_FIND_ESWAP);
+ reclaim_size = hybridswap_eswap_create(
+ memcg, &iowork->ioentry->eswapid,
+ &iowork->io_buf, &iowork->ioentry->manager_private);
+ hybperfiowrkend(&iowork->record, HYB_FIND_ESWAP);
+ if (unlikely(!reclaim_size)) {
+ if (iowork->ioentry->eswapid != -ENOENT)
+ *require_size = 0;
+ hybridswap_free(iowork->ioentry);
+ return -EAGAIN;
+ }
+
+ hybridswap_fill_entry(iowork->ioentry, &iowork->io_buf,
+ (void *)(&iowork->data));
+
+ hybperfiowrkstart(&iowork->record, HYB_IO_ESWAP);
+ ret = hybridswap_write_eswap(iowork->iohandle, iowork->ioentry);
+ hybperfiowrkend(&iowork->record, HYB_IO_ESWAP);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "hybridswap write failed! %d\n", ret);
+ *require_size = 0;
+ *errio = ret;
+ hybstatus_alloc_fail(HYB_RECLAIM_IN, ret);
+
+ return *errio;
+ }
+
+ ret = hybridswap_update_reclaim_sz(require_size, mcg_reclaimed_sz,
+ reclaim_size);
+ if (MEMCGRP_ITEM(memcg, force_swapout))
+ return 0;
+ return ret;
+}
+
+static int hybridswap_permcg_reclaim(struct mem_cgroup *memcg,
+ unsigned long require_size, unsigned long *mcg_reclaimed_sz)
+{
+ int ret, extcnt;
+ int errio = 0;
+ unsigned long require_size_before = 0;
+ struct io_work_arg *iowork = NULL;
+ ktime_t start = ktime_get();
+ unsigned long long start_ravg_sum = hybridswap_fetch_ravg_sum();
+ memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg);
+
+ ret = hybridswap_reclaim_check(memcg, &require_size);
+ if (ret)
+ return ret == -EAGAIN ? 0 : ret;
+
+ iowork = hybridswap_malloc(sizeof(struct io_work_arg), false, true);
+ if (unlikely(!iowork)) {
+ hybp(HYB_ERR, "alloc iowork failed!\n");
+ hybstatus_alloc_fail(HYB_RECLAIM_IN, -ENOMEM);
+
+ return -ENOMEM;
+ }
+
+ hybperf_start(&iowork->record, start, start_ravg_sum,
+ HYB_RECLAIM_IN);
+ hybperfiowrkstart(&iowork->record, HYB_INIT);
+ iowork->iohandle = hybridswap_init_plug(hybs->zram,
+ HYB_RECLAIM_IN, iowork);
+ hybperfiowrkend(&iowork->record, HYB_INIT);
+ if (unlikely(!iowork->iohandle)) {
+ hybp(HYB_ERR, "plug start failed!\n");
+ hybperf_end(&iowork->record);
+ hybridswap_free(iowork);
+ hybstatus_alloc_fail(HYB_RECLAIM_IN, -ENOMEM);
+ ret = -EIO;
+ goto out;
+ }
+
+ require_size_before = require_size;
+ while (require_size) {
+ if (hybridswap_reclaim_eswap(memcg, iowork,
+ &require_size, mcg_reclaimed_sz, &errio))
+ break;
+
+ atomic64_inc(&hybs->hybridswap_outextcnt);
+ extcnt = atomic_inc_return(&hybs->hybridswap_extcnt);
+ if (extcnt > atomic_read(&hybs->hybridswap_peakextcnt))
+ atomic_set(&hybs->hybridswap_peakextcnt, extcnt);
+ }
+
+ ret = hybridswap_plug_finish(iowork->iohandle);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "hybridswap write flush failed! %d\n", ret);
+ hybstatus_alloc_fail(HYB_RECLAIM_IN, ret);
+ require_size = 0;
+ } else {
+ ret = errio;
+ }
+ atomic64_inc(&hybs->hybridswap_outcnt);
+
+out:
+ hybp(HYB_INFO, "memcg %s %lu %lu out_to_eswap %lu KB eswap %lu zram %lu %d\n",
+ hybs->name, require_size_before, require_size,
+ (require_size_before - require_size) >> 10,
+ atomic64_read(&hybs->hybridswap_stored_size),
+ atomic64_read(&hybs->zram_stored_size), ret);
+ return ret;
+}
+
+static void hybridswap_reclaimin_inc(void)
+{
+ struct hybstatus *stat;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat))
+ return;
+ atomic64_inc(&stat->reclaimin_infight);
+}
+
+static void hybridswap_reclaimin_dec(void)
+{
+ struct hybstatus *stat;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat))
+ return;
+ atomic64_dec(&stat->reclaimin_infight);
+}
+
+static int hybridswap_permcg_reclaimin(struct mem_cgroup *memcg,
+ void *data)
+{
+ struct async_req *rq = (struct async_req *)data;
+ unsigned long mcg_reclaimed_size = 0, require_size;
+ int ret;
+ memcg_hybs_t *hybs;
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ if (!hybs)
+ return 0;
+
+ require_size = hybs->can_eswaped * rq->size / rq->out_size;
+ if (require_size < MIN_RECLAIM_ZRAM_SZ)
+ return 0;
+
+ if (!mutex_trylock(&hybs->swap_lock))
+ return 0;
+
+ ret = hybridswap_permcg_reclaim(memcg, require_size,
+ &mcg_reclaimed_size);
+ rq->reclaimined_sz += mcg_reclaimed_size;
+ mutex_unlock(&hybs->swap_lock);
+
+ hybp(HYB_INFO, "memcg %s mcg_reclaimed_size %lu rq->reclaimined_sz %lu rq->size %lu rq->out_size %lu ret %d\n",
+ hybs->name, mcg_reclaimed_size, rq->reclaimined_sz,
+ rq->size, rq->out_size, ret);
+
+ if (!ret && rq->reclaimined_sz >= rq->size)
+ return -EINVAL;
+
+ return ret;
+}
+
+static void hybridswap_reclaim_work(struct work_struct *work)
+{
+ struct async_req *rq = container_of(work, struct async_req, work);
+ int old_nice = task_nice(current);
+
+ set_user_nice(current, rq->nice);
+ hybridswap_reclaimin_inc();
+ hybridswap_memcg_iter(hybridswap_permcg_reclaimin, rq);
+ hybridswap_reclaimin_dec();
+ set_user_nice(current, old_nice);
+ hybp(HYB_INFO, "SWAPOUT want %lu MB real %lu Mb\n", rq->size >> 20,
+ rq->reclaimined_sz >> 20);
+ hybridswap_free(rq);
+}
+
+unsigned long hybridswap_out_to_eswap(unsigned long size)
+{
+ struct async_req *rq = NULL;
+ unsigned long out_size = 0;
+
+ if (!hybridswap_core_enabled() || !hybridswap_out_to_eswap_enable()
+ || hybridswap_reach_life_protect() || !size)
+ return 0;
+
+ hybridswap_memcg_iter(hybridswap_permcg_sz, &out_size);
+ if (!out_size)
+ return 0;
+
+ rq = hybridswap_malloc(sizeof(struct async_req), false, true);
+ if (unlikely(!rq)) {
+ hybp(HYB_ERR, "alloc async req fail!\n");
+ hybstatus_alloc_fail(HYB_RECLAIM_IN, -ENOMEM);
+ return 0;
+ }
+
+ if (out_size < size)
+ size = out_size;
+ rq->size = size;
+ rq->out_size = out_size;
+ rq->reclaimined_sz = 0;
+ rq->nice = task_nice(current);
+ INIT_WORK(&rq->work, hybridswap_reclaim_work);
+ queue_work(hybridswap_fetch_reclaim_workqueue(), &rq->work);
+
+ return out_size > size ? size : out_size;
+}
+
+static int hybridswap_batches_eswap(struct io_work_arg *iowork,
+ struct mem_cgroup *mcg,
+ bool preload,
+ int *errio)
+{
+ int ret;
+
+ hybperfiowrkstart(&iowork->record, HYB_IOENTRY_ALLOC);
+ iowork->ioentry = hybridswap_malloc(
+ sizeof(struct hybridswap_entry), !preload, preload);
+ hybperfiowrkend(&iowork->record, HYB_IOENTRY_ALLOC);
+ if (unlikely(!iowork->ioentry)) {
+ hybp(HYB_ERR, "alloc io entry failed!\n");
+ *errio = -ENOMEM;
+ hybstatus_alloc_fail(HYB_BATCH_OUT, -ENOMEM);
+
+ return *errio;
+ }
+
+ hybperfiowrkstart(&iowork->record, HYB_FIND_ESWAP);
+ iowork->ioentry->eswapid = hybridswap_find_eswap_by_memcg(
+ mcg, &iowork->io_buf,
+ &iowork->ioentry->manager_private);
+ hybperfiowrkend(&iowork->record, HYB_FIND_ESWAP);
+ if (iowork->ioentry->eswapid < 0) {
+ hybstatus_alloc_fail(HYB_BATCH_OUT,
+ iowork->ioentry->eswapid);
+ hybridswap_free(iowork->ioentry);
+ return -EAGAIN;
+ }
+
+ hybridswap_fill_entry(iowork->ioentry, &iowork->io_buf,
+ (void *)(&iowork->data));
+
+ hybperfiowrkstart(&iowork->record, HYB_IO_ESWAP);
+ ret = hybridswap_read_eswap(iowork->iohandle, iowork->ioentry);
+ hybperfiowrkend(&iowork->record, HYB_IO_ESWAP);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "hybridswap read failed! %d\n", ret);
+ hybstatus_alloc_fail(HYB_BATCH_OUT, ret);
+ *errio = ret;
+
+ return *errio;
+ }
+
+ return 0;
+}
+
+static int hybridswap_do_batches_init(struct io_work_arg **out_sched,
+ struct mem_cgroup *mcg, bool preload)
+{
+ struct io_work_arg *iowork = NULL;
+ ktime_t start = ktime_get();
+ unsigned long long start_ravg_sum = hybridswap_fetch_ravg_sum();
+
+ iowork = hybridswap_malloc(sizeof(struct io_work_arg),
+ !preload, preload);
+ if (unlikely(!iowork)) {
+ hybp(HYB_ERR, "alloc iowork failed!\n");
+ hybstatus_alloc_fail(HYB_BATCH_OUT, -ENOMEM);
+
+ return -ENOMEM;
+ }
+
+ hybperf_start(&iowork->record, start, start_ravg_sum,
+ preload ? HYB_PRE_OUT : HYB_BATCH_OUT);
+
+ hybperfiowrkstart(&iowork->record, HYB_INIT);
+ iowork->iohandle = hybridswap_init_plug(MEMCGRP_ITEM(mcg, zram),
+ preload ? HYB_PRE_OUT : HYB_BATCH_OUT,
+ iowork);
+ hybperfiowrkend(&iowork->record, HYB_INIT);
+ if (unlikely(!iowork->iohandle)) {
+ hybp(HYB_ERR, "plug start failed!\n");
+ hybperf_end(&iowork->record);
+ hybridswap_free(iowork);
+ hybstatus_alloc_fail(HYB_BATCH_OUT, -ENOMEM);
+
+ return -EIO;
+ }
+
+ *out_sched = iowork;
+
+ return 0;
+}
+
+static int hybridswap_do_batches(struct mem_cgroup *mcg,
+ unsigned long size, bool preload)
+{
+ int ret = 0;
+ int errio = 0;
+ struct io_work_arg *iowork = NULL;
+
+ if (unlikely(!mcg || !MEMCGRP_ITEM(mcg, zram))) {
+ hybp(HYB_WARN, "no zram in mcg!\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ ret = hybridswap_do_batches_init(&iowork, mcg, preload);
+ if (unlikely(ret))
+ goto out;
+
+ MEMCGRP_ITEM(mcg, in_swapin) = true;
+ while (size) {
+ if (hybridswap_batches_eswap(iowork, mcg, preload, &errio))
+ break;
+ size -= ESWAP_SIZE;
+ }
+
+ ret = hybridswap_plug_finish(iowork->iohandle);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "hybridswap read flush failed! %d\n", ret);
+ hybstatus_alloc_fail(HYB_BATCH_OUT, ret);
+ } else {
+ ret = errio;
+ }
+
+ if (atomic64_read(&MEMCGRP_ITEM(mcg, hybridswap_stored_size)) &&
+ hybridswap_loglevel() >= HYB_INFO)
+ hybridswap_check_infos_eswap((MEMCGRP_ITEM(mcg, zram)->infos));
+
+ atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_incnt));
+ MEMCGRP_ITEM(mcg, in_swapin) = false;
+out:
+ return ret;
+}
+
+static void hybridswap_batchout_inc(void)
+{
+ struct hybstatus *stat;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat))
+ return;
+ atomic64_inc(&stat->batchout_inflight);
+}
+
+static void hybridswap_batchout_dec(void)
+{
+ struct hybstatus *stat;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat))
+ return;
+ atomic64_dec(&stat->batchout_inflight);
+}
+
+int hybridswap_batches(struct mem_cgroup *mcg,
+ unsigned long size, bool preload)
+{
+ int ret;
+
+ if (!hybridswap_core_enabled())
+ return 0;
+
+ hybridswap_batchout_inc();
+ ret = hybridswap_do_batches(mcg, size, preload);
+ hybridswap_batchout_dec();
+
+ return ret;
+}
+
+static void hybridswap_fault_stat(struct zram *zram, u32 index)
+{
+ struct mem_cgroup *mcg = NULL;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (unlikely(!stat))
+ return;
+
+ atomic64_inc(&stat->fault_cnt);
+
+ mcg = hybridswap_zram_fetch_mcg(zram, index);
+ if (mcg)
+ atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_allfaultcnt));
+}
+
+static void hybridswap_fault2_stat(struct zram *zram, u32 index)
+{
+ struct mem_cgroup *mcg = NULL;
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (unlikely(!stat))
+ return;
+
+ atomic64_inc(&stat->hybridswap_fault_cnt);
+
+ mcg = hybridswap_zram_fetch_mcg(zram, index);
+ if (mcg)
+ atomic64_inc(&MEMCGRP_ITEM(mcg, hybridswap_faultcnt));
+}
+
+static bool hybridswap_page_fault_check(struct zram *zram,
+ u32 index, unsigned long *zentry)
+{
+ if (!hybridswap_core_enabled())
+ return false;
+
+ hybridswap_fault_stat(zram, index);
+
+ if (!zram_test_flag(zram, index, ZRAM_WB))
+ return false;
+
+ zram_set_flag(zram, index, ZRAM_BATCHING_OUT);
+ *zentry = zram_get_handle(zram, index);
+ zram_slot_unlock(zram, index);
+ return true;
+}
+
+static int hybridswap_page_fault_fetch_eswap(struct zram *zram,
+ struct io_work_arg *iowork,
+ unsigned long zentry,
+ u32 index)
+{
+ int wait_cycle = 0;
+
+ iowork->io_buf.zram = zram;
+ iowork->data.zram = zram;
+ iowork->io_buf.pool = NULL;
+ hybperfiowrkstart(&iowork->record, HYB_FIND_ESWAP);
+ iowork->ioentry->eswapid = hybridswap_find_eswap_by_index(zentry,
+ &iowork->io_buf, &iowork->ioentry->manager_private);
+ hybperfiowrkend(&iowork->record, HYB_FIND_ESWAP);
+ if (unlikely(iowork->ioentry->eswapid == -EBUSY)) {
+ while (1) {
+ zram_slot_lock(zram, index);
+ if (!zram_test_flag(zram, index, ZRAM_WB)) {
+ zram_slot_unlock(zram, index);
+ hybridswap_free(iowork->ioentry);
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ if (wait_cycle >= 1000)
+ atomic_long_dec(&page_fault_pause);
+#endif
+ return -EAGAIN;
+ }
+ zram_slot_unlock(zram, index);
+
+ hybperfiowrkstart(&iowork->record,
+ HYB_FIND_ESWAP);
+ iowork->ioentry->eswapid =
+ hybridswap_find_eswap_by_index(zentry,
+ &iowork->io_buf,
+ &iowork->ioentry->manager_private);
+ hybperfiowrkend(&iowork->record,
+ HYB_FIND_ESWAP);
+ if (likely(iowork->ioentry->eswapid != -EBUSY))
+ break;
+
+ if (wait_cycle < 100)
+ udelay(50);
+ else
+ usleep_range(50, 100);
+ wait_cycle++;
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ if (wait_cycle == 1000) {
+ atomic_long_inc(&page_fault_pause);
+ atomic_long_inc(&page_fault_pause_cnt);
+ }
+#endif
+ }
+ }
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ if (wait_cycle >= 1000)
+ atomic_long_dec(&page_fault_pause);
+#endif
+ if (iowork->ioentry->eswapid < 0) {
+ hybstatus_alloc_fail(HYB_FAULT_OUT,
+ iowork->ioentry->eswapid);
+
+ return iowork->ioentry->eswapid;
+ }
+ hybridswap_fault2_stat(zram, index);
+ hybridswap_fill_entry(iowork->ioentry, &iowork->io_buf,
+ (void *)(&iowork->data));
+ return 0;
+}
+
+static int hybridswap_page_fault_exit_check(struct zram *zram,
+ u32 index, int ret)
+{
+ zram_slot_lock(zram, index);
+ if (likely(!ret)) {
+ if (unlikely(zram_test_flag(zram, index, ZRAM_WB))) {
+ hybp(HYB_ERR, "still in WB status!\n");
+ ret = -EIO;
+ }
+ }
+ zram_clear_flag(zram, index, ZRAM_BATCHING_OUT);
+
+ return ret;
+}
+
+static int hybridswap_page_fault_eswap(struct zram *zram, u32 index,
+ struct io_work_arg *iowork, unsigned long zentry)
+{
+ int ret;
+
+ hybperfiowrkstart(&iowork->record, HYB_IOENTRY_ALLOC);
+ iowork->ioentry = hybridswap_malloc(sizeof(struct hybridswap_entry),
+ true, true);
+ hybperfiowrkend(&iowork->record, HYB_IOENTRY_ALLOC);
+ if (unlikely(!iowork->ioentry)) {
+ hybp(HYB_ERR, "alloc io entry failed!\n");
+ hybstatus_alloc_fail(HYB_FAULT_OUT, -ENOMEM);
+ hybridswap_fail_record(HYB_FAULT_OUT_ENTRY_ALLOC_FAIL,
+ index, 0, iowork->record.task_comm);
+ return -ENOMEM;
+ }
+
+ ret = hybridswap_page_fault_fetch_eswap(zram, iowork, zentry, index);
+ if (ret)
+ return ret;
+
+ hybperfiowrkstart(&iowork->record, HYB_IO_ESWAP);
+ ret = hybridswap_read_eswap(iowork->iohandle, iowork->ioentry);
+ hybperfiowrkend(&iowork->record, HYB_IO_ESWAP);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "hybridswap read failed! %d\n", ret);
+ hybstatus_alloc_fail(HYB_FAULT_OUT, ret);
+ }
+
+ return ret;
+}
+
+int hybridswap_page_fault(struct zram *zram, u32 index)
+{
+ int ret = 0;
+ int errio;
+ struct io_work_arg iowork;
+ unsigned long zentry;
+ ktime_t start = ktime_get();
+ unsigned long long start_ravg_sum = hybridswap_fetch_ravg_sum();
+
+ if (!hybridswap_page_fault_check(zram, index, &zentry))
+ return ret;
+
+ memset(&iowork.record, 0, sizeof(struct hybridswap_key_point_record));
+ hybperf_start(&iowork.record, start, start_ravg_sum,
+ HYB_FAULT_OUT);
+
+ hybperfiowrkstart(&iowork.record, HYB_INIT);
+ iowork.iohandle = hybridswap_init_plug(zram,
+ HYB_FAULT_OUT, &iowork);
+ hybperfiowrkend(&iowork.record, HYB_INIT);
+ if (unlikely(!iowork.iohandle)) {
+ hybp(HYB_ERR, "plug start failed!\n");
+ hybstatus_alloc_fail(HYB_FAULT_OUT, -ENOMEM);
+ ret = -EIO;
+ hybridswap_fail_record(HYB_FAULT_OUT_INIT_FAIL,
+ index, 0, iowork.record.task_comm);
+
+ goto out;
+ }
+
+ errio = hybridswap_page_fault_eswap(zram, index, &iowork, zentry);
+ ret = hybridswap_plug_finish(iowork.iohandle);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "hybridswap flush failed! %d\n", ret);
+ hybstatus_alloc_fail(HYB_FAULT_OUT, ret);
+ } else {
+ ret = (errio != -EAGAIN) ? errio : 0;
+ }
+out:
+ hybperfiowrkstart(&iowork.record, HYB_ZRAM_LOCK);
+ ret = hybridswap_page_fault_exit_check(zram, index, ret);
+ hybperfiowrkend(&iowork.record, HYB_ZRAM_LOCK);
+ hybperf_end(&iowork.record);
+
+ return ret;
+}
+
+bool hybridswap_delete(struct zram *zram, u32 index)
+{
+ if (!hybridswap_core_enabled())
+ return true;
+
+ if (zram_test_flag(zram, index, ZRAM_UNDER_WB)
+ || zram_test_flag(zram, index, ZRAM_BATCHING_OUT)) {
+ struct hybstatus *stat = hybridswap_fetch_stat_obj();
+
+ if (stat)
+ atomic64_inc(&stat->miss_free);
+ return false;
+ }
+
+ if (!zram_test_flag(zram, index, ZRAM_WB))
+ return true;
+
+ hybridswap_eswap_objs_del(zram, index);
+
+ return true;
+}
+
+void hybridswap_mem_cgroup_deinit(struct mem_cgroup *memcg)
+{
+ if (!hybridswap_core_enabled())
+ return;
+
+ hybridswap_manager_memcg_deinit(memcg);
+}
+
+void hybridswap_force_reclaim(struct mem_cgroup *mcg)
+{
+ unsigned long mcg_reclaimed_size = 0, require_size;
+ memcg_hybs_t *hybs;
+
+ if (!hybridswap_core_enabled() || !hybridswap_out_to_eswap_enable()
+ || hybridswap_reach_life_protect())
+ return;
+
+ if (!mcg)
+ return;
+
+ hybs = MEMCGRP_ITEM_DATA(mcg);
+ if (!hybs || !hybs->zram)
+ return;
+
+ mutex_lock(&hybs->swap_lock);
+ require_size = atomic64_read(&hybs->zram_stored_size);
+ hybs->force_swapout = true;
+ hybridswap_permcg_reclaim(mcg, require_size, &mcg_reclaimed_size);
+ hybs->force_swapout = false;
+ mutex_unlock(&hybs->swap_lock);
+}
+
+void mem_cgroup_id_remove_hook(void *data, struct mem_cgroup *memcg)
+{
+ if (!memcg->android_oem_data1)
+ return;
+
+ hybridswap_mem_cgroup_deinit(memcg);
+ hybp(HYB_DEBUG, "hybridswap remove mcg id = %d\n", memcg->id.id);
+}
diff --git a/drivers/block/zram/hybridswap/hybridswap_internal.h b/drivers/block/zram/hybridswap/hybridswap_internal.h
new file mode 100644
index 000000000000..526f9f49c9e7
--- /dev/null
+++ b/drivers/block/zram/hybridswap/hybridswap_internal.h
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020-2022 Oplus. All rights reserved.
+ */
+
+#ifndef HYBRIDSWAP_INTERNAL_H
+#define HYBRIDSWAP_INTERNAL_H
+
+#include
+#include
+#include
+#include
+#include
+
+#define ESWAP_SHIFT 15
+#define ESWAP_SIZE (1UL << ESWAP_SHIFT)
+#define ESWAP_PG_CNT (ESWAP_SIZE >> PAGE_SHIFT)
+#define ESWAP_SECTOR_SIZE (ESWAP_PG_CNT << 3)
+#define ESWAP_MAX_OBJ_CNT (30 * ESWAP_PG_CNT)
+#define ESWAP_MASK (~(ESWAP_SIZE - 1))
+#define ESWAP_ALIGN_UP(size) ((size + ESWAP_SIZE - 1) & ESWAP_MASK)
+
+#define MAX_FAIL_RECORD_NUM 4
+#define MAX_APP_GRADE 600
+
+#define HYBRIDSWAP_QUOTA_DAY 0x280000000 /* 10G bytes */
+#define HYBRIDSWAP_CHECK_GAP 86400 /* 24 hour */
+#define MEM_CGROUP_NAME_MAX_LEN 32
+
+#define MAX_RATIO 100
+#define MIN_RATIO 0
+
+enum {
+ HYB_ERR = 0,
+ HYB_WARN,
+ HYB_INFO,
+ HYB_DEBUG,
+ HYB_MAX
+};
+
+void hybridswap_loglevel_set(int level);
+int hybridswap_loglevel(void);
+
+#define DUMP_STACK_ON_ERR 0
+#define pt(l, f, ...) pr_err("[%s]<%d:%s>:"f, #l, __LINE__, __func__, ##__VA_ARGS__)
+static inline void pr_none(void) {}
+#define hybp(l, f, ...) do {\
+ (l <= hybridswap_loglevel()) ? pt(l, f, ##__VA_ARGS__) : pr_none();\
+ if (DUMP_STACK_ON_ERR && l == HYB_ERR) dump_stack();\
+} while (0)
+
+enum hybridswap_class {
+ HYB_RECLAIM_IN = 0,
+ HYB_FAULT_OUT,
+ HYB_BATCH_OUT,
+ HYB_PRE_OUT,
+ HYB_CLASS_BUTT
+};
+
+enum hybridswap_key_point {
+ HYB_START = 0,
+ HYB_INIT,
+ HYB_IOENTRY_ALLOC,
+ HYB_FIND_ESWAP,
+ HYB_IO_ESWAP,
+ HYB_SEGMENT_ALLOC,
+ HYB_BIO_ALLOC,
+ HYB_SUBMIT_BIO,
+ HYB_END_IO,
+ HYB_SCHED_WORK,
+ HYB_END_WORK,
+ HYB_CALL_BACK,
+ HYB_WAKE_UP,
+ HYB_ZRAM_LOCK,
+ HYB_DONE,
+ HYB_KYE_POINT_BUTT
+};
+
+enum hybridswap_mcg_member {
+ MCG_ZRAM_STORED_SZ = 0,
+ MCG_ZRAM_STORED_PG_SZ,
+ MCG_DISK_STORED_SZ,
+ MCG_DISK_STORED_PG_SZ,
+ MCG_ANON_FAULT_CNT,
+ MCG_DISK_FAULT_CNT,
+ MCG_ESWAPOUT_CNT,
+ MCG_ESWAPOUT_SZ,
+ MCG_ESWAPIN_CNT,
+ MCG_ESWAPIN_SZ,
+ MCG_DISK_SPACE,
+ MCG_DISK_SPACE_PEAK,
+};
+
+enum hybridswap_fail_point {
+ HYB_FAULT_OUT_INIT_FAIL = 0,
+ HYB_FAULT_OUT_ENTRY_ALLOC_FAIL,
+ HYB_FAULT_OUT_IO_ENTRY_PARA_FAIL,
+ HYB_FAULT_OUT_SEGMENT_ALLOC_FAIL,
+ HYB_FAULT_OUT_BIO_ALLOC_FAIL,
+ HYB_FAULT_OUT_BIO_ADD_FAIL,
+ HYB_FAULT_OUT_IO_FAIL,
+ HYBRIDSWAP_FAIL_POINT_BUTT
+};
+
+struct hybridswap_fail_record {
+ unsigned char task_comm[TASK_COMM_LEN];
+ enum hybridswap_fail_point point;
+ ktime_t time;
+ u32 index;
+ int eswapid;
+};
+
+struct hybridswap_fail_record_info {
+ int num;
+ spinlock_t lock;
+ struct hybridswap_fail_record record[MAX_FAIL_RECORD_NUM];
+};
+
+struct hybridswap_key_point_info {
+ unsigned int record_cnt;
+ unsigned int end_cnt;
+ ktime_t first_time;
+ ktime_t last_time;
+ s64 proc_total_time;
+ s64 proc_max_time;
+ unsigned long long last_ravg_sum;
+ unsigned long long proc_ravg_sum;
+ spinlock_t time_lock;
+};
+
+struct hybridswap_key_point_record {
+ struct timer_list lat_monitor;
+ unsigned long warn_level;
+ int page_cnt;
+ int segment_cnt;
+ int nice;
+ bool timeout_flag;
+ unsigned char task_comm[TASK_COMM_LEN];
+ struct task_struct *task;
+ enum hybridswap_class class;
+ struct hybridswap_key_point_info key_point[HYB_KYE_POINT_BUTT];
+};
+
+struct hybridswapiowrkstat {
+ atomic64_t total_lat;
+ atomic64_t max_lat;
+ atomic64_t timeout_cnt;
+};
+
+struct hybridswap_fault_timeout_cnt{
+ atomic64_t timeout_100ms_cnt;
+ atomic64_t timeout_500ms_cnt;
+};
+
+struct hybstatus {
+ atomic64_t reclaimin_cnt;
+ atomic64_t reclaimin_bytes;
+ atomic64_t reclaimin_real_load;
+ atomic64_t reclaimin_bytes_daily;
+ atomic64_t reclaimin_pages;
+ atomic64_t reclaimin_infight;
+ atomic64_t batchout_cnt;
+ atomic64_t batchout_bytes;
+ atomic64_t batchout_real_load;
+ atomic64_t batchout_pages;
+ atomic64_t batchout_inflight;
+ atomic64_t fault_cnt;
+ atomic64_t hybridswap_fault_cnt;
+ atomic64_t reout_pages;
+ atomic64_t reout_bytes;
+ atomic64_t zram_stored_pages;
+ atomic64_t zram_stored_size;
+ atomic64_t stored_pages;
+ atomic64_t stored_size;
+ atomic64_t notify_free;
+ atomic64_t frag_cnt;
+ atomic64_t mcg_cnt;
+ atomic64_t eswap_cnt;
+ atomic64_t miss_free;
+ atomic64_t memcgid_clear;
+ atomic64_t skip_track_cnt;
+ atomic64_t used_swap_pages;
+ atomic64_t null_memcg_skip_track_cnt;
+ atomic64_t stored_wm_scale;
+ atomic64_t dropped_eswap_size;
+ atomic64_t io_fail_cnt[HYB_CLASS_BUTT];
+ atomic64_t alloc_fail_cnt[HYB_CLASS_BUTT];
+ struct hybridswapiowrkstat lat[HYB_CLASS_BUTT];
+ struct hybridswap_fault_timeout_cnt fault_stat[2]; /* 0:bg 1:fg */
+ struct hybridswap_fail_record_info record;
+};
+
+struct hybridswap_page_pool {
+ struct list_head page_pool_list;
+ spinlock_t page_pool_lock;
+};
+
+struct io_eswapent {
+ int eswapid;
+ struct zram *zram;
+ struct mem_cgroup *mcg;
+ struct page *pages[ESWAP_PG_CNT];
+ u32 index[ESWAP_MAX_OBJ_CNT];
+ int cnt;
+ int real_load;
+
+ struct hybridswap_page_pool *pool;
+};
+
+struct hybridswap_buffer {
+ struct zram *zram;
+ struct hybridswap_page_pool *pool;
+ struct page **dest_pages;
+};
+
+struct hybridswap_entry {
+ int eswapid;
+ sector_t addr;
+ struct page **dest_pages;
+ int pages_sz;
+ struct list_head list;
+ void *private;
+ void *manager_private;
+};
+
+struct hybridswap_io_req;
+struct hybridswap_io {
+ struct block_device *bdev;
+ enum hybridswap_class class;
+ void (*done_callback)(struct hybridswap_entry *, int, struct hybridswap_io_req *);
+ void (*complete_notify)(void *);
+ void *private;
+ struct hybridswap_key_point_record *record;
+};
+
+struct hybridswap_io_req {
+ struct hybridswap_io io_para;
+ struct kref refcount;
+ struct mutex refmutex;
+ struct wait_queue_head io_wait;
+ atomic_t eswap_doing;
+ struct completion io_end_flag;
+ struct hyb_sgm *segment;
+ bool limit_doing_flag;
+ bool wait_io_finish_flag;
+ int page_cnt;
+ int segment_cnt;
+ int nice;
+ atomic64_t real_load;
+};
+
+/* Change hybridswap_event_item, you should change swapd_text togather*/
+enum hybridswap_event_item {
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ SWAPD_WAKEUP,
+ SWAPD_REFAULT,
+ SWAPD_MEMCG_RATIO_SKIP,
+ SWAPD_MEMCG_REFAULT_SKIP,
+ SWAPD_SHRINK_ANON,
+ SWAPD_SWAPOUT,
+ SWAPD_SKIP_SWAPOUT,
+ SWAPD_EMPTY_ROUND,
+ SWAPD_OVER_MIN_BUFFER_SKIP_TIMES,
+ SWAPD_EMPTY_ROUND_SKIP_TIMES,
+ SWAPD_SNAPSHOT_TIMES,
+ SWAPD_SKIP_SHRINK_OF_WINDOW,
+ SWAPD_MANUAL_PAUSE,
+#ifdef CONFIG_OPLUS_JANK
+ SWAPD_CPU_BUSY_SKIP_TIMES,
+ SWAPD_CPU_BUSY_BREAK_TIMES,
+#endif
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ AKCOMPRESSD_WAKEUP,
+#endif
+ NR_EVENT_ITEMS
+};
+
+struct swapd_event_state {
+ unsigned long event[NR_EVENT_ITEMS];
+};
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+struct cgroup_cache_page {
+ spinlock_t lock;
+ struct list_head head;
+ unsigned int cnt;
+ int id;
+ char compressing;
+ char dead;
+};
+#endif
+
+typedef struct mem_cgroup_hybridswap {
+#ifdef CONFIG_HYBRIDSWAP
+ atomic64_t ufs2zram_scale;
+ atomic_t zram2ufs_scale;
+ atomic64_t app_grade;
+ atomic64_t app_uid;
+ struct list_head grade_node;
+ char name[MEM_CGROUP_NAME_MAX_LEN];
+ struct zram *zram;
+ struct mem_cgroup *memcg;
+ refcount_t usage;
+#endif
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ atomic_t mem2zram_scale;
+ atomic_t pagefault_level;
+ unsigned long long reclaimed_pagefault;
+ long long can_reclaimed;
+#endif
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ unsigned long swap_sorted_list;
+ unsigned long eswap_lru;
+ struct list_head link_list;
+ spinlock_t zram_init_lock;
+ long long can_eswaped;
+
+ atomic64_t zram_stored_size;
+ atomic64_t zram_page_size;
+ unsigned long zram_watermark;
+
+ atomic_t hybridswap_extcnt;
+ atomic_t hybridswap_peakextcnt;
+
+ atomic64_t hybridswap_stored_pages;
+ atomic64_t hybridswap_stored_size;
+ atomic64_t hybridswap_eswap_notify_free;
+
+ atomic64_t hybridswap_outcnt;
+ atomic64_t hybridswap_incnt;
+ atomic64_t hybridswap_allfaultcnt;
+ atomic64_t hybridswap_faultcnt;
+
+ atomic64_t hybridswap_outextcnt;
+ atomic64_t hybridswap_inextcnt;
+
+ struct mutex swap_lock;
+ bool in_swapin;
+ bool force_swapout;
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ struct cgroup_cache_page cache;
+#endif
+}memcg_hybs_t;
+
+#define MEMCGRP_ITEM_DATA(memcg) ((memcg_hybs_t *)(memcg)->android_oem_data1)
+#define MEMCGRP_ITEM(memcg, item) (MEMCGRP_ITEM_DATA(memcg)->item)
+
+extern void __put_memcg_cache(memcg_hybs_t *hybs);
+
+static inline memcg_hybs_t *fetch_memcg_cache(memcg_hybs_t *hybs)
+{
+ refcount_inc(&hybs->usage);
+ return hybs;
+}
+
+static inline void put_memcg_cache(memcg_hybs_t *hybs)
+{
+ if (refcount_dec_and_test(&hybs->usage))
+ __put_memcg_cache(hybs);
+}
+
+DECLARE_PER_CPU(struct swapd_event_state, swapd_event_states);
+extern struct mutex reclaim_para_lock;
+
+static inline void __count_swapd_event(enum hybridswap_event_item item)
+{
+ raw_cpu_inc(swapd_event_states.event[item]);
+}
+
+static inline void count_swapd_event(enum hybridswap_event_item item)
+{
+ this_cpu_inc(swapd_event_states.event[item]);
+}
+
+static inline void __count_swapd_events(enum hybridswap_event_item item, long delta)
+{
+ raw_cpu_add(swapd_event_states.event[item], delta);
+}
+
+static inline void count_swapd_events(enum hybridswap_event_item item, long delta)
+{
+ this_cpu_add(swapd_event_states.event[item], delta);
+}
+
+void *hybridswap_malloc(size_t size, bool fast, bool nofail);
+void hybridswap_free(const void *mem);
+unsigned long hybridswap_zsmalloc(struct zs_pool *zs_pool,
+ size_t size, struct hybridswap_page_pool *pool);
+struct page *hybridswap_alloc_page(
+ struct hybridswap_page_pool *pool, gfp_t gfp,
+ bool fast, bool nofail);
+void hybridswap_page_recycle(struct page *page,
+ struct hybridswap_page_pool *pool);
+struct hybstatus *hybridswap_fetch_stat_obj(void);
+int hybridswap_manager_init(struct zram *zram);
+void hybridswap_manager_memcg_init(struct zram *zram,
+ struct mem_cgroup *memcg);
+void hybridswap_manager_memcg_deinit(struct mem_cgroup *mcg);
+void hybridswap_swap_sorted_list_add(struct zram *zram, u32 index,
+ struct mem_cgroup *memcg);
+void hybridswap_swap_sorted_list_del(struct zram *zram, u32 index);
+unsigned long hybridswap_eswap_create(struct mem_cgroup *memcg,
+ int *eswapid,
+ struct hybridswap_buffer *dest_buf,
+ void **private);
+void hybridswap_eswap_register(void *private, struct hybridswap_io_req *req);
+void hybridswap_eswap_objs_del(struct zram *zram, u32 index);
+int hybridswap_find_eswap_by_index(
+ unsigned long eswpentry, struct hybridswap_buffer *buf, void **private);
+int hybridswap_find_eswap_by_memcg(
+ struct mem_cgroup *mcg,
+ struct hybridswap_buffer *dest_buf, void **private);
+void hybridswap_eswap_destroy(void *private, enum hybridswap_class class);
+void hybridswap_eswap_exception(enum hybridswap_class class,
+ void *private);
+void hybridswap_manager_deinit(struct zram *zram);
+struct mem_cgroup *hybridswap_zram_fetch_mcg(struct zram *zram, u32 index);
+int hyb_io_work_begin(void);
+void *hybridswap_plug_start(struct hybridswap_io *io_para);
+int hybridswap_read_eswap(void *iohandle,
+ struct hybridswap_entry *ioentry);
+int hybridswap_write_eswap(void *iohandle,
+ struct hybridswap_entry *ioentry);
+
+int hybridswap_plug_finish(void *iohandle);
+
+void hybperf_start(
+ struct hybridswap_key_point_record *record,
+ ktime_t stsrt, unsigned long long start_ravg_sum,
+ enum hybridswap_class class);
+
+void hybperf_end(struct hybridswap_key_point_record *record);
+
+void hybperfiowrkstart(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type);
+
+void hybperfiowrkend(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type);
+
+void hybperfiowrkpoint(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type);
+
+void hybperf_async_perf(
+ struct hybridswap_key_point_record *record,
+ enum hybridswap_key_point type, ktime_t start,
+ unsigned long long start_ravg_sum);
+
+void hybperf_io_stat(
+ struct hybridswap_key_point_record *record, int page_cnt,
+ int segment_cnt);
+
+static inline unsigned long long hybridswap_fetch_ravg_sum(void)
+{
+ return 0;
+}
+
+void hybridswap_fail_record(enum hybridswap_fail_point point,
+ u32 index, int eswapid, unsigned char *task_comm);
+bool hybridswap_reach_life_protect(void);
+struct workqueue_struct *hybridswap_fetch_reclaim_workqueue(void);
+extern struct mem_cgroup *fetch_next_memcg(struct mem_cgroup *prev);
+extern void fetch_next_memcg_break(struct mem_cgroup *prev);
+extern memcg_hybs_t *hybridswap_cache_alloc(struct mem_cgroup *memcg, bool atomic);
+extern void memcg_app_grade_resort(void);
+extern unsigned long memcg_anon_pages(struct mem_cgroup *memcg);
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+extern bool hybridswap_core_enabled(void);
+extern bool hybridswap_out_to_eswap_enable(void);
+extern void hybridswap_mem_cgroup_deinit(struct mem_cgroup *memcg);
+extern unsigned long hybridswap_out_to_eswap(unsigned long size);
+extern int hybridswap_batches(struct mem_cgroup *mcg,
+ unsigned long size, bool preload);
+extern unsigned long zram_zsmalloc(struct zs_pool *zs_pool,
+ size_t size, gfp_t gfp);
+extern struct task_struct *fetch_task_from_proc(struct inode *inode);
+extern unsigned long long hybridswap_fetch_zram_pagefault(void);
+extern bool hybridswap_reclaim_work_running(void);
+extern void hybridswap_force_reclaim(struct mem_cgroup *mcg);
+extern bool hybridswap_stored_wm_ok(void);
+extern void mem_cgroup_id_remove_hook(void *data, struct mem_cgroup *memcg);
+extern int mem_cgroup_stored_wm_scale_write(
+ struct cgroup_subsys_state *css, struct cftype *cft, s64 val);
+extern s64 mem_cgroup_stored_wm_scale_read(
+ struct cgroup_subsys_state *css, struct cftype *cft);
+extern bool hybridswap_delete(struct zram *zram, u32 index);
+extern int hybridswap_stored_info(unsigned long *total, unsigned long *used);
+
+extern unsigned long long hybridswap_read_mcg_stats(
+ struct mem_cgroup *mcg, enum hybridswap_mcg_member mcg_member);
+extern int hybridswap_core_enable(void);
+extern void hybridswap_core_disable(void);
+extern int hybridswap_psi_show(struct seq_file *m, void *v);
+#else
+static inline unsigned long long hybridswap_read_mcg_stats(
+ struct mem_cgroup *mcg, enum hybridswap_mcg_member mcg_member)
+{
+ return 0;
+}
+
+static inline unsigned long long hybridswap_fetch_zram_pagefault(void)
+{
+ return 0;
+}
+
+static inline bool hybridswap_reclaim_work_running(void)
+{
+ return false;
+}
+
+static inline bool hybridswap_core_enabled(void) { return false; }
+static inline bool hybridswap_out_to_eswap_enable(void) { return false; }
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+extern atomic_long_t page_fault_pause;
+extern atomic_long_t page_fault_pause_cnt;
+extern struct cftype mem_cgroup_swapd_legacy_files[];
+extern bool zram_watermark_ok(void);
+extern void wake_all_swapd(void);
+extern void alloc_pages_slowpath_hook(void *data, gfp_t gfp_mask,
+ unsigned int order, unsigned long delta);
+extern void rmqueue_hook(void *data, struct zone *preferred_zone,
+ struct zone *zone, unsigned int order, gfp_t gfp_flags,
+ unsigned int alloc_flags, int migratetype);
+extern void __init swapd_pre_init(void);
+extern void swapd_pre_deinit(void);
+extern void update_swapd_mcg_setup(struct mem_cgroup *memcg);
+extern bool free_zram_is_ok(void);
+extern unsigned long fetch_nr_zram_total(void);
+extern int swapd_init(struct zram *zram);
+extern void swapd_exit(void);
+extern bool hybridswap_swapd_enabled(void);
+#else
+static inline bool hybridswap_swapd_enabled(void) { return false; }
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+extern spinlock_t cached_idr_lock;
+extern struct idr cached_idr;
+
+extern void __init akcompressd_pre_init(void);
+extern void __exit akcompressd_pre_deinit(void);
+extern int create_akcompressd_task(struct zram *zram);
+extern void clear_page_memcg(struct cgroup_cache_page *cache);
+#endif
+
+#endif /* end of HYBRIDSWAP_INTERNAL_H */
diff --git a/drivers/block/zram/hybridswap/hybridswap_main.c b/drivers/block/zram/hybridswap/hybridswap_main.c
new file mode 100644
index 000000000000..88d84bd023ee
--- /dev/null
+++ b/drivers/block/zram/hybridswap/hybridswap_main.c
@@ -0,0 +1,1029 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020-2022 Oplus. All rights reserved.
+ */
+
+#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "../zram_drv.h"
+#include "../zram_drv_internal.h"
+#include "hybridswap_internal.h"
+#include "hybridswap.h"
+
+static const char *swapd_text[NR_EVENT_ITEMS] = {
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ "swapd_wakeup",
+ "swapd_hit_pagefaults",
+ "swapd_memcg_scale_skip",
+ "swapd_memcg_pagefault_skip",
+ "swapd_shrink_anon",
+ "swapd_swapout",
+ "swapd_skip_swapout",
+ "swapd_nothing_ignore",
+ "swapd_over_min_buffer_skip_times",
+ "swapd_nothing_ignore_skip_times",
+ "swapd_snapshot_times",
+ "swapd_skip_shrink_of_window",
+ "swapd_manual_pause",
+#ifdef CONFIG_OPLUS_JANK
+ "swapd_cpu_busy_skip_times",
+ "swapd_cpu_busy_break_times",
+#endif
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ "akcompressd_running",
+#endif
+};
+
+enum scan_balance {
+ SCAN_EQUAL,
+ SCAN_FRACT,
+ SCAN_ANON,
+ SCAN_FILE,
+};
+
+static int log_level = HYB_MAX;
+static struct kmem_cache *hybridswap_cache;
+static struct list_head grade_head;
+static DEFINE_SPINLOCK(grade_list_lock);
+static DEFINE_MUTEX(hybridswap_enable_lock);
+static bool hybridswap_enabled = false;
+
+DEFINE_MUTEX(reclaim_para_lock);
+DEFINE_PER_CPU(struct swapd_event_state, swapd_event_states);
+
+extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
+ unsigned long nr_pages,
+ gfp_t gfp_mask,
+ bool may_swap);
+
+void hybridswap_loglevel_set(int level)
+{
+ log_level = level;
+}
+
+int hybridswap_loglevel(void)
+{
+ return log_level;
+}
+
+void __put_memcg_cache(memcg_hybs_t *hybs)
+{
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ if (hybs->cache.id > 0) {
+ spin_lock(&cached_idr_lock);
+ idr_replace(&cached_idr, NULL, hybs->cache.id);
+ idr_remove(&cached_idr, hybs->cache.id);
+ spin_unlock(&cached_idr_lock);
+ }
+
+ spin_lock(&hybs->cache.lock);
+ if (hybs->cache.dead != 1)
+ BUG();
+ spin_unlock(&hybs->cache.lock);
+#endif
+ kmem_cache_free(hybridswap_cache, (void *)hybs);
+}
+
+static inline void sum_hybridswap_vm_events(unsigned long *ret)
+{
+ int cpu;
+ int i;
+
+ memset(ret, 0, NR_EVENT_ITEMS * sizeof(unsigned long));
+
+ for_each_online_cpu(cpu) {
+ struct swapd_event_state *this =
+ &per_cpu(swapd_event_states, cpu);
+
+ for (i = 0; i < NR_EVENT_ITEMS; i++)
+ ret[i] += this->event[i];
+ }
+}
+
+static inline void all_hybridswap_vm_events(unsigned long *ret)
+{
+ get_online_cpus();
+ sum_hybridswap_vm_events(ret);
+ put_online_cpus();
+}
+
+ssize_t hybridswap_vmstat_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ unsigned long *vm_buf = NULL;
+ int len = 0;
+ int i = 0;
+
+ vm_buf = kzalloc(sizeof(struct swapd_event_state), GFP_KERNEL);
+ if (!vm_buf)
+ return -ENOMEM;
+ all_hybridswap_vm_events(vm_buf);
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ len += snprintf(buf + len, PAGE_SIZE - len, "%-32s %12lu\n",
+ "page_fault_pause", atomic_long_read(&page_fault_pause));
+ len += snprintf(buf + len, PAGE_SIZE - len, "%-32s %12lu\n",
+ "page_fault_pause_cnt", atomic_long_read(&page_fault_pause_cnt));
+#endif
+
+ for (;i < NR_EVENT_ITEMS; i++) {
+ len += snprintf(buf + len, PAGE_SIZE - len, "%-32s %12lu\n",
+ swapd_text[i], vm_buf[i]);
+ if (len == PAGE_SIZE)
+ break;
+ }
+ kfree(vm_buf);
+
+ return len;
+}
+
+ssize_t hybridswap_loglevel_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ char *type_buf = NULL;
+ unsigned long val;
+
+ type_buf = strstrip((char *)buf);
+ if (kstrtoul(type_buf, 0, &val))
+ return -EINVAL;
+
+ if (val >= HYB_MAX) {
+ hybp(HYB_ERR, "val %lu is not valid\n", val);
+ return -EINVAL;
+ }
+ hybridswap_loglevel_set((int)val);
+
+ return len;
+}
+
+ssize_t hybridswap_loglevel_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ ssize_t size = 0;
+
+ size += scnprintf(buf + size, PAGE_SIZE - size,
+ "Hybridswap log level: %d\n", hybridswap_loglevel());
+
+ return size;
+}
+
+/* Make sure the memcg is not NULL in caller */
+memcg_hybs_t *hybridswap_cache_alloc(struct mem_cgroup *memcg, bool atomic)
+{
+ memcg_hybs_t *hybs;
+ u64 ret;
+ gfp_t flags = GFP_KERNEL;
+
+ if (memcg->android_oem_data1)
+ BUG();
+
+ if (atomic)
+ flags &= ~__GFP_DIRECT_RECLAIM;
+
+ hybs = (memcg_hybs_t *)kmem_cache_zalloc(hybridswap_cache, flags);
+ if (!hybs)
+ return NULL;
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ spin_lock_init(&hybs->cache.lock);
+ INIT_LIST_HEAD(&hybs->cache.head);
+ hybs->cache.cnt = 0;
+ hybs->cache.compressing = 0;
+ hybs->cache.dead = 0;
+ spin_lock(&cached_idr_lock);
+ hybs->cache.id = idr_alloc(&cached_idr, NULL, 1, MEM_CGROUP_ID_MAX,
+ GFP_KERNEL);
+ if (hybs->cache.id < 0) {
+ spin_unlock(&cached_idr_lock);
+ kmem_cache_free(hybridswap_cache, (void*)hybs);
+ return NULL;
+ }
+ idr_replace(&cached_idr, &hybs->cache, hybs->cache.id);
+ spin_unlock(&cached_idr_lock);
+#endif
+ INIT_LIST_HEAD(&hybs->grade_node);
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ spin_lock_init(&hybs->zram_init_lock);
+#endif
+ atomic64_set(&hybs->app_grade, 300);
+ atomic64_set(&hybs->ufs2zram_scale, 100);
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ atomic_set(&hybs->mem2zram_scale, 80);
+ atomic_set(&hybs->zram2ufs_scale, 50);
+ atomic_set(&hybs->pagefault_level, 50);
+#endif
+ hybs->memcg = memcg;
+ refcount_set(&hybs->usage, 1);
+
+ ret = atomic64_cmpxchg((atomic64_t *)&memcg->android_oem_data1, 0, (u64)hybs);
+ if (ret != 0) {
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ hybs->cache.dead = 1;
+#endif
+ put_memcg_cache(hybs);
+ return (memcg_hybs_t *)ret;
+ }
+
+ return hybs;
+}
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+static void tune_scan_type_hook(void *data, char *scan_balance)
+{
+ /*hybrid swapd,scan anon only*/
+ if (current_is_swapd()) {
+ *scan_balance = SCAN_ANON;
+ return;
+ }
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ if (unlikely(!hybridswap_core_enabled()))
+ return;
+
+ /*real zram full, scan file only*/
+ if (!free_zram_is_ok()) {
+ *scan_balance = SCAN_FILE;
+ return;
+ }
+#endif
+}
+#endif
+
+static void mem_cgroup_alloc_hook(void *data, struct mem_cgroup *memcg)
+{
+ if (memcg->android_oem_data1)
+ BUG();
+
+ hybridswap_cache_alloc(memcg, true);
+}
+
+static void mem_cgroup_free_hook(void *data, struct mem_cgroup *memcg)
+{
+ memcg_hybs_t *hybs;
+
+ if (!memcg->android_oem_data1)
+ return;
+
+ hybs = (memcg_hybs_t *)memcg->android_oem_data1;
+ memcg->android_oem_data1 = 0;
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ clear_page_memcg(&hybs->cache);
+#endif
+ put_memcg_cache(hybs);
+}
+
+void memcg_app_grade_update(struct mem_cgroup *tarfetch)
+{
+ struct list_head *pos = NULL;
+ unsigned long flags;
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ update_swapd_mcg_setup(tarfetch);
+#endif
+ spin_lock_irqsave(&grade_list_lock, flags);
+ list_for_each(pos, &grade_head) {
+ memcg_hybs_t *hybs = list_entry(pos, memcg_hybs_t, grade_node);
+ if (atomic64_read(&hybs->app_grade) <
+ atomic64_read(&MEMCGRP_ITEM(tarfetch, app_grade)))
+ break;
+ }
+ list_move_tail(&MEMCGRP_ITEM(tarfetch, grade_node), pos);
+ spin_unlock_irqrestore(&grade_list_lock, flags);
+}
+
+static void mem_cgroup_css_online_hook(void *data,
+ struct cgroup_subsys_state *css, struct mem_cgroup *memcg)
+{
+ if (memcg->android_oem_data1)
+ memcg_app_grade_update(memcg);
+
+ css_get(css);
+}
+
+static void mem_cgroup_css_offline_hook(void *data,
+ struct cgroup_subsys_state *css, struct mem_cgroup *memcg)
+{
+ unsigned long flags;
+
+ if (memcg->android_oem_data1) {
+ spin_lock_irqsave(&grade_list_lock, flags);
+ list_del_init(&MEMCGRP_ITEM(memcg, grade_node));
+ spin_unlock_irqrestore(&grade_list_lock, flags);
+ }
+
+ css_put(css);
+}
+
+#define REGISTER_HOOK(name) do {\
+ rc = register_trace_android_vh_##name(name##_hook, NULL);\
+ if (rc) {\
+ hybp(HYB_ERR, "%s:%d register hook %s failed", __FILE__, __LINE__, #name);\
+ goto err_out_##name;\
+ }\
+} while (0)
+
+#define UNREGISTER_HOOK(name) do {\
+ unregister_trace_android_vh_##name(name##_hook, NULL);\
+} while (0)
+
+#define ERROR_OUT(name) err_out_##name
+
+static int register_all_hooks(void)
+{
+ int rc;
+
+ /* mem_cgroup_alloc_hook */
+ REGISTER_HOOK(mem_cgroup_alloc);
+ /* mem_cgroup_free_hook */
+ REGISTER_HOOK(mem_cgroup_free);
+ /* mem_cgroup_css_online_hook */
+ REGISTER_HOOK(mem_cgroup_css_online);
+ /* mem_cgroup_css_offline_hook */
+ REGISTER_HOOK(mem_cgroup_css_offline);
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ /* rmqueue_hook */
+ REGISTER_HOOK(rmqueue);
+ /* tune_scan_type_hook */
+ REGISTER_HOOK(tune_scan_type);
+#endif
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ /* mem_cgroup_id_remove_hook */
+ REGISTER_HOOK(mem_cgroup_id_remove);
+#endif
+ return 0;
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ UNREGISTER_HOOK(mem_cgroup_id_remove);
+ERROR_OUT(mem_cgroup_id_remove):
+#endif
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ UNREGISTER_HOOK(tune_scan_type);
+ERROR_OUT(tune_scan_type):
+ UNREGISTER_HOOK(rmqueue);
+ERROR_OUT(rmqueue):
+#endif
+ UNREGISTER_HOOK(mem_cgroup_css_offline);
+ERROR_OUT(mem_cgroup_css_offline):
+ UNREGISTER_HOOK(mem_cgroup_css_online);
+ERROR_OUT(mem_cgroup_css_online):
+ UNREGISTER_HOOK(mem_cgroup_free);
+ERROR_OUT(mem_cgroup_free):
+ UNREGISTER_HOOK(mem_cgroup_alloc);
+ERROR_OUT(mem_cgroup_alloc):
+ return rc;
+}
+
+static void unregister_all_hook(void)
+{
+ UNREGISTER_HOOK(mem_cgroup_alloc);
+ UNREGISTER_HOOK(mem_cgroup_free);
+ UNREGISTER_HOOK(mem_cgroup_css_offline);
+ UNREGISTER_HOOK(mem_cgroup_css_online);
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ UNREGISTER_HOOK(mem_cgroup_id_remove);
+#endif
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ UNREGISTER_HOOK(rmqueue);
+ UNREGISTER_HOOK(tune_scan_type);
+#endif
+}
+
+unsigned long memcg_anon_pages(struct mem_cgroup *memcg)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
+ struct lruvec *lruvec = NULL;
+ struct mem_cgroup_per_node *mz = NULL;
+#endif
+ if (!memcg)
+ return 0;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
+ mz = mem_cgroup_nodeinfo(memcg, 0);
+ if (!mz) {
+ fetch_next_memcg_break(memcg);
+ return 0;
+ }
+
+ lruvec = &mz->lruvec;
+ if (!lruvec) {
+ fetch_next_memcg_break(memcg);
+ return 0;
+ }
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)
+ return (mem_cgroup_get_lru_size(lruvec, LRU_ACTIVE_ANON) +
+ mem_cgroup_get_lru_size(lruvec, LRU_INACTIVE_ANON));
+#else
+ return (lruvec_page_state(lruvec, NR_ACTIVE_ANON) +
+ lruvec_page_state(lruvec, NR_INACTIVE_ANON));
+#endif
+#else
+ return (memcg_page_state_local(memcg, NR_ACTIVE_ANON) +
+ memcg_page_state_local(memcg, NR_INACTIVE_ANON));
+#endif
+}
+
+static unsigned long memcg_inactive_anon_pages(struct mem_cgroup *memcg)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
+ struct lruvec *lruvec = NULL;
+ struct mem_cgroup_per_node *mz = NULL;
+#endif
+
+ if (!memcg)
+ return 0;
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
+ mz = mem_cgroup_nodeinfo(memcg, 0);
+ if (!mz) {
+ fetch_next_memcg_break(memcg);
+ return 0;
+ }
+
+ lruvec = &mz->lruvec;
+ if (!lruvec) {
+ fetch_next_memcg_break(memcg);
+ return 0;
+ }
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)
+ return mem_cgroup_get_lru_size(lruvec, LRU_INACTIVE_ANON);
+#else
+ return lruvec_page_state(lruvec, NR_INACTIVE_ANON);
+#endif
+#else
+ return memcg_page_state_local(memcg, NR_INACTIVE_ANON);
+#endif
+}
+
+static ssize_t mem_cgroup_force_shrink_anon(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ struct mem_cgroup *memcg;
+ unsigned long nr_need_reclaim, reclaim_total, nr_reclaimed;
+ int ret;
+
+ buf = strstrip(buf);
+ ret = kstrtoul(buf, 0, &reclaim_total);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "reclaim_total %s value is error!\n", buf);
+ return -EINVAL;
+ }
+
+ memcg = mem_cgroup_from_css(of_css(of));
+
+ if (reclaim_total)
+ nr_need_reclaim = memcg_anon_pages(memcg);
+ else
+ nr_need_reclaim = memcg_inactive_anon_pages(memcg);
+
+ nr_reclaimed = try_to_free_mem_cgroup_pages(memcg, nr_need_reclaim,
+ GFP_KERNEL, true);
+
+ return nbytes;
+}
+
+static int memcg_total_info_per_app_show(struct seq_file *m, void *v)
+{
+ struct mem_cgroup *memcg = NULL;
+ unsigned long anon_size;
+ unsigned long zram_compress_size;
+ unsigned long eswap_compress_size;
+ unsigned long zram_page_size;
+ unsigned long eswap_page_size;
+
+ seq_printf(m, "%-8s %-8s %-8s %-8s %-8s %s \n",
+ "anon", "zram_c", "zram_p", "eswap_c", "eswap_p",
+ "memcg_n");
+ while ((memcg = fetch_next_memcg(memcg))) {
+ if (!MEMCGRP_ITEM_DATA(memcg))
+ continue;
+
+ anon_size = memcg_anon_pages(memcg);
+ zram_compress_size = hybridswap_read_mcg_stats(memcg,
+ MCG_ZRAM_STORED_SZ);
+ eswap_compress_size = hybridswap_read_mcg_stats(memcg,
+ MCG_DISK_STORED_SZ);
+ zram_page_size = hybridswap_read_mcg_stats(memcg,
+ MCG_ZRAM_STORED_PG_SZ);
+ eswap_page_size = hybridswap_read_mcg_stats(memcg,
+ MCG_DISK_STORED_PG_SZ);
+
+ anon_size *= PAGE_SIZE / SZ_1K;
+ zram_compress_size /= SZ_1K;
+ eswap_compress_size /= SZ_1K;
+ zram_page_size *= PAGE_SIZE / SZ_1K;
+ eswap_page_size *= PAGE_SIZE / SZ_1K;
+
+ seq_printf(m, "%-8lu %-8lu %-8lu %-8lu %-8lu %s \n",
+ anon_size, zram_compress_size, zram_page_size,
+ eswap_compress_size, eswap_page_size,
+ MEMCGRP_ITEM(memcg, name));
+ }
+
+ return 0;
+}
+
+static int memcg_swap_stat_show(struct seq_file *m, void *v)
+{
+ struct mem_cgroup *memcg = NULL;
+ unsigned long eswap_out_cnt;
+ unsigned long eswap_out_size;
+ unsigned long eswap_in_size;
+ unsigned long eswap_in_cnt;
+ unsigned long page_fault_cnt;
+ unsigned long cur_eswap_size;
+ unsigned long max_eswap_size;
+ unsigned long zram_compress_size, zram_page_size;
+ unsigned long eswap_compress_size, eswap_page_size;
+
+ memcg = mem_cgroup_from_css(seq_css(m));
+
+ zram_compress_size = hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_SZ);
+ zram_page_size = hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_PG_SZ);
+ eswap_compress_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_SZ);
+ eswap_page_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_PG_SZ);
+
+ eswap_out_cnt = hybridswap_read_mcg_stats(memcg, MCG_ESWAPOUT_CNT);
+ eswap_out_size = hybridswap_read_mcg_stats(memcg, MCG_ESWAPOUT_SZ);
+ eswap_in_size = hybridswap_read_mcg_stats(memcg, MCG_ESWAPIN_SZ);
+ eswap_in_cnt = hybridswap_read_mcg_stats(memcg, MCG_ESWAPIN_CNT);
+ page_fault_cnt = hybridswap_read_mcg_stats(memcg, MCG_DISK_FAULT_CNT);
+ cur_eswap_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_SPACE);
+ max_eswap_size = hybridswap_read_mcg_stats(memcg, MCG_DISK_SPACE_PEAK);
+
+ seq_printf(m, "%-32s %12lu KB\n", "zramCompressedSize:",
+ zram_compress_size / SZ_1K);
+ seq_printf(m, "%-32s %12lu KB\n", "zramOrignalSize:",
+ zram_page_size << (PAGE_SHIFT - 10));
+ seq_printf(m, "%-32s %12lu KB\n", "eswapCompressedSize:",
+ eswap_compress_size / SZ_1K);
+ seq_printf(m, "%-32s %12lu KB\n", "eswapOrignalSize:",
+ eswap_page_size << (PAGE_SHIFT - 10));
+ seq_printf(m, "%-32s %12lu \n", "eswapOutTotal:", eswap_out_cnt);
+ seq_printf(m, "%-32s %12lu KB\n", "eswapOutSize:", eswap_out_size / SZ_1K);
+ seq_printf(m, "%-32s %12lu\n", "eswapInTotal:", eswap_in_cnt);
+ seq_printf(m, "%-32s %12lu KB\n", "eswapInSize:", eswap_in_size / SZ_1K);
+ seq_printf(m, "%-32s %12lu\n", "pageInTotal:", page_fault_cnt);
+ seq_printf(m, "%-32s %12lu KB\n", "eswapSizeCur:", cur_eswap_size / SZ_1K);
+ seq_printf(m, "%-32s %12lu KB\n", "eswapSizeMax:", max_eswap_size / SZ_1K);
+
+ return 0;
+}
+
+static ssize_t mem_cgroup_name_write(struct kernfs_open_file *of, char *buf,
+ size_t nbytes, loff_t off)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
+ memcg_hybs_t *hybp = MEMCGRP_ITEM_DATA(memcg);
+ int len, w_len;
+
+ if (!hybp)
+ return -EINVAL;
+
+ buf = strstrip(buf);
+ len = strlen(buf) + 1;
+ if (len > MEM_CGROUP_NAME_MAX_LEN)
+ len = MEM_CGROUP_NAME_MAX_LEN;
+
+ w_len = snprintf(hybp->name, len, "%s", buf);
+ if (w_len > len)
+ hybp->name[len - 1] = '\0';
+
+ return nbytes;
+}
+
+static int mem_cgroup_name_show(struct seq_file *m, void *v)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
+
+ if (!MEMCGRP_ITEM_DATA(memcg))
+ return -EPERM;
+
+ seq_printf(m, "%s\n", MEMCGRP_ITEM(memcg, name));
+
+ return 0;
+}
+
+static int mem_cgroup_app_grade_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ struct mem_cgroup *memcg;
+ memcg_hybs_t *hybs;
+
+ if (val > MAX_APP_GRADE || val < 0)
+ return -EINVAL;
+
+ memcg = mem_cgroup_from_css(css);
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ if (!hybs) {
+ hybs = hybridswap_cache_alloc(memcg, false);
+ if (!hybs)
+ return -EINVAL;
+ }
+
+ if (atomic64_read(&MEMCGRP_ITEM(memcg, app_grade)) != val)
+ atomic64_set(&MEMCGRP_ITEM(memcg, app_grade), val);
+ memcg_app_grade_update(memcg);
+
+ return 0;
+}
+
+static s64 mem_cgroup_app_grade_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+
+ if (!MEMCGRP_ITEM_DATA(memcg))
+ return -EPERM;
+
+ return atomic64_read(&MEMCGRP_ITEM(memcg, app_grade));
+}
+
+int mem_cgroup_app_uid_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ struct mem_cgroup *memcg;
+ memcg_hybs_t *hybs;
+
+ if (val < 0)
+ return -EINVAL;
+
+ memcg = mem_cgroup_from_css(css);
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ if (!hybs) {
+ return -EINVAL;
+ }
+
+ if (atomic64_read(&MEMCGRP_ITEM(memcg, app_uid)) != val)
+ atomic64_set(&MEMCGRP_ITEM(memcg, app_uid), val);
+
+ return 0;
+}
+
+static s64 mem_cgroup_app_uid_read(struct cgroup_subsys_state *css, struct cftype *cft)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+
+ if (!MEMCGRP_ITEM_DATA(memcg))
+ return -EPERM;
+
+ return atomic64_read(&MEMCGRP_ITEM(memcg, app_uid));
+}
+
+static int mem_cgroup_ufs2zram_scale_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+
+ if (!MEMCGRP_ITEM_DATA(memcg))
+ return -EPERM;
+
+ if (val > MAX_RATIO || val < MIN_RATIO)
+ return -EINVAL;
+
+ atomic64_set(&MEMCGRP_ITEM(memcg, ufs2zram_scale), val);
+
+ return 0;
+}
+
+static s64 mem_cgroup_ufs2zram_scale_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+
+ if (!MEMCGRP_ITEM_DATA(memcg))
+ return -EPERM;
+
+ return atomic64_read(&MEMCGRP_ITEM(memcg, ufs2zram_scale));
+}
+
+static int mem_cgroup_force_swapin_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(css);
+ memcg_hybs_t *hybs;
+ unsigned long size = 0;
+ const unsigned int scale = 100;
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ if (!hybs)
+ return -EPERM;
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ size = atomic64_read(&hybs->hybridswap_stored_size);
+#endif
+ size = atomic64_read(&hybs->ufs2zram_scale) * size / scale;
+ size = ESWAP_ALIGN_UP(size);
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ hybridswap_batches(memcg, size, val ? true : false);
+#endif
+
+ return 0;
+}
+
+static int mem_cgroup_force_swapout_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ hybridswap_force_reclaim(mem_cgroup_from_css(css));
+#endif
+ return 0;
+}
+
+struct mem_cgroup *fetch_next_memcg(struct mem_cgroup *prev)
+{
+ memcg_hybs_t *hybs = NULL;
+ struct mem_cgroup *memcg = NULL;
+ struct list_head *pos = NULL;
+ unsigned long flags;
+ bool prev_got = true;
+
+ spin_lock_irqsave(&grade_list_lock, flags);
+find_again:
+ if (unlikely(!prev))
+ pos = &grade_head;
+ else
+ pos = &MEMCGRP_ITEM(prev, grade_node);
+
+ if (list_empty(pos)) /* deleted node */
+ goto unlock;
+
+ if (pos->next == &grade_head)
+ goto unlock;
+
+ hybs = list_entry(pos->next, struct mem_cgroup_hybridswap, grade_node);
+ memcg = hybs->memcg;
+ if (unlikely(!memcg))
+ goto unlock;
+
+ if (!css_tryget(&memcg->css)) {
+ if (prev && prev_got)
+ css_put(&prev->css);
+ prev = memcg;
+ prev_got = false;
+ goto find_again;
+ }
+
+unlock:
+ spin_unlock_irqrestore(&grade_list_lock, flags);
+ if (prev && prev_got)
+ css_put(&prev->css);
+
+ return memcg;
+}
+
+void fetch_next_memcg_break(struct mem_cgroup *memcg)
+{
+ if (memcg)
+ css_put(&memcg->css);
+}
+
+static struct cftype mem_cgroup_hybridswap_legacy_files[] = {
+ {
+ .name = "force_shrink_anon",
+ .write = mem_cgroup_force_shrink_anon,
+ },
+ {
+ .name = "total_info_per_app",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .seq_show = memcg_total_info_per_app_show,
+ },
+ {
+ .name = "swap_stat",
+ .seq_show = memcg_swap_stat_show,
+ },
+ {
+ .name = "name",
+ .write = mem_cgroup_name_write,
+ .seq_show = mem_cgroup_name_show,
+ },
+ {
+ .name = "app_score",
+ .write_s64 = mem_cgroup_app_grade_write,
+ .read_s64 = mem_cgroup_app_grade_read,
+ },
+ {
+ .name = "app_uid",
+ .write_s64 = mem_cgroup_app_uid_write,
+ .read_s64 = mem_cgroup_app_uid_read,
+ },
+ {
+ .name = "ub_ufs2zram_ratio",
+ .write_s64 = mem_cgroup_ufs2zram_scale_write,
+ .read_s64 = mem_cgroup_ufs2zram_scale_read,
+ },
+ {
+ .name = "force_swapin",
+ .write_s64 = mem_cgroup_force_swapin_write,
+ },
+ {
+ .name = "force_swapout",
+ .write_s64 = mem_cgroup_force_swapout_write,
+ },
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ {
+ .name = "psi",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .seq_show = hybridswap_psi_show,
+ },
+ {
+ .name = "stored_wm_ratio",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = mem_cgroup_stored_wm_scale_write,
+ .read_s64 = mem_cgroup_stored_wm_scale_read,
+ },
+#endif
+ { }, /* terminate */
+};
+
+static int hybridswap_enable(struct zram *zram)
+{
+ int ret = 0;
+
+ if (hybridswap_enabled) {
+ hybp(HYB_WARN, "hybridswap_enabled is true\n");
+ return ret;
+ }
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ ret = swapd_init(zram);
+ if (ret)
+ return ret;
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ ret = create_akcompressd_task(zram);
+ if (ret)
+ goto create_akcompressd_task_fail;
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ ret = hybridswap_core_enable();
+ if (ret)
+ goto hybridswap_core_enable_fail;
+#endif
+ hybridswap_enabled = true;
+
+ return 0;
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+hybridswap_core_enable_fail:
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ destroy_akcompressd_task(zram);
+create_akcompressd_task_fail:
+#endif
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ swapd_exit();
+#endif
+ return ret;
+}
+
+static void hybridswap_disable(struct zram * zram)
+{
+ if (!hybridswap_enabled) {
+ hybp(HYB_WARN, "hybridswap_enabled is false\n");
+ return;
+ }
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ hybridswap_core_disable();
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ destroy_akcompressd_task(zram);
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ swapd_exit();
+#endif
+ hybridswap_enabled = false;
+}
+
+ssize_t hybridswap_enable_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int len = snprintf(buf, PAGE_SIZE, "hybridswap %s out_to_eswap %s swapd %s\n",
+ hybridswap_core_enabled() ? "enable" : "disable",
+ hybridswap_out_to_eswap_enable() ? "enable" : "disable",
+ hybridswap_swapd_enabled() ? "enable" : "disable");
+
+ return len;
+}
+
+ssize_t hybridswap_enable_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ int ret;
+ unsigned long val;
+ char *kbuf;
+ struct zram *zram;
+
+ kbuf = strstrip((char *)buf);
+ ret = kstrtoul(kbuf, 0, &val);
+ if (unlikely(ret)) {
+ hybp(HYB_ERR, "val %s is invalid!\n", kbuf);
+
+ return -EINVAL;
+ }
+
+ mutex_lock(&hybridswap_enable_lock);
+ zram = dev_to_zram(dev);
+ if (val == 0)
+ hybridswap_disable(zram);
+ else
+ ret = hybridswap_enable(zram);
+ mutex_unlock(&hybridswap_enable_lock);
+
+ if (ret == 0)
+ ret = len;
+ return ret;
+}
+
+int __init hybridswap_pre_init(void)
+{
+ int ret;
+
+ INIT_LIST_HEAD(&grade_head);
+ log_level = HYB_INFO;
+
+ hybridswap_cache = kmem_cache_create("mem_cgroup_hybridswap",
+ sizeof(struct mem_cgroup_hybridswap),
+ 0, SLAB_PANIC, NULL);
+ if (!hybridswap_cache) {
+ hybp(HYB_ERR, "create hybridswap_cache failed\n");
+ ret = -ENOMEM;
+ return ret;
+ }
+
+ ret = cgroup_add_legacy_cftypes(&memory_cgrp_subsys,
+ mem_cgroup_hybridswap_legacy_files);
+ if (ret) {
+ hybp(HYB_INFO, "add mem_cgroup_hybridswap_legacy_files failed\n");
+ goto error_out;
+ }
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ ret = cgroup_add_legacy_cftypes(&memory_cgrp_subsys,
+ mem_cgroup_swapd_legacy_files);
+ if (ret) {
+ hybp(HYB_INFO, "add mem_cgroup_swapd_legacy_files failed!\n");
+ goto error_out;
+ }
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ akcompressd_pre_init();
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ swapd_pre_init();
+#endif
+ ret = register_all_hooks();
+ if (ret)
+ goto fail_out;
+
+ hybp(HYB_INFO, "hybridswap inited success!\n");
+ return 0;
+
+fail_out:
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ swapd_pre_deinit();
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ akcompressd_pre_deinit();
+#endif
+error_out:
+ if (hybridswap_cache) {
+ kmem_cache_destroy(hybridswap_cache);
+ hybridswap_cache = NULL;
+ }
+ return ret;
+}
+
+void __exit hybridswap_exit(void)
+{
+ unregister_all_hook();
+
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ swapd_pre_deinit();
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ akcompressd_pre_deinit();
+#endif
+
+ if (hybridswap_cache) {
+ kmem_cache_destroy(hybridswap_cache);
+ hybridswap_cache = NULL;
+ }
+}
diff --git a/drivers/block/zram/hybridswap/hybridswap_swapd.c b/drivers/block/zram/hybridswap/hybridswap_swapd.c
new file mode 100644
index 000000000000..437c60985475
--- /dev/null
+++ b/drivers/block/zram/hybridswap/hybridswap_swapd.c
@@ -0,0 +1,1908 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020-2022 Oplus. All rights reserved.
+ */
+
+#define pr_fmt(fmt) "[HYBRIDSWAP]" fmt
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+#include
+#endif
+
+#include "../zram_drv.h"
+#include "../zram_drv_internal.h"
+#include "hybridswap_internal.h"
+
+struct swapd_param {
+ unsigned int min_grade;
+ unsigned int max_grade;
+ unsigned int mem2zram_scale;
+ unsigned int zram2ufs_scale;
+ unsigned int pagefault_level;
+};
+
+struct hybridswapd_task {
+ wait_queue_head_t swapd_wait;
+ atomic_t swapd_wait_flag;
+ struct task_struct *swapd;
+ struct cpumask swapd_bind_cpumask;
+};
+#define PGDAT_ITEM_DATA(pgdat) ((struct hybridswapd_task*)(pgdat)->android_oem_data1)
+#define PGDAT_ITEM(pgdat, item) (PGDAT_ITEM_DATA(pgdat)->item)
+
+#define INFOS_PAGEFAULT_THRESHOLD 3600
+#define PAGEFAULT_SNAPSHOT_MIN_GAP 150
+#define NOTHING_IGNORE_VALUE 20
+#define MAX_SKIP_GAP 1000
+#define EMPTY_ROUND_CHECK_THRESHOLD 10
+#define ZRAM_WM_RATIO 75
+#define COMPRESS_RATIO 33
+#define SWAPD_MAX_LEVEL_NUM 4
+#define SWAPD_DEFAULT_BIND_CPUS "0-3"
+#define MAX_RECLAIMIN_SZ (200llu << 20)
+#define page_to_kb(nr) (nr << (PAGE_SHIFT - 10))
+#define SWAPD_SHRINK_WINDOW (HZ * 10)
+#define SWAPD_SHRINK_SIZE_PER_WINDOW 1024
+#define PAGES_TO_MB(pages) ((pages) >> 8)
+#define PAGES_PER_1MB (1 << 8)
+
+unsigned long long total_pagefault_percent;
+unsigned long long swapd_skip_interval;
+bool last_round_is_empty;
+unsigned long last_swapd_time;
+atomic64_t zram_wm_scale = ATOMIC_LONG_INIT(ZRAM_WM_RATIO);
+atomic64_t compress_scale = ATOMIC_LONG_INIT(COMPRESS_RATIO);
+atomic_t usable_mem = ATOMIC_INIT(0);
+atomic_t min_mem_watermark = ATOMIC_INIT(0);
+atomic_t high_mem_watermark = ATOMIC_INIT(0);
+atomic_t max_reclaim_size = ATOMIC_INIT(100);
+atomic64_t free_swap_level = ATOMIC64_INIT(0);
+atomic64_t zram_crit_thres = ATOMIC_LONG_INIT(0);
+atomic64_t cpuload_level = ATOMIC_LONG_INIT(0);
+atomic64_t infos_pagefault_level = ATOMIC_LONG_INIT(INFOS_PAGEFAULT_THRESHOLD);
+atomic64_t pagefault_refresh_min = ATOMIC_LONG_INIT(PAGEFAULT_SNAPSHOT_MIN_GAP);
+atomic64_t nothing_ignore_skip_interval = ATOMIC_LONG_INIT(NOTHING_IGNORE_VALUE);
+atomic64_t max_skip_interval = ATOMIC_LONG_INIT(MAX_SKIP_GAP);
+atomic64_t nothing_ignore_check_level = ATOMIC_LONG_INIT(EMPTY_ROUND_CHECK_THRESHOLD);
+static unsigned long reclaim_exceed_sleep_ms = 50;
+static unsigned long all_totalreserve_pages;
+
+static wait_queue_head_t refresh_daemonwait;
+static atomic_t refresh_daemonwait_flag;
+static atomic_t refresh_daemoninit_flag = ATOMIC_LONG_INIT(0);
+static struct task_struct *refresh_daemontask;
+static DEFINE_MUTEX(lowmem_event_lock);
+static pid_t swapid = -1;
+static unsigned long long infos_last_anon_pagefault;
+static unsigned long last_refresh_t;
+static struct swapd_param zswap_param[SWAPD_MAX_LEVEL_NUM];
+static enum cpuhp_state swapd_online;
+static struct zram *swapd_zram = NULL;
+static u64 max_reclaimin_size = MAX_RECLAIMIN_SZ;
+atomic_long_t page_fault_pause = ATOMIC_LONG_INIT(0);
+atomic_long_t page_fault_pause_cnt = ATOMIC_LONG_INIT(0);
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+static struct notifier_block fb_notif;
+static atomic_t display_off = ATOMIC_LONG_INIT(0);
+#endif
+static unsigned long swapd_shrink_window = SWAPD_SHRINK_WINDOW;
+static unsigned long swapd_shrink_limit_per_window = SWAPD_SHRINK_SIZE_PER_WINDOW;
+static unsigned long swapd_last_window_start;
+static unsigned long swapd_last_window_shrink;
+static atomic_t swapd_pause = ATOMIC_INIT(0);
+static atomic_t swapd_enabled = ATOMIC_INIT(0);
+static unsigned long swapd_nap_jiffies = 1;
+
+extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
+ unsigned long nr_pages,
+ gfp_t gfp_mask,
+ bool may_swap);
+#ifdef CONFIG_OPLUS_JANK
+extern u32 fetch_cpu_load(u32 win_cnt, struct cpumask *mask);
+#endif
+
+inline u64 fetch_zram_wm_scale_value(void)
+{
+ return atomic64_read(&zram_wm_scale);
+}
+
+inline u64 fetch_compress_scale_value(void)
+{
+ return atomic64_read(&compress_scale);
+}
+
+inline unsigned int fetch_usable_mem_value(void)
+{
+ return atomic_read(&usable_mem);
+}
+
+inline unsigned int fetch_min_mem_watermark_value(void)
+{
+ return atomic_read(&min_mem_watermark);
+}
+
+inline unsigned int fetch_high_mem_watermark_value(void)
+{
+ return atomic_read(&high_mem_watermark);
+}
+
+inline u64 fetch_swapd_max_reclaim_size(void)
+{
+ return atomic_read(&max_reclaim_size);
+}
+
+inline u64 fetch_free_swap_level_value(void)
+{
+ return atomic64_read(&free_swap_level);
+}
+
+inline unsigned long long fetch_infos_pagefault_level_value(void)
+{
+ return atomic64_read(&infos_pagefault_level);
+}
+
+inline unsigned long fetch_pagefault_refresh_min_value(void)
+{
+ return atomic64_read(&pagefault_refresh_min);
+}
+
+inline unsigned long long fetch_nothing_ignore_skip_interval_value(void)
+{
+ return atomic64_read(¬hing_ignore_skip_interval);
+}
+
+inline unsigned long long fetch_max_skip_interval_value(void)
+{
+ return atomic64_read(&max_skip_interval);
+}
+
+inline unsigned long long fetch_nothing_ignore_check_level_value(void)
+{
+ return atomic64_read(¬hing_ignore_check_level);
+}
+
+inline u64 fetch_zram_critical_level_value(void)
+{
+ return atomic64_read(&zram_crit_thres);
+}
+
+inline u64 fetch_cpuload_level_value(void)
+{
+ return atomic64_read(&cpuload_level);
+}
+
+static ssize_t usable_mem_params_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ unsigned int usable_mem_value;
+ unsigned int min_mem_watermark_value;
+ unsigned int high_mem_watermark_value;
+ u64 free_swap_level_value;
+
+ buf = strstrip(buf);
+
+ if (sscanf(buf, "%u %u %u %llu",
+ &usable_mem_value,
+ &min_mem_watermark_value,
+ &high_mem_watermark_value,
+ &free_swap_level_value) != 4)
+ return -EINVAL;
+
+ atomic_set(&usable_mem, usable_mem_value);
+ atomic_set(&min_mem_watermark, min_mem_watermark_value);
+ atomic_set(&high_mem_watermark, high_mem_watermark_value);
+ atomic64_set(&free_swap_level,
+ (free_swap_level_value * (SZ_1M / PAGE_SIZE)));
+
+ if (atomic_read(&min_mem_watermark) == 0)
+ atomic_set(&refresh_daemoninit_flag, 0);
+ else
+ atomic_set(&refresh_daemoninit_flag, 1);
+
+ wake_all_swapd();
+
+ return nbytes;
+}
+
+static int usable_mem_params_show(struct seq_file *m, void *v)
+{
+ seq_printf(m, "avail_buffers: %u\n",
+ atomic_read(&usable_mem));
+ seq_printf(m, "min_avail_buffers: %u\n",
+ atomic_read(&min_mem_watermark));
+ seq_printf(m, "high_avail_buffers: %u\n",
+ atomic_read(&high_mem_watermark));
+ seq_printf(m, "free_swap_threshold: %llu\n",
+ (atomic64_read(&free_swap_level) * PAGE_SIZE / SZ_1M));
+
+ return 0;
+}
+
+static ssize_t swapd_max_reclaim_size_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ const unsigned int base = 10;
+ u32 max_reclaim_size_value;
+ int ret;
+
+ buf = strstrip(buf);
+ ret = kstrtouint(buf, base, &max_reclaim_size_value);
+ if (ret)
+ return -EINVAL;
+
+ atomic_set(&max_reclaim_size, max_reclaim_size_value);
+
+ return nbytes;
+}
+
+static int swapd_max_reclaim_size_show(struct seq_file *m, void *v)
+{
+ seq_printf(m, "swapd_max_reclaim_size: %u\n",
+ atomic_read(&max_reclaim_size));
+
+ return 0;
+}
+
+static int infos_pagefault_level_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ atomic64_set(&infos_pagefault_level, val);
+
+ return 0;
+}
+
+static s64 infos_pagefault_level_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return atomic64_read(&infos_pagefault_level);
+}
+
+static int nothing_ignore_skip_interval_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ atomic64_set(¬hing_ignore_skip_interval, val);
+
+ return 0;
+}
+
+static s64 nothing_ignore_skip_interval_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return atomic64_read(¬hing_ignore_skip_interval);
+}
+
+static int max_skip_interval_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ atomic64_set(&max_skip_interval, val);
+
+ return 0;
+}
+
+static s64 max_skip_interval_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return atomic64_read(&max_skip_interval);
+}
+
+static int nothing_ignore_check_level_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ atomic64_set(¬hing_ignore_check_level, val);
+
+ return 0;
+}
+
+static s64 nothing_ignore_check_level_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return atomic64_read(¬hing_ignore_check_level);
+}
+
+static int pagefault_refresh_min_write(
+ struct cgroup_subsys_state *css, struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ atomic64_set(&pagefault_refresh_min, val);
+
+ return 0;
+}
+
+static s64 pagefault_refresh_min_read(
+ struct cgroup_subsys_state *css, struct cftype *cft)
+{
+ return atomic64_read(&pagefault_refresh_min);
+}
+
+static int zram_critical_thres_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ atomic64_set(&zram_crit_thres, val << (20 - PAGE_SHIFT));
+
+ return 0;
+}
+
+static s64 zram_critical_thres_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return atomic64_read(&zram_crit_thres) >> (20 - PAGE_SHIFT);
+}
+
+static s64 cpuload_level_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+
+{
+ return atomic64_read(&cpuload_level);
+}
+
+static int cpuload_level_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ atomic64_set(&cpuload_level, val);
+
+ return 0;
+}
+
+static s64 swapid_read(struct cgroup_subsys_state *css, struct cftype *cft)
+{
+ return swapid;
+}
+
+static void swapd_mcgs_setup_parse(int level_num)
+{
+ struct mem_cgroup *memcg = NULL;
+ memcg_hybs_t *hybs = NULL;
+ int i;
+
+ while ((memcg = fetch_next_memcg(memcg))) {
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+
+ for (i = 0; i < level_num; ++i) {
+ if (atomic64_read(&hybs->app_grade) >= zswap_param[i].min_grade &&
+ atomic64_read(&hybs->app_grade) <= zswap_param[i].max_grade)
+ break;
+ }
+ atomic_set(&hybs->mem2zram_scale, zswap_param[i].mem2zram_scale);
+ atomic_set(&hybs->zram2ufs_scale, zswap_param[i].zram2ufs_scale);
+ atomic_set(&hybs->pagefault_level, zswap_param[i].pagefault_level);
+ }
+}
+
+static void update_swapd_memcg_hybs(memcg_hybs_t *hybs)
+{
+ int i;
+
+ for (i = 0; i < SWAPD_MAX_LEVEL_NUM; ++i) {
+ if (!zswap_param[i].min_grade && !zswap_param[i].max_grade)
+ return;
+
+ if (atomic64_read(&hybs->app_grade) >= zswap_param[i].min_grade &&
+ atomic64_read(&hybs->app_grade) <= zswap_param[i].max_grade)
+ break;
+ }
+
+ if (i == SWAPD_MAX_LEVEL_NUM)
+ return;
+
+ atomic_set(&hybs->mem2zram_scale, zswap_param[i].mem2zram_scale);
+ atomic_set(&hybs->zram2ufs_scale, zswap_param[i].zram2ufs_scale);
+ atomic_set(&hybs->pagefault_level, zswap_param[i].pagefault_level);
+}
+
+void update_swapd_mcg_setup(struct mem_cgroup *memcg)
+{
+ memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg);
+
+ if (!hybs)
+ return;
+
+ update_swapd_memcg_hybs(hybs);
+}
+
+static int update_swapd_mcgs_setup(char *buf)
+{
+ const char delim[] = " ";
+ char *token = NULL;
+ int level_num;
+ int i;
+
+ buf = strstrip(buf);
+ token = strsep(&buf, delim);
+
+ if (!token)
+ return -EINVAL;
+
+ if (kstrtoint(token, 0, &level_num))
+ return -EINVAL;
+
+ if (level_num > SWAPD_MAX_LEVEL_NUM || level_num < 0)
+ return -EINVAL;
+
+ mutex_lock(&reclaim_para_lock);
+ for (i = 0; i < level_num; ++i) {
+ token = strsep(&buf, delim);
+ if (!token)
+ goto out;
+
+ if (kstrtoint(token, 0, &zswap_param[i].min_grade) ||
+ zswap_param[i].min_grade > MAX_APP_GRADE)
+ goto out;
+
+ token = strsep(&buf, delim);
+ if (!token)
+ goto out;
+
+ if (kstrtoint(token, 0, &zswap_param[i].max_grade) ||
+ zswap_param[i].max_grade > MAX_APP_GRADE)
+ goto out;
+
+ token = strsep(&buf, delim);
+ if (!token)
+ goto out;
+
+ if (kstrtoint(token, 0, &zswap_param[i].mem2zram_scale) ||
+ zswap_param[i].mem2zram_scale > MAX_RATIO)
+ goto out;
+
+ token = strsep(&buf, delim);
+ if (!token)
+ goto out;
+
+ if (kstrtoint(token, 0, &zswap_param[i].zram2ufs_scale) ||
+ zswap_param[i].zram2ufs_scale > MAX_RATIO)
+ goto out;
+
+ token = strsep(&buf, delim);
+ if (!token)
+ goto out;
+
+ if (kstrtoint(token, 0, &zswap_param[i].pagefault_level))
+ goto out;
+ }
+
+ swapd_mcgs_setup_parse(level_num);
+ mutex_unlock(&reclaim_para_lock);
+ return 0;
+
+out:
+ mutex_unlock(&reclaim_para_lock);
+ return -EINVAL;
+}
+
+static ssize_t swapd_mcgs_setup_write(struct kernfs_open_file *of, char *buf,
+ size_t nbytes, loff_t off)
+{
+ int ret = update_swapd_mcgs_setup(buf);
+
+ if (ret)
+ return ret;
+
+ return nbytes;
+}
+
+static int swapd_mcgs_setup_show(struct seq_file *m, void *v)
+{
+ int i;
+
+ for (i = 0; i < SWAPD_MAX_LEVEL_NUM; ++i) {
+ seq_printf(m, "level %d min score: %u\n",
+ i, zswap_param[i].min_grade);
+ seq_printf(m, "level %d max score: %u\n",
+ i, zswap_param[i].max_grade);
+ seq_printf(m, "level %d ub_mem2zram_ratio: %u\n",
+ i, zswap_param[i].mem2zram_scale);
+ seq_printf(m, "level %d ub_zram2ufs_ratio: %u\n",
+ i, zswap_param[i].zram2ufs_scale);
+ seq_printf(m, "memcg %d refault_threshold: %u\n",
+ i, zswap_param[i].pagefault_level);
+ }
+
+ return 0;
+}
+
+static ssize_t swapd_nap_jiffies_write(struct kernfs_open_file *of, char *buf,
+ size_t nbytes, loff_t off)
+{
+ unsigned long nap;
+
+ buf = strstrip(buf);
+ if (!buf)
+ return -EINVAL;
+
+ if (kstrtoul(buf, 0, &nap))
+ return -EINVAL;
+
+ swapd_nap_jiffies = nap;
+ return nbytes;
+}
+
+static int swapd_nap_jiffies_show(struct seq_file *m, void *v)
+{
+ seq_printf(m, "%lu\n", swapd_nap_jiffies);
+
+ return 0;
+}
+
+static ssize_t swapd_single_mcg_setup_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
+ unsigned int mem2zram_scale;
+ unsigned int zram2ufs_scale;
+ unsigned int pagefault_level;
+ memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg);
+
+ if (!hybs)
+ return -EINVAL;
+
+ buf = strstrip(buf);
+
+ if (sscanf(buf, "%u %u %u", &mem2zram_scale, &zram2ufs_scale,
+ &pagefault_level) != 3)
+ return -EINVAL;
+
+ if (mem2zram_scale > MAX_RATIO || zram2ufs_scale > MAX_RATIO)
+ return -EINVAL;
+
+ atomic_set(&MEMCGRP_ITEM(memcg, mem2zram_scale), mem2zram_scale);
+ atomic_set(&MEMCGRP_ITEM(memcg, zram2ufs_scale), zram2ufs_scale);
+ atomic_set(&MEMCGRP_ITEM(memcg, pagefault_level), pagefault_level);
+
+ return nbytes;
+}
+
+static int swapd_single_mcg_setup_show(struct seq_file *m, void *v)
+{
+ struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
+ memcg_hybs_t *hybs = MEMCGRP_ITEM_DATA(memcg);
+
+ if (!hybs)
+ return -EINVAL;
+
+ seq_printf(m, "memcg score: %lu\n",
+ atomic64_read(&hybs->app_grade));
+ seq_printf(m, "memcg ub_mem2zram_ratio: %u\n",
+ atomic_read(&hybs->mem2zram_scale));
+ seq_printf(m, "memcg ub_zram2ufs_ratio: %u\n",
+ atomic_read(&hybs->zram2ufs_scale));
+ seq_printf(m, "memcg refault_threshold: %u\n",
+ atomic_read(&hybs->pagefault_level));
+
+ return 0;
+}
+
+static int mem_cgroup_zram_wm_scale_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val > MAX_RATIO || val < MIN_RATIO)
+ return -EINVAL;
+
+ atomic64_set(&zram_wm_scale, val);
+
+ return 0;
+}
+
+static s64 mem_cgroup_zram_wm_scale_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return atomic64_read(&zram_wm_scale);
+}
+
+static int mem_cgroup_compress_scale_write(struct cgroup_subsys_state *css,
+ struct cftype *cft, s64 val)
+{
+ if (val > MAX_RATIO || val < MIN_RATIO)
+ return -EINVAL;
+
+ atomic64_set(&compress_scale, val);
+
+ return 0;
+}
+
+static s64 mem_cgroup_compress_scale_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return atomic64_read(&compress_scale);
+}
+
+static int memcg_active_app_info_list_show(struct seq_file *m, void *v)
+{
+ struct mem_cgroup *memcg = NULL;
+ unsigned long anon_size;
+ unsigned long zram_size;
+ unsigned long eswap_size;
+
+ while ((memcg = fetch_next_memcg(memcg))) {
+ u64 grade;
+
+ if (!MEMCGRP_ITEM_DATA(memcg))
+ continue;
+
+ grade = atomic64_read(&MEMCGRP_ITEM(memcg, app_grade));
+ anon_size = memcg_anon_pages(memcg);
+ eswap_size = hybridswap_read_mcg_stats(memcg,
+ MCG_DISK_STORED_PG_SZ);
+ zram_size = hybridswap_read_mcg_stats(memcg,
+ MCG_ZRAM_STORED_PG_SZ);
+
+ if (anon_size + zram_size + eswap_size == 0)
+ continue;
+
+ if (!strlen(MEMCGRP_ITEM(memcg, name)))
+ continue;
+
+ anon_size *= PAGE_SIZE / SZ_1K;
+ zram_size *= PAGE_SIZE / SZ_1K;
+ eswap_size *= PAGE_SIZE / SZ_1K;
+
+ seq_printf(m, "%s %llu %lu %lu %lu %llu\n",
+ MEMCGRP_ITEM(memcg, name), grade,
+ anon_size, zram_size, eswap_size,
+ MEMCGRP_ITEM(memcg, reclaimed_pagefault));
+ }
+ return 0;
+}
+
+static unsigned long fetch_totalreserve_pages(void)
+{
+ int nid;
+ unsigned long val = 0;
+
+ for_each_node_state(nid, N_MEMORY) {
+ pg_data_t *pgdat = NODE_DATA(nid);
+
+ if (pgdat)
+ val += pgdat->totalreserve_pages;
+ }
+
+ return val;
+}
+
+unsigned int system_cur_usable_mem(void)
+{
+ unsigned long reclaimable;
+ long buffers;
+ unsigned long pagecache;
+ unsigned long wmark_low = 0;
+ struct zone *zone;
+
+ buffers = global_zone_page_state(NR_FREE_PAGES) - all_totalreserve_pages;
+
+ for_each_zone(zone)
+ wmark_low += low_wmark_pages(zone);
+ pagecache = global_node_page_state(NR_ACTIVE_FILE) +
+ global_node_page_state(NR_INACTIVE_FILE);
+ pagecache -= min(pagecache / 2, wmark_low);
+ buffers += pagecache;
+
+ reclaimable = global_node_page_state(NR_SLAB_RECLAIMABLE) +
+ global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE);
+ buffers += reclaimable - min(reclaimable / 2, wmark_low);
+
+ if (buffers < 0)
+ buffers = 0;
+
+ return buffers >> 8; /* pages to MB */
+}
+
+static bool min_buffer_is_suitable(void)
+{
+ u32 curr_buffers = system_cur_usable_mem();
+
+ if (curr_buffers >= fetch_min_mem_watermark_value())
+ return true;
+
+ return false;
+}
+
+bool high_buffer_is_suitable(void)
+{
+ u32 curr_buffers = system_cur_usable_mem();
+
+ if (curr_buffers >= fetch_high_mem_watermark_value())
+ return true;
+
+ return false;
+}
+
+static void refresh_pagefaults(void)
+{
+ struct mem_cgroup *memcg = NULL;
+
+ while ((memcg = fetch_next_memcg(memcg))) {
+ MEMCGRP_ITEM(memcg, reclaimed_pagefault) =
+ hybridswap_read_mcg_stats(memcg, MCG_ANON_FAULT_CNT);
+ }
+
+ infos_last_anon_pagefault = hybridswap_fetch_zram_pagefault();
+ last_refresh_t = jiffies;
+}
+
+bool fetch_memcg_pagefault_status(struct mem_cgroup *memcg,
+ pg_data_t *pgdat)
+{
+ const unsigned int percent_constant = 100;
+ unsigned long long cur_anon_pagefault;
+ unsigned long anon_total;
+ unsigned long long scale, thresh;
+ memcg_hybs_t *hybs;
+
+ if (!memcg || !MEMCGRP_ITEM_DATA(memcg))
+ return false;
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ thresh = atomic_read(&hybs->pagefault_level);
+ if (thresh == 0)
+ return false;
+
+ cur_anon_pagefault = hybridswap_read_mcg_stats(memcg, MCG_ANON_FAULT_CNT);
+ if (cur_anon_pagefault == hybs->reclaimed_pagefault)
+ return false;
+
+ anon_total = memcg_anon_pages(memcg) +
+ hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_PG_SZ) +
+ hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_PG_SZ);
+ scale = (cur_anon_pagefault - hybs->reclaimed_pagefault) *
+ percent_constant / (anon_total + 1);
+ hybp(HYB_INFO, "memcg %16s scale %8llu level %8llu\n", hybs->name,
+ scale, thresh);
+
+ if (scale >= thresh)
+ return true;
+
+ return false;
+}
+
+static bool hybridswap_scale_ok(void)
+{
+ struct hybstatus *stat = NULL;
+
+ stat = hybridswap_fetch_stat_obj();
+ if (unlikely(!stat)) {
+ hybp(HYB_ERR, "can't fetch stat obj!\n");
+
+ return false;
+ }
+
+ return (atomic64_read(&stat->zram_stored_pages) >
+ atomic64_read(&stat->stored_pages));
+}
+
+static bool fetch_infos_pagefault_status(void)
+{
+ const unsigned int percent_constant = 1000;
+ unsigned long long cur_anon_pagefault;
+ unsigned long long cur_time;
+ unsigned long long scale = 0;
+
+ cur_anon_pagefault = hybridswap_fetch_zram_pagefault();
+ cur_time = jiffies;
+
+ if (cur_anon_pagefault == infos_last_anon_pagefault
+ || cur_time == last_refresh_t)
+ goto false_out;
+
+ scale = (cur_anon_pagefault - infos_last_anon_pagefault) *
+ percent_constant / (jiffies_to_msecs(cur_time -
+ last_refresh_t) + 1);
+
+ total_pagefault_percent = scale;
+
+ if (scale > fetch_infos_pagefault_level_value())
+ return true;
+
+ hybp(HYB_INFO, "current %llu t %llu last %llu t %llu scale %llu pagefault_scale %llu\n",
+ cur_anon_pagefault, cur_time,
+ infos_last_anon_pagefault, last_refresh_t,
+ scale, infos_pagefault_level);
+false_out:
+ return false;
+}
+
+static int reclaim_exceed_sleep_ms_write(
+ struct cgroup_subsys_state *css, struct cftype *cft, s64 val)
+{
+ if (val < 0)
+ return -EINVAL;
+
+ reclaim_exceed_sleep_ms = val;
+
+ return 0;
+}
+
+static s64 reclaim_exceed_sleep_ms_read(
+ struct cgroup_subsys_state *css, struct cftype *cft)
+{
+ return reclaim_exceed_sleep_ms;
+}
+
+static int max_reclaimin_size_mb_write(
+ struct cgroup_subsys_state *css, struct cftype *cft, u64 val)
+{
+ max_reclaimin_size = (val << 20);
+
+ return 0;
+}
+
+static u64 max_reclaimin_size_mb_read(
+ struct cgroup_subsys_state *css, struct cftype *cft)
+{
+ return max_reclaimin_size >> 20;
+}
+
+static ssize_t swapd_shrink_parameter_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ unsigned long window, limit;
+
+ buf = strstrip(buf);
+ if (sscanf(buf, "%lu %lu", &window, &limit) != 2)
+ return -EINVAL;
+
+ swapd_shrink_window = msecs_to_jiffies(window);
+ swapd_shrink_limit_per_window = limit;
+
+ return nbytes;
+}
+
+static int swapd_shrink_parameter_show(struct seq_file *m, void *v)
+{
+ seq_printf(m, "%-32s %lu(jiffies) %u(msec)\n", "swapd_shrink_window",
+ swapd_shrink_window, jiffies_to_msecs(swapd_shrink_window));
+ seq_printf(m, "%-32s %lu MB\n", "swapd_shrink_limit_per_window",
+ swapd_shrink_limit_per_window);
+ seq_printf(m, "%-32s %u msec\n", "swapd_last_window",
+ jiffies_to_msecs(jiffies - swapd_last_window_start));
+ seq_printf(m, "%-32s %lu MB\n", "swapd_last_window_shrink",
+ swapd_last_window_shrink);
+
+ return 0;
+}
+
+static int swapd_update_cpumask(struct task_struct *tsk, char *buf,
+ struct pglist_data *pgdat)
+{
+ int retval;
+ struct cpumask temp_mask;
+ const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id);
+ struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat);
+
+ if (unlikely(!hyb_task)) {
+ hybp(HYB_ERR, "set task %s cpumask %s node %d failed, "
+ "hyb_task is NULL\n", tsk->comm, buf, pgdat->node_id);
+ return -EINVAL;
+ }
+
+ cpumask_clear(&temp_mask);
+ retval = cpulist_parse(buf, &temp_mask);
+ if (retval < 0 || cpumask_empty(&temp_mask)) {
+ hybp(HYB_ERR, "%s are invalid, use default\n", buf);
+ goto use_default;
+ }
+
+ if (!cpumask_subset(&temp_mask, cpu_present_mask)) {
+ hybp(HYB_ERR, "%s is not subset of cpu_present_mask, use default\n",
+ buf);
+ goto use_default;
+ }
+
+ if (!cpumask_subset(&temp_mask, cpumask)) {
+ hybp(HYB_ERR, "%s is not subset of cpumask, use default\n", buf);
+ goto use_default;
+ }
+
+ set_cpus_allowed_ptr(tsk, &temp_mask);
+ cpumask_copy(&hyb_task->swapd_bind_cpumask, &temp_mask);
+ return 0;
+
+use_default:
+ if (cpumask_empty(&hyb_task->swapd_bind_cpumask))
+ set_cpus_allowed_ptr(tsk, cpumask);
+ return -EINVAL;
+}
+
+static ssize_t swapd_bind_write(struct kernfs_open_file *of, char *buf,
+ size_t nbytes, loff_t off)
+{
+ int ret = 0, nid;
+ struct pglist_data *pgdat;
+
+ buf = strstrip(buf);
+ for_each_node_state(nid, N_MEMORY) {
+ pgdat = NODE_DATA(nid);
+ if (!PGDAT_ITEM_DATA(pgdat))
+ continue;
+
+ if (PGDAT_ITEM(pgdat, swapd)) {
+ ret = swapd_update_cpumask(PGDAT_ITEM(pgdat, swapd),
+ buf, pgdat);
+ if (ret)
+ break;
+ }
+ }
+
+ if (ret)
+ return ret;
+
+ return nbytes;
+}
+
+static int swapd_bind_read(struct seq_file *m, void *v)
+{
+ int nid;
+ struct pglist_data *pgdat;
+ struct hybridswapd_task* hyb_task;
+
+ seq_printf(m, "%4s %s\n", "Node", "mask");
+ for_each_node_state(nid, N_MEMORY) {
+ pgdat = NODE_DATA(nid);
+ hyb_task = PGDAT_ITEM_DATA(pgdat);
+ if (!hyb_task)
+ continue;
+
+ if (!hyb_task->swapd)
+ continue;
+ seq_printf(m, "%4d %*pbl\n", nid,
+ cpumask_pr_args(&hyb_task->swapd_bind_cpumask));
+ }
+
+ return 0;
+}
+
+struct cftype mem_cgroup_swapd_legacy_files[] = {
+ {
+ .name = "active_app_info_list",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .seq_show = memcg_active_app_info_list_show,
+ },
+ {
+ .name = "zram_wm_ratio",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = mem_cgroup_zram_wm_scale_write,
+ .read_s64 = mem_cgroup_zram_wm_scale_read,
+ },
+ {
+ .name = "compress_ratio",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = mem_cgroup_compress_scale_write,
+ .read_s64 = mem_cgroup_compress_scale_read,
+ },
+ {
+ .name = "swapd_pid",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .read_s64 = swapid_read,
+ },
+ {
+ .name = "avail_buffers",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write = usable_mem_params_write,
+ .seq_show = usable_mem_params_show,
+ },
+ {
+ .name = "swapd_max_reclaim_size",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write = swapd_max_reclaim_size_write,
+ .seq_show = swapd_max_reclaim_size_show,
+ },
+ {
+ .name = "area_anon_refault_threshold",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = infos_pagefault_level_write,
+ .read_s64 = infos_pagefault_level_read,
+ },
+ {
+ .name = "empty_round_skip_interval",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = nothing_ignore_skip_interval_write,
+ .read_s64 = nothing_ignore_skip_interval_read,
+ },
+ {
+ .name = "max_skip_interval",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = max_skip_interval_write,
+ .read_s64 = max_skip_interval_read,
+ },
+ {
+ .name = "empty_round_check_threshold",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = nothing_ignore_check_level_write,
+ .read_s64 = nothing_ignore_check_level_read,
+ },
+ {
+ .name = "anon_refault_snapshot_min_interval",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = pagefault_refresh_min_write,
+ .read_s64 = pagefault_refresh_min_read,
+ },
+ {
+ .name = "swapd_mcgs_setup",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write = swapd_mcgs_setup_write,
+ .seq_show = swapd_mcgs_setup_show,
+ },
+ {
+ .name = "swapd_single_mcg_setup",
+ .write = swapd_single_mcg_setup_write,
+ .seq_show = swapd_single_mcg_setup_show,
+ },
+ {
+ .name = "zram_critical_threshold",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = zram_critical_thres_write,
+ .read_s64 = zram_critical_thres_read,
+ },
+ {
+ .name = "cpuload_threshold",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = cpuload_level_write,
+ .read_s64 = cpuload_level_read,
+ },
+ {
+ .name = "reclaim_exceed_sleep_ms",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_s64 = reclaim_exceed_sleep_ms_write,
+ .read_s64 = reclaim_exceed_sleep_ms_read,
+ },
+ {
+ .name = "swapd_bind",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write = swapd_bind_write,
+ .seq_show = swapd_bind_read,
+ },
+ {
+ .name = "max_reclaimin_size_mb",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write_u64 = max_reclaimin_size_mb_write,
+ .read_u64 = max_reclaimin_size_mb_read,
+ },
+ {
+ .name = "swapd_shrink_parameter",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write = swapd_shrink_parameter_write,
+ .seq_show = swapd_shrink_parameter_show,
+ },
+ {
+ .name = "swapd_nap_jiffies",
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ .write = swapd_nap_jiffies_write,
+ .seq_show = swapd_nap_jiffies_show,
+ },
+ { }, /* terminate */
+};
+
+void wakeup_refresh_daemon(void)
+{
+ unsigned long curr_refresh =
+ jiffies_to_msecs(jiffies - last_refresh_t);
+
+ if (curr_refresh >=
+ fetch_pagefault_refresh_min_value()) {
+ atomic_set(&refresh_daemonwait_flag, 1);
+ wake_up_interruptible(&refresh_daemonwait);
+ }
+}
+
+static int refresh_daemon(void *p)
+{
+ int ret;
+
+ while (!kthread_should_stop()) {
+ ret = wait_event_interruptible(refresh_daemonwait,
+ atomic_read(&refresh_daemonwait_flag));
+ if (ret)
+ continue;
+
+ if (unlikely(kthread_should_stop()))
+ break;
+
+ atomic_set(&refresh_daemonwait_flag, 0);
+
+ refresh_pagefaults();
+ count_swapd_event(SWAPD_SNAPSHOT_TIMES);
+ }
+
+ return 0;
+}
+
+static int refresh_daemonrun(void)
+{
+ atomic_set(&refresh_daemonwait_flag, 0);
+ init_waitqueue_head(&refresh_daemonwait);
+ refresh_daemontask = kthread_run(refresh_daemon, NULL, "snapshotd");
+
+ if (IS_ERR(refresh_daemontask)) {
+ hybp(HYB_ERR, "Failed to start refresh_daemon\n");
+ return PTR_ERR(refresh_daemontask);
+ }
+
+ return 0;
+}
+
+static void refresh_daemonexit(void)
+{
+ if (refresh_daemontask) {
+ atomic_set(&refresh_daemonwait_flag, 1);
+ kthread_stop(refresh_daemontask);
+ }
+ refresh_daemontask = NULL;
+}
+
+unsigned long fetch_nr_zram_total(void)
+{
+ unsigned long nr_zram = 1;
+
+ if (!swapd_zram)
+ return nr_zram;
+
+ nr_zram = swapd_zram->disksize >> PAGE_SHIFT;
+#if (defined CONFIG_ZRAM_WRITEBACK) || (defined CONFIG_HYBRIDSWAP_CORE)
+ nr_zram -= swapd_zram->increase_nr_pages;
+#endif
+ return nr_zram ?: 1;
+}
+
+static inline unsigned long hybridswap_fetch_zram_used_pages(void)
+{
+ if (swapd_zram)
+ return atomic64_read(&swapd_zram->stats.pages_stored);
+
+ return 0;
+}
+
+u64 get_hybridswap_meminfo(const char *type)
+{
+ if (!type || !swapd_zram)
+ return 0;
+
+ if (!strcmp(type, "same_pages"))
+ return (u64)atomic64_read(&swapd_zram->stats.same_pages);
+ if (!strcmp(type, "compr_data_size"))
+ return (u64)atomic64_read(&swapd_zram->stats.compr_data_size);
+ if (!strcmp(type, "pages_stored"))
+ return (u64)atomic64_read(&swapd_zram->stats.pages_stored);
+ return 0;
+}
+EXPORT_SYMBOL(get_hybridswap_meminfo);
+
+bool zram_watermark_ok(void)
+{
+ long long diff_buffers;
+ long long wm = 0;
+ long long cur_scale = 0;
+ unsigned long zram_used = hybridswap_fetch_zram_used_pages();
+ const unsigned int percent_constant = 100;
+
+ diff_buffers = fetch_high_mem_watermark_value() -
+ system_cur_usable_mem();
+ diff_buffers *= SZ_1M / PAGE_SIZE;
+ diff_buffers *= fetch_compress_scale_value() / 10;
+ diff_buffers = diff_buffers * percent_constant / fetch_nr_zram_total();
+
+ cur_scale = zram_used * percent_constant / fetch_nr_zram_total();
+ wm = min(fetch_zram_wm_scale_value(), fetch_zram_wm_scale_value()- diff_buffers);
+
+ return cur_scale > wm;
+}
+
+static inline bool zram_is_full(void)
+{
+ unsigned long nr_used = hybridswap_fetch_zram_used_pages();
+ unsigned long nr_total = fetch_nr_zram_total();
+
+ return nr_used >= nr_total;
+}
+
+bool free_zram_is_ok(void)
+{
+ unsigned long nr_used = hybridswap_fetch_zram_used_pages();
+ unsigned long nr_total = fetch_nr_zram_total();
+ unsigned long reserve = nr_total >> 6;
+
+ return (nr_used < (nr_total - reserve));
+}
+
+static bool zram_need_swapout(void)
+{
+ bool zram_wm_ok = zram_watermark_ok();
+ bool avail_buffer_wm_ok = !high_buffer_is_suitable();
+ bool ufs_wm_ok = true;
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ ufs_wm_ok = hybridswap_stored_wm_ok();
+#endif
+
+ if (zram_wm_ok && avail_buffer_wm_ok && ufs_wm_ok)
+ return true;
+
+ hybp(HYB_INFO, "zram_wm_ok %d avail_buffer_wm_ok %d ufs_wm_ok %d\n",
+ zram_wm_ok, avail_buffer_wm_ok, ufs_wm_ok);
+
+ return false;
+}
+
+bool zram_watermark_exceed(void)
+{
+ u64 nr_zram_used;
+ u64 nr_wm = fetch_zram_critical_level_value();
+
+ if (!nr_wm)
+ return false;
+
+ nr_zram_used = hybridswap_fetch_zram_used_pages();
+
+ if (nr_zram_used > nr_wm)
+ return true;
+
+ return false;
+}
+
+#ifdef CONFIG_OPLUS_JANK
+static bool is_cpu_busy(void)
+{
+ unsigned int cpuload = 0;
+ int i;
+ struct cpumask mask;
+
+ cpumask_clear(&mask);
+
+ for (i = 0; i < 6; i++)
+ cpumask_set_cpu(i, &mask);
+
+ cpuload = fetch_cpu_load(1, &mask);
+ if (cpuload > fetch_cpuload_level_value()) {
+ hybp(HYB_INFO, "cpuload %d\n", cpuload);
+ return true;
+ }
+
+ return false;
+}
+#endif
+
+static void wakeup_swapd(pg_data_t *pgdat)
+{
+ unsigned long curr_interval;
+ struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat);
+
+ if (!hyb_task || !hyb_task->swapd)
+ return;
+
+ if (atomic_read(&swapd_pause)) {
+ count_swapd_event(SWAPD_MANUAL_PAUSE);
+ return;
+ }
+
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+ if (atomic_read(&display_off))
+ return;
+#endif
+
+ if (!waitqueue_active(&hyb_task->swapd_wait))
+ return;
+
+ if (atomic_read(&refresh_daemoninit_flag) == 1)
+ wakeup_refresh_daemon();
+
+ if (min_buffer_is_suitable()) {
+ count_swapd_event(SWAPD_OVER_MIN_BUFFER_SKIP_TIMES);
+ return;
+ }
+
+ curr_interval = jiffies_to_msecs(jiffies - last_swapd_time);
+ if (curr_interval < swapd_skip_interval) {
+ count_swapd_event(SWAPD_EMPTY_ROUND_SKIP_TIMES);
+ return;
+ }
+
+ atomic_set(&hyb_task->swapd_wait_flag, 1);
+ wake_up_interruptible(&hyb_task->swapd_wait);
+}
+
+void wake_all_swapd(void)
+{
+ pg_data_t *pgdat = NULL;
+ int nid;
+
+ for_each_online_node(nid) {
+ pgdat = NODE_DATA(nid);
+ wakeup_swapd(pgdat);
+ }
+}
+
+bool free_swap_is_low(void)
+{
+ struct sysinfo info;
+
+ si_swapinfo(&info);
+
+ return (info.freeswap < fetch_free_swap_level_value());
+}
+EXPORT_SYMBOL(free_swap_is_low);
+
+static inline u64 __calc_nr_to_reclaim(void)
+{
+ u32 curr_buffers;
+ u64 high_buffers;
+ u64 max_reclaim_size_value;
+ u64 reclaim_size = 0;
+
+ high_buffers = fetch_high_mem_watermark_value();
+ curr_buffers = system_cur_usable_mem();
+ max_reclaim_size_value = fetch_swapd_max_reclaim_size();
+ if (curr_buffers < high_buffers)
+ reclaim_size = high_buffers - curr_buffers;
+
+ reclaim_size = min(reclaim_size, max_reclaim_size_value);
+
+ return reclaim_size * SZ_1M / PAGE_SIZE;
+}
+
+static inline u64 calc_shrink_scale(pg_data_t *pgdat)
+{
+ struct mem_cgroup *memcg = NULL;
+ const u32 percent_constant = 100;
+ u64 total_can_reclaimed = 0;
+
+ while ((memcg = fetch_next_memcg(memcg))) {
+ s64 nr_anon, nr_zram, nr_eswap, total, can_reclaimed, thresh;
+ memcg_hybs_t *hybs;
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ thresh = atomic_read(&hybs->mem2zram_scale);
+ if (!thresh || fetch_memcg_pagefault_status(memcg, pgdat)) {
+ hybs->can_reclaimed = 0;
+ continue;
+ }
+
+ nr_anon = memcg_anon_pages(memcg);
+ nr_zram = hybridswap_read_mcg_stats(memcg, MCG_ZRAM_STORED_PG_SZ);
+ nr_eswap = hybridswap_read_mcg_stats(memcg, MCG_DISK_STORED_PG_SZ);
+ total = nr_anon + nr_zram + nr_eswap;
+
+ can_reclaimed = total * thresh / percent_constant;
+ if (can_reclaimed <= (nr_zram + nr_eswap))
+ hybs->can_reclaimed = 0;
+ else
+ hybs->can_reclaimed = can_reclaimed - (nr_zram + nr_eswap);
+ hybp(HYB_INFO, "memcg %s can_reclaimed %lu nr_anon %lu zram %lu eswap %lu total %lu scale %lu thresh %lu\n",
+ hybs->name, page_to_kb(hybs->can_reclaimed),
+ page_to_kb(nr_anon), page_to_kb(nr_zram),
+ page_to_kb(nr_eswap), page_to_kb(total),
+ (nr_zram + nr_eswap) * 100 / (total + 1),
+ thresh);
+ total_can_reclaimed += hybs->can_reclaimed;
+ }
+
+ return total_can_reclaimed;
+}
+
+static unsigned long swapd_shrink_anon(pg_data_t *pgdat,
+ unsigned long nr_to_reclaim)
+{
+ struct mem_cgroup *memcg = NULL;
+ unsigned long nr_reclaimed = 0;
+ unsigned long reclaim_memcg_cnt = 0;
+ u64 total_can_reclaimed = calc_shrink_scale(pgdat);
+ unsigned long start_js = jiffies;
+ unsigned long reclaim_cycles;
+ bool exit = false;
+ unsigned long reclaim_size_per_cycle = PAGES_PER_1MB >> 1;
+
+ if (unlikely(total_can_reclaimed == 0))
+ goto out;
+
+ if (total_can_reclaimed < nr_to_reclaim)
+ nr_to_reclaim = total_can_reclaimed;
+
+ reclaim_cycles = nr_to_reclaim / reclaim_size_per_cycle;
+ while (reclaim_cycles) {
+ while ((memcg = fetch_next_memcg(memcg))) {
+ unsigned long memcg_nr_reclaimed, memcg_to_reclaim;
+ memcg_hybs_t *hybs;
+
+ if (high_buffer_is_suitable()) {
+ fetch_next_memcg_break(memcg);
+ exit = true;
+ break;
+ }
+
+ hybs = MEMCGRP_ITEM_DATA(memcg);
+ if (!hybs->can_reclaimed)
+ continue;
+
+ memcg_to_reclaim = reclaim_size_per_cycle * hybs->can_reclaimed / total_can_reclaimed;
+ memcg_nr_reclaimed = try_to_free_mem_cgroup_pages(memcg,
+ memcg_to_reclaim, GFP_KERNEL, true);
+ reclaim_memcg_cnt++;
+ hybs->can_reclaimed -= memcg_nr_reclaimed;
+ hybp(HYB_INFO, "memcg %s reclaim %lu want %lu\n", hybs->name,
+ memcg_nr_reclaimed, memcg_to_reclaim);
+ nr_reclaimed += memcg_nr_reclaimed;
+ if (nr_reclaimed >= nr_to_reclaim) {
+ fetch_next_memcg_break(memcg);
+ exit = true;
+ break;
+ }
+
+ if (hybs->can_reclaimed < 0)
+ hybs->can_reclaimed = 0;
+
+ if (swapd_nap_jiffies && time_after_eq(jiffies, start_js + swapd_nap_jiffies)) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout((jiffies - start_js) * 2);
+ start_js = jiffies;
+ }
+ }
+ if (exit)
+ break;
+
+ if (zram_is_full())
+ break;
+ reclaim_cycles--;
+ }
+
+out:
+ hybp(HYB_INFO, "total_reclaim %lu nr_to_reclaim %lu from memcg %lu total_can_reclaimed %lu\n",
+ page_to_kb(nr_reclaimed), page_to_kb(nr_to_reclaim),
+ reclaim_memcg_cnt, page_to_kb(total_can_reclaimed));
+ return nr_reclaimed;
+}
+
+static void swapd_shrink_node(pg_data_t *pgdat)
+{
+ const unsigned int increase_rate = 2;
+ unsigned long nr_reclaimed = 0;
+ unsigned long nr_to_reclaim;
+ unsigned int before_avail = system_cur_usable_mem();
+ unsigned int after_avail;
+
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+ if (atomic_read(&display_off))
+ return;
+#endif
+
+ if (zram_is_full())
+ return;
+
+ if (high_buffer_is_suitable())
+ return;
+
+#ifdef CONFIG_OPLUS_JANK
+ if (is_cpu_busy()) {
+ count_swapd_event(SWAPD_CPU_BUSY_BREAK_TIMES);
+ return;
+ }
+#endif
+
+ if ((jiffies - swapd_last_window_start) < swapd_shrink_window) {
+ if (swapd_last_window_shrink >= swapd_shrink_limit_per_window) {
+ count_swapd_event(SWAPD_SKIP_SHRINK_OF_WINDOW);
+ hybp(HYB_INFO, "swapd_last_window_shrink %lu, skip shrink\n",
+ swapd_last_window_shrink);
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout(msecs_to_jiffies(reclaim_exceed_sleep_ms));
+ return;
+ }
+ } else {
+ swapd_last_window_start = jiffies;
+ swapd_last_window_shrink = 0lu;
+ }
+
+ nr_to_reclaim = __calc_nr_to_reclaim();
+ if (!nr_to_reclaim)
+ return;
+
+ count_swapd_event(SWAPD_SHRINK_ANON);
+ nr_reclaimed = swapd_shrink_anon(pgdat, nr_to_reclaim);
+ swapd_last_window_shrink += PAGES_TO_MB(nr_reclaimed);
+
+ if (nr_reclaimed < fetch_nothing_ignore_check_level_value()) {
+ count_swapd_event(SWAPD_EMPTY_ROUND);
+ if (last_round_is_empty)
+ swapd_skip_interval = min(swapd_skip_interval *
+ increase_rate,
+ fetch_max_skip_interval_value());
+ else
+ swapd_skip_interval =
+ fetch_nothing_ignore_skip_interval_value();
+ last_round_is_empty = true;
+ } else {
+ swapd_skip_interval = 0;
+ last_round_is_empty = false;
+ }
+
+ after_avail = system_cur_usable_mem();
+ hybp(HYB_INFO, "total_reclaimed %lu KB, avail buffer %lu %lu MB, swapd_skip_interval %llu\n",
+ nr_reclaimed * 4, before_avail, after_avail, swapd_skip_interval);
+}
+
+static int swapd(void *p)
+{
+ pg_data_t *pgdat = (pg_data_t *)p;
+ struct task_struct *tsk = current;
+ struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat);
+ static unsigned long last_reclaimin_jiffies = 0;
+ long page_fault_pause_value;
+ int display_un_blank = 1;
+
+ swapid = tsk->pid;
+
+ cpumask_clear(&hyb_task->swapd_bind_cpumask);
+ (void)swapd_update_cpumask(tsk, SWAPD_DEFAULT_BIND_CPUS, pgdat);
+ set_freezable();
+
+ swapd_last_window_start = jiffies - swapd_shrink_window;
+ while (!kthread_should_stop()) {
+ bool pagefault = false;
+ u64 curr_buffers, avail;
+ u64 size, swapout_size = 0;
+
+ wait_event_freezable(hyb_task->swapd_wait,
+ atomic_read(&hyb_task->swapd_wait_flag));
+ atomic_set(&hyb_task->swapd_wait_flag, 0);
+ if (unlikely(kthread_should_stop()))
+ break;
+ count_swapd_event(SWAPD_WAKEUP);
+
+ if (fetch_infos_pagefault_status() && hybridswap_scale_ok()) {
+ pagefault = true;
+ count_swapd_event(SWAPD_REFAULT);
+ goto do_eswap;
+ }
+
+ swapd_shrink_node(pgdat);
+ last_swapd_time = jiffies;
+do_eswap:
+ page_fault_pause_value = atomic_long_read(&page_fault_pause);
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+ display_un_blank = !atomic_read(&display_off);
+#endif
+ if (!hybridswap_reclaim_work_running() && display_un_blank &&
+ (zram_need_swapout() || pagefault) && !page_fault_pause_value &&
+ jiffies_to_msecs(jiffies - last_reclaimin_jiffies) >= 50) {
+ avail = fetch_high_mem_watermark_value();
+ curr_buffers = system_cur_usable_mem();
+
+ if (curr_buffers < avail) {
+ size = (avail - curr_buffers) * SZ_1M;
+ size = min_t(u64, size, max_reclaimin_size);
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ swapout_size = hybridswap_out_to_eswap(size);
+ count_swapd_event(SWAPD_SWAPOUT);
+ last_reclaimin_jiffies = jiffies;
+#endif
+ hybp(HYB_DEBUG, "SWAPD_SWAPOUT curr %u avail %lu size %lu maybe swapout %lu\n",
+ curr_buffers, avail,
+ size / SZ_1M, swapout_size / SZ_1M);
+ } else {
+ hybp(HYB_INFO, "SWAPD_SKIP_SWAPOUT curr %u avail %lu\n",
+ curr_buffers, avail);
+ count_swapd_event(SWAPD_SKIP_SWAPOUT);
+ }
+ }
+ }
+
+ return 0;
+}
+
+int swapd_run(int nid)
+{
+ pg_data_t *pgdat = NODE_DATA(nid);
+ struct sched_param param = {
+ .sched_priority = DEFAULT_PRIO,
+ };
+ struct hybridswapd_task* hyb_task = PGDAT_ITEM_DATA(pgdat);
+ int ret;
+
+ if (!hyb_task || hyb_task->swapd)
+ return 0;
+
+ atomic_set(&hyb_task->swapd_wait_flag, 0);
+ hyb_task->swapd = kthread_create(swapd, pgdat, "hybridswapd:%d", nid);
+ if (IS_ERR(hyb_task->swapd)) {
+ hybp(HYB_ERR, "Failed to start swapd on node %d\n", nid);
+ ret = PTR_ERR(hyb_task->swapd);
+ hyb_task->swapd = NULL;
+ return ret;
+ }
+
+ sched_setscheduler_nocheck(hyb_task->swapd, SCHED_NORMAL, ¶m);
+ set_user_nice(hyb_task->swapd, PRIO_TO_NICE(param.sched_priority));
+ wake_up_process(hyb_task->swapd);
+
+ return 0;
+}
+
+void swapd_stop(int nid)
+{
+ struct pglist_data *pgdata = NODE_DATA(nid);
+ struct task_struct *swapd;
+ struct hybridswapd_task* hyb_task;
+
+ if (unlikely(!PGDAT_ITEM_DATA(pgdata))) {
+ hybp(HYB_ERR, "nid %d pgdata %p PGDAT_ITEM_DATA is NULL\n",
+ nid, pgdata);
+ return;
+ }
+
+ hyb_task = PGDAT_ITEM_DATA(pgdata);
+ swapd = hyb_task->swapd;
+ if (swapd) {
+ atomic_set(&hyb_task->swapd_wait_flag, 1);
+ kthread_stop(swapd);
+ hyb_task->swapd = NULL;
+ }
+
+ swapid = -1;
+}
+
+static int mem_hotplug_swapd_notifier(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct memory_notify *arg = (struct memory_notify*)data;
+ int nid = arg->status_change_nid;
+
+ if (action == MEM_ONLINE)
+ swapd_run(nid);
+ else if (action == MEM_OFFLINE)
+ swapd_stop(nid);
+
+ return NOTIFY_OK;
+}
+
+static struct notifier_block swapd_notifier_nb = {
+ .notifier_call = mem_hotplug_swapd_notifier,
+};
+
+static int swapd_cpu_online(unsigned int cpu)
+{
+ int nid;
+
+ for_each_node_state(nid, N_MEMORY) {
+ pg_data_t *pgdat = NODE_DATA(nid);
+ struct hybridswapd_task* hyb_task;
+ struct cpumask *mask;
+
+ hyb_task = PGDAT_ITEM_DATA(pgdat);
+ mask = &hyb_task->swapd_bind_cpumask;
+
+ if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids)
+ set_cpus_allowed_ptr(PGDAT_ITEM(pgdat, swapd), mask);
+ }
+ return 0;
+}
+
+void alloc_pages_slowpath_hook(void *data, gfp_t gfp_flags,
+ unsigned int order, unsigned long delta)
+{
+ if (gfp_flags & __GFP_KSWAPD_RECLAIM)
+ wake_all_swapd();
+}
+
+void rmqueue_hook(void *data, struct zone *preferred_zone,
+ struct zone *zone, unsigned int order, gfp_t gfp_flags,
+ unsigned int alloc_flags, int migratetype)
+{
+ if (gfp_flags & __GFP_KSWAPD_RECLAIM)
+ wake_all_swapd();
+}
+
+static int create_swapd_thread(struct zram *zram)
+{
+ int nid;
+ int ret;
+ struct pglist_data *pgdat;
+ struct hybridswapd_task *tsk_info;
+
+ for_each_node(nid) {
+ pgdat = NODE_DATA(nid);
+ if (!PGDAT_ITEM_DATA(pgdat)) {
+ tsk_info = kzalloc(sizeof(struct hybridswapd_task),
+ GFP_KERNEL);
+ if (!tsk_info) {
+ hybp(HYB_ERR, "kmalloc tsk_info failed node %d\n", nid);
+ goto error_out;
+ }
+
+ pgdat->android_oem_data1 = (u64)tsk_info;
+ }
+
+ init_waitqueue_head(&PGDAT_ITEM(pgdat, swapd_wait));
+ }
+
+ for_each_node_state(nid, N_MEMORY) {
+ if (swapd_run(nid))
+ goto error_out;
+ }
+
+ ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
+ "mm/swapd:online", swapd_cpu_online, NULL);
+ if (ret < 0) {
+ hybp(HYB_ERR, "swapd: failed to register hotplug callbacks.\n");
+ goto error_out;
+ }
+ swapd_online = ret;
+
+ return 0;
+
+error_out:
+ for_each_node(nid) {
+ pgdat = NODE_DATA(node);
+
+ if (!PGDAT_ITEM_DATA(pgdat))
+ continue;
+
+ if (PGDAT_ITEM(pgdat, swapd)) {
+ kthread_stop(PGDAT_ITEM(pgdat, swapd));
+ PGDAT_ITEM(pgdat, swapd) = NULL;
+ }
+
+ kfree((void*)PGDAT_ITEM_DATA(pgdat));
+ pgdat->android_oem_data1 = 0;
+ }
+
+ return -ENOMEM;
+}
+
+static void destroy_swapd_thread(void)
+{
+ int nid;
+ struct pglist_data *pgdat;
+
+ cpuhp_remove_state_nocalls(swapd_online);
+ for_each_node(nid) {
+ pgdat = NODE_DATA(node);
+ if (!PGDAT_ITEM_DATA(pgdat))
+ continue;
+
+ swapd_stop(nid);
+ kfree((void*)PGDAT_ITEM_DATA(pgdat));
+ pgdat->android_oem_data1 = 0;
+ }
+}
+
+ssize_t hybridswap_swapd_pause_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t len)
+{
+ char *type_buf = NULL;
+ bool val;
+
+ type_buf = strstrip((char *)buf);
+ if (kstrtobool(type_buf, &val))
+ return -EINVAL;
+ atomic_set(&swapd_pause, val);
+
+ return len;
+}
+
+ssize_t hybridswap_swapd_pause_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ ssize_t size = 0;
+
+ size += scnprintf(buf + size, PAGE_SIZE - size,
+ "%d\n", atomic_read(&swapd_pause));
+
+ return size;
+}
+
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+static int bright_fb_notifier_callback(struct notifier_block *self,
+ unsigned long event, void *data)
+{
+ struct msm_drm_notifier *evdata = data;
+ int *blank;
+
+ if (evdata && evdata->data) {
+ blank = evdata->data;
+
+ if (*blank == MSM_DRM_BLANK_POWERDOWN)
+ atomic_set(&display_off, 1);
+ else if (*blank == MSM_DRM_BLANK_UNBLANK)
+ atomic_set(&display_off, 0);
+ }
+
+ return NOTIFY_OK;
+}
+#endif
+
+void __init swapd_pre_init(void)
+{
+ all_totalreserve_pages = fetch_totalreserve_pages();
+}
+
+void swapd_pre_deinit(void)
+{
+ all_totalreserve_pages = 0;
+}
+
+int swapd_init(struct zram *zram)
+{
+ int ret;
+
+ ret = register_memory_notifier(&swapd_notifier_nb);
+ if (ret) {
+ hybp(HYB_ERR, "register_memory_notifier failed, ret = %d\n", ret);
+ return ret;
+ }
+
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+ fb_notif.notifier_call = bright_fb_notifier_callback;
+ ret = msm_drm_register_client(&fb_notif);
+ if (ret) {
+ hybp(HYB_ERR, "msm_drm_register_client failed, ret=%d\n", ret);
+ goto msm_drm_register_fail;
+ }
+#endif
+
+ ret = refresh_daemonrun();
+ if (ret) {
+ hybp(HYB_ERR, "refresh_daemonrun failed, ret=%d\n", ret);
+ goto refresh_daemonfail;
+ }
+
+ ret = create_swapd_thread(zram);
+ if (ret) {
+ hybp(HYB_ERR, "create_swapd_thread failed, ret=%d\n", ret);
+ goto create_swapd_fail;
+ }
+
+ swapd_zram = zram;
+ atomic_set(&swapd_enabled, 1);
+ return 0;
+
+create_swapd_fail:
+ refresh_daemonexit();
+refresh_daemonfail:
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+ msm_drm_unregister_client(&fb_notif);
+msm_drm_register_fail:
+#endif
+ unregister_memory_notifier(&swapd_notifier_nb);
+ return ret;
+}
+
+void swapd_exit(void)
+{
+ destroy_swapd_thread();
+ refresh_daemonexit();
+#if IS_ENABLED(CONFIG_DRM_MSM) || IS_ENABLED(CONFIG_DRM_OPLUS_NOTIFY)
+ msm_drm_unregister_client(&fb_notif);
+#endif
+ unregister_memory_notifier(&swapd_notifier_nb);
+ atomic_set(&swapd_enabled, 0);
+}
+
+bool hybridswap_swapd_enabled(void)
+{
+ return !!atomic_read(&swapd_enabled);
+}
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index e0c96c81a9a1..3c9f6b62a169 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -35,6 +35,10 @@
#include
#include "zram_drv.h"
+#include "zram_drv_internal.h"
+#ifdef CONFIG_HYBRIDSWAP
+#include "hybridswap/hybridswap.h"
+#endif
static DEFINE_IDR(zram_index_idr);
/* idr index must be protected */
@@ -55,32 +59,14 @@ static void zram_free_page(struct zram *zram, size_t index);
static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
u32 index, int offset, struct bio *bio);
+unsigned long znr_swap_pages;
+bool is_enable_zlimit;
static int zram_slot_trylock(struct zram *zram, u32 index)
{
return bit_spin_trylock(ZRAM_LOCK, &zram->table[index].flags);
}
-static void zram_slot_lock(struct zram *zram, u32 index)
-{
- bit_spin_lock(ZRAM_LOCK, &zram->table[index].flags);
-}
-
-static void zram_slot_unlock(struct zram *zram, u32 index)
-{
- bit_spin_unlock(ZRAM_LOCK, &zram->table[index].flags);
-}
-
-static inline bool init_done(struct zram *zram)
-{
- return zram->disksize;
-}
-
-static inline struct zram *dev_to_zram(struct device *dev)
-{
- return (struct zram *)dev_to_disk(dev)->private_data;
-}
-
static struct zram_entry *zram_get_entry(struct zram *zram, u32 index)
{
return zram->table[index].entry;
@@ -92,49 +78,11 @@ static void zram_set_entry(struct zram *zram, u32 index,
zram->table[index].entry = entry;
}
-/* flag operations require table entry bit_spin_lock() being held */
-static bool zram_test_flag(struct zram *zram, u32 index,
- enum zram_pageflags flag)
-{
- return zram->table[index].flags & BIT(flag);
-}
-
-static void zram_set_flag(struct zram *zram, u32 index,
- enum zram_pageflags flag)
-{
- zram->table[index].flags |= BIT(flag);
-}
-
-static void zram_clear_flag(struct zram *zram, u32 index,
- enum zram_pageflags flag)
-{
- zram->table[index].flags &= ~BIT(flag);
-}
-
-static inline void zram_set_element(struct zram *zram, u32 index,
- unsigned long element)
-{
- zram->table[index].element = element;
-}
-
static unsigned long zram_get_element(struct zram *zram, u32 index)
{
return zram->table[index].element;
}
-static size_t zram_get_obj_size(struct zram *zram, u32 index)
-{
- return zram->table[index].flags & (BIT(ZRAM_FLAG_SHIFT) - 1);
-}
-
-static void zram_set_obj_size(struct zram *zram,
- u32 index, size_t size)
-{
- unsigned long flags = zram->table[index].flags >> ZRAM_FLAG_SHIFT;
-
- zram->table[index].flags = (flags << ZRAM_FLAG_SHIFT) | size;
-}
-
static inline bool zram_allocated(struct zram *zram, u32 index)
{
return zram_get_obj_size(zram, index) ||
@@ -259,6 +207,11 @@ static ssize_t mem_limit_store(struct device *dev,
down_write(&zram->init_lock);
zram->limit_pages = PAGE_ALIGN(limit) >> PAGE_SHIFT;
+ if (zram->limit_pages) {
+ is_enable_zlimit = true;
+ znr_swap_pages = zram->limit_pages * 3;
+ } else
+ is_enable_zlimit = false;
up_write(&zram->init_lock);
return len;
@@ -325,6 +278,10 @@ static ssize_t idle_store(struct device *dev,
up_read(&zram->init_lock);
+#ifdef CONFIG_ZWB_HANDLE
+ wake_up_process(zwb_clear_tsk);
+#endif
+
return len;
}
@@ -785,6 +742,7 @@ next:
free_block_bdev(zram, blk_idx);
ret = len;
__free_page(page);
+ ksys_sync();
release_init_lock:
up_read(&zram->init_lock);
@@ -1294,9 +1252,31 @@ static void zram_free_page(struct zram *zram, size_t index)
atomic64_dec(&zram->stats.huge_pages);
}
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ if (zram_test_flag(zram, index, ZRAM_CACHED)) {
+ struct page *page = (struct page *)zram_get_page(zram, index);
+
+ del_page_from_cache(page);
+ page->mem_cgroup = NULL;
+ put_free_page(page);
+ zram_clear_flag(zram, index, ZRAM_CACHED);
+ goto out;
+ }
+
+ if (zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) {
+ zram_clear_flag(zram, index, ZRAM_CACHED_COMPRESS);
+ goto out;
+ }
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ hybridswap_untrack(zram, index);
+#endif
+
if (zram_test_flag(zram, index, ZRAM_WB)) {
zram_clear_flag(zram, index, ZRAM_WB);
free_block_bdev(zram, zram_get_element(zram, index));
+ atomic64_dec(&zram->stats.pages_stored);
goto out;
}
@@ -1307,6 +1287,7 @@ static void zram_free_page(struct zram *zram, size_t index)
if (zram_test_flag(zram, index, ZRAM_SAME)) {
zram_clear_flag(zram, index, ZRAM_SAME);
atomic64_dec(&zram->stats.same_pages);
+ atomic64_dec(&zram->stats.pages_stored);
goto out;
}
@@ -1318,14 +1299,134 @@ static void zram_free_page(struct zram *zram, size_t index)
atomic64_sub(zram_get_obj_size(zram, index),
&zram->stats.compr_data_size);
-out:
atomic64_dec(&zram->stats.pages_stored);
+
+out:
zram_set_entry(zram, index, NULL);
zram_set_obj_size(zram, index, 0);
WARN_ON_ONCE(zram->table[index].flags &
~(1UL << ZRAM_LOCK | 1UL << ZRAM_UNDER_WB));
}
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+void update_zram_index(struct zram *zram, u32 index, unsigned long page)
+{
+ zram_slot_lock(zram, index);
+ put_anon_pages((struct page*)page);
+
+ zram_free_page(zram, index);
+ zram_set_flag(zram, index, ZRAM_CACHED);
+ zram_set_page(zram, index, page);
+ zram_set_obj_size(zram, index, PAGE_SIZE);
+ zram_slot_unlock(zram, index);
+}
+
+int async_compress_page(struct zram *zram, struct page* page)
+{
+ int ret = 0;
+ unsigned long alloced_pages;
+ unsigned long handle = 0;
+ unsigned int comp_len = 0;
+ void *src, *dst;
+ struct zcomp_strm *zstrm;
+ int index = get_zram_index(page);
+
+compress_again:
+ zram_slot_lock(zram, index);
+ if (!zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) {
+ zram_slot_unlock(zram, index);
+ return 0;
+ }
+ zram_slot_unlock(zram, index);
+
+ zstrm = zcomp_stream_get(zram->comp);
+ src = kmap_atomic(page);
+ ret = zcomp_compress(zstrm, src, &comp_len);
+ kunmap_atomic(src);
+
+ if (unlikely(ret)) {
+ zcomp_stream_put(zram->comp);
+ pr_err("Compression failed! err=%d\n", ret);
+ zs_free(zram->mem_pool, handle);
+ return ret;
+ }
+
+ if (comp_len >= huge_class_size)
+ comp_len = PAGE_SIZE;
+
+ if (!handle)
+ handle = zs_malloc(zram->mem_pool, comp_len,
+ __GFP_KSWAPD_RECLAIM |
+ __GFP_NOWARN |
+ __GFP_HIGHMEM |
+ __GFP_MOVABLE |
+ __GFP_CMA);
+ if (!handle) {
+ zcomp_stream_put(zram->comp);
+ atomic64_inc(&zram->stats.writestall);
+ handle = zs_malloc(zram->mem_pool, comp_len,
+ GFP_NOIO | __GFP_HIGHMEM |
+ __GFP_MOVABLE | __GFP_CMA |
+ GFP_ATOMIC | ___GFP_HIGH_ATOMIC_ZRAM);
+ if (handle)
+ goto compress_again;
+ return -ENOMEM;
+ }
+
+ alloced_pages = zs_get_total_pages(zram->mem_pool);
+ update_used_max(zram, alloced_pages);
+
+ if (zram->limit_pages && alloced_pages > zram->limit_pages) {
+ zcomp_stream_put(zram->comp);
+ zs_free(zram->mem_pool, handle);
+ return -ENOMEM;
+ }
+
+ dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO);
+
+ src = zstrm->buffer;
+ if (comp_len == PAGE_SIZE)
+ src = kmap_atomic(page);
+ memcpy(dst, src, comp_len);
+ if (comp_len == PAGE_SIZE)
+ kunmap_atomic(src);
+
+ zcomp_stream_put(zram->comp);
+ zs_unmap_object(zram->mem_pool, handle);
+ atomic64_add(comp_len, &zram->stats.compr_data_size);
+
+ /*
+ * Free memory associated with this sector
+ * before overwriting unused sectors.
+ */
+ zram_slot_lock(zram, index);
+ if (!zram_test_flag(zram, index, ZRAM_CACHED_COMPRESS)) {
+ atomic64_sub(comp_len, &zram->stats.compr_data_size);
+ zs_free(zram->mem_pool, handle);
+ zram_slot_unlock(zram, index);
+ return 0;
+ }
+ zram_free_page(zram, index);
+
+ if (comp_len == PAGE_SIZE) {
+ zram_set_flag(zram, index, ZRAM_HUGE);
+ atomic64_inc(&zram->stats.huge_pages);
+ }
+
+ zram_set_handle(zram, index, handle);
+ zram_set_obj_size(zram, index, comp_len);
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ hybridswap_record(zram, index, page->mem_cgroup);
+#endif
+ zram_slot_unlock(zram, index);
+
+ /* Update stats */
+ atomic64_inc(&zram->stats.pages_stored);
+
+ return ret;
+}
+#endif
+
static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index,
struct bio *bio, bool partial_io)
{
@@ -1335,6 +1436,22 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index,
void *src, *dst;
zram_slot_lock(zram, index);
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ if (akcompress_cache_page_fault(zram, page, index))
+ return 0;
+#endif
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ if (likely(!bio)) {
+ ret = hybridswap_page_fault(zram, index);
+ if (unlikely(ret)) {
+ pr_err("search in hybridswap failed! err=%d, page=%u\n",
+ ret, index);
+ zram_slot_unlock(zram, index);
+ return ret;
+ }
+ }
+#endif
if (zram_test_flag(zram, index, ZRAM_WB)) {
struct bio_vec bvec;
@@ -1451,6 +1568,13 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
goto out;
}
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ if ((current_is_kswapd() || current_is_swapd(current)) &&
+ add_anon_page2cache(zram, index, page)) {
+ return 0;
+ }
+#endif
+
compress_again:
zstrm = zcomp_stream_get(zram->comp);
src = kmap_atomic(page);
@@ -1492,7 +1616,7 @@ compress_again:
atomic64_inc(&zram->stats.writestall);
entry = zram_entry_alloc(zram, comp_len,
GFP_NOIO | __GFP_HIGHMEM |
- __GFP_MOVABLE | __GFP_CMA);
+ __GFP_MOVABLE | __GFP_CMA | GFP_ATOMIC | ___GFP_HIGH_ATOMIC_ZRAM);
if (entry)
goto compress_again;
return -ENOMEM;
@@ -1501,6 +1625,14 @@ compress_again:
alloced_pages = zs_get_total_pages(zram->mem_pool);
update_used_max(zram, alloced_pages);
+ if (is_enable_zlimit) {
+ if (alloced_pages < zram->limit_pages)
+ znr_swap_pages = (zram->limit_pages
+ - alloced_pages) * 3;
+ else
+ znr_swap_pages = 0;
+ }
+
if (zram->limit_pages && alloced_pages > zram->limit_pages) {
zcomp_stream_put(zram->comp);
zram_entry_free(zram, entry);
@@ -1541,6 +1673,10 @@ out:
zram_set_entry(zram, index, entry);
zram_set_obj_size(zram, index, comp_len);
}
+
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ hybridswap_record(zram, index, page->mem_cgroup);
+#endif
zram_slot_unlock(zram, index);
/* Update stats */
@@ -1747,6 +1883,13 @@ static void zram_slot_free_notify(struct block_device *bdev,
return;
}
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ if (!hybridswap_delete(zram, index)) {
+ zram_slot_unlock(zram, index);
+ atomic64_inc(&zram->stats.miss_free);
+ return;
+ }
+#endif
zram_free_page(zram, index);
zram_slot_unlock(zram, index);
}
@@ -1810,6 +1953,7 @@ static void zram_reset_device(struct zram *zram)
down_write(&zram->init_lock);
zram->limit_pages = 0;
+ is_enable_zlimit = false;
if (!init_done(zram)) {
up_write(&zram->init_lock);
@@ -1967,6 +2111,27 @@ static DEVICE_ATTR_RW(use_dedup);
#else
static DEVICE_ATTR_RO(use_dedup);
#endif
+#ifdef CONFIG_HYBRIDSWAP
+static DEVICE_ATTR_RO(hybridswap_vmstat);
+static DEVICE_ATTR_RW(hybridswap_loglevel);
+static DEVICE_ATTR_RW(hybridswap_enable);
+#endif
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+static DEVICE_ATTR_RW(hybridswap_swapd_pause);
+#endif
+#ifdef CONFIG_HYBRIDSWAP_CORE
+static DEVICE_ATTR_RW(hybridswap_core_enable);
+static DEVICE_ATTR_RW(hybridswap_loop_device);
+static DEVICE_ATTR_RW(hybridswap_dev_life);
+static DEVICE_ATTR_RW(hybridswap_quota_day);
+static DEVICE_ATTR_RO(hybridswap_report);
+static DEVICE_ATTR_RO(hybridswap_stat_snap);
+static DEVICE_ATTR_RO(hybridswap_meminfo);
+static DEVICE_ATTR_RW(hybridswap_zram_increase);
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+static DEVICE_ATTR_RW(hybridswap_akcompress);
+#endif
static struct attribute *zram_disk_attrs[] = {
&dev_attr_disksize.attr,
@@ -1991,6 +2156,27 @@ static struct attribute *zram_disk_attrs[] = {
&dev_attr_bd_stat.attr,
#endif
&dev_attr_debug_stat.attr,
+#ifdef CONFIG_HYBRIDSWAP
+ &dev_attr_hybridswap_vmstat.attr,
+ &dev_attr_hybridswap_loglevel.attr,
+ &dev_attr_hybridswap_enable.attr,
+#endif
+#ifdef CONFIG_HYBRIDSWAP_SWAPD
+ &dev_attr_hybridswap_swapd_pause.attr,
+#endif
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ &dev_attr_hybridswap_core_enable.attr,
+ &dev_attr_hybridswap_report.attr,
+ &dev_attr_hybridswap_meminfo.attr,
+ &dev_attr_hybridswap_stat_snap.attr,
+ &dev_attr_hybridswap_loop_device.attr,
+ &dev_attr_hybridswap_dev_life.attr,
+ &dev_attr_hybridswap_quota_day.attr,
+ &dev_attr_hybridswap_zram_increase.attr,
+#endif
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ &dev_attr_hybridswap_akcompress.attr,
+#endif
NULL,
};
@@ -2132,6 +2318,9 @@ static int zram_remove(struct zram *zram)
del_gendisk(zram->disk);
blk_cleanup_queue(zram->disk->queue);
put_disk(zram->disk);
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ destroy_akcompressd_task(zram);
+#endif
kfree(zram);
return 0;
}
@@ -2255,6 +2444,11 @@ static int __init zram_init(void)
num_devices--;
}
+#ifdef CONFIG_HYBRIDSWAP
+ ret = hybridswap_pre_init();
+ if (ret)
+ goto out_error;
+#endif
return 0;
out_error:
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 22f8366d7971..ed9a8fd4f8fa 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -52,7 +52,16 @@ enum zram_pageflags {
ZRAM_UNDER_WB, /* page is under writeback */
ZRAM_HUGE, /* Incompressible page */
ZRAM_IDLE, /* not accessed page since last idle marking */
-
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ ZRAM_CACHED, /* page is cached in async compress cache buffer */
+ ZRAM_CACHED_COMPRESS, /* page is under async compress */
+#endif
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ ZRAM_BATCHING_OUT,
+ ZRAM_FROM_HYBRIDSWAP,
+ ZRAM_MCGID_CLEAR,
+ ZRAM_IN_BD, /* zram stored in back device */
+#endif
__NR_ZRAM_PAGEFLAGS,
};
@@ -71,6 +80,9 @@ struct zram_table_entry {
union {
struct zram_entry *entry;
unsigned long element;
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+ unsigned long page;
+#endif
};
unsigned long flags;
#ifdef CONFIG_ZRAM_MEMORY_TRACKING
@@ -148,6 +160,15 @@ struct zram {
#ifdef CONFIG_ZRAM_MEMORY_TRACKING
struct dentry *debugfs_dir;
#endif
+#if (defined CONFIG_ZRAM_WRITEBACK) || (defined CONFIG_HYBRIDSWAP_CORE)
+ struct block_device *bdev;
+ unsigned int old_block_size;
+ unsigned long nr_pages;
+ unsigned long increase_nr_pages;
+#endif
+#ifdef CONFIG_HYBRIDSWAP_CORE
+ struct hyb_info *infos;
+#endif
};
static inline bool zram_dedup_enabled(struct zram *zram)
@@ -160,4 +181,11 @@ static inline bool zram_dedup_enabled(struct zram *zram)
}
void zram_entry_free(struct zram *zram, struct zram_entry *entry);
+
+#ifdef CONFIG_ZRAM_WRITEBACK
+void ksys_sync(void);
+#endif
+#ifdef CONFIG_ZWB_HANDLE
+extern struct task_struct *zwb_clear_tsk;
+#endif
#endif
diff --git a/drivers/block/zram/zram_drv_internal.h b/drivers/block/zram/zram_drv_internal.h
new file mode 100644
index 000000000000..23ce13969f0a
--- /dev/null
+++ b/drivers/block/zram/zram_drv_internal.h
@@ -0,0 +1,42 @@
+#ifndef _ZRAM_DRV_INTERNAL_H_
+#define _ZRAM_DRV_INTERNAL_H_
+
+#include "zram_drv.h"
+
+#ifdef BIT
+#undef BIT
+#define BIT(nr) (1lu << (nr))
+#endif
+
+#define zram_slot_lock(zram, index) (bit_spin_lock(ZRAM_LOCK, &zram->table[index].flags))
+
+#define zram_slot_unlock(zram, index) (bit_spin_unlock(ZRAM_LOCK, &zram->table[index].flags))
+
+#define init_done(zram) (zram->disksize)
+
+#define dev_to_zram(dev) ((struct zram *)dev_to_disk(dev)->private_data)
+
+#define zram_get_handle(zram, index) ((unsigned long)(zram->table[index].entry))
+
+#define zram_set_handle(zram, index, handle_val) (zram->table[index].entry = (struct zram_entry *)handle_val)
+
+#define zram_test_flag(zram, index, flag) (zram->table[index].flags & BIT(flag))
+
+#define zram_set_flag(zram, index, flag) (zram->table[index].flags |= BIT(flag))
+
+#define zram_clear_flag(zram, index, flag) (zram->table[index].flags &= ~BIT(flag))
+
+#define zram_set_element(zram, index, element) (zram->table[index].element = element)
+
+#define zram_get_obj_size(zram, index) (zram->table[index].flags & (BIT(ZRAM_FLAG_SHIFT) - 1))
+
+#define zram_set_obj_size(zram, index, size) do {\
+ unsigned long flags = zram->table[index].flags >> ZRAM_FLAG_SHIFT; \
+ zram->table[index].flags = (flags << ZRAM_FLAG_SHIFT) | size; \
+} while(0)
+
+#ifdef CONFIG_HYBRIDSWAP_ASYNC_COMPRESS
+extern int async_compress_page(struct zram *zram, struct page* page);
+extern void update_zram_index(struct zram *zram, u32 index, unsigned long page);
+#endif
+#endif /* _ZRAM_DRV_INTERNAL_H_ */
diff --git a/drivers/block/zram/zwb_handle b/drivers/block/zram/zwb_handle
new file mode 120000
index 000000000000..78e1f952251e
--- /dev/null
+++ b/drivers/block/zram/zwb_handle
@@ -0,0 +1 @@
+../../../../../vendor/oplus/kernel/oplus_performance/zwb_handle/
\ No newline at end of file
diff --git a/drivers/bluetooth/bluetooth-power.c b/drivers/bluetooth/bluetooth-power.c
index f66ff5c3e34e..474008b35c6d 100644
--- a/drivers/bluetooth/bluetooth-power.c
+++ b/drivers/bluetooth/bluetooth-power.c
@@ -659,10 +659,13 @@ vdd_xtal_fail:
bt_vreg_unvote(bt_power_pdata->bt_vdd_rfa2);
if (bt_power_pdata->bt_vdd_rfa1)
bt_vreg_unvote(bt_power_pdata->bt_vdd_rfa1);
+ /*
+ * if did't have pm8009 dig power and aon power disable enter Retention mode
if (bt_power_pdata->bt_vdd_dig)
bt_vreg_unvote(bt_power_pdata->bt_vdd_dig);
if (bt_power_pdata->bt_vdd_aon)
bt_vreg_unvote(bt_power_pdata->bt_vdd_aon);
+ */
} else {
BT_PWR_ERR("Invalid power mode: %d", on);
rc = -1;
diff --git a/drivers/bluetooth/btfm_slim_codec.c b/drivers/bluetooth/btfm_slim_codec.c
index 1b38246db8db..5d456ae85656 100644
--- a/drivers/bluetooth/btfm_slim_codec.c
+++ b/drivers/bluetooth/btfm_slim_codec.c
@@ -210,9 +210,9 @@ static int btfm_slim_dai_prepare(struct snd_pcm_substream *substream,
/* save the enable channel status */
if (ret == 0)
bt_soc_enable_status = 1;
-
if (ret == -EISCONN) {
- BTFMSLIM_ERR("channel opened without closing, return success");
+ BTFMSLIM_ERR("channel opened without closing, returning success");
+
ret = 0;
}
return ret;
diff --git a/drivers/bus/mhi/core/mhi_init.c b/drivers/bus/mhi/core/mhi_init.c
index a27b96345f2f..0d9a14809fc5 100644
--- a/drivers/bus/mhi/core/mhi_init.c
+++ b/drivers/bus/mhi/core/mhi_init.c
@@ -1573,7 +1573,7 @@ int of_register_mhi_controller(struct mhi_controller *mhi_cntrl)
init_waitqueue_head(&mhi_cntrl->state_event);
mhi_cntrl->wq = alloc_ordered_workqueue("mhi_w",
- WQ_MEM_RECLAIM | WQ_HIGHPRI);
+ WQ_HIGHPRI);
if (!mhi_cntrl->wq)
goto error_alloc_cmd;
diff --git a/drivers/bus/mhi/core/mhi_pm.c b/drivers/bus/mhi/core/mhi_pm.c
index 710d17cb14bb..4c0bcbb52e75 100644
--- a/drivers/bus/mhi/core/mhi_pm.c
+++ b/drivers/bus/mhi/core/mhi_pm.c
@@ -1045,6 +1045,10 @@ error_dev_ctxt:
}
EXPORT_SYMBOL(mhi_async_power_up);
+#ifdef OPLUS_BUG_STABILITY
+extern bool direct_panic;
+#endif
+
/* Transition MHI into error state and notify critical clients */
void mhi_control_error(struct mhi_controller *mhi_cntrl)
{
@@ -1060,6 +1064,11 @@ void mhi_control_error(struct mhi_controller *mhi_cntrl)
memcpy(sfr_info->str, sfr_info->buf_addr, sfr_info->len);
MHI_CNTRL_ERR("mhi:%s sfr: %s\n", mhi_cntrl->name,
sfr_info->buf_addr);
+#ifdef OPLUS_BUG_STABILITY
+ if(strstr(sfr_info->buf_addr, "remotefs_sahara.c")) {
+ direct_panic = true;
+ }
+#endif
}
/* link is not down if device supports RDDM */
@@ -1142,10 +1151,18 @@ int mhi_sync_power_up(struct mhi_controller *mhi_cntrl)
if (ret)
return ret;
+#ifndef OPLUS_BUG_STABILITY
+ //Modify for: mhi timeout 10s to 20s
wait_event_timeout(mhi_cntrl->state_event,
MHI_IN_MISSION_MODE(mhi_cntrl->ee) ||
MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state),
msecs_to_jiffies(mhi_cntrl->timeout_ms));
+#else /* OPLUS_BUG_STABILITY */
+ wait_event_timeout(mhi_cntrl->state_event,
+ MHI_IN_MISSION_MODE(mhi_cntrl->ee) ||
+ MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state),
+ msecs_to_jiffies(20000));
+#endif /* OPLUS_BUG_STABILITY */
if (MHI_IN_MISSION_MODE(mhi_cntrl->ee))
return 0;
diff --git a/drivers/bus/mhi/devices/mhi_uci.c b/drivers/bus/mhi/devices/mhi_uci.c
index 2a7fbfa7062a..1ee002eda187 100644
--- a/drivers/bus/mhi/devices/mhi_uci.c
+++ b/drivers/bus/mhi/devices/mhi_uci.c
@@ -65,7 +65,12 @@ enum MHI_DEBUG_LEVEL msg_lvl = MHI_MSG_LVL_ERROR;
#ifdef CONFIG_MHI_DEBUG
-#define MHI_UCI_IPC_LOG_PAGES (25)
+#ifdef OPLUS_BUG_STABILITY
+#define MHI_UCI_IPC_LOG_PAGES (100)
+#else
+#define MHI_UCI_IPC_LOG_PAGES (25)
+#endif /* OPLUS_BUG_STABILITY */
+
#define MSG_VERB(fmt, ...) do { \
if (msg_lvl <= MHI_MSG_LVL_VERBOSE) \
pr_err("[D][%s] " fmt, __func__, ##__VA_ARGS__); \
diff --git a/drivers/char/adsprpc.c b/drivers/char/adsprpc.c
index d87f71f3f2c9..619bf6ef7f8e 100644
--- a/drivers/char/adsprpc.c
+++ b/drivers/char/adsprpc.c
@@ -3853,6 +3853,7 @@ static int fastrpc_file_free(struct fastrpc_file *fl)
mutex_destroy(&fl->map_mutex);
mutex_destroy(&fl->pm_qos_mutex);
mutex_destroy(&fl->internal_map_mutex);
+ mutex_destroy(&fl->pm_qos_mutex);
kfree(fl);
return 0;
}
diff --git a/drivers/char/diag/diag_ipc_logging.h b/drivers/char/diag/diag_ipc_logging.h
index 2e0b7ee4b822..5fa3d42cda90 100644
--- a/drivers/char/diag/diag_ipc_logging.h
+++ b/drivers/char/diag/diag_ipc_logging.h
@@ -7,7 +7,11 @@
#include
+#if defined(CONFIG_MHI_DEBUG) && defined(OPLUS_BUG_STABILITY)
+#define DIAG_IPC_LOG_PAGES 200
+#else
#define DIAG_IPC_LOG_PAGES 50
+#endif /* CONFIG_MHI_DEBUG and OPLUS_BUG_STABILITY */
#define DIAG_DEBUG_USERSPACE 0x0001
#define DIAG_DEBUG_MUX 0x0002
diff --git a/drivers/char/diag/diagfwd_bridge.c b/drivers/char/diag/diagfwd_bridge.c
index 7635f6d87faf..71a47570f9c9 100644
--- a/drivers/char/diag/diagfwd_bridge.c
+++ b/drivers/char/diag/diagfwd_bridge.c
@@ -22,6 +22,9 @@
#include "diagfwd_mhi.h"
#include "diag_dci.h"
#include "diag_ipc_logging.h"
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#include "diagfwd.h"
+#endif
#ifdef CONFIG_MHI_BUS
#define diag_mdm_init diag_mhi_init
@@ -310,6 +313,29 @@ int diagfwd_bridge_close(int id)
int diagfwd_bridge_write(int id, unsigned char *buf, int len)
{
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ uint16_t cmd_code;
+ uint16_t subsys_id;
+ uint16_t cmd_code_lo;
+ uint16_t cmd_code_hi;
+ unsigned char *temp = NULL;
+
+ temp = buf;
+ cmd_code = (uint16_t)(*(uint8_t *)temp);
+ temp += sizeof(uint8_t);
+ subsys_id = (uint16_t)(*(uint8_t *)temp);
+ temp += sizeof(uint8_t);
+ cmd_code_hi = (uint16_t)(*(uint16_t *)temp);
+ cmd_code_lo = (uint16_t)(*(uint16_t *)temp);
+ if (cmd_code == 0x4b && subsys_id == 0xb && cmd_code_hi == 0x35 && cmd_code_lo == 0x35) {
+ pr_err("diag command with 75 11 53\n");
+ if (!driver->hdlc_disabled)
+ diag_process_hdlc_pkt(buf, len, 0);
+ else
+ diag_process_non_hdlc_pkt(buf, len, 0);
+ }
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
if (id < 0 || id >= NUM_REMOTE_DEV)
return -EINVAL;
if (bridge_info[id].dev_ops && bridge_info[id].dev_ops->write) {
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 95f42baff399..474e9769e29b 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -28,6 +28,7 @@
#include
#include
#include
+#include
#include "clk.h"
@@ -103,6 +104,9 @@ struct clk_core {
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
struct hlist_node debug_node;
+#elif defined OPLUS_FEATURE_POWERINFO_RPMH
+ struct proc_dir_entry *dentry;
+ struct hlist_node debug_node;
#endif
struct kref ref;
struct clk_vdd_class *vdd_class;
@@ -4038,6 +4042,825 @@ static int __init clk_debug_init(void)
return 0;
}
late_initcall(clk_debug_init);
+#elif defined OPLUS_FEATURE_POWERINFO_RPMH
+static struct proc_dir_entry *rootdir;
+static int inited = 0;
+static u32 debug_suspend;
+static DEFINE_MUTEX(clk_debug_lock);
+static HLIST_HEAD(clk_debug_list);
+
+static struct hlist_head *all_lists[] = {
+ &clk_root_list,
+ &clk_orphan_list,
+ NULL,
+};
+
+static void clk_state_subtree(struct clk_core *c)
+{
+ int vdd_level = 0;
+ struct clk_core *child;
+
+ if (!c)
+ return;
+
+ if (c->vdd_class) {
+ vdd_level = clk_find_vdd_level(c, c->rate);
+ if (vdd_level < 0)
+ vdd_level = 0;
+ }
+
+ trace_clk_state(c->name, c->prepare_count, c->enable_count,
+ c->rate, vdd_level);
+
+ hlist_for_each_entry(child, &c->children, child_node)
+ clk_state_subtree(child);
+}
+
+static int clk_state_show(struct seq_file *s, void *data)
+{
+ struct clk_core *c;
+ struct hlist_head **lists = (struct hlist_head **)s->private;
+
+ clk_prepare_lock();
+
+ for (; *lists; lists++)
+ hlist_for_each_entry(c, *lists, child_node)
+ clk_state_subtree(c);
+
+ clk_prepare_unlock();
+
+ return 0;
+}
+
+
+static int clk_state_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, clk_state_show, inode->i_private);
+}
+
+static const struct file_operations clk_state_fops = {
+ .open = clk_state_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static void clk_summary_show_one(struct seq_file *s, struct clk_core *c,
+ int level)
+{
+ if (!c)
+ return;
+
+ seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu %5d %6d\n",
+ level * 3 + 1, "",
+ 30 - level * 3, c->name,
+ c->enable_count, c->prepare_count, c->protect_count,
+ clk_core_get_rate(c), clk_core_get_accuracy(c),
+ clk_core_get_phase(c),
+ clk_core_get_scaled_duty_cycle(c, 100000));
+}
+
+static void clk_summary_show_subtree(struct seq_file *s, struct clk_core *c,
+ int level)
+{
+ struct clk_core *child;
+
+ if (!c)
+ return;
+
+ if (c->ops->bus_vote)
+ c->ops->bus_vote(c->hw, true);
+ clk_summary_show_one(s, c, level);
+
+ hlist_for_each_entry(child, &c->children, child_node)
+ clk_summary_show_subtree(s, child, level + 1);
+ if (c->ops->bus_vote)
+ c->ops->bus_vote(c->hw, false);
+}
+
+static int clk_summary_show(struct seq_file *s, void *data)
+{
+ struct clk_core *c;
+ struct hlist_head **lists = (struct hlist_head **)s->private;
+
+ seq_puts(s, " enable prepare protect duty\n");
+ seq_puts(s, " clock count count count rate accuracy phase cycle\n");
+ seq_puts(s, "---------------------------------------------------------------------------------------------\n");
+
+ clk_prepare_lock();
+
+ for (; *lists; lists++)
+ hlist_for_each_entry(c, *lists, child_node)
+ clk_summary_show_subtree(s, c, 0);
+
+ clk_prepare_unlock();
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_summary);
+
+static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
+{
+ if (!c)
+ return;
+
+ /* This should be JSON format, i.e. elements separated with a comma */
+ seq_printf(s, "\"%s\": { ", c->name);
+ seq_printf(s, "\"enable_count\": %d,", c->enable_count);
+ seq_printf(s, "\"prepare_count\": %d,", c->prepare_count);
+ seq_printf(s, "\"protect_count\": %d,", c->protect_count);
+ seq_printf(s, "\"rate\": %lu,", clk_core_get_rate(c));
+ seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy(c));
+ seq_printf(s, "\"phase\": %d,", clk_core_get_phase(c));
+ seq_printf(s, "\"duty_cycle\": %u",
+ clk_core_get_scaled_duty_cycle(c, 100000));
+}
+
+static void clk_dump_subtree(struct seq_file *s, struct clk_core *c, int level)
+{
+ struct clk_core *child;
+
+ if (!c)
+ return;
+
+ if (c->ops->bus_vote)
+ c->ops->bus_vote(c->hw, true);
+
+ clk_dump_one(s, c, level);
+
+ hlist_for_each_entry(child, &c->children, child_node) {
+ seq_putc(s, ',');
+ clk_dump_subtree(s, child, level + 1);
+ }
+
+ seq_putc(s, '}');
+
+ if (c->ops->bus_vote)
+ c->ops->bus_vote(c->hw, false);
+}
+
+static int clk_dump_show(struct seq_file *s, void *data)
+{
+ struct clk_core *c;
+ bool first_node = true;
+ struct hlist_head **lists = (struct hlist_head **)s->private;
+
+ seq_putc(s, '{');
+ clk_prepare_lock();
+
+ for (; *lists; lists++) {
+ hlist_for_each_entry(c, *lists, child_node) {
+ if (!first_node)
+ seq_putc(s, ',');
+ first_node = false;
+ clk_dump_subtree(s, c, 0);
+ }
+ }
+
+ clk_prepare_unlock();
+
+ seq_puts(s, "}\n");
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_dump);
+
+static const struct {
+ unsigned long flag;
+ const char *name;
+} clk_flags[] = {
+#define ENTRY(f) { f, #f }
+ ENTRY(CLK_SET_RATE_GATE),
+ ENTRY(CLK_SET_PARENT_GATE),
+ ENTRY(CLK_SET_RATE_PARENT),
+ ENTRY(CLK_IGNORE_UNUSED),
+ ENTRY(CLK_IS_BASIC),
+ ENTRY(CLK_GET_RATE_NOCACHE),
+ ENTRY(CLK_SET_RATE_NO_REPARENT),
+ ENTRY(CLK_GET_ACCURACY_NOCACHE),
+ ENTRY(CLK_RECALC_NEW_RATES),
+ ENTRY(CLK_SET_RATE_UNGATE),
+ ENTRY(CLK_IS_CRITICAL),
+ ENTRY(CLK_OPS_PARENT_ENABLE),
+ ENTRY(CLK_DUTY_CYCLE_PARENT),
+#undef ENTRY
+};
+
+static int clk_flags_show(struct seq_file *s, void *data)
+{
+ struct clk_core *core = s->private;
+ unsigned long flags = core->flags;
+ unsigned int i;
+
+ for (i = 0; flags && i < ARRAY_SIZE(clk_flags); i++) {
+ if (flags & clk_flags[i].flag) {
+ seq_printf(s, "%s\n", clk_flags[i].name);
+ flags &= ~clk_flags[i].flag;
+ }
+ }
+ if (flags) {
+ /* Unknown flags */
+ seq_printf(s, "0x%lx\n", flags);
+ }
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_flags);
+
+static int possible_parents_show(struct seq_file *s, void *data)
+{
+ struct clk_core *core = s->private;
+ int i;
+
+ for (i = 0; i < core->num_parents - 1; i++)
+ seq_printf(s, "%s ", core->parent_names[i]);
+
+ seq_printf(s, "%s\n", core->parent_names[i]);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(possible_parents);
+
+static int clk_duty_cycle_show(struct seq_file *s, void *data)
+{
+ struct clk_core *core = s->private;
+ struct clk_duty *duty = &core->duty;
+
+ seq_printf(s, "%u/%u\n", duty->num, duty->den);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_duty_cycle);
+
+static ssize_t clock_debug_rate_store(struct file *file,
+ const char __user *buffer, size_t count, loff_t *ppos)
+{
+ char buff_temp[8];
+ char *end;
+ u64 val;
+ int ret ;
+ struct clk_core *core = ((struct seq_file *)file->private_data)->private;
+
+ if(count <= 0 || buffer == NULL){
+ pr_err("Input buf is NULL\n");
+ return 0;
+ }
+
+ copy_from_user(buff_temp, buffer, 8);
+ val = simple_strtoll(buff_temp, &end, 0);
+
+ clk_prepare_lock();
+ if (core->ops->bus_vote)
+ core->ops->bus_vote(core->hw, true);
+
+ ret = clk_set_rate(core->hw->clk, val);
+ if (ret)
+ pr_err("clk_set_rate(%llu) failed (%d)\n",
+ (unsigned long)val, ret);
+
+ if (core->ops->bus_vote)
+ core->ops->bus_vote(core->hw, false);
+ clk_prepare_unlock();
+
+ return count;
+}
+
+static int clock_debug_rate_show(struct seq_file *file, void *v)
+{
+ struct clk_core *core = file->private;
+ u64 val;
+
+ clk_prepare_lock();
+ if (core->ops->bus_vote)
+ core->ops->bus_vote(core->hw, true);
+
+ val = clk_get_rate(core->hw->clk);
+
+ if (core->ops->bus_vote)
+ core->ops->bus_vote(core->hw, false);
+ clk_prepare_unlock();
+
+ seq_printf(file, "%llu\n", val);
+ return 0;
+}
+
+static int clock_debug_rate_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, clock_debug_rate_show, PDE_DATA(inode));
+}
+
+static const struct file_operations clock_rate_fops = {
+ .open = clock_debug_rate_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+ .write = clock_debug_rate_store,
+};
+
+
+static int clock_parent_show(struct seq_file *file, void *v)
+{
+ char name[256] = {0};
+ struct clk_core *core = file->private;
+ struct clk_core *p = core->hw->core->parent;
+
+ snprintf(name, sizeof(name), "%s\n", p ? p->name : "None\n");
+
+ seq_printf(file, "%d\n", name);
+ return 0;
+ //return simple_read_from_buffer(ubuf, cnt, ppos, name, strlen(name));
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clock_parent);
+
+static ssize_t clock_enable_store(struct file *file,
+ const char __user *buffer, size_t count, loff_t *ppos)
+{
+ char buff_temp[8];
+ char *end;
+ u64 val;
+
+ struct clk_core *core = ((struct seq_file *)file->private_data)->private;
+ int rc = 0;
+
+
+ if(count <= 0 || buffer == NULL){
+ pr_err("Input buf is NULL\n");
+ return 0;
+ }
+
+ copy_from_user(buff_temp, buffer, 8);
+ val = simple_strtoll(buff_temp, &end, 0);
+
+ clk_prepare_lock();
+ if (core->ops->bus_vote)
+ core->ops->bus_vote(core->hw, true);
+
+ if (val)
+ rc = clk_prepare_enable(core->hw->clk);
+ else
+ clk_disable_unprepare(core->hw->clk);
+
+ if (core->ops->bus_vote)
+ core->ops->bus_vote(core->hw, false);
+ clk_prepare_unlock();
+
+ return count;
+}
+
+static int clock_enable_show(struct seq_file *file, void *v)
+{
+ struct clk_core *core = file->private;
+ int enabled = 0;
+
+ enabled = core->enable_count;
+
+ seq_printf(file, "%d\n", enabled);
+ return 0;
+}
+
+DEFINE_PROC_SHOW_STORE_ATTRIBUTE(clock_enable);
+
+#define clock_debug_output(m, c, fmt, ...) \
+do { \
+ if (m) \
+ seq_printf(m, fmt, ##__VA_ARGS__); \
+ else if (c) \
+ pr_cont(fmt, ##__VA_ARGS__); \
+ else \
+ pr_info(fmt, ##__VA_ARGS__); \
+} while (0)
+
+static int clock_debug_print_clock(struct clk_core *c, struct seq_file *s)
+{
+ char *start = "";
+ struct clk *clk;
+
+ if (!c || !c->prepare_count)
+ return 0;
+
+ clk = c->hw->clk;
+
+ clock_debug_output(s, 0, " ");
+
+ do {
+ if (clk->core->vdd_class)
+ clock_debug_output(s, 1, "%s%s:%u:%u [%ld, %d]", start,
+ clk->core->name,
+ clk->core->prepare_count,
+ clk->core->enable_count,
+ clk->core->rate,
+ clk_find_vdd_level(clk->core, clk->core->rate));
+ else
+ clock_debug_output(s, 1, "%s%s:%u:%u [%ld]", start,
+ clk->core->name,
+ clk->core->prepare_count,
+ clk->core->enable_count,
+ clk->core->rate);
+ start = " -> ";
+ } while ((clk = clk_get_parent(clk)));
+
+ clock_debug_output(s, 1, "\n");
+
+ return 1;
+}
+
+/*
+ * clock_debug_print_enabled_clocks() - Print names of enabled clocks
+ */
+static void clock_debug_print_enabled_clocks(struct seq_file *s)
+{
+ struct clk_core *core;
+ int cnt = 0;
+
+ if (!mutex_trylock(&clk_debug_lock))
+ return;
+
+ clock_debug_output(s, 0, "Enabled clocks:\n");
+
+ hlist_for_each_entry(core, &clk_debug_list, debug_node)
+ cnt += clock_debug_print_clock(core, s);
+
+ mutex_unlock(&clk_debug_lock);
+
+ if (cnt)
+ clock_debug_output(s, 0, "Enabled clock count: %d\n", cnt);
+ else
+ clock_debug_output(s, 0, "No clocks enabled.\n");
+}
+
+static int clk_enabled_list_show(struct seq_file *s, void *unused)
+{
+ clock_debug_print_enabled_clocks(s);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_enabled_list);
+
+void clk_debug_print_hw(struct clk_core *clk, struct seq_file *f)
+{
+ if (IS_ERR_OR_NULL(clk))
+ return;
+
+ clk_debug_print_hw(clk->parent, f);
+
+ clock_debug_output(f, false, "%s\n", clk->name);
+
+ if (!clk->ops->list_registers)
+ return;
+
+ clk->ops->list_registers(f, clk->hw);
+}
+EXPORT_SYMBOL(clk_debug_print_hw);
+
+static int clock_print_hw_show(struct seq_file *m, void *unused)
+{
+ struct clk_core *c = m->private;
+ struct clk_core *clk;
+
+ clk_prepare_lock();
+ for (clk = c; clk; clk = clk->parent)
+ if (clk->ops->bus_vote)
+ clk->ops->bus_vote(clk->hw, true);
+
+ clk_debug_print_hw(c, m);
+
+ for (clk = c; clk; clk = clk->parent)
+ if (clk->ops->bus_vote)
+ clk->ops->bus_vote(c->hw, false);
+ clk_prepare_unlock();
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clock_print_hw);
+
+static int list_rates_show(struct seq_file *s, void *unused)
+{
+ struct clk_core *core = s->private;
+ int level = 0, i = 0;
+ unsigned long rate, rate_max = 0;
+
+ /* Find max frequency supported within voltage constraints. */
+ if (!core->vdd_class) {
+ rate_max = ULONG_MAX;
+ } else {
+ for (level = 0; level < core->num_rate_max; level++)
+ if (core->rate_max[level])
+ rate_max = core->rate_max[level];
+ }
+
+ /*
+ * List supported frequencies <= rate_max. Higher frequencies may
+ * appear in the frequency table, but are not valid and should not
+ * be listed.
+ */
+ while (!IS_ERR_VALUE(rate =
+ core->ops->list_rate(core->hw, i++, rate_max))) {
+ if (rate <= 0)
+ break;
+ if (rate <= rate_max)
+ seq_printf(s, "%lu\n", rate);
+ }
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(list_rates);
+
+static void clock_print_rate_max_by_level(struct seq_file *s, int level)
+{
+ struct clk_core *core = s->private;
+ struct clk_vdd_class *vdd_class = core->vdd_class;
+ int off, i, vdd_level, nregs = vdd_class->num_regulators;
+
+ vdd_level = clk_find_vdd_level(core, core->rate);
+
+ seq_printf(s, "%2s%10lu", vdd_level == level ? "[" : "",
+ core->rate_max[level]);
+
+ for (i = 0; i < nregs; i++) {
+ off = nregs*level + i;
+ if (vdd_class->vdd_uv)
+ seq_printf(s, "%10u", vdd_class->vdd_uv[off]);
+ }
+
+ if (vdd_level == level)
+ seq_puts(s, "]");
+
+ seq_puts(s, "\n");
+}
+
+static int rate_max_show(struct seq_file *s, void *unused)
+{
+ struct clk_core *core = s->private;
+ struct clk_vdd_class *vdd_class = core->vdd_class;
+ int level = 0, i, nregs = vdd_class->num_regulators;
+ char reg_name[10];
+
+ int vdd_level = clk_find_vdd_level(core, core->rate);
+
+ if (vdd_level < 0) {
+ seq_printf(s, "could not find_vdd_level for %s, %ld\n",
+ core->name, core->rate);
+ return 0;
+ }
+
+ seq_printf(s, "%12s", "");
+ for (i = 0; i < nregs; i++) {
+ snprintf(reg_name, ARRAY_SIZE(reg_name), "reg %d", i);
+ seq_printf(s, "%10s", reg_name);
+ }
+
+ seq_printf(s, "\n%12s", "freq");
+ for (i = 0; i < nregs; i++)
+ seq_printf(s, "%10s", "uV");
+
+ seq_puts(s, "\n");
+
+ for (level = 0; level < core->num_rate_max; level++)
+ clock_print_rate_max_by_level(s, level);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(rate_max);
+
+static int clk_accuracy_show(struct seq_file *s, void *data)
+{
+ struct clk_core *core = s->private;
+
+ seq_printf(s, "%lu\n", core->accuracy);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_accuracy);
+
+static int clk_phase_show(struct seq_file *s, void *data)
+{
+ struct clk_core *core = s->private;
+
+ seq_printf(s, "%d\n", core->phase);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_phase);
+
+static int clk_prepare_count_show(struct seq_file *s, void *data)
+{
+ struct clk_core *core = s->private;
+
+ seq_printf(s, "%d\n", core->prepare_count);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_prepare_count);
+
+static int clk_notifier_count_show(struct seq_file *s, void *data)
+{
+ struct clk_core *core = s->private;
+
+ seq_printf(s, "%d\n", core->notifier_count);
+
+ return 0;
+}
+DEFINE_PROC_SHOW_ATTRIBUTE(clk_notifier_count);
+
+
+static int clk_debug_create_one(struct clk_core *core, struct proc_dir_entry *pdentry)
+{
+ struct proc_dir_entry *d;
+ int ret = -ENOMEM;
+
+ if (!core || !pdentry) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ d = proc_mkdir(core->name, pdentry);
+ if (!d)
+ goto out;
+
+ core->dentry = d;
+
+ d = proc_create_data("clk_rate", 0444, core->dentry, &clock_rate_fops, core);
+ if (!d)
+ goto err_out;
+
+ if (core->ops->list_rate) {
+ if (!proc_create_data("clk_list_rates",
+ 0444, core->dentry, &list_rates_fops, core))
+ goto err_out;
+ }
+
+ if (core->vdd_class && !proc_create_data("clk_rate_max",
+ 0444, core->dentry, &rate_max_fops, core))
+ goto err_out;
+
+ d = proc_create_data("clk_accuracy", 0444, core->dentry, &clk_accuracy_fops, core);
+ if (!d)
+ goto err_out;
+
+ d = proc_create_data("clk_phase", 0444, core->dentry, &clk_phase_fops, core);
+ if (!d)
+ goto err_out;
+
+ d = proc_create_data("clk_prepare_count", 0444, core->dentry, &clk_prepare_count_fops, core);
+ if (!d)
+ goto err_out;
+
+ d = proc_create_data("clk_flags", 0444, core->dentry, &clk_flags_fops, core);
+ if (!d)
+ goto err_out;
+
+ d = proc_create_data("clk_enable_count", 0444, core->dentry, &clock_enable_fops, core);
+ if (!d)
+ goto err_out;
+
+ d = proc_create_data("clk_notifier_count", 0444, core->dentry, &clk_notifier_count_fops, core);
+ if (!d)
+ goto err_out;
+
+ if (core->num_parents > 1) {
+ d = proc_create_data("clk_possible_parents", 0444,
+ core->dentry, &possible_parents_fops, core);
+ if (!d)
+ goto err_out;
+ }
+
+ d = proc_create_data("clk_parent", 0444, core->dentry, &clock_parent_fops, core);
+ if (!d)
+ goto err_out;
+
+ d = proc_create_data("clk_print_regs", 0444, core->dentry, &clock_print_hw_fops, core);
+ if (!d)
+ goto err_out;
+
+ //if (core->ops->debug_init)
+ // core->ops->debug_init(core->hw, core->dentry);
+
+ ret = 0;
+ goto out;
+
+err_out:
+ proc_remove(core->dentry);
+ core->dentry = NULL;
+out:
+ return ret;
+}
+
+/**
+ * clk_debug_register - add a clk node to the debugfs clk directory
+ * @core: the clk being added to the debugfs clk directory
+ *
+ * Dynamically adds a clk to the debugfs clk directory if debugfs has been
+ * initialized. Otherwise it bails out early since the debugfs clk directory
+ * will be created lazily by clk_debug_init as part of a late_initcall.
+ */
+static void clk_debug_register(struct clk_core *core)
+{
+ mutex_lock(&clk_debug_lock);
+ hlist_add_head(&core->debug_node, &clk_debug_list);
+ if (inited)
+ clk_debug_create_one(core, rootdir);
+ mutex_unlock(&clk_debug_lock);
+}
+
+ /**
+ * clk_debug_unregister - remove a clk node from the debugfs clk directory
+ * @core: the clk being removed from the debugfs clk directory
+ *
+ * Dynamically removes a clk and all its child nodes from the
+ * debugfs clk directory if clk->dentry points to debugfs created by
+ * clk_debug_register in __clk_core_init.
+ */
+static void clk_debug_unregister(struct clk_core *core)
+{
+ mutex_lock(&clk_debug_lock);
+ hlist_del_init(&core->debug_node);
+ proc_remove(core->dentry);
+ core->dentry = NULL;
+ mutex_unlock(&clk_debug_lock);
+}
+
+/*
+ * Print the names of all enabled clocks and their parents if
+ * debug_suspend is set from debugfs.
+ */
+void clock_debug_print_enabled(void)
+{
+ if (likely(!debug_suspend))
+ return;
+ clock_debug_print_enabled_clocks(NULL);
+}
+EXPORT_SYMBOL_GPL(clock_debug_print_enabled);
+
+static ssize_t debug_suspend_store(struct file *file,
+ const char __user *buffer, size_t count, loff_t *ppos)
+{
+ char buff_temp[8];
+ char *end;
+
+ if(count <= 0 || buffer == NULL){
+ pr_err("Input buf is NULL\n");
+ return 0;
+ }
+
+ copy_from_user(buff_temp, buffer, 8);
+ debug_suspend = simple_strtoll(buff_temp, &end, 0);
+
+ return count;
+}
+
+static int debug_suspend_show(struct seq_file *m, void *v)
+{
+ seq_printf(m, "%d\n", debug_suspend);
+ return 0;
+}
+DEFINE_PROC_SHOW_STORE_ATTRIBUTE(debug_suspend);
+/**
+ * oplus_clk_debug_init - lazily populate the debugfs clk directory
+ *
+ * clks are often initialized very early during boot before memory can be
+ * dynamically allocated and well before debugfs is setup. This function
+ * populates the debugfs clk directory once at boot-time when we know that
+ * debugfs is setup. It should only be called once at boot-time, all other clks
+ * added dynamically will be done so with clk_debug_register.
+ */
+static int __init oplus_clk_debug_init(void)
+{
+ struct proc_dir_entry *d;
+ struct clk_core *core;
+
+ rootdir = proc_mkdir("oplus_clk", NULL);
+ if(!rootdir) {
+ return -ENOMEM;
+ }
+
+ d = proc_create_data("clk_summary", 0444, rootdir, &clk_summary_fops, &all_lists);
+ if (!d)
+ return -ENOMEM;
+
+ d = proc_create_data("clk_dump", 0444, rootdir, &clk_dump_fops, &all_lists);
+ if (!d)
+ return -ENOMEM;
+
+ d = proc_create_data("clk_enabled_list", 0444, rootdir, &clk_enabled_list_fops, &clk_debug_list);
+ if (!d)
+ return -ENOMEM;
+
+ d = proc_create("debug_suspend", 0644, rootdir, &debug_suspend_fops);
+ if (!d)
+ return -ENOMEM;
+
+ d = proc_create_data("trace_clocks", 0444, rootdir, &clk_state_fops, &all_lists);
+ if (!d)
+ return -ENOMEM;
+
+ mutex_lock(&clk_debug_lock);
+ hlist_for_each_entry(core, &clk_debug_list, debug_node)
+ clk_debug_create_one(core, rootdir);
+
+ inited = 1;
+ mutex_unlock(&clk_debug_lock);
+ return 0;
+}
+late_initcall(oplus_clk_debug_init);
#else
static inline void clk_debug_register(struct clk_core *core) { }
static inline void clk_debug_reparent(struct clk_core *core,
@@ -4057,6 +4880,14 @@ void clock_debug_print_enabled(void)
}
#endif
+
+#if (defined OPLUS_FEATURE_POWERINFO_RPMH)||(defined CONFIG_DEBUG_FS)
+void oplus_clock_debug_print_enabled(void)
+{
+ clock_debug_print_enabled_clocks(NULL);
+}
+EXPORT_SYMBOL_GPL(oplus_clock_debug_print_enabled);
+#endif
/**
* __clk_core_init - initialize the data structures in a struct clk_core
* @core: clk_core being initialized
@@ -5554,4 +6385,4 @@ void __init of_clk_init(const struct of_device_id *matches)
force = true;
}
}
-#endif
+#endif
\ No newline at end of file
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index b050316480fc..42904ffee78a 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -34,6 +34,16 @@
#include
#include
+#ifdef CONFIG_OPLUS_FEATURE_TPD
+#include
+#endif
+
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+#include
+#endif
+#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED)
+#include
+#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */
static LIST_HEAD(cpufreq_policy_list);
@@ -200,6 +210,14 @@ struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
}
EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
+#ifdef OPLUS_FEATURE_HEALTHINFO
+struct list_head *get_cpufreq_policy_list(void)
+{
+ return &cpufreq_policy_list;
+}
+EXPORT_SYMBOL(get_cpufreq_policy_list);
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
unsigned int cpufreq_generic_get(unsigned int cpu)
{
struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
@@ -361,6 +379,9 @@ static void cpufreq_notify_transition(struct cpufreq_policy *policy,
cpufreq_stats_record_transition(policy, freqs->new);
cpufreq_times_record_transition(policy, freqs->new);
policy->cur = freqs->new;
+#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED)
+ update_freq_info(policy);
+#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */
}
}
@@ -507,7 +528,15 @@ EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);
unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
unsigned int target_freq)
{
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+ unsigned int old_target_freq = target_freq;
+#endif
target_freq = clamp_val(target_freq, policy->min, policy->max);
+
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+ jankinfo_update_freq_reach_limit_count(policy,
+ old_target_freq, target_freq, DO_CLAMP);
+#endif
policy->cached_target_freq = target_freq;
if (cpufreq_driver->target_index) {
@@ -905,6 +934,19 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
}
+#ifdef OPLUS_FEATURE_HEALTHINFO
+#ifdef CONFIG_OPLUS_HEALTHINFO
+static ssize_t show_freq_change_info(struct cpufreq_policy *policy, char *buf)
+{
+ ssize_t i = 0;
+
+ i += sprintf(buf, "%u,%s\n", policy->org_max, policy->change_comm);
+
+ return i;
+}
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
cpufreq_freq_attr_ro(cpuinfo_min_freq);
cpufreq_freq_attr_ro(cpuinfo_max_freq);
@@ -915,6 +957,11 @@ cpufreq_freq_attr_ro(scaling_cur_freq);
cpufreq_freq_attr_ro(bios_limit);
cpufreq_freq_attr_ro(related_cpus);
cpufreq_freq_attr_ro(affected_cpus);
+#ifdef OPLUS_FEATURE_HEALTHINFO
+#ifdef CONFIG_OPLUS_HEALTHINFO
+cpufreq_freq_attr_ro(freq_change_info);
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
cpufreq_freq_attr_rw(scaling_min_freq);
cpufreq_freq_attr_rw(scaling_max_freq);
cpufreq_freq_attr_rw(scaling_governor);
@@ -932,6 +979,11 @@ static struct attribute *default_attrs[] = {
&scaling_driver.attr,
&scaling_available_governors.attr,
&scaling_setspeed.attr,
+#ifdef OPLUS_FEATURE_HEALTHINFO
+#ifdef CONFIG_OPLUS_HEALTHINFO
+ &freq_change_info.attr,
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
NULL
};
@@ -1279,6 +1331,9 @@ static int cpufreq_online(unsigned int cpu)
per_cpu(cpufreq_cpu_data, j) = policy;
add_cpu_dev_symlink(policy, j);
}
+#ifdef CONFIG_OPLUS_FEATURE_TPD
+ tpd_init_policy(policy);
+#endif
} else {
policy->min = policy->user_policy.min;
policy->max = policy->user_policy.max;
@@ -1902,8 +1957,14 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
unsigned int target_freq)
{
int ret;
-
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+ unsigned int old_target_freq = target_freq;
+#endif
target_freq = clamp_val(target_freq, policy->min, policy->max);
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+ jankinfo_update_freq_reach_limit_count(policy,
+ old_target_freq, target_freq, DO_CLAMP | DO_INCREASE);
+#endif
ret = cpufreq_driver->fast_switch(policy, target_freq);
if (ret) {
@@ -2010,6 +2071,10 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
/* Make sure that target_freq is within supported range */
target_freq = clamp_val(target_freq, policy->min, policy->max);
+#if IS_ENABLED(CONFIG_OPLUS_FEATURE_CPU_JANKINFO)
+ jankinfo_update_freq_reach_limit_count(policy,
+ old_target_freq, target_freq, DO_CLAMP);
+#endif
pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
policy->cpu, target_freq, relation, old_target_freq);
@@ -2247,7 +2312,11 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
new_policy->cpu, new_policy->min, new_policy->max);
-
+#ifdef OPLUS_FEATURE_HEALTHINFO
+#ifdef CONFIG_OPLUS_HEALTHINFO
+ policy->org_max = new_policy->max;
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
/*
@@ -2286,6 +2355,16 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
policy->max = new_policy->max;
trace_cpu_frequency_limits(policy);
+#ifdef OPLUS_FEATURE_HEALTHINFO
+#ifdef CONFIG_OPLUS_HEALTHINFO
+ strncpy(policy->change_comm, current->comm, TASK_COMM_LEN);
+#endif
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
+#if defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED)
+ update_freq_limit_info(policy);
+#endif /* defined(OPLUS_FEATURE_TASK_CPUSTATS) && defined(CONFIG_OPLUS_SCHED) */
+
arch_set_max_freq_scale(policy->cpus, policy->max);
policy->cached_target_freq = UINT_MAX;
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 21b919bfaecc..9ff33943e972 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -212,7 +212,7 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
/* We failed, release resources */
policy->stats = NULL;
- kfree(stats->time_in_state);
+
free_stat:
kfree(stats);
}
diff --git a/drivers/cpufreq/cpufreq_times.c b/drivers/cpufreq/cpufreq_times.c
index 210742e963e0..a41a6c66a3a7 100644
--- a/drivers/cpufreq/cpufreq_times.c
+++ b/drivers/cpufreq/cpufreq_times.c
@@ -25,6 +25,10 @@
#include
#include
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+#include
+#endif
+
#define UID_HASH_BITS 10
static DECLARE_HASHTABLE(uid_hash_table, UID_HASH_BITS);
@@ -424,6 +428,9 @@ void cpufreq_acct_update_power(struct task_struct *p, u64 cputime)
uid_entry->time_in_state[state] += cputime;
spin_unlock_irqrestore(&uid_lock, flags);
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+ midas_record_task_times(uid, cputime, p, state);
+#endif
rcu_read_lock();
uid_entry = find_uid_entry_rcu(uid);
if (!uid_entry) {
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 219704cd87eb..8c9e44a13b86 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -228,6 +228,9 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
trace_cpu_idle_rcuidle(index, dev->cpu);
time_start = ns_to_ktime(local_clock());
+#ifdef CONFIG_OPLUS_FEATURE_GAME_OPT
+ g_time_in_state_update_idle(dev->cpu, 1);
+#endif
stop_critical_timings();
entered_state = target_state->enter(dev, drv, index);
@@ -235,6 +238,9 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
sched_clock_idle_wakeup_event();
time_end = ns_to_ktime(local_clock());
+#ifdef CONFIG_OPLUS_FEATURE_GAME_OPT
+ g_time_in_state_update_idle(dev->cpu, 0);
+#endif
trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
/* The cpu is no longer idle or about to enter idle. */
diff --git a/drivers/cpuidle/cpuidle.h b/drivers/cpuidle/cpuidle.h
index 2965ab32a583..6d2556f08117 100644
--- a/drivers/cpuidle/cpuidle.h
+++ b/drivers/cpuidle/cpuidle.h
@@ -5,7 +5,9 @@
#ifndef __DRIVER_CPUIDLE_H
#define __DRIVER_CPUIDLE_H
-
+#ifdef CONFIG_OPLUS_FEATURE_GAME_OPT
+#include "../soc/oplus/game_opt/game_ctrl.h"
+#endif
/* For internal use only */
extern struct cpuidle_governor *cpuidle_curr_governor;
extern struct list_head cpuidle_governors;
diff --git a/drivers/devfreq/governor_bw_hwmon.c b/drivers/devfreq/governor_bw_hwmon.c
index 1076d3ca99c6..23e07809ac99 100644
--- a/drivers/devfreq/governor_bw_hwmon.c
+++ b/drivers/devfreq/governor_bw_hwmon.c
@@ -113,6 +113,13 @@ show_attr(__attr) \
store_attr(__attr, (min), (max)) \
static DEVICE_ATTR(__attr, 0644, show_##__attr, store_##__attr)
+#ifdef VENDOR_EDIT
+#define gov_attr_rw(__attr, min, max) \
+show_attr(__attr) \
+store_attr(__attr, (min), (max)) \
+static DEVICE_ATTR(__attr, 0664, show_##__attr, store_##__attr)
+#endif /* VENDOR_EDIT */
+
#define show_list_attr(name, n) \
static ssize_t show_list_##name(struct device *dev, \
struct device_attribute *attr, char *buf) \
@@ -808,9 +815,17 @@ gov_attr(up_scale, 0U, 500U);
gov_attr(up_thres, 1U, 100U);
gov_attr(down_thres, 0U, 90U);
gov_attr(down_count, 0U, 90U);
+
+#ifdef VENDOR_EDIT
+gov_attr_rw(hist_memory, 0U, 90U);
+gov_attr_rw(hyst_trigger_count, 0U, 90U);
+gov_attr_rw(hyst_length, 0U, 90U);
+#else
gov_attr(hist_memory, 0U, 90U);
gov_attr(hyst_trigger_count, 0U, 90U);
gov_attr(hyst_length, 0U, 90U);
+#endif /* VENDOR_EDIT */
+
gov_attr(idle_mbps, 0U, 2000U);
gov_attr(use_ab, 0U, 1U);
gov_list_attr(mbps_zones, NUM_MBPS_ZONES, 0U, UINT_MAX);
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 5fadc4c2910d..23f714774c61 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -44,6 +44,16 @@
#include
#include
+#ifdef OPLUS_FEATURE_LOWMEM_DBG
+/* Add for dump memory */
+/* usage when lowmmem occurs. */
+#include
+#endif /* OPLUS_FEATURE_LOWMEM_DBG */
+
+#if defined(OPLUS_FEATURE_PERFORMANCE) && defined(CONFIG_PROC_FS)
+#include
+#endif
+
static inline int is_dma_buf_file(struct file *);
struct dma_buf_list {
@@ -522,6 +532,15 @@ static inline int is_dma_buf_file(struct file *file)
return file->f_op == &dma_buf_fops;
}
+#ifdef OPLUS_FEATURE_LOWMEM_DBG
+/* Add for dump memory */
+/* usage when lowmmem occurs. */
+inline int oplus_is_dma_buf_file(struct file *file)
+{
+ return is_dma_buf_file(file);
+}
+#endif /* OPLUS_FEATURE_LOWMEM_DBG */
+
static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags)
{
struct file *file;
@@ -1328,7 +1347,7 @@ int dma_buf_get_uuid(struct dma_buf *dmabuf, uuid_t *uuid)
}
EXPORT_SYMBOL_GPL(dma_buf_get_uuid);
-#ifdef CONFIG_DEBUG_FS
+#if defined(CONFIG_DEBUG_FS) || (defined(OPLUS_FEATURE_PERFORMANCE) && defined(CONFIG_PROC_FS))
static int dma_buf_debug_show(struct seq_file *s, void *unused)
{
int ret;
@@ -1568,6 +1587,7 @@ static const struct file_operations dma_procs_debug_fops = {
.release = single_release
};
+#ifdef CONFIG_DEBUG_FS
static struct dentry *dma_buf_debugfs_dir;
static int dma_buf_init_debugfs(void)
@@ -1608,6 +1628,64 @@ static void dma_buf_uninit_debugfs(void)
{
debugfs_remove_recursive(dma_buf_debugfs_dir);
}
+#else /* CONFIG_DEBUG_FS */
+static inline int dma_buf_init_debugfs(void)
+{
+ return 0;
+}
+static inline void dma_buf_uninit_debugfs(void)
+{
+}
+#endif /* CONFIG_DEBUG_FS */
+
+#if defined(OPLUS_FEATURE_PERFORMANCE) && defined(CONFIG_PROC_FS)
+static struct proc_dir_entry *dma_buf_procfs_root;
+
+int dma_buf_init_procfs(void)
+{
+ struct proc_dir_entry *p;
+ int err = 0;
+
+ p = proc_mkdir("dma_buf", NULL);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+
+ dma_buf_procfs_root = p;
+
+ p = proc_create_data("bufinfo",
+ S_IFREG | 0664,
+ dma_buf_procfs_root,
+ &dma_buf_debug_fops,
+ NULL);
+ if (IS_ERR(p)) {
+ pr_debug("dma_buf: procfs: failed to create node bufinfo\n");
+ proc_remove(dma_buf_procfs_root);
+ dma_buf_procfs_root = NULL;
+ err = PTR_ERR(dma_buf_procfs_root);
+ return err;
+ }
+
+ p = proc_create_data("dmaprocs",
+ S_IFREG | 0664,
+ dma_buf_procfs_root,
+ &dma_procs_debug_fops,
+ NULL);
+ if (IS_ERR(p)) {
+ pr_debug("dma_buf: procfs: failed to create node dmaprocs\n");
+ proc_remove(dma_buf_procfs_root);
+ dma_buf_procfs_root = NULL;
+ err = PTR_ERR(dma_buf_procfs_root);
+ }
+
+ return err;
+}
+
+void dma_buf_uninit_procfs(void)
+{
+ proc_remove(dma_buf_procfs_root);
+}
+#endif /* defined(OPLUS_FEATURE_PERFORMANCE) && defined(CONFIG_PROC_FS) */
+
#else
static inline int dma_buf_init_debugfs(void)
{
@@ -1627,6 +1705,9 @@ static int __init dma_buf_init(void)
mutex_init(&db_list.lock);
INIT_LIST_HEAD(&db_list.head);
dma_buf_init_debugfs();
+#if defined(OPLUS_FEATURE_PERFORMANCE) && defined(CONFIG_PROC_FS)
+ dma_buf_init_procfs();
+#endif
return 0;
}
subsys_initcall(dma_buf_init);
@@ -1635,5 +1716,8 @@ static void __exit dma_buf_deinit(void)
{
dma_buf_uninit_debugfs();
kern_unmount(dma_buf_mnt);
+#if defined(OPLUS_FEATURE_PERFORMANCE) && defined(CONFIG_PROC_FS)
+ dma_buf_uninit_procfs();
+#endif
}
__exitcall(dma_buf_deinit);
diff --git a/drivers/esoc/esoc-mdm-4x.c b/drivers/esoc/esoc-mdm-4x.c
index 2a0dcc95f2f0..1ce447d0d5c6 100644
--- a/drivers/esoc/esoc-mdm-4x.c
+++ b/drivers/esoc/esoc-mdm-4x.c
@@ -9,6 +9,16 @@
#include
#include
#include "esoc-mdm.h"
+#include
+
+#ifdef OPLUS_BUG_STABILITY
+/*Add for 5G modem dump*/
+extern bool delay_panic;
+#endif
+
+#ifdef OPLUS_FEATURE_MODEM_MINIDUMP
+#include
+#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/
enum gpio_update_config {
GPIO_UPDATE_BOOTING_CONFIG = 1,
@@ -363,13 +373,42 @@ static void mdm_status_fn(struct work_struct *work)
mdm_update_gpio_configs(mdm, GPIO_UPDATE_RUNNING_CONFIG);
}
+#ifdef OPLUS_FEATURE_MODEM_MINIDUMP
+extern void mdmreason_set(char * buf);
+#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/
+
+#ifdef OPLUS_FEATURE_MODEM_MINIDUMP
+static int strn(const char *p, const char chr)
+{
+ int count = 0;
+ while(*p)
+ {
+ if(*p == chr)
+ ++count;
+ ++p;
+ }
+ return count;
+}
+#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/
+
+bool modem_force_rst = false;
+
static void mdm_get_restart_reason(struct work_struct *work)
{
int ret, ntries = 0;
+#ifdef OPLUS_FEATURE_MODEM_MINIDUMP
+ char mdmflag = ':';
+ int mdmnum,mdmret1,mdmret2,mdmret3=0;
+ char sfr_buf2[RD_BUF_SIZE];
+#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/
+
char sfr_buf[RD_BUF_SIZE];
struct mdm_ctrl *mdm =
container_of(work, struct mdm_ctrl, restart_reason_work);
struct device *dev = mdm->dev;
+#ifdef OPLUS_FEATURE_MODEM_MINIDUMP
+ const char *name = mdm->esoc->subsys.name;
+#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/
do {
ret = sysmon_get_reason(&mdm->esoc->subsys, sfr_buf,
@@ -377,6 +416,35 @@ static void mdm_get_restart_reason(struct work_struct *work)
if (!ret) {
esoc_mdm_log("restart reason is %s\n", sfr_buf);
dev_err(dev, "mdm restart reason is %s\n", sfr_buf);
+#ifdef OPLUS_FEATURE_MODEM_MINIDUMP
+ mdmnum = strn(sfr_buf,mdmflag);
+ mdmret1=0;
+ mdmret2=0;
+ mdmret3=0;
+ if(mdmnum >= 2)
+ {
+ mdmnum = 2;
+ }
+ while(mdmret3++ < mdmnum)
+ {
+ while(sfr_buf[mdmret1++] != mdmflag);
+ }
+ while(sfr_buf[mdmret1])
+ {
+ sfr_buf2[mdmret2++] = sfr_buf[mdmret1++];
+ }
+ sfr_buf2[mdmret2]='\0';
+ if (!strcmp(name , "esoc0")){
+ if (modem_force_rst) {
+ modem_force_rst = false;
+ mdmreason_set("Force modem reset");
+ __subsystem_send_uevent(dev, "Force modem reset");
+ } else {
+ mdmreason_set(sfr_buf2);
+ __subsystem_send_uevent(dev, sfr_buf2);
+ }
+ }
+#endif /*OPLUS_FEATURE_MODEM_MINIDUMP*/
break;
}
msleep(SFR_RETRY_INTERVAL);
@@ -387,6 +455,17 @@ static void mdm_get_restart_reason(struct work_struct *work)
__func__, ret);
}
mdm->get_restart_reason = false;
+
+#ifdef OPLUS_BUG_STABILITY
+/*Add for 5G modem dump*/
+ if (delay_panic) {
+ snprintf(sfr_buf + strlen(sfr_buf), RD_BUF_SIZE - strlen(sfr_buf), " :SDX5x esoc0 modem crash");
+ dev_err(dev, "SDX5x trigger dump after 5s !\n");
+ msleep(5000);
+ mdm_power_down(mdm);
+ panic(sfr_buf);
+ }
+#endif
}
void mdm_wait_for_status_low(struct mdm_ctrl *mdm, bool atomic)
diff --git a/drivers/esoc/esoc-mdm-drv.c b/drivers/esoc/esoc-mdm-drv.c
index 5301be93d38f..9b31642e16bb 100644
--- a/drivers/esoc/esoc-mdm-drv.c
+++ b/drivers/esoc/esoc-mdm-drv.c
@@ -271,6 +271,23 @@ static void esoc_client_link_mdm_crash(struct esoc_clink *esoc_clink)
}
}
+static void mdm_force_reset(const struct subsys_desc *mdm_subsys)
+{
+ struct esoc_clink *esoc_clink =
+ container_of(mdm_subsys,
+ struct esoc_clink,
+ subsys);
+ struct mdm_ctrl *mdm = get_esoc_clink_data(esoc_clink);
+
+ esoc_mdm_log("MDM force reset\n");
+
+ if (mdm->pon_ops->soft_reset) {
+ mdm->pon_ops->soft_reset(mdm, true);
+ }
+
+ return;
+}
+
static void mdm_crash_shutdown(const struct subsys_desc *mdm_subsys)
{
struct esoc_clink *esoc_clink =
@@ -557,6 +574,7 @@ static int mdm_register_ssr(struct esoc_clink *esoc_clink)
subsys->ramdump = mdm_subsys_ramdumps;
subsys->powerup = mdm_subsys_powerup;
subsys->crash_shutdown = mdm_crash_shutdown;
+ subsys->force_reset = mdm_force_reset;
return esoc_clink_register_ssr(esoc_clink);
}
diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig
index 7ab2b74ed528..62ac622e2125 100644
--- a/drivers/firmware/qcom/Kconfig
+++ b/drivers/firmware/qcom/Kconfig
@@ -1,7 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
config MSM_TZ_LOG
tristate "MSM Trust Zone (TZ) Log Driver"
- depends on DEBUG_FS
+ #ifdef OPLUS_FEATURE_SECURITY_COMMON
+ #depends on DEBUG_FS
+ #endif
help
This option enables a driver with a debugfs interface for messages
produced by the Secure code (Trust zone). These messages provide
diff --git a/drivers/firmware/qcom/tz_log.c b/drivers/firmware/qcom/tz_log.c
index 15abf43254dd..8dbb79fefd17 100644
--- a/drivers/firmware/qcom/tz_log.c
+++ b/drivers/firmware/qcom/tz_log.c
@@ -23,6 +23,10 @@
#include
#include
+//#ifdef OPLUS_FEATURE_SECURITY_COMMON
+#include
+#define TZDBG_DIR_NAME "tzdbg"
+//#endif
/* QSEE_LOG_BUF_SIZE = 32K */
#define QSEE_LOG_BUF_SIZE 0x8000
@@ -1131,7 +1135,12 @@ static ssize_t tzdbgfs_read_unencrypted(struct file *file, char __user *buf,
size_t count, loff_t *offp)
{
int len = 0;
- int tz_id = *(int *)(file->private_data);
+//#ifdef OPLUS_FEATURE_SECURITY_COMMON
+ struct seq_file *seq = file->private_data;
+ int tz_id = *(int *)(seq->private);
+//else
+ //int tz_id = *(int *)(file->private_data);
+//#endif
if (tz_id == TZDBG_BOOT || tz_id == TZDBG_RESET ||
tz_id == TZDBG_INTERRUPT || tz_id == TZDBG_GENERAL ||
@@ -1253,10 +1262,27 @@ static ssize_t tzdbgfs_read(struct file *file, char __user *buf,
return tzdbgfs_read_encrypted(file, buf, count, offp);
}
+//#ifdef OPLUS_FEATURE_SECURITY_COMMON
+static int tzdbg_proc_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, NULL, PDE_DATA(inode));
+}
+
+static int tzdbg_proc_release(struct inode *inode, struct file *file)
+{
+ return single_release(inode, file);
+}
+//#endif
+
static const struct file_operations tzdbg_fops = {
.owner = THIS_MODULE,
.read = tzdbgfs_read,
- .open = simple_open,
+//#ifdef OPLUS_FEATURE_SECURITY_COMMON
+ .open = tzdbg_proc_open,
+ .release = tzdbg_proc_release,
+//else
+ //.open = simple_open,
+//#endif
};
@@ -1410,6 +1436,63 @@ static void tzdbg_free_encrypted_log_buf(struct platform_device *pdev)
enc_qseelog_info.vaddr, enc_qseelog_info.paddr);
}
+//#ifdef OPLUS_FEATURE_SECURITY_COMMON
+//change tzdbg node to proc.
+static int tzdbg_procfs_init(struct platform_device *pdev)
+{
+ int rc = 0;
+ int i;
+ struct proc_dir_entry *dent_dir;
+ struct proc_dir_entry *dent;
+
+ dent_dir = proc_mkdir(TZDBG_DIR_NAME, NULL);
+ if (dent_dir == NULL) {
+ dev_err(&pdev->dev, "tzdbg proc_mkdir failed\n");
+ return -ENOMEM;
+ }
+
+ for (i = 0; i < TZDBG_STATS_MAX; i++) {
+ tzdbg.debug_tz[i] = i;
+ dent = proc_create_data(tzdbg.stat[i].name,
+ 0444, dent_dir,
+ &tzdbg_fops, &tzdbg.debug_tz[i]);
+ if (dent == NULL) {
+ dev_err(&pdev->dev, "TZ proc_create_data failed\n");
+ rc = -ENOMEM;
+ goto err;
+ }
+ }
+ tzdbg.disp_buf = kzalloc(max(debug_rw_buf_size,
+ tzdbg.hyp_debug_rw_buf_size), GFP_KERNEL);
+ if (tzdbg.disp_buf == NULL)
+ goto err;
+ platform_set_drvdata(pdev, dent_dir);
+ return 0;
+err:
+ if(dent_dir){
+ remove_proc_entry(TZDBG_DIR_NAME, NULL);
+ }
+
+ return rc;
+}
+
+static void tzdbg_procfs_exit(struct platform_device *pdev)
+{
+ struct proc_dir_entry *dent_dir;
+
+ if (g_qsee_log) {
+ qtee_shmbridge_deregister(qseelog_shmbridge_handle);
+ dma_free_coherent(&pdev->dev, QSEE_LOG_BUF_SIZE,
+ (void *)g_qsee_log, coh_pmem);
+ }
+ kzfree(tzdbg.disp_buf);
+ dent_dir = platform_get_drvdata(pdev);
+ if(dent_dir){
+ remove_proc_entry(TZDBG_DIR_NAME, NULL);
+ }
+}
+//else
+/*
static int tzdbgfs_init(struct platform_device *pdev)
{
int rc = 0;
@@ -1449,7 +1532,8 @@ static void tzdbgfs_exit(struct platform_device *pdev)
dent_dir = platform_get_drvdata(pdev);
debugfs_remove_recursive(dent_dir);
}
-
+*/
+//#endif
static int __update_hypdbg_base(struct platform_device *pdev,
void __iomem *virt_iobase)
{
@@ -1671,8 +1755,13 @@ static int tz_log_probe(struct platform_device *pdev)
goto exit_free_encr_log_buf;
}
- if (tzdbgfs_init(pdev))
+//#ifdef OPLUS_FEATURE_SECURITY_COMMON
+ if (tzdbg_procfs_init(pdev))
+//else
+ //if (tzdbgfs_init(pdev))
+//#endif
goto exit_free_disp_buf;
+
return 0;
exit_free_disp_buf:
@@ -1689,7 +1778,11 @@ exit_free_diag_buf:
static int tz_log_remove(struct platform_device *pdev)
{
- tzdbgfs_exit(pdev);
+ //#ifdef OPLUS_FEATURE_SECURITY_COMMON
+ tzdbg_procfs_exit(pdev);
+ //else
+ //tzdbgfs_exit(pdev);
+ //#endif
dma_free_coherent(&pdev->dev, display_buf_size,
(void *)tzdbg.disp_buf, disp_buf_paddr);
tzdbg_free_encrypted_log_buf(pdev);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 602dce9a1759..3c91dd8c6e6f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -33,6 +33,11 @@
#define CREATE_TRACE_POINTS
#include
+#ifdef OPLUS_FEATURE_CHG_BASIC
+extern bool oplus_vooc_adapter_update_is_tx_gpio(unsigned long gpio_num);
+extern bool oplus_vooc_adapter_update_is_rx_gpio(unsigned long gpio_num);
+#endif /* OPLUS_FEATURE_CHG_BASIC */
+
/* Implementation infrastructure for GPIO interfaces.
*
* The GPIO programming interface allows for inlining speed-critical
@@ -2839,9 +2844,24 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc)
chip = desc->gdev->chip;
offset = gpio_chip_hwgpio(desc);
+#ifndef OPLUS_FEATURE_CHG_BASIC
value = chip->get ? chip->get(chip, offset) : -EIO;
value = value < 0 ? value : !!value;
trace_gpio_value(desc_to_gpio(desc), 1, value);
+#else
+ if(oplus_vooc_adapter_update_is_rx_gpio(desc_to_gpio(desc))) {
+ if(chip->get_oplus_vooc) {
+ value = chip->get_oplus_vooc(chip, offset);
+ } else {
+ pr_err("%s get_oplus_vooc not exist\n", __func__);
+ value = chip->get ? chip->get(chip, offset) : 0;
+ }
+ } else {
+ value = chip->get ? chip->get(chip, offset) : -EIO;
+ value = !!value;
+ trace_gpio_value(desc_to_gpio(desc), 1, value);
+ }
+#endif /* OPLUS_FEATURE_CHG_BASIC */
return value;
}
@@ -3076,8 +3096,22 @@ static void gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value)
struct gpio_chip *chip;
chip = desc->gdev->chip;
+#ifndef OPLUS_FEATURE_CHG_BASIC
trace_gpio_value(desc_to_gpio(desc), 0, value);
chip->set(chip, gpio_chip_hwgpio(desc), value);
+#else
+ if(oplus_vooc_adapter_update_is_tx_gpio(desc_to_gpio(desc)) == false) {
+ trace_gpio_value(desc_to_gpio(desc), 0, value);
+ chip->set(chip, gpio_chip_hwgpio(desc), value);
+ } else {
+ if(chip->set_oplus_vooc) {
+ chip->set_oplus_vooc(chip, gpio_chip_hwgpio(desc), value);
+ } else {
+ pr_err("%s set_oplus_vooc not exist\n", __func__);
+ chip->set(chip, gpio_chip_hwgpio(desc), value);
+ }
+ }
+#endif /* OPLUS_FEATURE_CHG_BASIC */
}
/*
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index a6771cef85e2..725ee0f7cb63 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -87,7 +87,9 @@ obj-y += tilcdc/
obj-$(CONFIG_DRM_QXL) += qxl/
obj-$(CONFIG_DRM_BOCHS) += bochs/
obj-$(CONFIG_DRM_VIRTIO_GPU) += virtio/
-obj-$(CONFIG_DRM_MSM) += msm/
+#ifdef OPLUS_BUG_STABILITY
+#obj-$(CONFIG_DRM_MSM) += msm/
+#endif
obj-$(CONFIG_DRM_TEGRA) += tegra/
obj-$(CONFIG_DRM_STM) += stm/
obj-$(CONFIG_DRM_STI) += sti/
diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 14aae7184efd..a63eaedec094 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -1059,7 +1059,11 @@ EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_scanline);
int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
u16 brightness)
{
+#ifndef OPLUS_BUG_STABILITY
u8 payload[2] = { brightness & 0xff, brightness >> 8 };
+#else /*OPLUS_BUG_STABILITY*/
+ u8 payload[2] = { brightness >> 8, brightness & 0xff};
+#endif /*OPLUS_BUG_STABILITY*/
ssize_t err;
err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 7550435c3ac5..0829e6a50675 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -958,6 +958,9 @@ static bool drm_mode_match_timings(const struct drm_display_mode *mode1,
mode1->vsync_start == mode2->vsync_start &&
mode1->vsync_end == mode2->vsync_end &&
mode1->vtotal == mode2->vtotal &&
+#ifdef OPLUS_BUG_STABILITY
+ drm_mode_vrefresh(mode1) == drm_mode_vrefresh(mode2) &&
+#endif /* OPLUS_BUG_STABILITY */
mode1->vscan == mode2->vscan;
}
diff --git a/drivers/gpu/msm/Makefile b/drivers/gpu/msm/Makefile
index 126bafb1ec18..f39aff88dde7 100644
--- a/drivers/gpu/msm/Makefile
+++ b/drivers/gpu/msm/Makefile
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: GPL-2.0-only
ccflags-y += -I$(src)
+#ifdef OPLUS_BUG_STABILITY
+ccflags-y += -I$(srctree)/techpack/display/oplus
+#endif /*OPLUS_BUG_STABILITY*/
msm_kgsl_core-y = \
kgsl.o \
diff --git a/drivers/gpu/msm/adreno_a6xx_preempt.c b/drivers/gpu/msm/adreno_a6xx_preempt.c
index a58f8b2c899a..b03b9b26b33e 100644
--- a/drivers/gpu/msm/adreno_a6xx_preempt.c
+++ b/drivers/gpu/msm/adreno_a6xx_preempt.c
@@ -487,7 +487,7 @@ void a6xx_preemption_schedule(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
- if (!adreno_is_preemption_enabled(adreno_dev))
+ if (!ADRENO_FEATURE(adreno_dev, ADRENO_PREEMPTION))
return;
mutex_lock(&device->mutex);
@@ -602,7 +602,7 @@ void a6xx_preemption_start(struct adreno_device *adreno_dev)
struct adreno_ringbuffer *rb;
unsigned int i;
- if (!adreno_is_preemption_enabled(adreno_dev))
+ if (!ADRENO_FEATURE(adreno_dev, ADRENO_PREEMPTION))
return;
/* Force the state to be clear */
diff --git a/drivers/gpu/msm/adreno_dispatch.c b/drivers/gpu/msm/adreno_dispatch.c
index b6db7f848305..9c969ce1613d 100644
--- a/drivers/gpu/msm/adreno_dispatch.c
+++ b/drivers/gpu/msm/adreno_dispatch.c
@@ -2211,6 +2211,10 @@ static int dispatcher_do_fault(struct adreno_device *adreno_dev)
adreno_readreg64(adreno_dev, ADRENO_REG_CP_RB_BASE,
ADRENO_REG_CP_RB_BASE_HI, &base);
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ device->snapshotfault = fault;
+ #endif /*OPLUS_FEATURE_GPU_MINIDUMP*/
+
/*
* Force the CP off for anything but a hard fault to make sure it is
* good and stopped
diff --git a/drivers/gpu/msm/kgsl.c b/drivers/gpu/msm/kgsl.c
index 8e6bb0341cb5..9b162ab82df0 100644
--- a/drivers/gpu/msm/kgsl.c
+++ b/drivers/gpu/msm/kgsl.c
@@ -28,6 +28,9 @@
#include "kgsl_reclaim.h"
#include "kgsl_sync.h"
#include "kgsl_trace.h"
+#if defined(OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY) && defined(CONFIG_VIRTUAL_RESERVE_MEMORY)
+#include "kgsl_reserve.h"
+#endif
#ifndef arch_mmap_check
#define arch_mmap_check(addr, len, flags) (0)
@@ -700,6 +703,7 @@ void kgsl_context_detach(struct kgsl_context *context)
kgsl_del_event_group(&context->events);
kgsl_sync_timeline_detach(context->ktimeline);
+
kgsl_context_put(context);
}
@@ -4777,7 +4781,6 @@ static unsigned long _gpu_set_svm_region(struct kgsl_process_private *private,
* trying to map a SVM region at the same time
*/
spin_lock(&entry->memdesc.gpuaddr_lock);
-
if (entry->memdesc.gpuaddr) {
spin_unlock(&entry->memdesc.gpuaddr_lock);
return (unsigned long) -EBUSY;
@@ -4814,7 +4817,6 @@ static unsigned long _gpu_find_svm(struct kgsl_process_private *private,
{
uint64_t addr = kgsl_mmu_find_svm_region(private->pagetable,
(uint64_t) start, (uint64_t)end, (uint64_t) len, align);
-
WARN(!IS_ERR_VALUE((unsigned long)addr) && (addr > ULONG_MAX),
"Couldn't find range\n");
@@ -4827,7 +4829,6 @@ static unsigned long _cpu_get_unmapped_area(unsigned long bottom,
{
struct vm_unmapped_area_info info;
unsigned long addr, err;
-
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.low_limit = bottom;
info.high_limit = top;
@@ -4837,8 +4838,9 @@ static unsigned long _cpu_get_unmapped_area(unsigned long bottom,
addr = vm_unmapped_area(&info);
- if (IS_ERR_VALUE(addr))
+ if (IS_ERR_VALUE(addr)) {
return addr;
+ }
err = security_mmap_addr(addr);
return err ? err : addr;
@@ -4881,7 +4883,8 @@ static unsigned long _search_range(struct kgsl_process_private *private,
/* move downward to the next empty spot on the GPU */
gpu = _gpu_find_svm(private, start, cpu, len, align);
- if (IS_ERR_VALUE(gpu)) {
+
+ if (IS_ERR_VALUE(gpu)) {
result = gpu;
break;
}
@@ -4974,6 +4977,11 @@ static unsigned long _get_svm_area(struct kgsl_process_private *private,
* Search downwards from the hint first. If that fails we
* must try to search above it.
*/
+#if defined(OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY) && defined(CONFIG_VIRTUAL_RESERVE_MEMORY)
+ result = kgsl_get_unmmaped_area_from_anti_fragment(private, entry, len, align);
+ if (result > 0)
+ return result;
+#endif
result = _search_range(private, entry, start, addr, len, align);
if (IS_ERR_VALUE(result) && hint != 0)
result = _search_range(private, entry, addr, end, len, align);
@@ -5026,7 +5034,11 @@ kgsl_get_unmapped_area(struct file *file, unsigned long addr,
pid_nr(private->pid),
current->mm->mmap_base, addr,
pgoff, len, (int) val);
+
}
+#if defined(OPLUS_FEATURE_VIRTUAL_RESERVE_MEMORY) && defined(CONFIG_VIRTUAL_RESERVE_MEMORY)
+ update_oom_pid_and_time(len, val, flags);
+#endif
put:
kgsl_mem_entry_put(entry);
@@ -5383,9 +5395,15 @@ int kgsl_device_platform_probe(struct kgsl_device *device)
PM_QOS_CPU_DMA_LATENCY,
PM_QOS_DEFAULT_VALUE);
}
-
+#ifdef OPLUS_FEATURE_SCHED_ASSIST
+ if (sysctl_sched_assist_enabled)
+ device->events_wq = alloc_workqueue("kgsl-events",
+ WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_SYSFS | WQ_HIGHPRI | WQ_UX, 0);
+#else
device->events_wq = alloc_workqueue("kgsl-events",
WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_SYSFS | WQ_HIGHPRI, 0);
+#endif
+
/* Initialize the snapshot engine */
kgsl_device_snapshot_init(device);
diff --git a/drivers/gpu/msm/kgsl_device.h b/drivers/gpu/msm/kgsl_device.h
index 55008e288e72..46b210c65d8e 100644
--- a/drivers/gpu/msm/kgsl_device.h
+++ b/drivers/gpu/msm/kgsl_device.h
@@ -323,6 +323,11 @@ struct kgsl_device {
unsigned int num_l3_pwrlevels;
/* store current L3 vote to determine if we should change our vote */
unsigned int cur_l3_pwrlevel;
+
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ bool snapshot_control;
+ int snapshotfault;
+ #endif /* OPLUS_FEATURE_GPU_MINIDUMP */
/** @timelines: Iterator for assigning IDs to timelines */
struct idr timelines;
/** @timelines_lock: Spinlock to protect the timelines idr */
@@ -551,6 +556,10 @@ struct kgsl_snapshot {
bool gmu_fault;
bool recovered;
struct kgsl_device *device;
+
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ char snapshot_hashid[96];
+ #endif /* OPLUS_FEATURE_GPU_MINIDUMP */
};
/**
diff --git a/drivers/gpu/msm/kgsl_iommu.c b/drivers/gpu/msm/kgsl_iommu.c
index e4b9924baec2..3897793e189d 100644
--- a/drivers/gpu/msm/kgsl_iommu.c
+++ b/drivers/gpu/msm/kgsl_iommu.c
@@ -21,6 +21,10 @@
#include "kgsl_sharedmem.h"
#include "kgsl_trace.h"
+#ifdef OPLUS_BUG_STABILITY
+#include
+#endif /*OPLUS_BUG_STABILITY*/
+
#define _IOMMU_PRIV(_mmu) (&((_mmu)->priv.iommu))
#define ADDR_IN_GLOBAL(_mmu, _a) \
@@ -826,6 +830,13 @@ static int kgsl_iommu_fault_handler(struct iommu_domain *domain,
no_page_fault_log = kgsl_mmu_log_fault_addr(mmu, ptbase, addr);
if (!no_page_fault_log && __ratelimit(&_rs)) {
+ #ifdef OPLUS_BUG_STABILITY
+ mm_fb_kevent(OPLUS_MM_DIRVER_FB_EVENT_DISPLAY,
+ OPLUS_DISPLAY_EVENTID_GPU_FAULT,
+ "gpu fault", MM_FB_KEY_RATELIMIT_1H,
+ "pid=%08lx,comm=%d", ptname, comm);
+ #endif /*OPLUS_BUG_STABILITY*/
+
dev_crit(ctx->kgsldev->dev,
"GPU PAGE FAULT: addr = %lX pid= %d name=%s\n", addr,
ptname, comm);
@@ -1046,6 +1057,7 @@ static void setup_64bit_pagetable(struct kgsl_mmu *mmu,
pt->compat_va_end = KGSL_IOMMU_SECURE_BASE(mmu);
pt->va_start = KGSL_IOMMU_VA_BASE64;
pt->va_end = KGSL_IOMMU_VA_END64;
+
}
if (pagetable->name != KGSL_MMU_GLOBAL_PT &&
diff --git a/drivers/gpu/msm/kgsl_mmu.c b/drivers/gpu/msm/kgsl_mmu.c
index efe6d6513ab2..9d68eaf8ac6b 100644
--- a/drivers/gpu/msm/kgsl_mmu.c
+++ b/drivers/gpu/msm/kgsl_mmu.c
@@ -448,7 +448,6 @@ void kgsl_mmu_put_gpuaddr(struct kgsl_memdesc *memdesc)
if (!kgsl_memdesc_is_global(memdesc))
memdesc->gpuaddr = 0;
-
}
EXPORT_SYMBOL(kgsl_mmu_put_gpuaddr);
diff --git a/drivers/gpu/msm/kgsl_pool.c b/drivers/gpu/msm/kgsl_pool.c
index ecb05b9b9a06..14970659c10b 100644
--- a/drivers/gpu/msm/kgsl_pool.c
+++ b/drivers/gpu/msm/kgsl_pool.c
@@ -316,6 +316,7 @@ int kgsl_pool_alloc_page(int *page_size, struct page **pages,
if (page == NULL) {
gfp_t gfp_mask = kgsl_gfp_mask(order);
+#ifndef OPLUS_FEATURE_SPECIALOPT
/* Only allocate non-reserved memory for certain pools */
if (!pool->allocation_allowed && pool_idx > 0) {
size = PAGE_SIZE <<
@@ -324,6 +325,16 @@ int kgsl_pool_alloc_page(int *page_size, struct page **pages,
}
page = alloc_pages(gfp_mask, order);
+#else
+ page = alloc_pages(gfp_mask, order);
+
+ /* Only allocate non-reserved memory for certain pools */
+ if (!page &&!pool->allocation_allowed && pool_idx > 0) {
+ size = PAGE_SIZE <<
+ kgsl_pools[pool_idx-1].pool_order;
+ goto eagain;
+ }
+#endif
if (!page) {
if (pool_idx > 0) {
diff --git a/drivers/gpu/msm/kgsl_pwrctrl.c b/drivers/gpu/msm/kgsl_pwrctrl.c
index efc0e77da52a..9a6b61491361 100644
--- a/drivers/gpu/msm/kgsl_pwrctrl.c
+++ b/drivers/gpu/msm/kgsl_pwrctrl.c
@@ -1432,6 +1432,26 @@ static ssize_t gpu_busy_percentage_show(struct device *dev,
return ret;
}
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+static ssize_t gpu_status_time_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct kgsl_device *device = dev_get_drvdata(dev);
+ struct kgsl_pwrctrl *pwr;
+
+ u64 slumber_time = 0;
+
+ if (device == NULL)
+ return 0;
+ pwr = &device->pwrctrl;
+
+ slumber_time = pwr->gpu_stats.gpu_pwr_stats[PWR_STAT_SLUMBER].total;
+
+ return scnprintf(buf, PAGE_SIZE, "%llu\n", slumber_time);
+}
+#endif
+
static ssize_t min_clock_mhz_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1613,6 +1633,9 @@ static DEVICE_ATTR_RW(max_clock_mhz);
static DEVICE_ATTR_RO(clock_mhz);
static DEVICE_ATTR_RO(freq_table_mhz);
static DEVICE_ATTR_RW(pwrscale);
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+static DEVICE_ATTR_RO(gpu_status_time);
+#endif
static const struct attribute *pwrctrl_attr_list[] = {
&dev_attr_gpuclk.attr,
@@ -1642,6 +1665,9 @@ static const struct attribute *pwrctrl_attr_list[] = {
&dev_attr_freq_table_mhz.attr,
&dev_attr_temp.attr,
&dev_attr_pwrscale.attr,
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+ &dev_attr_gpu_status_time.attr,
+#endif
NULL,
};
@@ -3055,6 +3081,11 @@ int kgsl_pwrctrl_change_state(struct kgsl_device *device, int state)
_record_pwrevent(device, t, KGSL_PWREVENT_STATE);
}
+
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+ oplus_pwrctrl_update_stats_info(device);
+#endif
+
return status;
}
EXPORT_SYMBOL(kgsl_pwrctrl_change_state);
@@ -3445,3 +3476,38 @@ int kgsl_pwrctrl_set_default_gpu_pwrlevel(struct kgsl_device *device)
/* Request adjusted DCVS level */
return kgsl_clk_set_rate(device, pwr->active_pwrlevel);
}
+
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+/**
+ * oplus_pwrctrl_update_stats_info() - update oplus gpu_info
+ * @device: Pointer to the kgsl_device struct
+ *
+ * Update gpu state changes in gpu_info only, now only
+ * consider KGSL_STATE_SLUMBER status.
+ */
+void oplus_pwrctrl_update_stats_info(struct kgsl_device *device)
+{
+ struct kgsl_pwrctrl *pwr = &device->pwrctrl;
+ u64 total;
+ ktime_t tmp;
+
+ tmp = ktime_get();
+ total = ktime_us_delta(tmp, pwr->gpu_stats.timestamp);
+
+ if (pwr->gpu_stats.last_state == KGSL_STATE_NONE) {
+ if(device->state == KGSL_STATE_SLUMBER)
+ goto update;
+ }
+ else {
+ // it means we met state transition
+ if(pwr->gpu_stats.last_state == KGSL_STATE_SLUMBER) {
+ pwr->gpu_stats.gpu_pwr_stats[PWR_STAT_SLUMBER].total += total;
+ goto update;
+ }
+ }
+
+update:
+ pwr->gpu_stats.timestamp = tmp;
+ pwr->gpu_stats.last_state = device->state;
+}
+#endif
diff --git a/drivers/gpu/msm/kgsl_pwrctrl.h b/drivers/gpu/msm/kgsl_pwrctrl.h
index 406486a8f065..3f90d051db45 100644
--- a/drivers/gpu/msm/kgsl_pwrctrl.h
+++ b/drivers/gpu/msm/kgsl_pwrctrl.h
@@ -79,6 +79,41 @@ enum kgsl_pwrctrl_timer_type {
struct platform_device;
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+// KGSL_MAX_PWRLEVELS + SLUMBER
+#define MAX_GPU_PWR_STAT KGSL_MAX_PWRLEVELS + 1
+#define PWR_STAT_SLUMBER KGSL_MAX_PWRLEVELS
+
+/**
+ * struct gpu_pwr_stats - Struct holding different gpu power info obtained from
+ * pwrscale and pwrctrl
+ * @total: total us seconds are sampled in this power level
+ * @busy: total busy us seconds in this power level when sampled
+ * @ram_time: total ram read+write us seconds in this power level when sampled
+ * @ram_wait: total ram wait us seconds in this power level when sampled
+ */
+struct gpu_pwr_stats {
+ u64 total;
+ u64 busy;
+ u64 ram_time;
+ u64 ram_wait;
+};
+
+/**
+ * struct gpu_info - Struct holding gpu info we want to record
+ * @gpu_pwr_stats: gpu_pwr_stats of each power level + SLUMBER
+ * @gpu_total: total us seconds are sampled
+ * @timestamp: last timestamp when sampled
+ * @last_state: last KGSL device state when sampled
+ */
+struct gpu_info {
+ struct gpu_pwr_stats gpu_pwr_stats[MAX_GPU_PWR_STAT];
+ u64 gpu_total;
+ ktime_t timestamp;
+ int last_state;
+};
+#endif
+
struct kgsl_clk_stats {
unsigned int busy;
unsigned int total;
@@ -243,6 +278,10 @@ struct kgsl_pwrctrl {
unsigned int gpu_bimc_int_clk_freq;
bool gpu_bimc_interface_enabled;
struct gpu_cx_ipeak_client gpu_ipeak_client[2];
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+/* gpu_stats - collect gpu power status of each pwrlevel */
+ struct gpu_info gpu_stats;
+#endif
};
int kgsl_pwrctrl_init(struct kgsl_device *device);
@@ -293,4 +332,7 @@ int kgsl_pwrctrl_set_default_gpu_pwrlevel(struct kgsl_device *device);
void kgsl_pwrctrl_disable_unused_opp(struct kgsl_device *device,
struct device *dev);
+#ifdef CONFIG_OPLUS_FEATURE_MIDAS
+void oplus_pwrctrl_update_stats_info(struct kgsl_device *device);
+#endif
#endif /* __KGSL_PWRCTRL_H */
diff --git a/drivers/gpu/msm/kgsl_reserve.h b/drivers/gpu/msm/kgsl_reserve.h
new file mode 120000
index 000000000000..37d68e409f86
--- /dev/null
+++ b/drivers/gpu/msm/kgsl_reserve.h
@@ -0,0 +1 @@
+../../../../../vendor/oplus/kernel/oplus_performance/gloom_new/kgsl_reserve.h
\ No newline at end of file
diff --git a/drivers/gpu/msm/kgsl_sharedmem.c b/drivers/gpu/msm/kgsl_sharedmem.c
index 621ab3db5a49..6a2fce9417f1 100644
--- a/drivers/gpu/msm/kgsl_sharedmem.c
+++ b/drivers/gpu/msm/kgsl_sharedmem.c
@@ -339,6 +339,13 @@ void kgsl_process_init_sysfs(struct kgsl_device *device,
kgsl_reclaim_proc_sysfs_init(private);
}
+#ifdef OPLUS_FEATURE_HEALTHINFO
+unsigned long gpu_total(void)
+{
+ return (unsigned long)atomic_long_read(&kgsl_driver.stats.page_alloc);
+}
+#endif /* OPLUS_FEATURE_HEALTHINFO */
+
static ssize_t memstat_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
diff --git a/drivers/gpu/msm/kgsl_snapshot.c b/drivers/gpu/msm/kgsl_snapshot.c
index a4fe2efad2f0..b9271fdf9748 100644
--- a/drivers/gpu/msm/kgsl_snapshot.c
+++ b/drivers/gpu/msm/kgsl_snapshot.c
@@ -639,6 +639,47 @@ static void set_isdb_breakpoint_registers(struct kgsl_device *device)
isdb_write(device->qdss_gfx_virt, 0x5000);
}
+#if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+
+/************************************************
+adreno.h
+#define ADRENO_SOFT_FAULT BIT(0)
+#define ADRENO_HARD_FAULT BIT(1)
+#define ADRENO_TIMEOUT_FAULT BIT(2)
+#define ADRENO_IOMMU_PAGE_FAULT BIT(3)
+#define ADRENO_PREEMPT_FAULT BIT(4)
+#define ADRENO_GMU_FAULT BIT(5)
+#define ADRENO_CTX_DETATCH_TIMEOUT_FAULT BIT(6)
+#define ADRENO_GMU_FAULT_SKIP_SNAPSHOT BIT(7)
+*************************************************/
+char* kgsl_get_reason(int faulttype, bool gmu_fault){
+ if(gmu_fault){
+ return "GMUFAULT";
+ }else{
+ switch(faulttype){
+ case 0:
+ return "SOFTFAULT";
+ case 1:
+ return "HANGFAULT";
+ case 2:
+ return "TIMEOUTFAULT";
+ case 3:
+ return "IOMMUPAGEFAULT";
+ case 4:
+ return "PREEMPTFAULT";
+ case 5:
+ return "GMUFAULT";
+ case 6:
+ return "CTXDETATCHFAULT";
+ case 7:
+ return "GMUSKIPFAULT";
+ default:
+ return "UNKNOW";
+ }
+ }
+}
+#endif /*OPLUS_FEATURE_GPU_MINIDUMP*/
+
/**
* kgsl_snapshot() - construct a device snapshot
* @device: device to snapshot
@@ -756,6 +797,17 @@ void kgsl_device_snapshot(struct kgsl_device *device,
dev_err(device->dev, "%s snapshot created at pa %pa++0x%zx\n",
gmu_fault ? "GMU" : "GPU", &pa, snapshot->size);
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ if(context!= NULL){
+ dev_err(device->dev, "falut=%s, pid=%d, processname=%s\n",
+ kgsl_get_reason(device->snapshotfault, gmu_fault), context->proc_priv->pid, context->proc_priv->comm);
+
+ memset(snapshot->snapshot_hashid, '\0', sizeof(snapshot->snapshot_hashid));
+ scnprintf(snapshot->snapshot_hashid, sizeof(snapshot->snapshot_hashid), "%d@%s@%s",
+ context->proc_priv->pid, context->proc_priv->comm, kgsl_get_reason(device->snapshotfault, gmu_fault));
+ }
+ #endif /* OPLUS_FEATURE_GPU_MINIDUMP */
+
if (device->skip_ib_capture)
BUG_ON(device->force_panic);
@@ -835,6 +887,41 @@ static int snapshot_release(struct kgsl_device *device,
return ret;
}
+#if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+static bool snapshot_ontrol_on = 0;
+
+static ssize_t snapshot_control_show(struct kgsl_device *device, char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%d\n", device->snapshot_control);
+}
+
+static ssize_t snapshot_control_store(struct kgsl_device *device, const char *buf,
+ size_t count)
+{
+ unsigned int val = 0;
+ int ret;
+
+ if (device && count > 0)
+ device->snapshot_control = 0;
+
+ ret = kgsl_sysfs_store(buf, &val);
+
+ if (!ret && device){
+ device->snapshot_control = (bool)val;
+ snapshot_ontrol_on = device->snapshot_control;
+ }
+
+ return (ssize_t) ret < 0 ? ret : count;
+}
+
+static ssize_t snapshot_hashid_show(struct kgsl_device *device, char *buf)
+{
+ if(device->snapshot == NULL)
+ return 0;
+ return strlcpy(buf, device->snapshot->snapshot_hashid, PAGE_SIZE);
+}
+#endif /*OPLUS_FEATURE_GPU_MINIDUMP*/
+
/* Dump the sysfs binary data to the user */
static ssize_t snapshot_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t off,
@@ -846,6 +933,13 @@ static ssize_t snapshot_show(struct file *filep, struct kobject *kobj,
struct snapshot_obj_itr itr;
int ret = 0;
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ if (snapshot_ontrol_on) {
+ dev_err(device->dev, "snapshot: snapshot_ontrol_on is true, skip snapshot\n");
+ return 0;
+ }
+ #endif /* OPLUS_FEATURE_GPU_MINIDUMP */
+
mutex_lock(&device->mutex);
snapshot = device->snapshot;
if (snapshot != NULL) {
@@ -1064,6 +1158,11 @@ static SNAPSHOT_ATTR(snapshot_legacy, 0644, snapshot_legacy_show,
static SNAPSHOT_ATTR(skip_ib_capture, 0644, skip_ib_capture_show,
skip_ib_capture_store);
+#if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+static SNAPSHOT_ATTR(snapshot_hashid, 0666, snapshot_hashid_show, NULL);
+static SNAPSHOT_ATTR(snapshot_control, 0666, snapshot_control_show, snapshot_control_store);
+#endif /* OPLUS_FEATURE_GPU_MINIDUMP */
+
static ssize_t snapshot_sysfs_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
@@ -1157,6 +1256,10 @@ int kgsl_device_snapshot_init(struct kgsl_device *device)
device->snapshot_crashdumper = true;
device->snapshot_legacy = false;
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ device->snapshot_control = 0;
+ #endif /* OPLUS_FEATURE_GPU_MINIDUMP */
+
/*
* Set this to false so that we only ever keep the first snapshot around
* If we want to over-write with a gmu snapshot, then set it to true
@@ -1175,6 +1278,16 @@ int kgsl_device_snapshot_init(struct kgsl_device *device)
ret = sysfs_create_files(&device->snapshot_kobj, snapshot_attrs);
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ ret = sysfs_create_file(&device->snapshot_kobj, &attr_snapshot_hashid.attr);
+ if (ret)
+ return ret;
+
+ ret = sysfs_create_file(&device->snapshot_kobj, &attr_snapshot_control.attr);
+ if (ret)
+ return ret;
+ #endif /* OPLUS_FEATURE_GPU_MINIDUMP */
+
return ret;
}
EXPORT_SYMBOL(kgsl_device_snapshot_init);
@@ -1200,6 +1313,10 @@ void kgsl_device_snapshot_close(struct kgsl_device *device)
device->snapshot_faultcount = 0;
device->force_panic = false;
device->snapshot_crashdumper = true;
+
+ #if defined(OPLUS_FEATURE_GPU_MINIDUMP)
+ device->snapshot_control = 0;
+ #endif /* OPLUS_FEATURE_GPU_MINIDUMP */
}
EXPORT_SYMBOL(kgsl_device_snapshot_close);
diff --git a/drivers/gpu/msm/kgsl_sync.c b/drivers/gpu/msm/kgsl_sync.c
index 229f8baa7822..817f134c08e7 100644
--- a/drivers/gpu/msm/kgsl_sync.c
+++ b/drivers/gpu/msm/kgsl_sync.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
- * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2020,2021 The Linux Foundation. All rights reserved.
*/
#include
@@ -250,8 +250,6 @@ static void kgsl_sync_timeline_value_str(struct dma_fence *fence,
struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
struct kgsl_sync_timeline *ktimeline = kfence->parent;
struct kgsl_context *context = NULL;
- unsigned long flags;
- int ret = 0;
unsigned int timestamp_retired;
unsigned int timestamp_queued;
@@ -261,21 +259,17 @@ static void kgsl_sync_timeline_value_str(struct dma_fence *fence,
if (!ktimeline->device)
goto put_timeline;
- spin_lock_irqsave(&ktimeline->lock, flags);
- ret = _kgsl_context_get(ktimeline->context);
- context = ret ? ktimeline->context : NULL;
- spin_unlock_irqrestore(&ktimeline->lock, flags);
-
- /* Get the last signaled timestamp if the context is not valid */
timestamp_queued = ktimeline->last_timestamp;
timestamp_retired = timestamp_queued;
+ if (!ktimeline->detached)
+ context = kgsl_context_get(ktimeline->device,
+ ktimeline->context_id);
if (context) {
kgsl_readtimestamp(ktimeline->device, context,
KGSL_TIMESTAMP_RETIRED, ×tamp_retired);
kgsl_readtimestamp(ktimeline->device, context,
KGSL_TIMESTAMP_QUEUED, ×tamp_queued);
-
kgsl_context_put(context);
}
@@ -312,15 +306,9 @@ int kgsl_sync_timeline_create(struct kgsl_context *context)
{
struct kgsl_sync_timeline *ktimeline;
- /* Put context at detach time */
- if (!_kgsl_context_get(context))
- return -ENOENT;
-
ktimeline = kzalloc(sizeof(*ktimeline), GFP_KERNEL);
- if (ktimeline == NULL) {
- kgsl_context_put(context);
+ if (ktimeline == NULL)
return -ENOMEM;
- }
kref_init(&ktimeline->kref);
ktimeline->name = kasprintf(GFP_KERNEL, "%s_%d-%.15s(%d)-%.15s(%d)",
@@ -333,12 +321,8 @@ int kgsl_sync_timeline_create(struct kgsl_context *context)
INIT_LIST_HEAD(&ktimeline->child_list_head);
spin_lock_init(&ktimeline->lock);
ktimeline->device = context->device;
-
- /*
- * The context pointer is valid till detach time, where we put the
- * refcount on the context
- */
- ktimeline->context = context;
+ ktimeline->context_id = context->id;
+ ktimeline->detached = false;
context->ktimeline = ktimeline;
@@ -372,14 +356,7 @@ static void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline,
void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline)
{
- unsigned long flags;
- struct kgsl_context *context = ktimeline->context;
-
- /* Set context pointer to NULL and drop our refcount on the context */
- spin_lock_irqsave(&ktimeline->lock, flags);
- ktimeline->context = NULL;
- spin_unlock_irqrestore(&ktimeline->lock, flags);
- kgsl_context_put(context);
+ ktimeline->detached = true;
}
static void kgsl_sync_timeline_destroy(struct kref *kref)
diff --git a/drivers/gpu/msm/kgsl_sync.h b/drivers/gpu/msm/kgsl_sync.h
index f49f9e04f255..f41318aa8e9c 100644
--- a/drivers/gpu/msm/kgsl_sync.h
+++ b/drivers/gpu/msm/kgsl_sync.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
- * Copyright (c) 2012-2014,2018-2021 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2014,2018-2020,2021 The Linux Foundation. All rights reserved.
*/
#ifndef __KGSL_SYNC_H
#define __KGSL_SYNC_H
@@ -9,6 +9,7 @@
/**
* struct kgsl_sync_timeline - A sync timeline associated with a kgsl context
+ * @kref: Refcount to keep the struct alive until all its fences are released
* @kref: Refcount to keep the struct alive until all its fences are signaled,
and as long as the context exists
* @name: String to describe this timeline
@@ -18,7 +19,8 @@
* @lock: Spinlock to protect this timeline
* @last_timestamp: Last timestamp when signaling fences
* @device: kgsl device
- * @context: kgsl context
+ * @context_id: kgsl context id
+ * @detached: whether the context is detached
*/
struct kgsl_sync_timeline {
struct kref kref;
@@ -31,7 +33,8 @@ struct kgsl_sync_timeline {
spinlock_t lock;
unsigned int last_timestamp;
struct kgsl_device *device;
- struct kgsl_context *context;
+ unsigned int context_id;
+ bool detached;
};
/**
@@ -119,8 +122,7 @@ static inline int kgsl_sync_timeline_create(struct kgsl_context *context)
return 0;
}
-static inline void kgsl_sync_timeline_detach(
- struct kgsl_sync_timeline *ktimeline)
+static inline void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline)
{
}
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 4549fbb74156..18ee1193e0ba 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -910,7 +910,16 @@ static int hid_scan_report(struct hid_device *hid)
hid->group = HID_GROUP_RMI;
break;
}
+#ifdef OPLUS_BUG_STABILITY
+//add for BLE-M1 uhid group change HID_GROUP_GENERIC
+ if (0x248a == hid->vendor && 2 == hid->group) {
+ hid_warn(hid, "scan_report change to GENERIC %u\n", hid->group);
+ hid->group = HID_GROUP_GENERIC;
+ }
+ /* fall back to generic driver in case specific driver doesn't exist */
+ hid_warn(hid, "report vendor %u,group %u\n", hid->vendor, hid->group);
+#endif /* OPLUS_BUG_STABILITY */
kfree(parser->collection_stack);
vfree(parser);
return 0;
diff --git a/drivers/hid/hid-uclogic.c b/drivers/hid/hid-uclogic.c
index e0bc31ee1576..baecbe927602 100644
--- a/drivers/hid/hid-uclogic.c
+++ b/drivers/hid/hid-uclogic.c
@@ -944,6 +944,9 @@ static int uclogic_probe(struct hid_device *hdev,
struct usb_device *udev = hid_to_usb_dev(hdev);
struct uclogic_drvdata *drvdata;
+ if (!hid_is_usb(hdev))
+ return -EINVAL;
+
/*
* libinput requires the pad interface to be on a different node
* than the pen, so use QUIRK_MULTI_INPUT for all tablets.
diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index 116d4914a799..0df601746dcf 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -22,12 +22,21 @@
#include
#include
#include
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#include "../../power/oplus/oplus_vooc.h"
+#include
+#endif
#define SE_I2C_TX_TRANS_LEN (0x26C)
#define SE_I2C_RX_TRANS_LEN (0x270)
#define SE_I2C_SCL_COUNTERS (0x278)
#define SE_GENI_IOS (0x908)
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define SE_I2C_NOISE_CANCEL_CTL (0x234)
+#endif
+
+
#define SE_I2C_ERR (M_CMD_OVERRUN_EN | M_ILLEGAL_CMD_EN | M_CMD_FAILURE_EN |\
M_GP_IRQ_1_EN | M_GP_IRQ_3_EN | M_GP_IRQ_4_EN)
#define SE_I2C_ABORT (1U << 1)
@@ -128,6 +137,11 @@ struct geni_i2c_dev {
bool is_shared;
u32 dbg_num;
struct dbg_buf_ctxt *dbg_buf_ptr;
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ u32 noise_rjct_scl;
+ u32 noise_rjct_sda;
+ bool noise_rjct_support;
+#endif
};
static struct geni_i2c_dev *gi2c_dev_dbg[MAX_SE];
@@ -201,6 +215,13 @@ static inline void qcom_geni_i2c_conf(struct geni_i2c_dev *gi2c, int dfs)
geni_write_reg(((itr->t_high << 20) | (itr->t_low << 10) |
itr->t_cycle), gi2c->base, SE_I2C_SCL_COUNTERS);
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ if (gi2c->noise_rjct_support) {
+ geni_write_reg(gi2c->noise_rjct_scl << 1 | gi2c->noise_rjct_sda << 3,
+ gi2c->base, SE_I2C_NOISE_CANCEL_CTL);
+ }
+#endif
+
/*
* Ensure Clk config completes before return.
*/
@@ -724,7 +745,103 @@ geni_i2c_gsi_xfer_out:
ret = gi2c->err;
return ret;
}
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#define MAX_RESET_COUNT 10
+#define MIN_RESET_COUNT 0
+#define I2C_RESET_BUS 0
+#define FG_DEVICE_ADDR 0x55
+#define DA9313_DEVICE_ADDR 0x68
+//#define CHARGER_DEVICE_ADDR 0x5c
+//#define MCU_DEVICE_ADDR 0x26
+static bool i2c_err_occured = false;
+static unsigned int err_count = MAX_RESET_COUNT;
+extern int rpmb_is_enable(void);
+bool oplus_get_fg_i2c_err_occured(void)
+{
+ return i2c_err_occured;
+}
+EXPORT_SYMBOL(oplus_get_fg_i2c_err_occured);
+
+void oplus_set_fg_i2c_err_occured(bool i2c_err)
+{
+ i2c_err_occured = i2c_err;
+}
+EXPORT_SYMBOL(oplus_set_fg_i2c_err_occured);
+
+static void i2c_oplus_gpio_reset(struct geni_i2c_dev *gi2c)
+{
+ int ret = 0;
+ int i = 0;
+ static bool i2c_reset_processing = false;
+ int boot_mode = get_boot_mode();
+
+ //dev_err(gi2c->dev, "%s: start, return\n", __func__);
+ if (gi2c == NULL)
+ return;
+
+ if ((boot_mode != MSM_BOOT_MODE__NORMAL)
+ && (boot_mode != MSM_BOOT_MODE__RECOVERY)
+ && (boot_mode != MSM_BOOT_MODE__SILENCE)
+ && (boot_mode != MSM_BOOT_MODE__SAU)
+ && (boot_mode != MSM_BOOT_MODE__CHARGE)) {
+ dev_err(gi2c->dev, "%s: get_boot_mode[%d], return\n", __func__, boot_mode);
+ return;
+ }
+
+ if (i2c_reset_processing == true) {
+ dev_err(gi2c->dev, "%s: i2c_reset is processing, return\n", __func__);
+ return;
+ }
+
+ i2c_reset_processing = true;
+
+ if (!IS_ERR_OR_NULL(gi2c->i2c_rsc.geni_gpio_pulldown)) {
+ dev_err(gi2c->dev, "%s: set geni_gpio_pulldown\n", __func__);
+ ret = pinctrl_select_state(gi2c->i2c_rsc.geni_pinctrl, gi2c->i2c_rsc.geni_gpio_pulldown);
+ if (ret) {
+ dev_err(gi2c->dev, "%s: error pinctrl_select_state pulldown, ret:%d\n", __func__, ret);
+ goto err;
+ }
+ } else {
+ goto err;
+ }
+
+ for (i = 0; i < 220; i++) {
+ usleep_range(10000, 11000);
+ if (oplus_vooc_get_fastchg_started() == true && oplus_vooc_get_fastchg_ing() == false) {
+ dev_err(gi2c->dev, "%s: vooc ready to start, don't pull down i2c, i:%d\n", __func__, i);
+ break;
+ }
+ }
+ oplus_set_fg_i2c_err_occured(true);
+
+ if (!IS_ERR_OR_NULL(gi2c->i2c_rsc.geni_gpio_pullup)) {
+ dev_err(gi2c->dev, "%s: set geni_gpio_pullup\n", __func__);
+ ret = pinctrl_select_state(gi2c->i2c_rsc.geni_pinctrl, gi2c->i2c_rsc.geni_gpio_pullup);
+ if (ret) {
+ dev_err(gi2c->dev, "%s:error pinctrl_select_state pullup, ret:%d\n", __func__, ret);
+ }
+ }
+ if (!IS_ERR_OR_NULL(gi2c->i2c_rsc.geni_gpio_active)) {
+ dev_err(gi2c->dev, "%s: set geni_gpio_active\n", __func__);
+ ret = pinctrl_select_state(gi2c->i2c_rsc.geni_pinctrl, gi2c->i2c_rsc.geni_gpio_active);
+ if (ret) {
+ dev_err(gi2c->dev, "%s:error pinctrl_select_state active, ret:%d\n", __func__, ret);
+ goto err;
+ }
+ } else {
+ goto err;
+ }
+
+ i2c_reset_processing = false;
+ dev_err(gi2c->dev, "%s: gpio reset successful id:%d\n", __func__, gi2c->adap.nr);
+ return;
+
+err:
+ i2c_reset_processing = false;
+}
+#endif /*OPLUS_FEATURE_CHG_BASIC*/
static int geni_i2c_xfer(struct i2c_adapter *adap,
struct i2c_msg msgs[],
int num)
@@ -902,6 +1019,23 @@ static int geni_i2c_xfer(struct i2c_adapter *adap,
}
ret = gi2c->err;
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ if(msgs[i].addr == FG_DEVICE_ADDR || msgs[i].addr == DA9313_DEVICE_ADDR) {
+ if (gi2c->err) {
+ dev_err(gi2c->dev, "gi2c->adap.nr[%d], err_count[%d], msgs[i].addr[0x%x]\n", gi2c->adap.nr, err_count, msgs[i].addr);
+ if (err_count > MIN_RESET_COUNT && err_count < MAX_RESET_COUNT) {
+ i2c_oplus_gpio_reset(gi2c);
+ } else {
+ dev_err(gi2c->dev, "err_count(%d) >= %d so not reset\n", err_count, MAX_RESET_COUNT);
+ }
+ err_count++;
+ } else {
+ if(msgs[i].addr == FG_DEVICE_ADDR) {
+ err_count = 0;
+ }
+ }
+ }
+#endif
if (gi2c->err) {
GENI_SE_ERR(gi2c->ipcl, true, gi2c->dev,
"i2c error :%d\n", gi2c->err);
@@ -1027,7 +1161,24 @@ static int geni_i2c_probe(struct platform_device *pdev)
gi2c->is_shared = true;
dev_info(&pdev->dev, "Multi-EE usecase\n");
}
-
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ gi2c->i2c_rsc.geni_gpio_pulldown =
+ pinctrl_lookup_state(gi2c->i2c_rsc.geni_pinctrl,
+ PINCTRL_PULLDOWN);
+ if (IS_ERR_OR_NULL(gi2c->i2c_rsc.geni_gpio_pulldown)) {
+ /*dev_err(&pdev->dev, "No pulldown config specified\n");
+ ret = PTR_ERR(gi2c->i2c_rsc.geni_gpio_pulldown);
+ return ret;*/
+ }
+ gi2c->i2c_rsc.geni_gpio_pullup =
+ pinctrl_lookup_state(gi2c->i2c_rsc.geni_pinctrl,
+ PINCTRL_PULLUP);
+ if (IS_ERR_OR_NULL(gi2c->i2c_rsc.geni_gpio_pullup)) {
+ /*dev_err(&pdev->dev, "No pulldown config specified\n");
+ ret = PTR_ERR(gi2c->i2c_rsc.geni_gpio_pullup);
+ return ret;*/
+ }
+#endif
if (of_property_read_u32(pdev->dev.of_node, "qcom,clk-freq-out",
&gi2c->i2c_rsc.clk_freq_out)) {
gi2c->i2c_rsc.clk_freq_out = KHz(400);
@@ -1035,6 +1186,22 @@ static int geni_i2c_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "Bus frequency is set to %dHz\n",
gi2c->i2c_rsc.clk_freq_out);
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ gi2c->noise_rjct_scl = 0;
+ gi2c->noise_rjct_sda = 0;
+ gi2c->noise_rjct_support = true;
+
+ ret = of_property_read_u32(pdev->dev.of_node, "qcom,noise-rjct-scl",
+ &gi2c->noise_rjct_scl);
+ if(ret < 0)
+ gi2c->noise_rjct_support = false;
+
+ of_property_read_u32(pdev->dev.of_node, "qcom,noise-rjct-sda",
+ &gi2c->noise_rjct_sda);
+ if(ret < 0)
+ gi2c->noise_rjct_support = false;
+#endif
+
gi2c->irq = platform_get_irq(pdev, 0);
if (gi2c->irq < 0) {
dev_err(gi2c->dev, "IRQ error for i2c-geni\n");
diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c
index d5f06dffb7de..8045cf3c2d82 100644
--- a/drivers/iio/adc/qcom-spmi-adc5.c
+++ b/drivers/iio/adc/qcom-spmi-adc5.c
@@ -142,6 +142,11 @@ struct adc_channel_prop {
unsigned int lut_index;
enum vadc_scale_fn_type scale_fn_type;
const char *datasheet_name;
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ int cust_type;
+ int cust_scale_fn_type;
+#endif
};
/**
@@ -405,9 +410,14 @@ static int adc_pre_configure_usb_in_read(struct adc_chip *adc)
u8 data = ADC_CAL_DELAY_CTL_VAL_256S;
bool channel_check = false;
- if (adc->pmic_rev_id)
+ if (adc->pmic_rev_id){
+#ifndef OPLUS_FEATURE_CHG_BASIC
if (adc->pmic_rev_id->pmic_subtype == PMI632_SUBTYPE)
+#else
+ if (adc->pmic_rev_id->pmic_subtype == PMI632_SUBTYPE || adc->pmic_rev_id->pmic_subtype == PM7250B_SUBTYPE)
+#endif
channel_check = true;
+ }
/* Increase calibration measurement interval to 256s */
ret = regmap_bulk_write(adc->regmap,
@@ -483,9 +493,14 @@ static int adc_configure(struct adc_chip *adc,
u8 conv_req = 0;
bool channel_check = false;
- if (adc->pmic_rev_id)
+ if (adc->pmic_rev_id){
+#ifndef OPLUS_FEATURE_CHG_BASIC
if (adc->pmic_rev_id->pmic_subtype == PMI632_SUBTYPE)
+#else
+ if (adc->pmic_rev_id->pmic_subtype == PMI632_SUBTYPE || adc->pmic_rev_id->pmic_subtype == PM7250B_SUBTYPE)
+#endif
channel_check = true;
+ }
/* Read registers 0x42 through 0x46 */
ret = adc_read(adc, ADC_USR_DIG_PARAM, buf, ADC5_MULTI_TRANSFER);
@@ -767,10 +782,38 @@ static int adc_read_raw(struct iio_dev *indio_dev,
struct adc_channel_prop *prop;
u16 adc_code_volt, adc_code_cur;
int ret;
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ s64 voltage = 0, adc_vdd_ref_mv = 1875;
+#endif
prop = &adc->chan_props[chan->address];
switch (mask) {
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ case IIO_CHAN_INFO_OFFSET:
+ ret = adc_do_conversion(adc, prop, chan,
+ &adc_code_volt, &adc_code_cur);
+ if (ret)
+ break;
+ if (*val2 < 0) {
+ voltage = (s64) adc_code_volt * adc_vdd_ref_mv * 1000;
+ voltage = div64_s64(voltage, adc->data->full_scale_code_volt);
+ pr_err("%s : adc_code_volt before compensation : %d(uV)\n", __func__, voltage);
+ voltage += *val2;
+ pr_err("%s : adc_code_volt after compensation : %d(uV)\n", __func__, voltage);
+ voltage = voltage * adc->data->full_scale_code_volt;
+ adc_code_volt = (u16)div64_s64(voltage, (adc_vdd_ref_mv * 1000));
+ }
+ if ((chan->type == IIO_VOLTAGE) || (chan->type == IIO_TEMP))
+ ret = qcom_vadc_hw_scale(prop->scale_fn_type,
+ &adc_prescale_ratios[prop->prescale],
+ adc->data, prop->lut_index,
+ adc_code_volt, val);
+ if (ret)
+ break;
+
+ return IIO_VAL_INT;
+#endif
case IIO_CHAN_INFO_PROCESSED:
ret = adc_do_conversion(adc, prop, chan,
&adc_code_volt, &adc_code_cur);
@@ -905,10 +948,25 @@ static const struct adc_channels adc_chans_pmic5[ADC_MAX_CHANNEL] = {
SCALE_HW_CALIB_THERM_100K_PULLUP)
[ADC_AMUX_THM2_PU2] = ADC_CHAN_TEMP("amux_thm2_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
+#ifdef CONFIG_OPLUS_SM7250R_CHARGER //OPLUS_FEATURE_CHG_BASIC
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
[ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_VOLT("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
[ADC_AMUX_THM4_PU2] = ADC_CHAN_TEMP("amux_thm4_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_AMUX_THM4] = ADC_CHAN_VOLT("amux_thm4", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
[ADC_PARALLEL_ISENSE] = ADC_CHAN_VOLT("parallel_isense", 1,
SCALE_HW_CALIB_CUR)
[ADC_INT_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
@@ -929,10 +987,469 @@ static const struct adc_channels adc_chans_pmic5[ADC_MAX_CHANNEL] = {
SCALE_HW_CALIB_THERM_100K_PULLUP)
[ADC_GPIO3_PU2] = ADC_CHAN_TEMP("gpio3_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3] = ADC_CHAN_VOLT("gpio7_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+
+ [ADC_GPIO3_DIV3] = ADC_CHAN_VOLT("gpio7_div3", 1,
+ SCALE_HW_CALIB_DEFAULT)
+
+#ifdef CONFIG_OPLUS_SM7250R_CHARGER //OPLUS_FEATURE_CHG_BASIC
[ADC_GPIO4_PU2] = ADC_CHAN_TEMP("gpio4_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
+#else
+ [ADC_GPIO4_PU2] = ADC_CHAN_VOLT("gpio8_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_GPIO4] = ADC_CHAN_VOLT("gpio8_vol", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+#ifdef OPLUS_CUSTOM_OP_DEF
+#ifdef CONFIG_ARCH_LITO
+ [ADC_GPIO1_PU1] = ADC_CHAN_VOLT("usb_temp_l", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_GPIO2_PU1] = ADC_CHAN_VOLT("usb_temp_r", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM4_PU1] = ADC_CHAN_VOLT("usb_temp_adc", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_GPIO4_PU1] = ADC_CHAN_VOLT("usb_supplementary_temp_adc", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif // CONFIG_ARCH_LITO
+#endif // OPLUS_CUSTOM_OP_DEF
+#endif // OPLUS_FEATURE_CHG_BASIC
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO1] = ADC_CHAN_VOLT("board_id_vdata", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+ [ADC_INT_EXT_ISENSE] = ADC_CHAN_VOLT("ext_isense", 1,
+ SCALE_HW_CALIB_CUR)
};
+static const struct adc_channels adc_chans_pmic5_21027[ADC_MAX_CHANNEL] = {
+ [ADC_REF_GND] = ADC_CHAN_VOLT("ref_gnd", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_1P25VREF] = ADC_CHAN_VOLT("vref_1p25", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VPH_PWR] = ADC_CHAN_VOLT("vph_pwr", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VBAT_SNS] = ADC_CHAN_VOLT("vbat_sns", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VCOIN] = ADC_CHAN_VOLT("vcoin", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_DIE_TEMP] = ADC_CHAN_TEMP("die_temp", 1,
+ SCALE_HW_CALIB_PMIC_THERM)
+ [ADC_USB_IN_I] = ADC_CHAN_VOLT("usb_in_i_uv", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_USB_IN_V_16] = ADC_CHAN_VOLT("usb_in_v_div_16", 16,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_CHG_TEMP] = ADC_CHAN_TEMP("chg_temp", 1,
+ SCALE_HW_CALIB_PM5_CHG_TEMP)
+ /* Charger prescales SBUx and MID_CHG to fit within 1.8V upper unit */
+ [ADC_SBUx] = ADC_CHAN_VOLT("chg_sbux", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_MID_CHG_DIV6] = ADC_CHAN_VOLT("chg_mid_chg", 6,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_XO_THERM_PU2] = ADC_CHAN_TEMP("xo_therm", 1,
+ SCALE_HW_CALIB_XOTHERM)
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* gaoxian,2021/10/29, add for battemp_adc */
+ [ADC_BAT_THERM_PU2] = ADC_CHAN_VOLT("bat_therm_pu2", 1,
+ SCALE_HW_CALIB_BATT_THERM_100K)
+#else
+ [ADC_BAT_THERM_PU2] = ADC_CHAN_TEMP("bat_therm_pu2", 1,
+ SCALE_HW_CALIB_BATT_THERM_100K)
+#endif
+ [ADC_BAT_THERM_PU1] = ADC_CHAN_TEMP("bat_therm_pu1", 1,
+ SCALE_HW_CALIB_BATT_THERM_30K)
+ [ADC_BAT_THERM_PU3] = ADC_CHAN_TEMP("bat_therm_pu3", 1,
+ SCALE_HW_CALIB_BATT_THERM_400K)
+ [ADC_BAT_ID_PU2] = ADC_CHAN_TEMP("bat_id", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_AMUX_THM1_PU2] = ADC_CHAN_TEMP("amux_thm1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* gaoxian,2021/10/29, add for usbtemp_adc */
+ [ADC_AMUX_THM2_PU2] = ADC_CHAN_TEMP("amux_thm2_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM2_PU2] = ADC_CHAN_TEMP("amux_thm2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_VOLT("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_TEMP("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_AMUX_THM4] = ADC_CHAN_VOLT("amux_thm4", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+ [ADC_PARALLEL_ISENSE] = ADC_CHAN_VOLT("parallel_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_INT_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "int_ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER("ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_PARALLEL_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "parallel_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* gaoxian,2021/10/29, add for usbtemp_adc */
+ [ADC_AMUX_THM2] = ADC_CHAN_TEMP("amux_thm2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#else
+ [ADC_AMUX_THM2] = ADC_CHAN_TEMP("amux_thm2", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+#endif
+
+ [ADC_AMUX_THM3] = ADC_CHAN_TEMP("amux_thm3", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+ [ADC_GPIO1_PU2] = ADC_CHAN_TEMP("gpio1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO2_PU2] = ADC_CHAN_TEMP("gpio2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3_PU2] = ADC_CHAN_TEMP("gpio3_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3] = ADC_CHAN_VOLT("gpio7_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+
+ [ADC_GPIO3_DIV3] = ADC_CHAN_VOLT("gpio7_div3", 1,
+ SCALE_HW_CALIB_DEFAULT)
+
+#ifdef CONFIG_OPLUS_SM7250R_CHARGER //OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO4_PU2] = ADC_CHAN_TEMP("gpio4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#else
+ [ADC_GPIO4_PU2] = ADC_CHAN_VOLT("gpio8_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_GPIO4] = ADC_CHAN_VOLT("gpio8_vol", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO1] = ADC_CHAN_VOLT("board_id_vdata", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+};
+
+//#ifdef OPLUS_FEATURE_TEMP_ADAPTER
+static const struct adc_channels adc_chans_pmic5_temp[ADC_MAX_CHANNEL] = {
+ [ADC_REF_GND] = ADC_CHAN_VOLT("ref_gnd", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_1P25VREF] = ADC_CHAN_VOLT("vref_1p25", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VPH_PWR] = ADC_CHAN_VOLT("vph_pwr", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VBAT_SNS] = ADC_CHAN_VOLT("vbat_sns", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VCOIN] = ADC_CHAN_VOLT("vcoin", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_DIE_TEMP] = ADC_CHAN_TEMP("die_temp", 1,
+ SCALE_HW_CALIB_PMIC_THERM)
+ [ADC_USB_IN_I] = ADC_CHAN_VOLT("usb_in_i_uv", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_USB_IN_V_16] = ADC_CHAN_VOLT("usb_in_v_div_16", 16,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_CHG_TEMP] = ADC_CHAN_TEMP("chg_temp", 1,
+ SCALE_HW_CALIB_PM5_CHG_TEMP)
+ /* Charger prescales SBUx and MID_CHG to fit within 1.8V upper unit */
+ [ADC_SBUx] = ADC_CHAN_VOLT("chg_sbux", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_MID_CHG_DIV6] = ADC_CHAN_VOLT("chg_mid_chg", 6,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_XO_THERM_PU2] = ADC_CHAN_TEMP("xo_therm", 1,
+ SCALE_HW_CALIB_XOTHERM)
+ [ADC_BAT_THERM_PU2] = ADC_CHAN_TEMP("bat_therm_pu2", 1,
+ SCALE_HW_CALIB_BATT_THERM_100K)
+ [ADC_BAT_THERM_PU1] = ADC_CHAN_TEMP("bat_therm_pu1", 1,
+ SCALE_HW_CALIB_BATT_THERM_30K)
+ [ADC_BAT_THERM_PU3] = ADC_CHAN_TEMP("bat_therm_pu3", 1,
+ SCALE_HW_CALIB_BATT_THERM_400K)
+ [ADC_BAT_ID_PU2] = ADC_CHAN_TEMP("bat_id", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_AMUX_THM1_PU2] = ADC_CHAN_TEMP("amux_thm1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_AMUX_THM2_PU2] = ADC_CHAN_TEMP("amux_thm2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_VOLT("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_TEMP("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_AMUX_THM4] = ADC_CHAN_VOLT("amux_thm4", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+ [ADC_PARALLEL_ISENSE] = ADC_CHAN_VOLT("parallel_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_INT_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "int_ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER("ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_PARALLEL_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "parallel_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_AMUX_THM2] = ADC_CHAN_TEMP("amux_thm2", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+ [ADC_AMUX_THM3] = ADC_CHAN_TEMP("amux_thm3", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+ [ADC_GPIO1_PU2] = ADC_CHAN_TEMP("gpio1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO2_PU2] = ADC_CHAN_TEMP("gpio2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3_PU2] = ADC_CHAN_TEMP("gpio3_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3] = ADC_CHAN_VOLT("gpio7_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#ifdef CONFIG_OPLUS_SM7250R_CHARGER //OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO4_PU2] = ADC_CHAN_TEMP("gpio4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#else
+ [ADC_GPIO4_PU2] = ADC_CHAN_VOLT("gpio8_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_GPIO4] = ADC_CHAN_VOLT("gpio8_vol", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO1] = ADC_CHAN_VOLT("board_id_vdata", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+};
+//#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+static const struct adc_channels adc_chans_pmic5_7225[ADC_MAX_CHANNEL] = {
+ [ADC_REF_GND] = ADC_CHAN_VOLT("ref_gnd", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_1P25VREF] = ADC_CHAN_VOLT("vref_1p25", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VPH_PWR] = ADC_CHAN_VOLT("vph_pwr", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VBAT_SNS] = ADC_CHAN_VOLT("vbat_sns", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VCOIN] = ADC_CHAN_VOLT("vcoin", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_DIE_TEMP] = ADC_CHAN_TEMP("die_temp", 1,
+ SCALE_HW_CALIB_PMIC_THERM)
+ [ADC_USB_IN_I] = ADC_CHAN_VOLT("usb_in_i_uv", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_USB_IN_V_16] = ADC_CHAN_VOLT("usb_in_v_div_16", 16,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_CHG_TEMP] = ADC_CHAN_TEMP("chg_temp", 1,
+ SCALE_HW_CALIB_PM5_CHG_TEMP)
+ /* Charger prescales SBUx and MID_CHG to fit within 1.8V upper unit */
+ [ADC_SBUx] = ADC_CHAN_VOLT("chg_sbux", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_MID_CHG_DIV6] = ADC_CHAN_VOLT("chg_mid_chg", 6,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_XO_THERM_PU2] = ADC_CHAN_TEMP("xo_therm", 1,
+ SCALE_HW_CALIB_XOTHERM)
+ [ADC_BAT_THERM_PU2] = ADC_CHAN_TEMP("bat_therm_pu2", 1,
+ SCALE_HW_CALIB_BATT_THERM_100K)
+ [ADC_BAT_THERM_PU1] = ADC_CHAN_TEMP("bat_therm_pu1", 1,
+ SCALE_HW_CALIB_BATT_THERM_30K)
+ [ADC_BAT_THERM_PU3] = ADC_CHAN_TEMP("bat_therm_pu3", 1,
+ SCALE_HW_CALIB_BATT_THERM_400K)
+ [ADC_BAT_ID_PU2] = ADC_CHAN_TEMP("bat_id", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_AMUX_THM1_PU2] = ADC_CHAN_TEMP("amux_thm1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_AMUX_THM2_PU2] = ADC_CHAN_TEMP("amux_thm2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#ifdef CONFIG_OPLUS_SM7225R_CHARGER
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_VOLT("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_VOLT("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_TEMP("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_AMUX_THM4] = ADC_CHAN_VOLT("amux_thm4", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+ [ADC_PARALLEL_ISENSE] = ADC_CHAN_VOLT("parallel_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_INT_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "int_ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER("ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_PARALLEL_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "parallel_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_AMUX_THM2] = ADC_CHAN_TEMP("amux_thm2", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+ [ADC_AMUX_THM3] = ADC_CHAN_TEMP("amux_thm3", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+ [ADC_GPIO1_PU2] = ADC_CHAN_TEMP("gpio1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO2_PU2] = ADC_CHAN_TEMP("gpio2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3_PU2] = ADC_CHAN_TEMP("gpio3_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3] = ADC_CHAN_VOLT("gpio7_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#ifdef CONFIG_OPLUS_SM7250R_CHARGER //OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO4_PU2] = ADC_CHAN_TEMP("gpio4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#else
+ [ADC_GPIO4_PU2] = ADC_CHAN_VOLT("gpio8_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_GPIO4] = ADC_CHAN_VOLT("gpio8_vol", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO1] = ADC_CHAN_VOLT("board_id_vdata", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+};
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+static const struct adc_channels adc_chans_pmic5_7225_s[ADC_MAX_CHANNEL] = {
+ [ADC_REF_GND] = ADC_CHAN_VOLT("ref_gnd", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_1P25VREF] = ADC_CHAN_VOLT("vref_1p25", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VPH_PWR] = ADC_CHAN_VOLT("vph_pwr", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VBAT_SNS] = ADC_CHAN_VOLT("vbat_sns", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_VCOIN] = ADC_CHAN_VOLT("vcoin", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_DIE_TEMP] = ADC_CHAN_TEMP("die_temp", 1,
+ SCALE_HW_CALIB_PMIC_THERM)
+ [ADC_USB_IN_I] = ADC_CHAN_VOLT("usb_in_i_uv", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_USB_IN_V_16] = ADC_CHAN_VOLT("usb_in_v_div_16", 16,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_CHG_TEMP] = ADC_CHAN_TEMP("chg_temp", 1,
+ SCALE_HW_CALIB_PM5_CHG_TEMP)
+ /* Charger prescales SBUx and MID_CHG to fit within 1.8V upper unit */
+ [ADC_SBUx] = ADC_CHAN_VOLT("chg_sbux", 3,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_MID_CHG_DIV6] = ADC_CHAN_VOLT("chg_mid_chg", 6,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_XO_THERM_PU2] = ADC_CHAN_TEMP("xo_therm", 1,
+ SCALE_HW_CALIB_XOTHERM)
+ [ADC_BAT_THERM_PU2] = ADC_CHAN_TEMP("bat_therm_pu2", 1,
+ SCALE_HW_CALIB_BATT_THERM_100K)
+ [ADC_BAT_THERM_PU1] = ADC_CHAN_TEMP("bat_therm_pu1", 1,
+ SCALE_HW_CALIB_BATT_THERM_30K)
+ [ADC_BAT_THERM_PU3] = ADC_CHAN_TEMP("bat_therm_pu3", 1,
+ SCALE_HW_CALIB_BATT_THERM_400K)
+ [ADC_BAT_ID_PU2] = ADC_CHAN_TEMP("bat_id", 1,
+ SCALE_HW_CALIB_DEFAULT)
+ [ADC_AMUX_THM1_PU2] = ADC_CHAN_TEMP("amux_thm1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_AMUX_THM2_PU2] = ADC_CHAN_TEMP("amux_thm2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+//#ifdef CONFIG_OPLUS_SM7225R_CHARGER
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_VOLT("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+//#else
+// [ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
+// SCALE_HW_CALIB_THERM_100K_PULLUP)
+//#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_VOLT("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM4_PU2] = ADC_CHAN_TEMP("amux_thm4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_AMUX_THM4] = ADC_CHAN_VOLT("amux_thm4", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+ [ADC_PARALLEL_ISENSE] = ADC_CHAN_VOLT("parallel_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_INT_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "int_ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_EXT_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER("ext_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_PARALLEL_ISENSE_VBAT_VDATA] = ADC_CHAN_POWER(
+ "parallel_vbat_isense", 1,
+ SCALE_HW_CALIB_CUR)
+ [ADC_AMUX_THM2] = ADC_CHAN_TEMP("amux_thm2", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+ [ADC_AMUX_THM3] = ADC_CHAN_TEMP("amux_thm3", 1,
+ SCALE_HW_CALIB_PM5_SMB_TEMP)
+ [ADC_GPIO1_PU2] = ADC_CHAN_TEMP("gpio1_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO2_PU2] = ADC_CHAN_TEMP("gpio2_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3_PU2] = ADC_CHAN_TEMP("gpio3_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+ [ADC_GPIO3] = ADC_CHAN_VOLT("gpio7_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#ifdef CONFIG_OPLUS_SM7250R_CHARGER //OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO4_PU2] = ADC_CHAN_TEMP("gpio4_pu2", 1,
+ SCALE_HW_CALIB_THERM_100K_PULLUP)
+#else
+ [ADC_GPIO4_PU2] = ADC_CHAN_VOLT("gpio8_v", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+/* yangmingjin,2020/3/9, add for usbtemp_adc */
+ [ADC_GPIO4] = ADC_CHAN_VOLT("gpio8_vol", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ [ADC_GPIO1] = ADC_CHAN_VOLT("board_id_vdata", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#endif
+};
+#endif
+
static const struct adc_channels adc7_chans_pmic[ADC_MAX_CHANNEL] = {
[ADC7_REF_GND] = ADC_CHAN_VOLT("ref_gnd", 0,
SCALE_HW_CALIB_DEFAULT)
@@ -981,8 +1498,13 @@ static const struct adc_channels adc_chans_rev2[ADC_MAX_CHANNEL] = {
SCALE_HW_CALIB_PMIC_THERM)
[ADC_AMUX_THM1_PU2] = ADC_CHAN_TEMP("amux_thm1_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
+#ifdef CONFIG_OPLUS_SM7250R_CHARGER //OPLUS_FEATURE_CHG_BASIC
[ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
+ SCALE_HW_CALIB_DEFAULT)
+#else
+ [ADC_AMUX_THM3_PU2] = ADC_CHAN_TEMP("amux_thm3_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
+#endif
[ADC_AMUX_THM5_PU2] = ADC_CHAN_TEMP("amux_thm5_pu2", 1,
SCALE_HW_CALIB_THERM_100K_PULLUP)
[ADC_XO_THERM_PU2] = ADC_CHAN_TEMP("xo_therm", 1,
@@ -1102,6 +1624,17 @@ static int adc_get_dt_channel_data(struct adc_chip *adc,
else
prop->cal_method = ADC_ABSOLUTE_CAL;
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ if (!of_property_read_u32(node, "oplus,cust_type", &value))
+ prop->cust_type = value;
+ else
+ prop->cust_type = -1;
+
+ if (!of_property_read_u32(node, "oplus,cust_scale_fn_type", &value))
+ prop->cust_scale_fn_type = value;
+ else
+ prop->cust_scale_fn_type = -1;
+#endif
/*
* Default to using timer calibration. Using a fresh calibration value
* for every conversion will increase the overall time for a request.
@@ -1123,6 +1656,53 @@ const struct adc_data data_pmic5 = {
800, 900, 1, 2, 4, 6, 8, 10},
};
+const struct adc_data data_pmic5_21027 = {
+ .full_scale_code_volt = 0x70e4,
+ /* On PM8150B, IBAT LSB = 10A/32767 */
+ .full_scale_code_cur = 10000,
+ .adc_chans = adc_chans_pmic5_21027,
+ .decimation = (unsigned int []) {250, 420, 840},
+ .hw_settle = (unsigned int []) {15, 100, 200, 300, 400, 500, 600, 700,
+ 800, 900, 1, 2, 4, 6, 8, 10},
+ .battemp_for_adc = 1,
+};
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+const struct adc_data data_pmic5_7225 = {
+ .full_scale_code_volt = 0x70e4,
+ /* On PM8150B, IBAT LSB = 10A/32767 */
+ .full_scale_code_cur = 10000,
+ .adc_chans = adc_chans_pmic5_7225,
+ .decimation = (unsigned int []) {250, 420, 840},
+ .hw_settle = (unsigned int []) {15, 100, 200, 300, 400, 500, 600, 700,
+ 800, 900, 1, 2, 4, 6, 8, 10},
+};
+#endif
+
+//#ifdef OPLUS_FEATURE_TEMP_ADAPTER
+const struct adc_data data_pmic5_temp = {
+ .full_scale_code_volt = 0x70e4,
+ /* On PM8150B, IBAT LSB = 10A/32767 */
+ .full_scale_code_cur = 10000,
+ .adc_chans = adc_chans_pmic5_temp,
+ .decimation = (unsigned int []) {250, 420, 840},
+ .hw_settle = (unsigned int []) {15, 100, 200, 300, 400, 500, 600, 700,
+ 800, 900, 1, 2, 4, 6, 8, 10},
+};
+//#endif
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+const struct adc_data data_pmic5_7225_s = {
+ .full_scale_code_volt = 0x70e4,
+ /* On PM8150B, IBAT LSB = 10A/32767 */
+ .full_scale_code_cur = 10000,
+ .adc_chans = adc_chans_pmic5_7225_s,
+ .decimation = (unsigned int []) {250, 420, 840},
+ .hw_settle = (unsigned int []) {15, 100, 200, 300, 400, 500, 600, 700,
+ 800, 900, 1, 2, 4, 6, 8, 10},
+};
+#endif
+
const struct adc_data data_pmic5_lite = {
.full_scale_code_volt = 0x70e4,
/* On PMI632, IBAT LSB = 5A/32767 */
@@ -1155,6 +1735,30 @@ static const struct of_device_id adc_match_table[] = {
.compatible = "qcom,spmi-adc5",
.data = &data_pmic5,
},
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ {
+ .compatible = "qcom,spmi-adc5-7225",
+ .data = &data_pmic5_7225,
+ },
+#endif
+//#ifdef OPLUS_FEATURE_TEMP_ADAPTER
+ {
+ .compatible = "qcom,spmi-adc5-temp",
+ .data = &data_pmic5_temp,
+ },
+//#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ {
+ .compatible = "qcom,spmi-adc5-7225_s",
+ .data = &data_pmic5_7225_s,
+ },
+#endif
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ {
+ .compatible = "qcom,spmi-adc5_21027",
+ .data = &data_pmic5_21027,
+ },
+#endif
{
.compatible = "qcom,spmi-adc7",
.data = &adc7_data_pmic,
@@ -1224,6 +1828,15 @@ static int adc_get_dt_data(struct adc_chip *adc, struct device_node *node)
iio_chan->info_mask_separate = adc_chan->info_mask;
iio_chan->type = adc_chan->type;
iio_chan->address = index;
+
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ if(prop.cust_type != -1 && prop.cust_scale_fn_type != -1) {
+ pr_err("%s: force to cust_type %d, cust_scale_fn_type %d\n", prop.datasheet_name, prop.cust_type, prop.cust_scale_fn_type);
+ iio_chan->type = prop.cust_type;
+ iio_chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_PROCESSED);
+ adc->chan_props[index].scale_fn_type = prop.cust_scale_fn_type;
+ }
+#endif
iio_chan++;
index++;
}
diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
index 8467d0fbddf4..49e3d186f853 100644
--- a/drivers/iio/adc/qcom-vadc-common.c
+++ b/drivers/iio/adc/qcom-vadc-common.c
@@ -246,7 +246,81 @@ static const struct vadc_map_pt adcmap_batt_therm_100k_6125[] = {
* Voltage to temperature table for 30k pull up for bat_therm with
* Alium.
*/
-static const struct vadc_map_pt adcmap_batt_therm_30k[] = {
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ static const struct vadc_map_pt adcmap_batt_therm_30k[] = {
+ { 1623 , -400 },
+ { 1600 , -380 },
+ { 1575 , -360 },
+ { 1548 , -340 },
+ { 1520 , -320 },
+ { 1491 , -300 },
+ { 1460 , -280 },
+ { 1429 , -260 },
+ { 1396 , -240 },
+ { 1363 , -220 },
+ { 1328 , -200 },
+ { 1293 , -180 },
+ { 1258 , -160 },
+ { 1222 , -140 },
+ { 1186 , -120 },
+ { 1150 , -100 },
+ { 1114 , -80 },
+ { 1078 , -60 },
+ { 1042 , -40 },
+ { 1008 , -20 },
+ { 973 , 0 },
+ { 940 , 20 },
+ { 907 , 40 },
+ { 875 , 60 },
+ { 845 , 80 },
+ { 815 , 100 },
+ { 786 , 120 },
+ { 759 , 140 },
+ { 732 , 160 },
+ { 707 , 180 },
+ { 683 , 200 },
+ { 660 , 220 },
+ { 638 , 240 },
+ { 618 , 260 },
+ { 598 , 280 },
+ { 579 , 300 },
+ { 562 , 320 },
+ { 545 , 340 },
+ { 529 , 360 },
+ { 514 , 380 },
+ { 501 , 400 },
+ { 487 , 420 },
+ { 475 , 440 },
+ { 463 , 460 },
+ { 452 , 480 },
+ { 442 , 500 },
+ { 433 , 520 },
+ { 423 , 540 },
+ { 415 , 560 },
+ { 407 , 580 },
+ { 399 , 600 },
+ { 392 , 620 },
+ { 386 , 640 },
+ { 379 , 660 },
+ { 374 , 680 },
+ { 368 , 700 },
+ { 363 , 720 },
+ { 358 , 740 },
+ { 353 , 760 },
+ { 349 , 780 },
+ { 345 , 800 },
+ { 341 , 820 },
+ { 338 , 840 },
+ { 334 , 860 },
+ { 331 , 880 },
+ { 328 , 900 },
+ { 325 , 920 },
+ { 323 , 940 },
+ { 320 , 960 },
+ { 318 , 980 },
+ };
+#else
+ static const struct vadc_map_pt adcmap_batt_therm_30k[] = {
{1864, -400},
{1863, -380},
{1861, -360},
@@ -317,7 +391,9 @@ static const struct vadc_map_pt adcmap_batt_therm_30k[] = {
{349, 940},
{332, 960},
{315, 980}
-};
+ };
+#endif
+
/*
* Voltage to temperature table for 30k pull up for bat_therm with
@@ -1421,8 +1497,17 @@ int qcom_vadc_hw_scale(enum vadc_scale_fn_type scaletype,
return qcom_vadc_scale_hw_calib_therm(prescale, data,
adc_code, result);
case SCALE_HW_CALIB_BATT_THERM_100K:
- return qcom_vadc_scale_hw_calib_batt_therm_100(prescale,
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ if (data->battemp_for_adc == 1) {
+ return qcom_vadc_scale_hw_calib_volt(prescale,
+ data,adc_code, result);
+ } else {
+#endif
+ return qcom_vadc_scale_hw_calib_batt_therm_100(prescale,
data, lut_index, adc_code, result);
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ }
+#endif
case SCALE_HW_CALIB_BATT_THERM_30K:
return qcom_vadc_scale_hw_calib_batt_therm_30(prescale,
data, lut_index, adc_code, result);
diff --git a/drivers/iio/adc/qcom-vadc-common.h b/drivers/iio/adc/qcom-vadc-common.h
index e0ff98bf5f15..3b900ff2151f 100644
--- a/drivers/iio/adc/qcom-vadc-common.h
+++ b/drivers/iio/adc/qcom-vadc-common.h
@@ -208,6 +208,9 @@ struct adc_data {
const struct adc_channels *adc_chans;
unsigned int *decimation;
unsigned int *hw_settle;
+#ifdef OPLUS_FEATURE_CHG_BASIC
+ int battemp_for_adc;
+#endif
};
int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index a78c8309bb3f..6c46da3cfc91 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -213,6 +213,10 @@ source "drivers/input/misc/Kconfig"
source "drivers/input/rmi4/Kconfig"
+#ifdef OPLUS_FEATURE_FINGERPRINT
+source "drivers/input/oplus_fp_drivers/Kconfig"
+source "drivers/input/oplus_secure_drivers/Kconfig"
+#endif
endif
menu "Hardware I/O ports"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index d670bfc10bbe..a72c026c6403 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -31,3 +31,11 @@ obj-$(CONFIG_INPUT_KEYRESET) += keyreset.o
obj-$(CONFIG_INPUT_KEYCOMBO) += keycombo.o
obj-$(CONFIG_RMI4_CORE) += rmi4/
+
+#ifdef OPLUS_FEATURE_FINGERPRINT
+ifneq ($(TARGET_PRODUCT), qssi)
+obj-$(CONFIG_OPLUS_FINGERPRINT) += oplus_fp_drivers/
+obj-$(CONFIG_OPLUS_SECURE) += oplus_secure_drivers/
+#endif /* OPLUS_FEATURE_FINGERPRINT */
+endif
+#endif
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 159dd87b93b0..e00a03158339 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -29,6 +29,7 @@
#include
#include "input-compat.h"
+
MODULE_AUTHOR("Vojtech Pavlik ");
MODULE_DESCRIPTION("Input core");
MODULE_LICENSE("GPL");
@@ -378,11 +379,20 @@ static int input_get_disposition(struct input_dev *dev,
return disposition;
}
+#ifdef OPLUS_FEATURE_SAUPWK
+extern void __attribute__((weak)) oplus_sync_saupwk_event(unsigned int , unsigned int , int);
+#endif /* OPLUS_FEATURE_SAUPWK */
+
static void input_handle_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
{
int disposition = input_get_disposition(dev, type, code, &value);
+#ifdef OPLUS_FEATURE_SAUPWK
+ if(oplus_sync_saupwk_event)
+ oplus_sync_saupwk_event(type, code, value);
+#endif /* OPLUS_FEATURE_SAUPWK */
+
if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
add_input_randomness(type, code, value);
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 492a971b95b5..93aabf3460db 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -380,6 +380,15 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
input_event(input, type, *bdata->code, state);
}
input_sync(input);
+
+#ifdef OPLUS_FEATURE_TP_BASIC
+ if (!strcmp(button->desc, "volume_up")) {
+ dev_info(input->dev.parent, "vol_up %s\n", !!state?"pressed":"release");
+ }
+ if (!strcmp(button->desc, "volume_down")) {
+ dev_info(input->dev.parent, "vol_down %s\n", !!state?"pressed":"release");
+ }
+#endif
}
static void gpio_keys_gpio_work_func(struct work_struct *work)
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 3d7ca037962d..4d539df73afc 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -885,4 +885,14 @@ config INPUT_SC27XX_VIBRA
To compile this driver as a module, choose M here. The module will
be called sc27xx_vibra.
+config STMVL53L1
+ tristate "STM VL53L1 Proximity support"
+ depends on I2C=y
+ default y
+ help
+ Say Y here if you want to use STMicroelectronics's vl53L1 TOF AF sensor
+ through I2C interface.
+
+ To compile this driver as a module, choose M here: the
+ module will be called stmvl53l1.
endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index a99ea9586234..7d75a9aef844 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -85,3 +85,4 @@ obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
obj-$(CONFIG_INPUT_YEALINK) += yealink.o
obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o
+obj-$(CONFIG_STMVL53L1) += vl53L1/
diff --git a/drivers/input/misc/qpnp-power-on.c b/drivers/input/misc/qpnp-power-on.c
index 56918e9ef768..dda507e05fb1 100644
--- a/drivers/input/misc/qpnp-power-on.c
+++ b/drivers/input/misc/qpnp-power-on.c
@@ -26,6 +26,18 @@
#include
#include
+#ifdef OPLUS_FEATURE_THEIA
+#include
+#include
+#endif
+
+#ifdef CONFIG_OPLUS_FEATURE_MISC
+#include
+#include
+#include
+#include
+#endif
+
#define PMIC_VER_8941 0x01
#define PMIC_VERSION_REG 0x0105
#define PMIC_VERSION_REV4_REG 0x0103
@@ -191,6 +203,56 @@ struct pon_regulator {
bool enabled;
};
+#ifdef OPLUS_FEATURE_QCOM_PMICWD
+#ifndef CONFIG_OPLUS_FEATURE_QCOM_PMICWD
+struct qpnp_pon {
+ struct device *dev;
+ struct regmap *regmap;
+ struct input_dev *pon_input;
+ struct qpnp_pon_config *pon_cfg;
+ struct pon_regulator *pon_reg_cfg;
+ struct list_head list;
+ struct delayed_work bark_work;
+ struct dentry *debugfs;
+ u16 base;
+ u8 subtype;
+ u8 pon_ver;
+ u8 warm_reset_reason1;
+ u8 warm_reset_reason2;
+ int num_pon_config;
+ int num_pon_reg;
+ int pon_trigger_reason;
+ int pon_power_off_reason;
+ u32 dbc_time_us;
+ u32 uvlo;
+ int warm_reset_poff_type;
+ int hard_reset_poff_type;
+ int shutdown_poff_type;
+ int resin_warm_reset_type;
+ int resin_hard_reset_type;
+ int resin_shutdown_type;
+ bool is_spon;
+ bool store_hard_reset_reason;
+ bool resin_hard_reset_disable;
+ bool resin_shutdown_disable;
+ bool ps_hold_hard_reset_disable;
+ bool ps_hold_shutdown_disable;
+ bool kpdpwr_dbc_enable;
+ bool resin_pon_reset;
+ ktime_t kpdpwr_last_release_time;
+};
+#endif
+
+static int pon_ship_mode_en;
+module_param_named(
+ ship_mode_en, pon_ship_mode_en, int, 0600
+);
+
+#ifndef CONFIG_OPLUS_FEATURE_QCOM_PMICWD
+static struct qpnp_pon *sys_reset_dev;
+#endif
+
+#else
struct qpnp_pon {
struct device *dev;
struct regmap *regmap;
@@ -235,6 +297,8 @@ module_param_named(
);
static struct qpnp_pon *sys_reset_dev;
+#endif /* OPLUS_FEATURE_QCOM_PMICWD */
+
static struct qpnp_pon *modem_reset_dev;
static DEFINE_SPINLOCK(spon_list_slock);
static LIST_HEAD(spon_dev_list);
@@ -305,8 +369,18 @@ static const char * const qpnp_poff_reason[] = {
[39] = "Triggered from S3_RESET_KPDPWR_ANDOR_RESIN",
};
+#ifdef OPLUS_FEATURE_QCOM_PMICWD
+#ifdef CONFIG_OPLUS_FEATURE_QCOM_PMICWD
+int qpnp_pon_masked_write(struct qpnp_pon *pon, u16 addr, u8 mask, u8 val)
+#else
static int
qpnp_pon_masked_write(struct qpnp_pon *pon, u16 addr, u8 mask, u8 val)
+#endif
+
+#else
+static int
+qpnp_pon_masked_write(struct qpnp_pon *pon, u16 addr, u8 mask, u8 val)
+#endif /* OPLUS_FEATURE_QCOM_PMICWD */
{
int rc;
@@ -690,7 +764,7 @@ out:
if (!!pon_ship_mode_en) {
batt_psy = power_supply_get_by_name("battery");
if (batt_psy) {
- pr_debug("Setting ship mode\n");
+ pr_err("Setting ship mode\n");
val.intval = 1;
rc = power_supply_set_property(batt_psy,
POWER_SUPPLY_PROP_SET_SHIP_MODE, &val);
@@ -930,7 +1004,7 @@ static int qpnp_pon_input_dispatch(struct qpnp_pon *pon, u32 pon_type)
elapsed_us = ktime_us_delta(ktime_get(),
pon->kpdpwr_last_release_time);
if (elapsed_us < pon->dbc_time_us) {
- pr_debug("Ignoring kpdpwr event; within debounce time\n");
+ pr_err("Ignoring kpdpwr event; within debounce time\n");
return 0;
}
}
@@ -943,6 +1017,16 @@ static int qpnp_pon_input_dispatch(struct qpnp_pon *pon, u32 pon_type)
switch (cfg->pon_type) {
case PON_KPDPWR:
pon_rt_bit = QPNP_PON_KPDPWR_N_SET;
+#ifdef CONFIG_OPLUS_FEATURE_MISC
+ if ((pon_rt_sts & pon_rt_bit) == 0) {
+ pr_debug("Power-Key UP\n");
+ cancel_delayed_work(&pon->press_work);
+ } else {
+ pr_debug("Power-Key DOWN\n");
+ schedule_delayed_work(&pon->press_work,
+ msecs_to_jiffies(4000));
+ }
+#endif
break;
case PON_RESIN:
pon_rt_bit = QPNP_PON_RESIN_N_SET;
@@ -957,7 +1041,7 @@ static int qpnp_pon_input_dispatch(struct qpnp_pon *pon, u32 pon_type)
return -EINVAL;
}
- pr_debug("PMIC input: code=%d, status=0x%02X\n", cfg->key_code,
+ pr_err("PMIC input: code=%d, status=0x%02X\n", cfg->key_code,
pon_rt_sts);
key_status = pon_rt_sts & pon_rt_bit;
@@ -979,6 +1063,21 @@ static int qpnp_pon_input_dispatch(struct qpnp_pon *pon, u32 pon_type)
input_sync(pon->pon_input);
}
+ #ifdef OPLUS_FEATURE_QCOM_PMICWD
+ #ifdef CONFIG_OPLUS_FEATURE_QCOM_PMICWD
+ pr_err("keycode = %d,key_st = %d\n",cfg->key_code, key_status);
+ #endif
+ #endif /* OPLUS_FEATURE_QCOM_PMICWD */
+
+ #ifdef OPLUS_FEATURE_THEIA
+ pr_err("keycode = %d,key_st = %d old_state= %d %d \n",cfg->key_code, key_status,cfg->old_state ,KEY_POWER);
+ if(cfg->key_code == KEY_POWER && key_status == 1 && cfg->old_state == 0){
+ //we should canel per work
+ black_screen_timer_restart();
+ bright_screen_timer_restart();
+ }
+ #endif
+
input_report_key(pon->pon_input, cfg->key_code, key_status);
input_sync(pon->pon_input);
@@ -1132,6 +1231,44 @@ static void bark_work_func(struct work_struct *work)
}
}
+#ifdef CONFIG_OPLUS_FEATURE_MISC
+static void press_work_func(struct work_struct *work)
+{
+ int display_bl, boot_mode;
+ int rc;
+ uint pon_rt_sts = 0;
+ struct qpnp_pon_config *cfg;
+ struct qpnp_pon *pon =
+ container_of(work, struct qpnp_pon, press_work.work);
+
+ cfg = qpnp_get_cfg(pon, PON_KPDPWR);
+ if (!cfg) {
+ dev_err(pon->dev, "Invalid config pointer\n");
+ goto err_return;
+ }
+ /* check the RT status to get the current status of the line */
+ rc = regmap_read(pon->regmap, QPNP_PON_RT_STS(pon), &pon_rt_sts);
+ if (rc) {
+ dev_err(pon->dev, "Unable to read PON RT status\n");
+ goto err_return;
+ }
+ if ((pon_rt_sts & QPNP_PON_KPDPWR_N_SET) == 1) {
+ dev_err(pon->dev, "after 4s Power-Key is still DOWN\n");
+ display_bl = dsi_panel_backlight_get();
+ boot_mode = get_boot_mode();
+ if (display_bl == 0 && boot_mode == MSM_BOOT_MODE__NORMAL) {
+ oplus_switch_fulldump(0);
+ show_state_filter(TASK_UNINTERRUPTIBLE);
+ panic("power key still pressed\n");
+ }
+ }
+ msleep(20);
+ ksys_sync();
+err_return:
+ return;
+}
+#endif
+
static irqreturn_t qpnp_resin_bark_irq(int irq, void *_pon)
{
struct qpnp_pon *pon = _pon;
@@ -2086,6 +2223,12 @@ static int qpnp_pon_configure_s3_reset(struct qpnp_pon *pon)
return 0;
}
+#ifdef OPLUS_BUG_STABILITY
+extern char pon_reason[];
+extern char poff_reason[];
+int preason_initialized;
+#endif /*OPLUS_BUG_STABILITY*/
+
static int qpnp_pon_read_hardware_info(struct qpnp_pon *pon, bool sys_reset)
{
struct device *dev = pon->dev;
@@ -2131,25 +2274,45 @@ static int qpnp_pon_read_hardware_info(struct qpnp_pon *pon, bool sys_reset)
/* PON reason */
rc = qpnp_pon_read(pon, QPNP_PON_REASON1(pon), &pon_sts);
- if (rc)
+ if (rc){
+#ifdef OPLUS_BUG_STABILITY
+ dev_err(dev,"Unable to read PON_RESASON1 reg rc: %d\n",rc);
+ if (!preason_initialized) {
+ snprintf(pon_reason, 128, "Unable to read PON_RESASON1 reg rc: %d\n", rc);
+ preason_initialized = 1;
+ }
+#endif /*OPLUS_BUG_STABILITY*/
return rc;
-
+ }
if (sys_reset)
boot_reason = ffs(pon_sts);
index = ffs(pon_sts) - 1;
+#ifdef OPLUS_BUG_STABILITY
+ if (pon_sts & 0x80)
+ index = 7;
+#endif /*OPLUS_BUG_STABILITY*/
cold_boot = sys_reset_dev ? !_qpnp_pon_is_warm_reset(sys_reset_dev)
: !_qpnp_pon_is_warm_reset(pon);
if (index >= ARRAY_SIZE(qpnp_pon_reason) || index < 0) {
dev_info(dev, "PMIC@SID%d Power-on reason: Unknown and '%s' boot\n",
to_spmi_device(dev->parent)->usid,
cold_boot ? "cold" : "warm");
+#ifdef OPLUS_BUG_STABILITY
+ if (!preason_initialized)
+ snprintf(pon_reason, 128, "Unknown[0x%02X] and '%s' boot\n", pon_sts, cold_boot ? "cold" : "warm");
+#endif /*OPLUS_BUG_STABILITY*/
} else {
pon->pon_trigger_reason = index;
dev_info(dev, "PMIC@SID%d Power-on reason: %s and '%s' boot\n",
to_spmi_device(dev->parent)->usid,
qpnp_pon_reason[index],
cold_boot ? "cold" : "warm");
+#ifdef OPLUS_BUG_STABILITY
+ if (!preason_initialized)
+ snprintf(pon_reason, 128, "[0x%02X]%s and '%s' boot\n", pon_sts,
+ qpnp_pon_reason[index], cold_boot ? "cold" : "warm");
+#endif /*OPLUS_BUG_STABILITY*/
}
/* POFF reason */
@@ -2157,13 +2320,19 @@ static int qpnp_pon_read_hardware_info(struct qpnp_pon *pon, bool sys_reset)
rc = qpnp_pon_read_gen2_pon_off_reason(pon, &poff_sts,
&reason_index_offset);
if (rc)
- return rc;
+ return rc;
} else {
rc = regmap_bulk_read(pon->regmap, QPNP_POFF_REASON1(pon), buf,
2);
if (rc) {
dev_err(dev, "Register read failed, addr=0x%04X, rc=%d\n",
QPNP_POFF_REASON1(pon), rc);
+#ifdef OPLUS_BUG_STABILITY
+ if (!preason_initialized) {
+ snprintf(poff_reason, 128, "Unable to read POFF_RESASON regs rc:%d\n", rc);
+ preason_initialized = 1;
+ }
+#endif /*OPLUS_BUG_STABILITY*/
return rc;
}
poff_sts = buf[0] | (u16)(buf[1] << 8);
@@ -2173,11 +2342,23 @@ static int qpnp_pon_read_hardware_info(struct qpnp_pon *pon, bool sys_reset)
index < reason_index_offset) {
dev_info(dev, "PMIC@SID%d: Unknown power-off reason\n",
to_spmi_device(dev->parent)->usid);
+#ifdef OPLUS_BUG_STABILITY
+ if (!preason_initialized) {
+ snprintf(poff_reason, 128, "Unknown[0x%4X]\n", poff_sts);
+ preason_initialized = 1;
+ }
+#endif /*OPLUS_BUG_STABILITY*/
} else {
pon->pon_power_off_reason = index;
dev_info(dev, "PMIC@SID%d: Power-off reason: %s\n",
to_spmi_device(dev->parent)->usid,
qpnp_poff_reason[index]);
+#ifdef OPLUS_BUG_STABILITY
+ if (!preason_initialized) {
+ snprintf(poff_reason, 128, "[0x%04X]%s\n", poff_sts, qpnp_poff_reason[index]);
+ preason_initialized = 1;
+ }
+#endif /*OPLUS_BUG_STABILITY*/
}
if ((pon->pon_trigger_reason == PON_SMPL ||
@@ -2338,7 +2519,9 @@ static int qpnp_pon_probe(struct platform_device *pdev)
dev_set_drvdata(dev, pon);
INIT_DELAYED_WORK(&pon->bark_work, bark_work_func);
-
+#ifdef CONFIG_OPLUS_FEATURE_MISC
+ INIT_DELAYED_WORK(&pon->press_work, press_work_func);
+#endif
rc = qpnp_pon_parse_dt_power_off_config(pon);
if (rc)
return rc;
@@ -2397,7 +2580,14 @@ static int qpnp_pon_probe(struct platform_device *pdev)
if (modem_reset)
modem_reset_dev = pon;
- qpnp_pon_debugfs_init(pon);
+ qpnp_pon_debugfs_init(pon);
+
+ #ifdef OPLUS_FEATURE_QCOM_PMICWD
+ #ifdef CONFIG_OPLUS_FEATURE_QCOM_PMICWD
+ pmicwd_init(pdev, pon, sys_reset);
+ kpdpwr_init(pon, sys_reset);
+ #endif
+ #endif /* OPLUS_FEATURE_QCOM_PMICWD */
return 0;
}
@@ -2428,6 +2618,11 @@ static const struct of_device_id qpnp_pon_match_table[] = {
static struct platform_driver qpnp_pon_driver = {
.driver = {
+ #ifdef OPLUS_FEATURE_QCOM_PMICWD
+ #ifdef CONFIG_OPLUS_FEATURE_QCOM_PMICWD
+ .pm = &qpnp_pm_ops,
+ #endif
+ #endif /* OPLUS_FEATURE_QCOM_PMICWD */
.name = "qcom,qpnp-power-on",
.of_match_table = qpnp_pon_match_table,
},
diff --git a/drivers/input/misc/vl53L1/Makefile b/drivers/input/misc/vl53L1/Makefile
new file mode 100644
index 000000000000..98bec8a7a9c3
--- /dev/null
+++ b/drivers/input/misc/vl53L1/Makefile
@@ -0,0 +1,6 @@
+$(warning, "wkj $(TARGET_PRODUCT)")
+ifeq ($(TARGET_PRODUCT), kona)
+obj-$(CONFIG_STMVL53L1) += kona/
+else ifeq ($(TARGET_PRODUCT), lito)
+obj-$(CONFIG_STMVL53L1) += lito/
+endif
diff --git a/drivers/input/misc/vl53L1/kona/Kbuild b/drivers/input/misc/vl53L1/kona/Kbuild
new file mode 100644
index 000000000000..a4a62d819181
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/Kbuild
@@ -0,0 +1,30 @@
+#
+# Kbuild for the vl53L1 drivers.
+#
+
+ccflags-y += -I$(src)/inc -I$(src)/ipp -I$(src)
+ccflags-y += -Itechpack/camera/drivers/cam_sensor_module/cam_cci
+
+# define this environment variable if you want to compile driver for an old
+# kernel
+ifdef OLD_NETLINK_API
+ccflags-y += -DOLD_NETLINK_API
+endif
+
+ifdef VL53L1_LOG_ENABLE
+ccflags-y += -DVL53L1_LOG_ENABLE
+endif
+
+obj-$(CONFIG_STMVL53L1) += stmvl53l1.o
+stmvl53l1-objs := stmvl53l1_module.o stmvl53l1_module-i2c.o stmvl53l1_module-cci.o
+stmvl53l1-objs += stmvl53l1_i2c.o stmvl53l1_ipp_nl.o stmvl53l1_log.o
+stmvl53l1-objs += src/vl53l1_api.o src/vl53l1_api_core.o
+stmvl53l1-objs += src/vl53l1_api_strings.o src/vl53l1_error_strings.o
+stmvl53l1-objs += src/vl53l1_core.o src/vl53l1_register_funcs.o
+stmvl53l1-objs += src/vl53l1_api_preset_modes.o
+stmvl53l1-objs += src/vl53l1_api_calibration.o
+stmvl53l1-objs += src/vl53l1_silicon_core.o
+stmvl53l1-objs += src/vl53l1_zone_presets.o src/vl53l1_nvm.o
+stmvl53l1-objs += src/vl53l1_api_debug.o src/vl53l1_core_support.o
+stmvl53l1-objs += src/vl53l1_wait.o ipp/ipp_linux.o
+stmvl53l1-objs += src/vl53l1_nvm_debug.o
diff --git a/drivers/input/misc/vl53L1/kona/Makefile b/drivers/input/misc/vl53L1/kona/Makefile
new file mode 100644
index 000000000000..4dd06f8d49f8
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/Makefile
@@ -0,0 +1,12 @@
+ifneq ($(KERNELRELEASE),)
+include Kbuild
+
+else
+KDIR ?= /lib/modules/`uname -r`/build
+
+default:
+ CONFIG_STMVL53L1=m $(MAKE) -C $(KDIR) M=$$PWD
+clean:
+ CONFIG_STMVL53L1=m $(MAKE) -C $(KDIR) M=$$PWD clean
+
+endif
\ No newline at end of file
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_api.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api.h
new file mode 100644
index 000000000000..28ccd45c7e61
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api.h
@@ -0,0 +1,1497 @@
+
+/******************************************************************************
+ * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+ ******************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+ *******************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+ *******************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones mentioned above :
+
+ *******************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+ *******************************************************************************
+ */
+
+#ifndef _VL53L1_API_H_
+#define _VL53L1_API_H_
+
+#include "vl53l1_api_strings.h"
+#include "vl53l1_api_core.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#if !defined(VL53L1DevDataGet)
+#warning "PALDevDataGet is deprecated define VL53L1DevDataGet instead"
+#define VL53L1DevDataGet(Dev, field) (Dev->Data.field)
+#endif
+
+#if !defined(VL53L1DevDataSet)
+#warning "PALDevDataSet is deprecated define VL53L1DevDataSet instead"
+#define VL53L1DevDataSet(Dev, field, data) ((Dev->Data.field) = (data))
+#endif
+
+/** @defgroup VL53L1_cut11_group VL53L1 cut1.1 Function Definition
+ * @brief VL53L1 cut1.1 Function Definition
+ * @{
+ */
+
+/** @defgroup VL53L1_general_group VL53L1 General Functions
+ * @brief General functions and definitions
+ * @{
+ */
+
+/**
+ * @brief Return the VL53L1 driver Version
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param pVersion Rer to current driver Version
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetVersion(VL53L1_Version_t *pVersion);
+
+/**
+ * @brief Reads the Product Revision for a for given Device
+ * This function can be used to distinguish cut1.0 from cut1.1.
+ *
+ * @param Dev Device Handle
+ * @param pProductRevisionMajor Pointer to Product Revision Major
+ * for a given Device
+ * @param pProductRevisionMinor Pointer to Product Revision Minor
+ * for a given Device
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetProductRevision(VL53L1_DEV Dev,
+ uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor);
+
+/**
+ * @brief Reads the Device information for given Device
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pVL53L1_DeviceInfo Pointer to current device info for a given
+ * Device
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetDeviceInfo(VL53L1_DEV Dev,
+ VL53L1_DeviceInfo_t *pVL53L1_DeviceInfo);
+
+/**
+ * @brief Reads the Device unique identifier
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pUid Pointer to current device unique ID
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetUID(VL53L1_DEV Dev, uint64_t *pUid);
+
+/**
+ * @brief Human readable Range Status string for a given RangeStatus
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param RangeStatus The RangeStatus code as stored on
+ * @a VL53L1_RangingMeasurementData_t
+ * @param pRangeStatusString The returned RangeStatus string. Shall be
+ * defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetRangeStatusString(uint8_t RangeStatus,
+ char *pRangeStatusString);
+
+/**
+ * @brief Human readable error string for driver error status
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param PalErrorCode The error code as stored on @a VL53L1_Error
+ * @param pPalErrorString The error string corresponding to the
+ * PalErrorCode. Shall be defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetPalErrorString(VL53L1_Error PalErrorCode,
+ char *pPalErrorString);
+
+/**
+ * @brief Human readable driver State string
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param PalStateCode The State code as stored on @a VL53L1_State
+ * @param pPalStateString The State string corresponding to the
+ * PalStateCode. Shall be defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetPalStateString(VL53L1_State PalStateCode,
+ char *pPalStateString);
+
+/**
+ * @brief Reads the internal state of the driver for a given Device
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPalState Pointer to current state of the PAL for a
+ * given Device
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetPalState(VL53L1_DEV Dev,
+ VL53L1_State *pPalState);
+
+
+
+/** @} VL53L1_general_group */
+
+/** @defgroup VL53L1_init_group VL53L1 Init Functions
+ * @brief VL53L1 Init Functions
+ * @{
+ */
+
+/**
+ * @brief Set new device address
+ *
+ * After completion the device will answer to the new address programmed.
+ * This function should be called when several devices are used in parallel
+ * before start programming the sensor.
+ * When a single device us used, there is no need to call this function.
+ *
+ * When it is requested for multi devices system this function MUST be called
+ * prior to VL53L1_DataInit()
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param DeviceAddress The new Device address
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetDeviceAddress(VL53L1_DEV Dev,
+ uint8_t DeviceAddress);
+
+/**
+ *
+ * @brief One time device initialization
+ *
+ * To be called after device has been powered on and booted
+ * see @a VL53L1_WaitDeviceBooted()
+ *
+ * @par Function Description
+ * When not used after a fresh device "power up", it may return
+ * @a #VL53L1_ERROR_CALIBRATION_WARNING meaning wrong calibration data
+ * may have been fetched from device that can result in ranging offset error\n
+ * If VL53L1_DataInit is called several times then the application must restore
+ * calibration calling @a VL53L1_SetOffsetCalibrationData()
+ * It implies application has gathered calibration data thanks to
+ * @a VL53L1_GetOffsetCalibrationData() after an initial calibration stage.
+ * This function will change the VL53L1_State from VL53L1_STATE_POWERDOWN to
+ * VL53L1_STATE_WAIT_STATICINIT.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_DataInit(VL53L1_DEV Dev);
+
+
+/**
+ * @brief Do basic device init (and eventually patch loading)
+ * This function will change the VL53L1_State from
+ * VL53L1_STATE_WAIT_STATICINIT to VL53L1_STATE_IDLE.
+ * In this stage all default setting will be applied.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_StaticInit(VL53L1_DEV Dev);
+
+/**
+ * @brief Wait for device booted after chip enable (hardware standby)
+ * This function can be run only when VL53L1_State is VL53L1_STATE_POWERDOWN.
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ *
+ */
+VL53L1_Error VL53L1_WaitDeviceBooted(VL53L1_DEV Dev);
+
+
+/** @} VL53L1_init_group */
+
+/** @defgroup VL53L1_parameters_group VL53L1 Parameters Functions
+ * @brief Functions used to prepare and setup the device
+ * @{
+ */
+
+/**
+ * @brief Set a new Preset Mode
+ * @par Function Description
+ * Set device to a new Operating Mode (High speed ranging, Multi objects ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @warning This function change the timing budget to 16 ms and the inter-
+ * measurement period to 1000 ms. Also the VL53L1_DISTANCEMODE_LONG is used.
+ *
+ * @param Dev Device Handle
+ * @param PresetMode New Preset mode to apply
+ *
Valid values are:
+ */
+/**
+ * @li VL53L1_PRESETMODE_MULTIZONES_SCANNING
+ * @li VL53L1_PRESETMODE_RANGING
+ * @li VL53L1_PRESETMODE_AUTONOMOUS
+ * @li VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS
+ * @li VL53L1_PRESETMODE_LITE_RANGING
+ * @li VL53L1_PRESETMODE_OLT
+ */
+/**
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when PresetMode is
+ * not in the supported list
+ */
+VL53L1_Error VL53L1_SetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes PresetMode);
+
+/**
+ * @brief Get current Preset Mode
+ * @par Function Description
+ * Get actual mode of the device(ranging, histogram ...)
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pPresetMode Pointer to current apply mode value
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * DeviceMode is not in the supported list
+ */
+VL53L1_Error VL53L1_GetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes *pPresetMode);
+
+
+/**
+ * @brief Set the distance mode
+ * @par Function Description
+ * Set the distance mode to be used for the next ranging.
+ * The modes Short, Medium and Long are used to optimize the ranging accuracy
+ * in a specific range of distance.
The user select one of these modes to
+ * select the distance range.
+ * Two additional modes are supported: AUTO and AUTO_LITE the difference between
+ * these modes is the following.
+ * The mode AUTO take into account both the ranging distance (RangeMilliMeter)
+ * and the dmax distance (DmaxMilliMeter).
The algorithm uses the ranging
+ * distance when the range status is ok and uses the dmax distance when the
+ * range status is not ok.
+ * The AUTO_LITE take into account only the ranging distance, so nothing is done
+ * in case of range error i.e. the distance mode will not be changed.
+ * @note This function doesn't Access to the device
+ *
+ * @warning This function should be called after @a VL53L1_SetPresetMode().
+
+ * @param Dev Device Handle
+ * @param DistanceMode Distance mode to apply valid values are:
+ * @li VL53L1_DISTANCEMODE_SHORT
+ * @li VL53L1_DISTANCEMODE_MEDIUM
+ * @li VL53L1_DISTANCEMODE_LONG
+ * @li VL53L1_DISTANCEMODE_AUTO_LITE
+ * @li VL53L1_DISTANCEMODE_AUTO
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when DistanceMode
+ * is not in the supported list
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes DistanceMode);
+
+/**
+ * @brief Get the distance mode
+ * @par Function Description
+ * Get the distance mode used for the next ranging.
+ *
+ * @param Dev Device Handle
+ * @param *pDistanceMode Pointer to Distance mode
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes *pDistanceMode);
+
+
+/**
+ * @brief Set the output mode
+ * @par Function Description
+ * Set the output mode to be used for the next ranging. The output mode is used
+ * to select, in case of multiple objects, which one will be used in
+ * function @a VL53L1_GetRangingMeasurementData().
+ * VL53L1_SetOutputMode also sets the object used by automatic
+ * distance mode algorithm when @a VL53L1_SetDistanceMode() is
+ * set to automatic mode.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @warning This function should be called after @a VL53L1_SetPresetMode().
+
+ * @param Dev Device Handle
+ * @param OutputMode Output mode to apply valid values are:
+ * @li VL53L1_OUTPUTMODE_NEAREST
+ * @li VL53L1_OUTPUTMODE_STRONGEST
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when OutputMode
+ * is not in the supported list
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes OutputMode);
+
+/**
+ * @brief Get the output mode
+ * @par Function Description
+ * Get the output mode used for the next ranging.
+ *
+ * @param Dev Device Handle
+ * @param *pOutputMode Pointer to Output mode
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes *pOutputMode);
+
+
+/**
+ * @brief Set Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Defines the maximum time allowed by the user to the device to run a
+ * full ranging sequence for the current mode (ranging, histogram, ASL ...)
+ *
+ * @param Dev Device Handle
+ * @param MeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS Error timing parameter not
+ * supported.
+ * The maximum accepted value for the
+ * computed timing budget is 10 seconds
+ * the minimum value depends on the preset
+ * mode selected.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetMeasurementTimingBudgetMicroSeconds(
+ VL53L1_DEV Dev, uint32_t MeasurementTimingBudgetMicroSeconds);
+
+/**
+ * @brief Get Ranging Timing Budget in microseconds
+ *
+ * @par Function Description
+ * Returns the programmed the maximum time allowed by the user to the
+ * device to run a full ranging sequence for the current mode
+ * (ranging, histogram, ASL ...)
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementTimingBudgetMicroSeconds Max measurement time in
+ * microseconds.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMeasurementTimingBudgetMicroSeconds(
+ VL53L1_DEV Dev, uint32_t *pMeasurementTimingBudgetMicroSeconds);
+
+
+/**
+ * Program continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ * When trying to set too short time return INVALID_PARAMS minimal value
+ *
+ * @param Dev Device Handle
+ * @param InterMeasurementPeriodMilliSeconds Inter-Measurement Period in ms.
+ * this value should be greater than the duration set in
+ * @a VL53L1_SetMeasurementTimingBudgetMicroSeconds() to ensure smooth ranging
+ * operation.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetInterMeasurementPeriodMilliSeconds(
+ VL53L1_DEV Dev, uint32_t InterMeasurementPeriodMilliSeconds);
+
+/**
+ * Get continuous mode Inter-Measurement period in milliseconds
+ *
+ * @par Function Description
+ *
+ * @param Dev Device Handle
+ * @param pInterMeasurementPeriodMilliSeconds Pointer to programmed
+ * Inter-Measurement Period in milliseconds.
+ * @return VL53L1_ERROR_NONE
+ */
+VL53L1_Error VL53L1_GetInterMeasurementPeriodMilliSeconds(
+ VL53L1_DEV Dev, uint32_t *pInterMeasurementPeriodMilliSeconds);
+
+/**
+ * @brief target reflectance for Dmax setting
+ * @par Function Description
+ * Allow user to set the value for target reflectance @ 940nm to calculate the
+ * ambient DMAX values for. Set to 50% by default by @a VL53L1_DataInit()
+ *
+ * @param Dev Device Handle
+ * @param DmaxReflectance Reflectance % in 16.16 fixed point
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS in case input value is not in range
+ * from 0 to 100. Note that this is a fix point value so the max value is
+ * 100 * 65536.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t DmaxReflectance);
+
+/**
+ * @brief Get target reflectance for Dmax
+ * @par Function Description
+ * Retrieves the value for target reflectance @ 940nm to calculate the
+ * ambient DMAX values for. Set to 50% by default by @a VL53L1_DataInit()
+ *
+ * @param Dev Device Handle
+ * @param pDmaxReflectance pointer to Reflectance % in 16.16 fixed point
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t *pDmaxReflectance);
+/**
+ * @brief Set function for ambient Dmax mode
+ *
+ *
+ * @param Dev Device Handle
+ * @param DmaxMode DMAX mode to be used in ranging
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+
+VL53L1_Error VL53L1_SetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes DmaxMode);
+
+/**
+ * @brief Get function for ambient Dmax mode
+ *
+ * @param Dev Device Handle
+ * @param pDmaxMode output pointer to DMAX mode currently in use
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_GetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes *pDmaxMode);
+
+/** @} VL53L1_parameters_group */
+
+
+/** @defgroup VL53L1_limitcheck_group VL53L1 Limit Check Functions
+ * @brief Functions used for the Limit checks
+ * @{
+ */
+
+
+
+/**
+ * @brief Get the number of the check limit managed by a given Device
+ *
+ * @par Function Description
+ * This function give the number of the check limit managed by the Device
+ *
+ * @param pNumberOfLimitCheck Pointer to the number of check limit.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetNumberOfLimitCheck(
+ uint16_t *pNumberOfLimitCheck);
+
+/**
+ * @brief Return a description string for a given limit check number
+ *
+ * @par Function Description
+ * This function returns a description string for a given limit check number.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckString Pointer to the description string of
+ * the given check limit. Shall be defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckInfo(uint16_t LimitCheckId,
+ char *pLimitCheckString);
+
+/**
+ * @brief Return a the Status of the specified check limit
+ *
+ * @par Function Description
+ * This function returns the Status of the specified check limit.
+ * The value indicate if the check is fail or not.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckStatus Pointer to the
+ Limit Check Status of the given check limit.
+ * LimitCheckStatus :
+ * 0 the check is not fail or not enabled
+ * 1 the check if fail
+ *
+ *
+ * - VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE: the sigma indicate the quality
+ * of the measure. The more it is little the better it is.
+ * The status is 1 when current sigma is greater then the limit.
+ * - VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE: the signal rate indicate
+ * the strength of the returned signal. The more it is big the better it is.
+ * The status is 1 when current signal is lower then the limit.
+ *
+ *
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckStatus(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckStatus);
+
+/**
+ * @brief Enable/Disable a specific limit check
+ *
+ * @par Function Description
+ * This function Enable/Disable a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param LimitCheckEnable
+ * @li set LimitCheckEnable=1 enables the LimitCheckId limit
+ * @li set LimitCheckEnable=0 disables the LimitCheckId limit
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetLimitCheckEnable(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, uint8_t LimitCheckEnable);
+
+/**
+ * @brief Get specific limit check enable state
+ *
+ * @par Function Description
+ * This function get the enable state of a specific limit check.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckEnable Pointer to the check limit enable
+ * value.
+ * @li if 1 the check limit corresponding to LimitCheckId is Enabled
+ * @li if 0 the check limit corresponding to LimitCheckId is disabled
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS This error is returned
+ * when LimitCheckId value is out of range.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckEnable(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, uint8_t *pLimitCheckEnable);
+
+/**
+ * @brief Set a specific limit check value
+ *
+ * @par Function Description
+ * This function set a specific limit check value.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note Note that the value written with that function will not be applied if
+ * the limit is not enabled. In other words this function will not enable the
+ * limit but change only the value. In case the limit is not enabled the value
+ * is saved internally and applied with VL53L1_SetLimitCheckEnable.
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param LimitCheckValue Limit check Value for a given
+ * LimitCheckId
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetLimitCheckValue(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t LimitCheckValue);
+
+/**
+ * @brief Get a specific limit check value
+ *
+ * @par Function Description
+ * This function get a specific limit check value from device then it updates
+ * internal values and check enables.
+ * The limit check is identified with the LimitCheckId.
+ *
+ * @note This function get the current value from device if zero then the value
+ * returned is the one stored by the user, but in that case the check is store
+ * as disabled. If the value from device is not zero, this is returned and set
+ * into the memory at the same way that user call VL53L1_SetLimitCheckValue()
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckValue Pointer to Limit
+ * check Value for a given LimitCheckId.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckValue(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckValue);
+
+/**
+ * @brief Get the current value of the signal used for the limit check
+ *
+ * @par Function Description
+ * This function get a the current value of the signal used for the limit check.
+ * To obtain the latest value you should run a valid ranging before.
+ * The value reported is linked to the limit check identified with the
+ * LimitCheckId.
+ *
+ * @param Dev Device Handle
+ * @param LimitCheckId Limit Check ID
+ * (0<= LimitCheckId < VL53L1_GetNumberOfLimitCheck() ).
+ * @param pLimitCheckCurrent Pointer to current Value for a
+ * given LimitCheckId.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetLimitCheckCurrent(VL53L1_DEV Dev,
+ uint16_t LimitCheckId, FixPoint1616_t *pLimitCheckCurrent);
+
+/** @} VL53L1_limitcheck_group */
+
+
+
+/** @defgroup VL53L1_ROI_group VL53L1 ROI Functions
+ * @brief Functions used to select ROIs
+ * @{
+ */
+
+/**
+ * @brief Get the Maximum number of ROI Zones managed by the Device
+ *
+ * @par Function Description
+ * Get Maximum number of ROI Zones managed by the Device.
+ *
+ * @note The number of Zone depends on the preset mode used so to have the
+ * right number this function should be call after @a VL53L1_SetPresetMode()
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMaxNumberOfROI Pointer to the Maximum Number
+ * of ROI Zones value.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMaxNumberOfROI(VL53L1_DEV Dev,
+ uint8_t *pMaxNumberOfROI);
+/**
+ * @brief Set the ROI to be used for ranging
+ *
+ * @par Function Description
+ * The user defined ROIs are rectangles described as per the following system
+ * from the Top Left corner to the Bottom Right corner.
+ *
Minimal ROI size is 4x4 spads
+ * @image html roi_coord.png
+ *
+ * @param Dev Device Handle
+ * @param pRoiConfig Pointer to the Structure containing all the
+ * ROI to be used.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig);
+
+/**
+ * @brief Get the ROI managed by the Device
+ *
+ * @par Function Description
+ * Get the ROI managed by the Device
+ *
+ * @param Dev Device Handle
+ * @param pRoiConfig Pointer to the Structure containing all the
+ * ROI to be used.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig);
+
+/** @} VL53L1_ROI_group */
+
+/* \internal */
+/** @defgroup VL53L1_sequencestep_group VL53L1 Sequence Step Functions
+ * @brief Functions used to select Steps done on each ranging
+ * @{
+ */
+
+/**
+ * @brief Gets number of sequence steps managed by the API.
+ *
+ * @par Function Description
+ * This function retrieves the number of sequence steps currently managed
+ * by the API
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param pNumberOfSequenceSteps Out parameter reporting the number of
+ * sequence steps.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetNumberOfSequenceSteps(VL53L1_DEV Dev,
+ uint8_t *pNumberOfSequenceSteps);
+
+/**
+ * @brief Gets the name of a given sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the name of sequence steps corresponding to
+ * SequenceStepId.
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param SequenceStepId Sequence step identifier.
+ * @param pSequenceStepsString Pointer to Info string. Shall be
+ * defined as char buf[VL53L1_MAX_STRING_LENGTH]
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetSequenceStepsInfo(
+ VL53L1_SequenceStepId SequenceStepId, char *pSequenceStepsString);
+
+
+
+/**
+ * @brief Sets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function enables/disables a requested sequence step.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param SequenceStepEnabled Demanded state {0=Off,1=On}
+ * is enabled.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled);
+
+/**
+ * @brief Gets the (on/off) state of a requested sequence step.
+ *
+ * @par Function Description
+ * This function retrieves the state of a requested sequence step, i.e. on/off.
+ *
+ * @note This function Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param SequenceStepId Sequence step identifier.
+ * @param pSequenceStepEnabled Out parameter reporting if the sequence step
+ * is enabled {0=Off,1=On}.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS Error SequenceStepId parameter not
+ * supported.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled);
+
+
+/** @} VL53L1_sequencestep_group */
+/* \endinternal */
+
+
+
+/** @defgroup VL53L1_measurement_group VL53L1 Measurement Functions
+ * @brief Functions used for the measurements
+ * @{
+ */
+
+/**
+ * @brief Start device measurement
+ *
+ * @details Started measurement will depend on preset parameters set through
+ * @a VL53L1_SetPreseMode()
+ * This function will change the VL53L1_State from VL53L1_STATE_IDLE to
+ * VL53L1_STATE_RUNNING.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED This error occurs when
+ * PresetMode programmed with @a VL53L1_SetPresetMode
+ * @return VL53L1_ERROR_TIME_OUT Time out on start measurement
+ * @return VL53L1_ERROR_INVALID_PARAMS This error might occur in timed mode
+ * when inter measurement period is smaller or too close to the timing budget.
+ * In such case measurements are not started and user must correct the timings
+ * passed to @a VL53L1_SetMeasurementTimingBudgetMicroSeconds() and
+ * @a VL53L1_SetInterMeasurementPeriodMilliSeconds() functions.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev);
+
+/**
+ * @brief Stop device measurement
+ *
+ * @details Will set the device in standby mode at end of current measurement\n
+ * Not necessary in single mode as device shall return automatically
+ * in standby mode at end of measurement.
+ * This function will change the VL53L1_State from VL53L1_STATE_RUNNING
+ * to VL53L1_STATE_IDLE.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_StopMeasurement(VL53L1_DEV Dev);
+
+/**
+ * @brief Clear the Interrupt flag and start new measurement
+ * *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ClearInterruptAndStartMeasurement(VL53L1_DEV Dev);
+
+/**
+ * @brief Return Measurement Data Ready
+ *
+ * @par Function Description
+ * This function indicate that a measurement data is ready.
+ * This function is used for non-blocking capture.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param pMeasurementDataReady Pointer to Measurement Data Ready.
+ * 0 = data not ready, 1 = data ready
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMeasurementDataReady(VL53L1_DEV Dev,
+ uint8_t *pMeasurementDataReady);
+
+/**
+ * @brief Wait for measurement data ready.
+ * Blocking function.
+ * Note that the timeout is given by:
+ * VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS defined in def.h
+ *
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_TIME_OUT In case of timeout
+ */
+VL53L1_Error VL53L1_WaitMeasurementDataReady(VL53L1_DEV Dev);
+
+
+/**
+ * @brief Retrieve the measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement
+ */
+/**
+ * @warning this function will return only the first ROI data and only the
+ * first object. For multi objects or multi ROI use:
+ * @a Vl53L1_GetMultiRangingData.
+ * In case of RANGING only one output is given, this can
+ * be selected with the help of @a VL53L1_SetOutputMode()
+ * In case of MULTIZONES_SCANNING and error will be raised because not
+ * supported in that function.
+ */
+/**
+ *
+ * @warning USER must call @a VL53L1_ClearInterruptAndStartMeasurement() prior
+ * to call again this function
+ *
+ * @note This function Access to the device
+ *
+ * @note The first valid value returned by this function will have a range
+ * status equal to VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK which means that
+ * the data is valid but no wrap around check have been done. User should take
+ * care about that.
+ *
+ * @param Dev Device Handle
+ * @param pRangingMeasurementData Pointer to the data structure to fill up.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_MODE_NOT_SUPPORTED in case of MULTIZONES_SCANNING
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetRangingMeasurementData(VL53L1_DEV Dev,
+ VL53L1_RangingMeasurementData_t *pRangingMeasurementData);
+
+/**
+ * @brief Retrieve all ROI's measurements from device for a given setup
+ *
+ * @par Function Description
+ * Get data from last successful Ranging measurement
+ * @warning USER should take care about @a VL53L1_GetNumberOfROI()
+ * before get data.
+ * Bare driver will fill a NumberOfROI times the corresponding data
+ * structure used in the measurement function.
+ *
+ * @warning USER must call @a VL53L1_ClearInterruptAndStartMeasurement() prior
+ * to call again this function
+ *
+ * @note This function Access to the device
+ *
+ * @note The first valid value returned by this function will have a range
+ * status equal to VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK which means that
+ * the data is valid but no wrap around check have been done. User should take
+ * care about that.
+ *
+ * @param Dev Device Handle
+ * @param pMultiRangingData Pointer to the data structure to fill up.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetMultiRangingData(VL53L1_DEV Dev,
+ VL53L1_MultiRangingData_t *pMultiRangingData);
+
+/**
+ * @brief Get Additional Data
+ *
+ * @par Function Description
+ * This function is used to get lld debugging data on the last histogram
+ * measurement. shall be called when a new measurement is ready (interrupt or
+ * positive VL53L1_GetMeasurementDataReady() polling) and before a call to
+ * VL53L1_ClearInterruptAndStartMeasurement(). Depending on the PresetMode
+ * currently set parts of the returned data structure may be not relevant.
+ *
+ * @param Dev Device Handle
+ * @param pAdditionalData Pointer to Additional data
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetAdditionalData(VL53L1_DEV Dev,
+ VL53L1_AdditionalData_t *pAdditionalData);
+
+
+/** @} VL53L1_measurement_group */
+
+/** @defgroup VL53L1_Calibration_group VL53L1 Calibration Functions
+ * @brief Functions used for Calibration
+ * @{
+ */
+
+
+/**
+ * @brief Set Tuning Parameter value for a given parameter ID
+ *
+ * @par Function Description
+ * This function is used to improve the performance of the device. It permit to
+ * change a particular value used for a timeout or a threshold or a constant
+ * in an algorithm. The function will change the value of the parameter
+ * identified by an unique ID.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param TuningParameterId Tuning Parameter ID
+ * @param TuningParameterValue Tuning Parameter Value
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetTuningParameter(VL53L1_DEV Dev,
+ uint16_t TuningParameterId, int32_t TuningParameterValue);
+
+/**
+ * @brief Get Tuning Parameter value for a given parameter ID
+ *
+ * @par Function Description
+ * This function is used to get the value of the parameter
+ * identified by an unique ID.
+ *
+ * @note This function doesn't Access to the device
+ *
+ * @param Dev Device Handle
+ * @param TuningParameterId Tuning Parameter ID
+ * @param pTuningParameterValue Pointer to Tuning Parameter Value
+ * for a given TuningParameterId.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetTuningParameter(VL53L1_DEV Dev,
+ uint16_t TuningParameterId, int32_t *pTuningParameterValue);
+
+/**
+ * @brief Performs Reference Spad Management
+ *
+ * @par Function Description
+ * The reference SPAD initialization procedure determines the minimum amount
+ * of reference spads to be enables to achieve a target reference signal rate
+ * and should be performed once during initialization.
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformRefSpadManagement(VL53L1_DEV Dev);
+
+/**
+ * @brief Enable/Disable dynamic Xtalk compensation feature
+ *
+ * Enable/Disable dynamic Xtalk compensation (aka smudge correction).
+ *
+ * @param Dev Device Handle
+ * @param Mode Set the smudge correction mode
+ * See ::VL53L1_SmudgeCorrectionModes
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SmudgeCorrectionEnable(VL53L1_DEV Dev,
+ VL53L1_SmudgeCorrectionModes Mode);
+
+/**
+ * @brief Enable/Disable Cross talk compensation feature
+ *
+ * Enable/Disable Cross Talk correction.
+ *
+ * @param Dev Device Handle
+ * @param XTalkCompensationEnable Cross talk compensation
+ * to be set 0 = disabled or 1 = enabled.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetXTalkCompensationEnable(VL53L1_DEV Dev,
+uint8_t XTalkCompensationEnable);
+
+/**
+ * @brief Get Cross talk compensation rate enable
+ *
+ * Get if the Cross Talk is Enabled or Disabled.
+ *
+ * @note This function doesn't access to the device
+ *
+ * @param Dev Device Handle
+ * @param pXTalkCompensationEnable Pointer to the Cross talk compensation
+ * state 0=disabled or 1 = enabled
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetXTalkCompensationEnable(VL53L1_DEV Dev,
+ uint8_t *pXTalkCompensationEnable);
+
+
+/**
+ * @brief Perform XTalk Calibration
+ *
+ * @details Perform a XTalk calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts
+ * are enabled an interrupt will be done.
+ * This function will clear the interrupt generated automatically.
+ * This function will program a new value for the XTalk compensation
+ * and it will enable the cross talk before exit.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param CalibrationOption Select the Calibration to be run :
+ * @param CalibrationOption
+ * @li VL53L1_XTALKCALIBRATIONMODE_SINGLE_TARGET the calibration uses current
+ * preset and distance mode without altering them.
+ * User must call @a VL53L1_SetPresetMode() with VL53L1_PRESETMODE_AUTONOMOUS,
+ * VL53L1_PRESETMODE_LITE_RANGING or VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS
+ * parameter prior to launch calibration
+ * @li VL53L1_XTALKCALIBRATIONMODE_NO_TARGET the calibration sets appropriate
+ * preset and distance mode and thus override existing ones
+ * User must call @a VL53L1_SetPresetMode() again after calibration to set the
+ * desired one. during this calibration mode no object must be put below a 80cm
+ * distance from the target
+ * @li VL53L1_XTALKCALIBRATIONMODE_FULL_ROI the calibration sets appropriate
+ * preset and distance mode and thus override existing ones
+ * User must call @a VL53L1_SetPresetMode() again after calibration to set the
+ * desired one.
+ * The ROI settings must define a single 16x16 ROI before to launch this
+ * function.
+ * The calibration uses a target which should be located at least @60cm from the
+ * device. The actual location of the target shall be passed
+ * through the bare driver tuning parameters table
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformXTalkCalibration(VL53L1_DEV Dev,
+ uint8_t CalibrationOption);
+
+/**
+ * @brief Define the mode to be used for the offset calibration
+ *
+ * Define the mode to be used for the offset calibration. This function should
+ * be called before run the @a VL53L1_PerformOffsetCalibration()
+ *
+ * @param Dev Device Handle
+ * @param OffsetCalibrationMode Offset Calibration Mode valid values are:
+ * @li VL53L1_OFFSETCALIBRATIONMODE_STANDARD
+ * @li VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY
+ * @li VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetOffsetCalibrationMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationModes OffsetCalibrationMode);
+
+/**
+ * @brief Define the mode to be used for the offset correction
+ *
+ * Define the mode to be used for the offset correction.
+ *
+ * @param Dev Device Handle
+ * @param OffsetCorrectionMode Offset Correction Mode valid values are:
+ * @li VL53L1_OFFSETCORRECTIONMODE_STANDARD
+ * @li VL53L1_OFFSETCORRECTIONMODE_PERZONE
+ * @li VL53L1_OFFSETCORRECTIONMODE_PERVCSEL
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetOffsetCorrectionMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionModes OffsetCorrectionMode);
+
+
+/**
+ * @brief Perform Offset Calibration
+ *
+ * @details Perform a Offset calibration of the Device.
+ * This function will launch a ranging measurement, if interrupts are
+ * enabled interrupts will be done.
+ * This function will program a new value for the Offset calibration value
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param CalDistanceMilliMeter Calibration distance value used for the
+ * offset compensation.
+ * @param CalReflectancePercent Calibration Target reflectance @ 940nm
+ * in percentage.
+ *
+ * @return VL53L1_ERROR_NONE
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformOffsetCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter,
+ FixPoint1616_t CalReflectancePercent);
+
+/**
+ * @brief Perform Offset simple Calibration
+ *
+ * @details Perform a very simple offset calibration of the Device.
+ * This function will launch few ranging measurements and computes offset
+ * calibration. The preset mode and the distance mode MUST be set by the
+ * application before to call this function.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param CalDistanceMilliMeter Calibration distance value used for the
+ * offset compensation.
+ *
+ * @return VL53L1_ERROR_NONE
+ * @return VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL the calibration failed by
+ * lack of valid measurements
+ * @return VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH means that the target
+ * distance combined to the number of loops performed in the calibration lead to
+ * an internal overflow. Try to reduce the distance of the target (140 mm)
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformOffsetSimpleCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter);
+
+/**
+ * @brief Perform Offset simple Calibration with a "zero distance" target
+ *
+ * @details Perform a simple offset calibration of the Device.
+ * This function will launch few ranging measurements and computes offset
+ * calibration. The preset mode and the distance mode MUST be set by the
+ * application before to call this function.
+ * A target must be place very close to the device.
+ * Ideally the target shall be touching the coverglass.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ *
+ * @return VL53L1_ERROR_NONE
+ * @return VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL the calibration failed by
+ * lack of valid measurements
+ * @return VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH means that the target
+ * distance is too large, try to put the target closer to the device
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformOffsetZeroDistanceCalibration(VL53L1_DEV Dev);
+
+/**
+ * @brief Perform Offset per Vcsel Calibration. i.e. per distance mode
+ *
+ * @details Perform offset calibration of the Device depending on the
+ * three distance mode settings: short, medium and long.
+ * This function will launch few ranging measurements and computes offset
+ * calibration in each of the three distance modes.
+ * The preset mode MUST be set by the application before to call this function.
+ *
+ * @warning This function is a blocking function
+ *
+ * @note This function Access to the device
+ *
+ * @param Dev Device Handle
+ * @param CalDistanceMilliMeter Distance of the target used for the
+ * offset compensation calibration.
+ *
+ * @return VL53L1_ERROR_NONE
+ * @return VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL the calibration failed by
+ * lack of valid measurements
+ * @return VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH means that the target
+ * distance combined to the number of loops performed in the calibration lead to
+ * an internal overflow. Try to reduce the distance of the target (140 mm)
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_PerformOffsetPerVcselCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter);
+/**
+ * @brief Sets the Calibration Data.
+ *
+ * @par Function Description
+ * This function set all the Calibration Data issued from the functions
+ * @a VL53L1_PerformRefSpadManagement(), @a VL53L1_PerformXTalkCalibration,
+ * @a VL53L1_PerformOffsetCalibration()
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param *pCalibrationData Pointer to Calibration data to be set.
+ * @return VL53L1_ERROR_NONE Success
+ * @return VL53L1_ERROR_INVALID_PARAMS pCalibrationData points to an older
+ * version of the inner structure. Need for support to convert its content.
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData);
+
+/**
+ * @brief Gets the Calibration Data.
+ *
+ * @par Function Description
+ * This function get all the Calibration Data issued from the functions
+ * @a VL53L1_PerformRefSpadManagement(), @a VL53L1_PerformXTalkCalibration,
+ * @a VL53L1_PerformOffsetCalibration()
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param *pCalibrationData pointer where to store Calibration
+ * data.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData);
+
+/**
+ * @brief Sets the Zone Calibration Data.
+ *
+ * @par Function Description
+ * This function set all the Zone nCalibration Data issued from the functions
+ * @a VL53L1_PerformOffsetCalibration() in multi zone
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param *pZoneCalibrationData Pointer to Zone Calibration data to be
+ * set.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_SetZoneCalibrationData(VL53L1_DEV Dev,
+ VL53L1_ZoneCalibrationData_t *pZoneCalibrationData);
+
+/**
+ * @brief Gets the Zone Calibration Data.
+ *
+ * @par Function Description
+ * This function get all the Zone Calibration Data issued from the functions
+ * @a VL53L1_PerformOffsetCalibration()
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param *pZoneCalibrationData pointer where to store Zone Calibration
+ * data.
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetZoneCalibrationData(VL53L1_DEV Dev,
+ VL53L1_ZoneCalibrationData_t *pZoneCalibrationData);
+/**
+ * @brief Gets the optical center.
+ *
+ * @par Function Description
+ * This function get the optical center issued from the nvm set at FTM stage
+ * expressed in the same coordinate system as the ROI are
+ *
+ * @note This function doesn't Accesses the device
+ *
+ * @param Dev Device Handle
+ * @param pOpticalCenterX pointer to the X position of center
+ * in 16.16 fix point
+ * @param pOpticalCenterY pointer to the Y position of center
+ * in 16.16 fix point
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_GetOpticalCenter(VL53L1_DEV Dev,
+ FixPoint1616_t *pOpticalCenterX,
+ FixPoint1616_t *pOpticalCenterY);
+
+/** @} VL53L1_Calibration_group */
+
+/** @defgroup VL53L1_Thresholds_group VL53L1 IRQ Triggered events Functions
+ * @brief Functions used to configure interrupt to be triggered only when
+ * a measurement satisfies some thresholds parameters
+ * @{
+ */
+
+/**
+ * @brief Configure the interrupt config, from the given structure
+ *
+ * @param[in] Dev : Device Handle
+ * @param[in] pConfig : pointer to configuration structure
+ */
+
+VL53L1_Error VL53L1_SetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig);
+
+/**
+ * @brief Retrieves the interrupt config structure currently programmed
+ * into the API
+ *
+ * @param[in] Dev : Device Handle
+ * @param[out] pConfig : pointer to configuration structure
+ */
+
+VL53L1_Error VL53L1_GetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig);
+
+
+/** @} VL53L1_Thresholds_group */
+
+
+/** @} VL53L1_cut11_group */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L1_API_H_ */
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_calibration.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_calibration.h
new file mode 100644
index 000000000000..62cb011a37f2
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_calibration.h
@@ -0,0 +1,596 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_CALIBRATION_H_
+#define _VL53L1_API_CALIBRATION_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_ref_spad_char(VL53L1_DEV Dev,
+ VL53L1_Error * pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_device_test(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_spad_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode,
+ VL53L1_DeviceSscArray array_select,
+ uint32_t ssc_config_timeout_us,
+ VL53L1_spad_rate_data_t *pspad_rate_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_xtalk_extraction(
+ VL53L1_DEV Dev,
+ VL53L1_Error *pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_and_avg_xtalk_samples(
+ VL53L1_DEV Dev,
+ uint8_t num_of_samples,
+ uint8_t measurement_mode,
+ int16_t xtalk_filter_thresh_max_mm,
+ int16_t xtalk_filter_thresh_min_mm,
+ uint16_t xtalk_max_valid_rate_kcps,
+ uint8_t xtalk_result_id,
+ uint8_t xtalk_histo_id,
+ VL53L1_xtalk_range_results_t *pxtalk_results,
+ VL53L1_histogram_bin_data_t *psum_histo,
+ VL53L1_histogram_bin_data_t *pavg_histo);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_offset_calibration(
+ VL53L1_DEV Dev,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_phasecal_average(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode,
+ uint8_t phasecal_result__vcsel_start,
+ uint16_t phasecal_num_of_samples,
+ VL53L1_range_results_t *prange_results,
+ uint16_t *pphasecal_result__reference_phase,
+ uint16_t *pzero_distance_phase);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_zone_calibration(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ VL53L1_DeviceZonePreset zone_preset,
+ VL53L1_zone_config_t *pzone_cfg,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_xtalk_extract_data_init(
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_update(
+ int16_t target_distance_mm,
+ uint16_t target_width_oversize,
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_fini(
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data,
+ VL53L1_xtalk_calibration_results_t *pxtalk_cal,
+ VL53L1_xtalk_histogram_shape_t *pxtalk_shape);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_run_hist_xtalk_extraction(
+ VL53L1_DEV Dev,
+ int16_t cal_distance_mm,
+ VL53L1_Error *pcal_status);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_core.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_core.h
new file mode 100644
index 000000000000..9c853c7ef81c
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_core.h
@@ -0,0 +1,1944 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_CORE_H_
+#define _VL53L1_API_CORE_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_version(
+ VL53L1_DEV Dev,
+ VL53L1_ll_version_t *pversion);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_device_firmware_version(
+ VL53L1_DEV Dev,
+ uint16_t *pfw_version);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_data_init(
+ VL53L1_DEV Dev,
+ uint8_t read_p2p_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_p2p_data(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_software_reset(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_tuning_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_tuning_parameters_t *ptun_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t inter_measurement_period_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t *pinter_measurement_period_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t *pphasecal_config_timeout_us,
+ uint32_t *pmm_config_timeout_us,
+ uint32_t *prange_config_timeout_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t cal_config__repeat_period);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t *pcal_config__repeat_period);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t *pvalue);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity interrupt_polarity);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity *pinterrupt_polarity);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t range_ignore_thresh_mult,
+ uint16_t range_ignore_threshold_mcps);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t *prange_ignore_thresh_mult,
+ uint16_t *prange_ignore_threshold_mcps_internal,
+ uint16_t *prange_ignore_threshold_mcps_current);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_mode_mitigation_roi(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *pmm_roi);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_preset_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint32_t inter_measurement_period_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_preset_mode_timing_cfg(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ uint16_t *pdss_config__target_total_rate_mcps,
+ uint32_t *pphasecal_config_timeout_us,
+ uint32_t *pmm_config_timeout_us,
+ uint32_t *prange_config_timeout_us);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_preset(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceZonePreset zone_preset);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_enable_xtalk_compensation(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_xtalk_compensation(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_get_xtalk_compensation_enable(
+ VL53L1_DEV Dev,
+ uint8_t *pcrosstalk_compensation_enable);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_and_start_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode,
+ VL53L1_DeviceConfigLevel device_config_level);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_stop_range(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_measurement_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_result_level);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_device_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_result_level,
+ VL53L1_range_results_t *prange_results);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_clear_interrupt_and_enable_next_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_bin_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *phist_data);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_sys_and_core_results_to_range_results(
+ int32_t gain_factor,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore,
+ VL53L1_range_results_t *presults);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_dss_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_calc_ambient_dmax(
+ VL53L1_DEV Dev,
+ uint16_t target_reflectance,
+ int16_t *pambient_dmax_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_distance,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_rate,
+ uint8_t intr_new_measure_ready,
+ uint8_t intr_no_target,
+ uint8_t intr_combined_mode,
+ uint16_t thresh_distance_high,
+ uint16_t thresh_distance_low,
+ uint16_t thresh_rate_high,
+ uint16_t thresh_rate_low
+ );
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t intconf);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode *pdmax_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dmax_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode,
+ uint8_t zone_id,
+ VL53L1_dmax_calibration_data_t *pdmax_cal);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode offset_cal_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode *poffset_cal_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode offset_cor_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionMode *poffset_cor_mode);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pphase_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t phase_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pevent_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t event_consistency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t *pamb_thresh_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t amb_thresh_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t *plite_mincountrate);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t lite_mincountrate);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t *plite_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t lite_sigma);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_restore_xtalk_nvm_default(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t *pmax_valid_range_mm,
+ int16_t *pmin_valid_range_mm,
+ uint16_t *pmax_valid_rate_kcps,
+ uint16_t *pmax_sigma_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t max_valid_range_mm,
+ int16_t min_valid_range_mm,
+ uint16_t max_valid_rate_kcps,
+ uint16_t max_sigma_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder *phist_target_order);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder hist_target_order);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_vhv_config(
+ VL53L1_DEV Dev,
+ uint8_t vhv_init_en,
+ uint8_t vhv_init_value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_vhv_config(
+ VL53L1_DEV Dev,
+ uint8_t *pvhv_init_en,
+ uint8_t *pvhv_init_value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_vhv_loopbound(
+ VL53L1_DEV Dev,
+ uint8_t vhv_loopbound);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_vhv_loopbound(
+ VL53L1_DEV Dev,
+ uint8_t *pvhv_loopbound);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_tuning_parm(
+ VL53L1_DEV Dev,
+ VL53L1_TuningParms tuning_parm_key,
+ int32_t *ptuning_parm_value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_tuning_parm(
+ VL53L1_DEV Dev,
+ VL53L1_TuningParms tuning_parm_key,
+ int32_t tuning_parm_value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_enable(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_disable(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_apply_enable(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_apply_disable(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_single_apply_enable(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_single_apply_disable(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_set_scalers(
+ VL53L1_DEV Dev,
+ int16_t x_scaler_in,
+ int16_t y_scaler_in,
+ uint8_t user_scaler_set_in
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_current_xtalk_settings(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_calibration_results_t *pxtalk
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_current_xtalk_settings(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_calibration_results_t *pxtalk
+ );
+
+VL53L1_Error VL53L1_load_patch(VL53L1_DEV Dev);
+
+VL53L1_Error VL53L1_unload_patch(VL53L1_DEV Dev);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_debug.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_debug.h
new file mode 100644
index 000000000000..f7161fbcd849
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_debug.h
@@ -0,0 +1,756 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_DEBUG_H_
+#define _VL53L1_API_DEBUG_H_
+
+#include "vl53l1_platform.h"
+#include "vl53l1_nvm_structs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_decode_calibration_data_buffer(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_calibration_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_nvm_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_decoded_nvm_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_histogram_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_additional_data(
+ VL53L1_DEV Dev,
+ VL53L1_additional_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_xtalk_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_debug_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_offset_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_offset_debug_data_t *pdata);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_signed_fixed_point_sprintf(
+ int32_t fp_value,
+ uint8_t frac_bits,
+ uint16_t buf_size,
+ char *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_histogram_bin_data(
+ VL53L1_histogram_bin_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_histogram_data(
+ VL53L1_xtalk_histogram_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_histogram_shape_data(
+ VL53L1_xtalk_histogram_shape_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_range_results(
+ VL53L1_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_range_data(
+ VL53L1_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_offset_range_results(
+ VL53L1_offset_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_offset_range_data(
+ VL53L1_offset_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_cal_peak_rate_map(
+ VL53L1_cal_peak_rate_map_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_additional_offset_cal_data(
+ VL53L1_additional_offset_cal_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_additional_data(
+ VL53L1_additional_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_gain_calibration_data(
+ VL53L1_gain_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_zone_calibration_data(
+ VL53L1_zone_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_zone_calibration_results(
+ VL53L1_zone_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_range_results(
+ VL53L1_xtalk_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_range_data(
+ VL53L1_xtalk_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_calibration_results(
+ VL53L1_xtalk_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_config(
+ VL53L1_xtalk_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_extract_config(
+ VL53L1_xtalkextract_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_zone_cal_config(
+ VL53L1_zonecal_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_offset_cal_config(
+ VL53L1_offsetcal_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_dmax_calibration_data(
+ VL53L1_dmax_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_calibration_data(
+ VL53L1_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_xtalk_debug_data(
+ VL53L1_xtalk_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_offset_debug_data(
+ VL53L1_offset_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_optical_centre(
+ VL53L1_optical_centre_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_user_zone(
+ VL53L1_user_zone_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_zone_config(
+ VL53L1_zone_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_spad_rate_data(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_spad_rate_map(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_preset_modes.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_preset_modes.h
new file mode 100644
index 000000000000..3126bae2f85e
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_preset_modes.h
@@ -0,0 +1,1637 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_API_PRESET_MODES_H_
+#define _VL53L1_API_PRESET_MODES_H_
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_dmax_structs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_refspadchar_config_struct(
+ VL53L1_refspadchar_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_ssc_config_struct(
+ VL53L1_ssc_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_xtalk_config_struct(
+ VL53L1_customer_nvm_managed_t *pnvm,
+ VL53L1_xtalk_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_xtalk_extract_config_struct(
+ VL53L1_xtalkextract_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_offset_cal_config_struct(
+ VL53L1_offsetcal_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_zone_cal_config_struct(
+ VL53L1_zonecal_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_hist_post_process_config_struct(
+ uint8_t xtalk_compensation_enable,
+ VL53L1_hist_post_process_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_dmax_calibration_data_struct(
+ VL53L1_dmax_calibration_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_tuning_parm_storage_struct(
+ VL53L1_tuning_parm_storage_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_hist_gen3_dmax_config_struct(
+ VL53L1_hist_gen3_dmax_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_short_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_long_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm1_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm2_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_short_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_long_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_low_power_auto_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_low_power_auto_data_t *plpadata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_low_power_auto_short_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_low_power_auto_data_t *plpadata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_low_power_auto_long_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_low_power_auto_data_t *plpadata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm2_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_ref(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_characterisation(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_planar(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_short_timing(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_special_histogram_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_olt(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_singleshot_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_hist_cfg_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_hist_bins_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_timing_config_t *ptiming);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_strings.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_strings.h
new file mode 100644
index 000000000000..051fcb2b000c
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_api_strings.h
@@ -0,0 +1,210 @@
+
+/******************************************************************************
+ * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+ ******************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+ *******************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+ *******************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones mentioned above :
+
+ *******************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+ *******************************************************************************
+ */
+
+/**
+ * @file vl53l1_api_strings.h
+ * @brief VL53L1 API function declarations for decoding error codes to a
+ * text strings
+ */
+
+
+#ifndef VL53L1_API_STRINGS_H_
+#define VL53L1_API_STRINGS_H_
+
+#include "vl53l1_def.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+/**
+ * @brief Generates a string for the input device range status code
+ *
+ * @param[in] RangeStatus : Device Range AStatus Code
+ * @param[out] pRangeStatusString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_get_range_status_string(
+ uint8_t RangeStatus,
+ char *pRangeStatusString);
+
+/**
+ * @brief Generates an error string for the input PAL error code
+ *
+ * @param[in] PalErrorCode : PAL Error Code
+ * @param[out] pPalErrorString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_get_pal_error_string(
+ VL53L1_Error PalErrorCode,
+ char *pPalErrorString);
+
+/**
+ * @brief Generates a string for the input PAL State code
+ *
+ * @param[in] PalStateCode : PAL State Code
+ * @param[out] pPalStateString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_get_pal_state_string(
+ VL53L1_State PalStateCode,
+ char *pPalStateString);
+
+
+/**
+ * @brief Generates a string for the sequence step Id
+ *
+ * @param[in] SequenceStepId : Sequence Step Id
+ * @param[out] pSequenceStepsString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_get_sequence_steps_info(
+ VL53L1_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString);
+
+/**
+ * @brief Generates a string for the limit check Id
+ *
+ * @param[in] LimitCheckId : Limit check Id
+ * @param[out] pLimitCheckString : pointer to character buffer
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
+ char *pLimitCheckString);
+
+#ifndef VL53L1_USE_EMPTY_STRING
+ #define VL53L1_STRING_DEVICE_INFO_NAME0 "VL53L1 cut1.0"
+ #define VL53L1_STRING_DEVICE_INFO_NAME1 "VL53L1 cut1.1"
+ #define VL53L1_STRING_DEVICE_INFO_TYPE "VL53L1"
+
+ /* Range Status */
+ #define VL53L1_STRING_RANGESTATUS_NONE "No Update"
+ #define VL53L1_STRING_RANGESTATUS_RANGEVALID "Range Valid"
+ #define VL53L1_STRING_RANGESTATUS_SIGMA "Sigma Fail"
+ #define VL53L1_STRING_RANGESTATUS_SIGNAL "Signal Fail"
+ #define VL53L1_STRING_RANGESTATUS_MINRANGE "Min Range Fail"
+ #define VL53L1_STRING_RANGESTATUS_PHASE "Phase Fail"
+ #define VL53L1_STRING_RANGESTATUS_HW "Hardware Fail"
+
+
+ /* Range Status */
+ #define VL53L1_STRING_STATE_POWERDOWN "POWERDOWN State"
+ #define VL53L1_STRING_STATE_WAIT_STATICINIT \
+ "Wait for staticinit State"
+ #define VL53L1_STRING_STATE_STANDBY "STANDBY State"
+ #define VL53L1_STRING_STATE_IDLE "IDLE State"
+ #define VL53L1_STRING_STATE_RUNNING "RUNNING State"
+ #define VL53L1_STRING_STATE_RESET "RESET State"
+ #define VL53L1_STRING_STATE_UNKNOWN "UNKNOWN State"
+ #define VL53L1_STRING_STATE_ERROR "ERROR State"
+
+
+
+ /* Check Enable */
+ #define VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \
+ "SIGMA FINAL RANGE"
+ #define VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \
+ "SIGNAL RATE FINAL RANGE"
+ #define VL53L1_STRING_CHECKENABLE_SIGNAL_MIN_CLIP \
+ "SIGNAL MIN CLIP"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \
+ "RANGE IGNORE THRESHOLD"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_HIGH \
+ "RANGE PHASE HIGH"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_LOW \
+ "RANGE PHASE LOW"
+ #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_CONSISTENCY \
+ "RANGE PHASE CONSISTENCY"
+
+ /* Sequence Step */
+ #define VL53L1_STRING_SEQUENCESTEP_VHV "VHV"
+ #define VL53L1_STRING_SEQUENCESTEP_PHASECAL "PHASE CAL"
+ #define VL53L1_STRING_SEQUENCESTEP_REFPHASE "REF PHASE"
+ #define VL53L1_STRING_SEQUENCESTEP_DSS1 "DSS1"
+ #define VL53L1_STRING_SEQUENCESTEP_DSS2 "DSS2"
+ #define VL53L1_STRING_SEQUENCESTEP_MM1 "MM1"
+ #define VL53L1_STRING_SEQUENCESTEP_MM2 "MM2"
+ #define VL53L1_STRING_SEQUENCESTEP_RANGE "RANGE"
+#endif /* VL53L1_USE_EMPTY_STRING */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_core.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_core.h
new file mode 100644
index 000000000000..c6b2e6e634a9
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_core.h
@@ -0,0 +1,1926 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_CORE_H_
+#define _VL53L1_CORE_H_
+
+#include "vl53l1_platform.h"
+#include "vl53l1_core_support.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+void VL53L1_init_version(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_ll_driver_state(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceState ll_state);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_ll_driver_rd_state(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_check_ll_driver_rd_state(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_ll_driver_cfg_state(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_rtn_good_spads_to_buffer(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_system_results(
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+void V53L1_init_zone_results_structure(
+ uint8_t active_zones,
+ VL53L1_zone_results_t *pdata);
+
+
+
+
+
+
+
+
+
+void V53L1_init_zone_dss_configs(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_histogram_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_histogram_multizone_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_xtalk_bin_data_struct(
+ uint32_t bin_value,
+ uint16_t VL53L1_p_024,
+ VL53L1_xtalk_histogram_shape_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_uint16_t(
+ uint16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_i2c_decode_uint16_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_int16_t(
+ int16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+int16_t VL53L1_i2c_decode_int16_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_uint32_t(
+ uint32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_i2c_decode_uint32_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_i2c_decode_with_mask(
+ uint16_t count,
+ uint8_t *pbuffer,
+ uint32_t bit_mask,
+ uint32_t down_shift,
+ uint32_t offset);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_i2c_encode_int32_t(
+ int32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+int32_t VL53L1_i2c_decode_int32_t(
+ uint16_t count,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_start_test(
+ VL53L1_DEV Dev,
+ uint8_t test_mode__ctrl);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_firmware_enable_register(
+ VL53L1_DEV Dev,
+ uint8_t value);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_enable_firmware(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_firmware(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_powerforce_register(
+ VL53L1_DEV Dev,
+ uint8_t value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_enable_powerforce(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_powerforce(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_clear_interrupt(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_force_shadow_stream_count_to_zero(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_macro_period_us(
+ uint16_t fast_osc_frequency,
+ uint8_t VL53L1_p_009);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_calc_range_ignore_threshold(
+ uint32_t central_rate,
+ int16_t x_gradient,
+ int16_t y_gradient,
+ uint8_t rate_mult);
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_timeout_mclks(
+ uint32_t timeout_us,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_calc_encoded_timeout(
+ uint32_t timeout_us,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_timeout_us(
+ uint32_t timeout_mclks,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_decoded_timeout_us(
+ uint16_t timeout_encoded,
+ uint32_t macro_period_us);
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_encode_timeout(
+ uint32_t timeout_mclks);
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_decode_timeout(
+ uint16_t encoded_timeout);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_calc_timeout_register_values(
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint16_t fast_osc_frequency,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming);
+
+
+
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_encode_vcsel_period(
+ uint8_t VL53L1_p_031);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_decode_unsigned_integer(
+ uint8_t *pbuffer,
+ uint8_t no_of_bytes);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_encode_unsigned_integer(
+ uint32_t ip_value,
+ uint8_t no_of_bytes,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_copy_and_scale_ambient_info(
+ VL53L1_zone_hist_info_t *pidata,
+ VL53L1_histogram_bin_data_t *podata);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_get_bin_sequence_config(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_phase_consistency_check(
+ VL53L1_DEV Dev,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_results_t *prange_curr);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_events_consistency_check(
+ uint8_t event_sigma,
+ uint16_t min_effective_spad_count,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_object_data_t *prange_prev,
+ VL53L1_range_data_t *prange_curr,
+ int32_t *pevents_tolerance,
+ int32_t *pevents_delta,
+ VL53L1_DeviceError *prange_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_merged_pulse_check(
+ int16_t min_max_tolerance_mm,
+ VL53L1_range_data_t *pdata,
+ VL53L1_DeviceError *prange_status);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xmonitor_consistency_check(
+ VL53L1_DEV Dev,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_data_t *prange_curr);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_wrap_dmax(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_histogram_bin_data_t *pcurrent,
+ int16_t *pwrap_dmax_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_combine_mm1_mm2_offsets(
+ int16_t mm1_offset_mm,
+ int16_t mm2_offset_mm,
+ uint8_t encoded_mm_roi_centre,
+ uint8_t encoded_mm_roi_size,
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ VL53L1_additional_offset_cal_data_t *pcal_data,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ int16_t *prange_offset_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_window(
+ int16_t target_distance_mm,
+ uint16_t target_width_oversize,
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_event_sums(
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_rate_per_spad(
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_shape(
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data,
+ VL53L1_xtalk_histogram_shape_t *pxtalk_shape);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xtalk_shape_model(
+ uint16_t events_per_bin,
+ uint16_t pulse_centre,
+ uint16_t pulse_width,
+ VL53L1_xtalk_histogram_shape_t *pxtalk_shape);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_hist_xtalk_shape_model_interp(
+ uint16_t events_per_bin,
+ uint32_t phase_delta);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_spad_number_to_byte_bit_index(
+ uint8_t spad_number,
+ uint8_t *pbyte_index,
+ uint8_t *pbit_index,
+ uint8_t *pbit_mask);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_encode_row_col(
+ uint8_t row,
+ uint8_t col,
+ uint8_t *pspad_number);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_decode_zone_size(
+ uint8_t encoded_xy_size,
+ uint8_t *pwidth,
+ uint8_t *pheight);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_encode_zone_size(
+ uint8_t width,
+ uint8_t height,
+ uint8_t *pencoded_xy_size);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_decode_zone_limits(
+ uint8_t encoded_xy_centre,
+ uint8_t encoded_xy_size,
+ int16_t *px_ll,
+ int16_t *py_ll,
+ int16_t *px_ur,
+ int16_t *py_ur);
+
+
+
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_is_aperture_location(
+ uint8_t row,
+ uint8_t col);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_calc_max_effective_spads(
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ uint16_t *pmax_effective_spads);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_calc_mm_effective_spads(
+ uint8_t encoded_mm_roi_centre,
+ uint8_t encoded_mm_roi_size,
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ uint16_t *pmm_inner_effective_spads,
+ uint16_t *pmm_outer_effective_spads);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_copy_results_to_sys_and_core(
+ VL53L1_histogram_bin_data_t *pbins,
+ VL53L1_range_results_t *phist,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_sum_histogram_data(
+ VL53L1_histogram_bin_data_t *phist_input,
+ VL53L1_histogram_bin_data_t *phist_output);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_avg_histogram_data(
+ uint8_t no_of_samples,
+ VL53L1_histogram_bin_data_t *phist_sum,
+ VL53L1_histogram_bin_data_t *phist_avg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_save_cfg_data(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_zone_update(
+ VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_internal_stream_counters(
+ VL53L1_DEV Dev,
+ uint8_t external_stream_count,
+ uint8_t *pinternal_stream_count,
+ uint8_t *pinternal_stream_count_val
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_multizone_hist_bins_update(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_multizone_initial_bin_config(
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_histogram_config_t *phist_cfg,
+ VL53L1_histogram_config_t *pmulti_hist
+ );
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_encode_GPIO_interrupt_config(
+ VL53L1_GPIO_interrupt_config_t *pintconf);
+
+
+
+
+
+
+
+
+
+VL53L1_GPIO_interrupt_config_t VL53L1_decode_GPIO_interrupt_config(
+ uint8_t system__interrupt_config);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_distance_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_rate_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low);
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_thresholds_from_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_ref_spad_char_config(
+ VL53L1_DEV Dev,
+ uint8_t vcsel_period_a,
+ uint32_t phasecal_timeout_us,
+ uint16_t total_rate_target_mcps,
+ uint16_t max_count_rate_rtn_limit_mcps,
+ uint16_t min_count_rate_rtn_limit_mcps,
+ uint16_t fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_ssc_config(
+ VL53L1_DEV Dev,
+ VL53L1_ssc_config_t *pssc_cfg,
+ uint16_t fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_spad_rate_data(
+ VL53L1_DEV Dev,
+ VL53L1_spad_rate_data_t *pspad_rates);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_crosstalk_plane_offset_with_margin(
+ uint32_t plane_offset_kcps,
+ int16_t margin_offset_kcps);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_low_power_auto_data_init(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_low_power_auto_data_stop_range(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_calc_required_samples(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_calc_new_xtalk(
+ VL53L1_DEV Dev,
+ uint32_t xtalk_offset_out,
+ VL53L1_smudge_corrector_config_t *pconfig,
+ VL53L1_smudge_corrector_data_t *pout,
+ uint8_t add_smudge,
+ uint8_t soft_update
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_corrector(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_data_init(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_output_init(
+ VL53L1_LLDriverResults_t *pres
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_xtalk_cal_data_init(
+ VL53L1_DEV Dev
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_config_low_power_auto_mode(
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_low_power_auto_data_t *plpadata
+ );
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_low_power_auto_setup_manual_calibration(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_low_power_auto_update_DSS(
+ VL53L1_DEV Dev);
+
+
+
+
+
+VL53L1_Error VL53L1_compute_histo_merge_nb(
+ VL53L1_DEV Dev, uint8_t *histo_merge_nb);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_core_support.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_core_support.h
new file mode 100644
index 000000000000..3cc76a2de52c
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_core_support.h
@@ -0,0 +1,414 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_CORE_SUPPORT_H_
+#define _VL53L1_CORE_SUPPORT_H_
+
+#include "vl53l1_types.h"
+#include "vl53l1_hist_structs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_pll_period_us(
+ uint16_t fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_duration_maths(
+ uint32_t pll_period_us,
+ uint32_t vcsel_parm_pclks,
+ uint32_t window_vclks,
+ uint32_t periods_elapsed_mclks);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_events_per_spad_maths(
+ int32_t VL53L1_p_013,
+ uint16_t num_spads,
+ uint32_t duration);
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_isqrt(
+ uint32_t num);
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_calc_zero_distance_phase(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_estimate_ambient_from_thresholded_bins(
+ int32_t ambient_threshold_sigma,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_remove_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint32_t VL53L1_calc_pll_period_mm(
+ uint16_t fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_rate_maths(
+ int32_t VL53L1_p_008,
+ uint32_t time_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+uint16_t VL53L1_rate_per_spad_maths(
+ uint32_t frac_bits,
+ uint32_t peak_count_rate,
+ uint16_t num_spads,
+ uint32_t max_output_value);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+int32_t VL53L1_range_maths(
+ uint16_t fast_osc_frequency,
+ uint16_t VL53L1_p_017,
+ uint16_t zero_distance_phase,
+ uint8_t fractional_bits,
+ int32_t gain_factor,
+ int32_t range_offset_mm);
+
+
+
+
+
+
+
+
+
+
+
+
+uint8_t VL53L1_decode_vcsel_period(
+ uint8_t vcsel_period_reg);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_copy_xtalk_bin_data_to_histogram_data_struct(
+ VL53L1_xtalk_histogram_shape_t *pxtalk,
+ VL53L1_histogram_bin_data_t *phist);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_init_histogram_bin_data_struct(
+ int32_t bin_value,
+ uint16_t VL53L1_p_024,
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_decode_row_col(
+ uint8_t spad_number,
+ uint8_t *prow,
+ uint8_t *pcol);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_find_min_max_bin_values(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_hist_estimate_ambient_from_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_def.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_def.h
new file mode 100644
index 000000000000..0560050cba2e
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_def.h
@@ -0,0 +1,852 @@
+/******************************************************************************
+ * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+ ******************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+ *******************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+ *******************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones mentioned above :
+
+ *******************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+ *******************************************************************************
+ */
+
+/**
+ * @file vl53l1_def.h
+ *
+ * @brief Type definitions for VL53L1 API.
+ *
+ */
+
+
+#ifndef _VL53L1_DEF_H_
+#define _VL53L1_DEF_H_
+
+#include "vl53l1_ll_def.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @defgroup VL53L1_globaldefine_group VL53L1 Defines
+ * @brief VL53L1 Defines
+ * @{
+ */
+
+
+/** VL53L1 IMPLEMENTATION major version */
+#define VL53L1_IMPLEMENTATION_VER_MAJOR 6
+/** VL53L1 IMPLEMENTATION minor version */
+#define VL53L1_IMPLEMENTATION_VER_MINOR 4
+/** VL53L1 IMPLEMENTATION sub version */
+#define VL53L1_IMPLEMENTATION_VER_SUB 2
+/** VL53L1 IMPLEMENTATION sub version */
+#define VL53L1_IMPLEMENTATION_VER_REVISION 2365
+
+/****************************************
+ * PRIVATE define do not edit
+ ****************************************/
+
+/** @brief Defines the parameters of the Get Version Functions
+ */
+typedef struct {
+ uint32_t revision; /*!< revision number */
+ uint8_t major; /*!< major number */
+ uint8_t minor; /*!< minor number */
+ uint8_t build; /*!< build number */
+} VL53L1_Version_t;
+
+
+#define VL53L1_DEVINFO_STRLEN 32
+
+/** @brief Defines the parameters of the Get Device Info Functions
+ */
+typedef struct {
+ char Name[VL53L1_DEVINFO_STRLEN];
+ /*!< Full Name of the Device e.g. VL53L1 cut1.1 */
+ char Type[VL53L1_DEVINFO_STRLEN];
+ /*!< Type of the Device e.g VL53L1 */
+ char ProductId[VL53L1_DEVINFO_STRLEN];
+ /*!< Product Identifier String
+ * @warning Not yet implemented
+ */
+ uint8_t ProductType;
+ /*!< Product Type, VL53L1 = 0xCC, VL53L3 = 0xAA
+ * Stands as module_type in the datasheet
+ */
+ uint8_t ProductRevisionMajor;
+ /*!< Product revision major */
+ uint8_t ProductRevisionMinor;
+ /*!< Product revision minor */
+} VL53L1_DeviceInfo_t;
+
+
+
+/** @defgroup VL53L1_define_PresetModes_group Defines Preset modes
+ * Defines all possible preset modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_PresetModes;
+
+#define VL53L1_PRESETMODE_RANGING ((VL53L1_PresetModes) 1)
+#define VL53L1_PRESETMODE_MULTIZONES_SCANNING ((VL53L1_PresetModes) 2)
+#define VL53L1_PRESETMODE_AUTONOMOUS ((VL53L1_PresetModes) 3)
+#define VL53L1_PRESETMODE_LITE_RANGING ((VL53L1_PresetModes) 4)
+#define VL53L1_PRESETMODE_OLT ((VL53L1_PresetModes) 7)
+#define VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS ((VL53L1_PresetModes) 8)
+#define VL53L1_PRESETMODE_PROXY_RANGING_MODE ((VL53L1_PresetModes) 9)
+
+/** default preset ranging mode */
+//songyt test replace VL53L1_PRESETMODE_RANGING
+#define STMVL53L1_CFG_DEFAULT_MODE VL53L1_PRESETMODE_RANGING
+
+ /* ... Modes to be added depending on device */
+/** @} VL53L1_define_PresetModes_group */
+
+
+/** @defgroup VL53L1_define_DistanceModes_group Defines Distance modes
+ * Defines all possible Distance modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_DistanceModes;
+
+#define VL53L1_DISTANCEMODE_SHORT ((VL53L1_DistanceModes) 1)
+#define VL53L1_DISTANCEMODE_MEDIUM ((VL53L1_DistanceModes) 2)
+#define VL53L1_DISTANCEMODE_LONG ((VL53L1_DistanceModes) 3)
+/** @} VL53L1_define_DistanceModes_group */
+
+/** @defgroup VL53L1_define_OutputModes_group Defines Output modes
+ * Defines all possible Output modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_OutputModes;
+
+#define VL53L1_OUTPUTMODE_NEAREST ((VL53L1_OutputModes) 1)
+#define VL53L1_OUTPUTMODE_STRONGEST ((VL53L1_OutputModes) 2)
+
+/** @} VL53L1_define_OutputModes_group */
+
+/** @defgroup VL53L1_define_XtalkCal_group Defines Xtalk Calibration modes
+ * Defines all possible Offset Calibration modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_XtalkCalibrationModes;
+
+#define VL53L1_XTALKCALIBRATIONMODE_NO_TARGET \
+ ((VL53L1_OffsetCalibrationModes) 0)
+/*!< To perform Xtalk calibration with no target below 80 cm */
+#define VL53L1_XTALKCALIBRATIONMODE_SINGLE_TARGET \
+ ((VL53L1_OffsetCalibrationModes) 1)
+/*!< To perform Xtalk calibration with one target */
+#define VL53L1_XTALKCALIBRATIONMODE_FULL_ROI \
+ ((VL53L1_OffsetCalibrationModes) 2)
+/*!< To perform Xtalk calibration based on histogram with full ROI */
+
+/** @} VL53L1_define_XtalkCal_group */
+
+/** @defgroup VL53L1_define_OffsetCal_group Defines Offset Calibration modes
+ * Defines all possible Offset Calibration modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_OffsetCalibrationModes;
+
+#define VL53L1_OFFSETCALIBRATIONMODE_STANDARD \
+ ((VL53L1_OffsetCalibrationModes) 1)
+#define VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY \
+ ((VL53L1_OffsetCalibrationModes) 2)
+#define VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE \
+ ((VL53L1_OffsetCalibrationModes) 3)
+
+/** @} VL53L1_define_OffsetCal_group */
+
+/** @defgroup VL53L1_define_DeviceDmaxModes_group Defines Dmax source modes
+ * Defines all possible sources for Dmax calibration for the device
+ * @{
+ */
+typedef uint8_t VL53L1_DeviceDmaxModes;
+
+#define VL53L1_DMAXMODE_FMT_CAL_DATA ((VL53L1_DeviceDmaxModes) 1)
+#define VL53L1_DMAXMODE_CUSTCAL_DATA ((VL53L1_DeviceDmaxModes) 2)
+#define VL53L1_DMAXMODE_PER_ZONE_CAL_DATA ((VL53L1_DeviceDmaxModes) 3)
+
+/** @} VL53L1_define_DeviceDmaxModes_group */
+
+/** @defgroup VL53L1_define_OffsetCorrectionModesBD_group
+ * Device Offset Correction Mode
+ *
+ * @brief Defines all possible offset correction modes for the device
+ * @{
+ */
+typedef uint8_t VL53L1_OffsetCorrectionModes;
+
+#define VL53L1_OFFSETCORRECTIONMODE_STANDARD ((VL53L1_OffsetCorrectionMode) 1)
+#define VL53L1_OFFSETCORRECTIONMODE_PERZONE ((VL53L1_OffsetCorrectionMode) 2)
+#define VL53L1_OFFSETCORRECTIONMODE_PERVCSEL ((VL53L1_OffsetCorrectionMode) 3)
+
+/** @} VL53L1_define_OffsetCorrectionModesBD_group */
+
+/** @defgroup VL53L1_define_RoiStatus_group Defines Roi Status
+ * Defines the read status mode
+ * @{
+ */
+typedef uint8_t VL53L1_RoiStatus;
+
+#define VL53L1_ROISTATUS_NOT_VALID ((VL53L1_RoiStatus) 0)
+#define VL53L1_ROISTATUS_VALID_NOT_LAST ((VL53L1_RoiStatus) 1)
+#define VL53L1_ROISTATUS_VALID_LAST ((VL53L1_RoiStatus) 2)
+/** @} VL53L1_define_RoiStatus_group */
+
+
+/** @defgroup VL53L1_CheckEnable_group Check Enable list
+ * @brief Check Enable code
+ *
+ * Define used to specify the LimitCheckId.
+ * Use @a VL53L1_GetLimitCheckInfo() to get the string.
+ * @{
+ */
+
+#define VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE 0
+#define VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE 1
+
+#define VL53L1_CHECKENABLE_NUMBER_OF_CHECKS 2
+
+/** @} end of VL53L1_CheckEnable_group */
+
+
+/** @defgroup VL53L1_ThresholdMode_gropup Detection Functionality
+ * @brief Defines the different functionalities for the detection feature
+ * @{
+ */
+typedef uint8_t VL53L1_ThresholdMode;
+
+#define VL53L1_THRESHOLD_CROSSED_LOW \
+ ((VL53L1_ThresholdMode) 0)
+ /*!< Trigger interrupt if value < thresh_low */
+#define VL53L1_THRESHOLD_CROSSED_HIGH \
+ ((VL53L1_ThresholdMode) 1)
+ /*!< Trigger interrupt if value > thresh_high */
+#define VL53L1_THRESHOLD_OUT_OF_WINDOW \
+ ((VL53L1_ThresholdMode) 2)
+ /*!< Trigger interrupt if value < thresh_low OR value > thresh_high */
+#define VL53L1_THRESHOLD_IN_WINDOW \
+ ((VL53L1_ThresholdMode) 3)
+ /*!< Trigger interrupt if value > thresh_low AND value < thresh_high */
+
+/** @} end of VL53L1_ThresholdMode_gropup */
+
+/** @brief Defines parameters for Distance detection Thresholds configuration
+ */
+typedef struct {
+ VL53L1_ThresholdMode CrossMode;
+ uint16_t High; /*!< Distance threshold high limit in mm */
+ uint16_t Low; /*!< Distance threshold low limit in mm */
+} VL53L1_DistanceThreshold_t;
+
+/** @brief Defines parameters for Signal rate detection Thresholds configuration
+ */
+typedef struct {
+ VL53L1_ThresholdMode CrossMode;
+ FixPoint1616_t High; /*!< Signal rate threshold high limit */
+ FixPoint1616_t Low; /*!< Signal rate threshold low limit */
+} VL53L1_RateThreshold_t;
+
+/** @defgroup VL53L1_DetectionMode_group Gpio Functionality
+ * @brief Defines conditions leading to device's IT on GPIO
+ * @{
+ */
+typedef uint8_t VL53L1_DetectionMode;
+
+#define VL53L1_DETECTION_NORMAL_RUN \
+ ((VL53L1_DetectionMode) 0)
+ /*!< Trigger interrupt on new measurement regardless of threshold
+ * just like after a VL53L1_SetPresetMode() call
+ */
+#define VL53L1_DETECTION_DISTANCE_ONLY \
+ ((VL53L1_DetectionMode) 1)
+ /*!< Trigger interrupt if "threshold event" occurs on distance */
+#define VL53L1_DETECTION_RATE_ONLY \
+ ((VL53L1_DetectionMode) 2)
+ /*!< Trigger interrupt if "threshold event" occurs on signal rate */
+#define VL53L1_DETECTION_DISTANCE_AND_RATE \
+ ((VL53L1_DetectionMode) 3)
+ /*!< Trigger interrupt if "threshold event" occurs on distance AND rate
+ */
+#define VL53L1_DETECTION_DISTANCE_OR_RATE \
+ ((VL53L1_DetectionMode) 4)
+ /*!< Trigger interrupt if "threshold event" occurs on distance OR rate
+ */
+
+/** @} end of VL53L1_DetectionMode_group */
+
+/** @brief Defines parameters for User/object Detection configuration
+ */
+typedef struct {
+ VL53L1_DetectionMode DetectionMode; /*!< See #VL53L1_DetectionMode*/
+ uint8_t IntrNoTarget; /*!< 1 to trigger IT in case of no target found */
+ VL53L1_DistanceThreshold_t Distance; /*!< limits in mm */
+ VL53L1_RateThreshold_t Rate;/*!< limits in FixPoint1616_t */
+} VL53L1_DetectionConfig_t;
+
+
+/** @brief Defines all parameters for the device
+ */
+typedef struct {
+ VL53L1_PresetModes PresetMode;
+ /*!< Defines the operating mode to be used for the next measure */
+ VL53L1_OutputModes OutputMode;
+ /*!< Defines the Output mode to be used for the next measure */
+ VL53L1_DistanceModes DistanceMode;
+ /*!< Defines the operating mode to be used for the next measure */
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+ /*!< Defines the allowed total time for a single measurement */
+ uint8_t LimitChecksEnable[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array store all the Limit Check enable for this device. */
+ uint8_t LimitChecksStatus[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array stores all the Status of the check linked to last
+ * measurement.
+ */
+ FixPoint1616_t LimitChecksValue[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array stores all the Limit Check value for this device */
+ FixPoint1616_t LimitChecksCurrent[VL53L1_CHECKENABLE_NUMBER_OF_CHECKS];
+ /*!< This Array stores all the Limit Check current value from latest
+ * ranging
+ */
+} VL53L1_DeviceParameters_t;
+
+
+/** @defgroup VL53L1_define_State_group Defines the current status of the device
+ * Defines the current status of the device
+ * @{
+ */
+
+typedef uint8_t VL53L1_State;
+
+#define VL53L1_STATE_POWERDOWN ((VL53L1_State) 0)
+ /*!< Device is in HW reset */
+#define VL53L1_STATE_WAIT_STATICINIT ((VL53L1_State) 1)
+ /*!< Device is initialized and wait for static initialization */
+#define VL53L1_STATE_STANDBY ((VL53L1_State) 2)
+ /*!< Device is in Low power Standby mode */
+#define VL53L1_STATE_IDLE ((VL53L1_State) 3)
+ /*!< Device has been initialized and ready to do measurements */
+#define VL53L1_STATE_RUNNING ((VL53L1_State) 4)
+ /*!< Device is performing measurement */
+#define VL53L1_STATE_RESET ((VL53L1_State) 5)
+ /*!< Soft reset has been run on Device */
+#define VL53L1_STATE_UNKNOWN ((VL53L1_State) 98)
+ /*!< Device is in unknown state and need to be rebooted */
+#define VL53L1_STATE_ERROR ((VL53L1_State) 99)
+ /*!< Device is in error state and need to be rebooted */
+
+/** @} VL53L1_define_State_group */
+
+/** @defgroup VL53L1_define_Smudge_Mode_group Defines smudge correction modes
+ * Defines the smudge correction modes
+ * @{
+ */
+
+typedef uint8_t VL53L1_SmudgeCorrectionModes;
+
+#define VL53L1_SMUDGE_CORRECTION_NONE ((VL53L1_SmudgeCorrectionModes) 0)
+ /*!< Smudge correction is applied continously accross the rangings */
+#define VL53L1_SMUDGE_CORRECTION_CONTINUOUS ((VL53L1_SmudgeCorrectionModes) 1)
+ /*!< Smudge correction is applied continously accross the rangings */
+#define VL53L1_SMUDGE_CORRECTION_SINGLE ((VL53L1_SmudgeCorrectionModes) 2)
+ /*!< Smudge correction is applied only once accross the rangings */
+#define VL53L1_SMUDGE_CORRECTION_DEBUG ((VL53L1_SmudgeCorrectionModes) 3)
+ /*!< Smudge detection is applied continously but Xtalk values are not
+ * updated automatically within the driver
+ */
+
+/** @} VL53L1_define_Smudge_Correction_Mode_group */
+
+
+/**
+ * @struct VL53L1_RangingMeasurementData_t
+ * @brief Single Range measurement data.
+ */
+typedef struct {
+ uint32_t TimeStamp;
+ /*!< 32-bit time stamp.
+ * @warning Not yet implemented
+ */
+
+ uint8_t StreamCount;
+ /*!< 8-bit Stream Count. */
+
+ uint8_t RangeQualityLevel;
+ /*!< indicate a quality level in percentage from 0 to 100
+ * @warning Not yet implemented
+ */
+
+ FixPoint1616_t SignalRateRtnMegaCps;
+ /*!< Return signal rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of target
+ * reflectance.
+ */
+
+ FixPoint1616_t AmbientRateRtnMegaCps;
+ /*!< Return ambient rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of the ambien
+ * t light.
+ */
+
+ uint16_t EffectiveSpadRtnCount;
+ /*!< Return the effective SPAD count for the return signal.
+ * To obtain Real value it should be divided by 256
+ */
+
+ FixPoint1616_t SigmaMilliMeter;
+ /*!< Return the Sigma value in millimeter */
+
+ int16_t RangeMilliMeter;
+ /*!< range distance in millimeter. This should be between
+ * RangeMinMilliMeter and RangeMaxMilliMeter
+ */
+
+ uint8_t RangeFractionalPart;
+ /*!< Fractional part of range distance. Final value is a
+ * RangeMilliMeter + RangeFractionalPart/256.
+ * @warning Not yet implemented
+ */
+
+ uint8_t RangeStatus;
+ /*!< Range Status for the current measurement. This is device
+ * dependent. Value = 0 means value is valid.
+ */
+} VL53L1_RangingMeasurementData_t;
+
+/**
+ * @struct VL53L1_TargetRangeData_t
+ * @brief One Range measurement data for each target.
+ */
+typedef struct {
+ uint8_t RangeQualityLevel;
+ /*!< indicate a quality level in percentage from 0 to 100
+ * @warning Not yet implemented
+ */
+
+ int16_t RangeMaxMilliMeter;
+ /*!< Tells what is the maximum detection distance of the object
+ * in current setup and environment conditions (Filled when
+ * applicable)
+ */
+
+ int16_t RangeMinMilliMeter;
+ /*!< Tells what is the minimum detection distance of the object
+ * in current setup and environment conditions (Filled when
+ * applicable)
+ */
+
+ FixPoint1616_t SignalRateRtnMegaCps;
+ /*!< Return signal rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of target
+ * reflectance.
+ */
+
+ FixPoint1616_t AmbientRateRtnMegaCps;
+ /*!< Return ambient rate (MCPS)\n these is a 16.16 fix point
+ * value, which is effectively a measure of the ambien
+ * t light.
+ */
+
+ FixPoint1616_t SigmaMilliMeter;
+ /*!< Return the Sigma value in millimeter */
+
+ int16_t RangeMilliMeter;
+ /*!< range distance in millimeter. This should be between
+ * RangeMinMilliMeter and RangeMaxMilliMeter
+ */
+
+ uint8_t RangeFractionalPart;
+ /*!< Fractional part of range distance. Final value is a
+ * RangeMilliMeter + RangeFractionalPart/256.
+ * @warning Not yet implemented
+ */
+
+ uint8_t RangeStatus;
+ /*!< Range Status for the current measurement. This is device
+ * dependent. Value = 0 means value is valid.
+ */
+} VL53L1_TargetRangeData_t;
+/**
+ * @struct VL53L1_MultiRangingData_t
+ * @brief Structure for storing the set of range results for a single ROI
+ *
+ */
+typedef struct {
+ uint32_t TimeStamp;
+ /*!< 32-bit time stamp.
+ * @warning Not yet implemented
+ */
+
+ uint8_t StreamCount;
+ /*!< 8-bit Stream Count. */
+
+ uint8_t RoiNumber;
+ /*!< Denotes on which ROI the range data is related to. */
+ uint8_t NumberOfObjectsFound;
+ /*!< Indicate the number of objects found in the current ROI.
+ * This is used to know how many ranging data should be get.
+ * NumberOfObjectsFound is in the range 0 to
+ * VL53L1_MAX_RANGE_RESULTS.
+ */
+ VL53L1_RoiStatus RoiStatus;
+ /*!< Indicate if the data read is valid or not or if this is
+ * the last valid data in the ROI.
+ */
+ VL53L1_TargetRangeData_t RangeData[VL53L1_MAX_RANGE_RESULTS];
+ /*!< Range data each target distance */
+ uint8_t HasXtalkValueChanged;
+ /*!< set to 1 if a new Xtalk value has been computed whilst
+ * smudge correction mode enable by with
+ * VL53L1_SmudgeCorrectionEnable() function is either
+ * VL53L1_SMUDGE_CORRECTION_CONTINUOUS or
+ * VL53L1_SMUDGE_CORRECTION_SINGLE.
+ */
+ uint16_t EffectiveSpadRtnCount;
+ /*!< Return the effective SPAD count for the return signal.
+ * To obtain Real value it should be divided by 256
+ */
+ int16_t DmaxMilliMeter;
+ /*!< range Dmax distance in millimeter.
+ */
+ VL53L1_DistanceModes RecommendedDistanceMode;
+ /*!< suggestion for a better distance mode choice to improve
+ * range accuracy.
+ */
+} VL53L1_MultiRangingData_t;
+
+
+/** @brief Defines User Zone(ROI) parameters
+ *
+ */
+typedef struct {
+
+ uint8_t TopLeftX; /*!< Top Left x coordinate: 0-15 range */
+ uint8_t TopLeftY; /*!< Top Left y coordinate: 0-15 range */
+ uint8_t BotRightX; /*!< Bot Right x coordinate: 0-15 range */
+ uint8_t BotRightY; /*!< Bot Right y coordinate: 0-15 range */
+
+} VL53L1_UserRoi_t;
+
+
+/** @brief Defines ROI configuration parameters
+ *
+ * Support up a max of 16 zones, Each Zone has the same size
+ *
+ */
+typedef struct {
+
+ uint8_t NumberOfRoi; /*!< Number of Rois defined*/
+
+ VL53L1_UserRoi_t UserRois[VL53L1_MAX_USER_ZONES];
+ /*!< List of Rois */
+
+} VL53L1_RoiConfig_t;
+
+/**
+ * @struct VL53L1_CustomerNvmManaged_t
+ *
+ */
+
+typedef struct {
+ uint8_t global_config__spad_enables_ref_0;
+ uint8_t global_config__spad_enables_ref_1;
+ uint8_t global_config__spad_enables_ref_2;
+ uint8_t global_config__spad_enables_ref_3;
+ uint8_t global_config__spad_enables_ref_4;
+ uint8_t global_config__spad_enables_ref_5;
+ uint8_t global_config__ref_en_start_select;
+ uint8_t ref_spad_man__num_requested_ref_spads;
+ uint8_t ref_spad_man__ref_location;
+ uint32_t algo__crosstalk_compensation_plane_offset_kcps;
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+ uint16_t ref_spad_char__total_rate_target_mcps;
+ int16_t algo__part_to_part_range_offset_mm;
+ int16_t mm_config__inner_offset_mm;
+ int16_t mm_config__outer_offset_mm;
+} VL53L1_CustomerNvmManaged_t;
+
+/**
+ * @struct VL53L1_CalibrationData_t
+ * @brief Structure for storing the Calibration Data
+ *
+ */
+
+typedef struct {
+
+ uint32_t struct_version;
+ VL53L1_CustomerNvmManaged_t customer;
+ VL53L1_dmax_calibration_data_t fmt_dmax_cal;
+ VL53L1_dmax_calibration_data_t cust_dmax_cal;
+ VL53L1_additional_offset_cal_data_t add_off_cal_data;
+ VL53L1_optical_centre_t optical_centre;
+ VL53L1_xtalk_histogram_data_t xtalkhisto;
+ VL53L1_gain_calibration_data_t gain_cal;
+ VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
+ VL53L1_per_vcsel_period_offset_cal_data_t per_vcsel_cal_data;
+ uint32_t algo__xtalk_cpo_HistoMerge_kcps[VL53L1_BIN_REC_SIZE];
+} VL53L1_CalibrationData_t;
+
+#define VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION 0x10
+/** VL53L1 additional Calibration Data struct version final struct version
+ * is given by adding it to VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION
+ */
+
+#define VL53L1_CALIBRATION_DATA_STRUCT_VERSION \
+ (VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION + \
+ VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION)
+/* VL53L1 Calibration Data struct version */
+
+/**
+ * @struct VL53L1_AdditionalData_t
+ * @brief Structure for storing the Additional Data
+ *
+ */
+typedef VL53L1_additional_data_t VL53L1_AdditionalData_t;
+
+/**
+ * @struct VL53L1_ZoneCalibrationData_t
+ * @brief Structure for storing the Zone Calibration Data
+ *
+ */
+typedef VL53L1_zone_calibration_results_t VL53L1_ZoneCalibrationData_t;
+
+/** @defgroup VL53L1_define_SequenceStepId_group Defines the SequenceStep
+ * Defines the the sequence steps performed during ranging..
+ * @{
+ */
+typedef uint8_t VL53L1_SequenceStepId;
+
+#define VL53L1_SEQUENCESTEP_VHV ((VL53L1_SequenceStepId) 0)
+/*!>12)&0xFFFF)
+#define VL53L1_FIXPOINT44TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<12)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT72(Value) \
+ (uint16_t)((Value>>14)&0xFFFF)
+#define VL53L1_FIXPOINT72TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<14)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT97(Value) \
+ (uint16_t)((Value>>9)&0xFFFF)
+#define VL53L1_FIXPOINT97TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<9)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT88(Value) \
+ (uint16_t)((Value>>8)&0xFFFF)
+#define VL53L1_FIXPOINT88TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<8)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT412(Value) \
+ (uint16_t)((Value>>4)&0xFFFF)
+#define VL53L1_FIXPOINT412TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<4)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT313(Value) \
+ (uint16_t)((Value>>3)&0xFFFF)
+#define VL53L1_FIXPOINT313TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<3)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT08(Value) \
+ (uint8_t)((Value>>8)&0x00FF)
+#define VL53L1_FIXPOINT08TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<8)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT53(Value) \
+ (uint8_t)((Value>>13)&0x00FF)
+#define VL53L1_FIXPOINT53TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<13)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT102(Value) \
+ (uint16_t)((Value>>14)&0x0FFF)
+#define VL53L1_FIXPOINT102TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<14)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT142(Value) \
+ (uint16_t)((Value>>14)&0xFFFF)
+#define VL53L1_FIXPOINT142TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<14)
+
+#define VL53L1_FIXPOINT1616TOFIXPOINT160(Value) \
+ (uint16_t)((Value>>16)&0xFFFF)
+#define VL53L1_FIXPOINT160TOFIXPOINT1616(Value) \
+ (FixPoint1616_t)((uint32_t)Value<<16)
+
+#define VL53L1_MAKEUINT16(lsb, msb) (uint16_t)((((uint16_t)msb)<<8) + \
+ (uint16_t)lsb)
+
+#ifndef SUPPRESS_UNUSED_WARNING
+#define SUPPRESS_UNUSED_WARNING(x) ((void) (x))
+#endif
+
+/** @} VL53L1_define_GeneralMacro_group */
+
+/** @} VL53L1_globaldefine_group */
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _VL53L1_DEF_H_ */
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_dmax_structs.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_dmax_structs.h
new file mode 100644
index 000000000000..969be0ba40e8
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_dmax_structs.h
@@ -0,0 +1,210 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_DMAX_STRUCTS_H_
+#define _VL53L1_DMAX_STRUCTS_H_
+
+#include "vl53l1_types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+#define VL53L1_MAX_AMBIENT_DMAX_VALUES 5
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+ uint16_t ref__actual_effective_spads;
+
+
+ uint16_t ref__peak_signal_count_rate_mcps;
+
+
+ uint16_t ref__distance_mm;
+
+
+ uint16_t ref_reflectance_pc;
+
+
+
+
+
+
+ uint16_t coverglass_transmission;
+
+
+
+} VL53L1_dmax_calibration_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+ uint8_t signal_thresh_sigma;
+
+
+ uint8_t ambient_thresh_sigma;
+
+
+ int32_t min_ambient_thresh_events;
+
+
+ int32_t signal_total_events_limit;
+
+
+
+ uint16_t target_reflectance_for_dmax_calc[
+ VL53L1_MAX_AMBIENT_DMAX_VALUES];
+
+
+ uint16_t max_effective_spads;
+
+
+
+
+
+
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+ uint8_t dss_config__aperture_attenuation;
+
+
+
+} VL53L1_hist_gen3_dmax_config_t;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_codes.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_codes.h
new file mode 100644
index 000000000000..1bf727eaf560
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_codes.h
@@ -0,0 +1,273 @@
+/******************************************************************************
+ * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+ ******************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+ *******************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+ *******************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones mentioned above :
+
+ *******************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+ *******************************************************************************
+ */
+
+/**
+ * @file vl53l1_error_codes.h
+ *
+ * @brief Error Code definitions for VL53L1 API.
+ *
+ */
+
+#ifndef _VL53L1_ERROR_CODES_H_
+#define _VL53L1_ERROR_CODES_H_
+
+#include "vl53l1_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ ****************************************
+ * PRIVATE define do not edit
+ ***************************************
+ */
+
+/*
+ * @defgroup VL53L1_define_Error_group Error and Warning code returned by API
+ * The following DEFINE are used to identify the PAL ERROR
+ * @{
+ */
+
+typedef int8_t VL53L1_Error;
+
+#define VL53L1_ERROR_NONE ((VL53L1_Error) 0)
+#define VL53L1_ERROR_CALIBRATION_WARNING ((VL53L1_Error) - 1)
+ /*!< Warning invalid calibration data may be in used
+ * \a VL53L1_InitData()
+ * \a VL53L1_GetOffsetCalibrationData
+ * \a VL53L1_SetOffsetCalibrationData
+ */
+#define VL53L1_ERROR_MIN_CLIPPED ((VL53L1_Error) - 2)
+ /*!< Warning parameter passed was clipped to min before to be applied */
+
+#define VL53L1_ERROR_UNDEFINED ((VL53L1_Error) - 3)
+ /*!< Unqualified error */
+#define VL53L1_ERROR_INVALID_PARAMS ((VL53L1_Error) - 4)
+ /*!< Parameter passed is invalid or out of range */
+#define VL53L1_ERROR_NOT_SUPPORTED ((VL53L1_Error) - 5)
+ /*!< Function is not supported in current mode or configuration */
+#define VL53L1_ERROR_RANGE_ERROR ((VL53L1_Error) - 6)
+ /*!< Device report a ranging error interrupt status */
+#define VL53L1_ERROR_TIME_OUT ((VL53L1_Error) - 7)
+ /*!< Aborted due to time out */
+#define VL53L1_ERROR_MODE_NOT_SUPPORTED ((VL53L1_Error) - 8)
+ /*!< Asked mode is not supported by the device */
+#define VL53L1_ERROR_BUFFER_TOO_SMALL ((VL53L1_Error) - 9)
+ /*!< ... */
+#define VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL ((VL53L1_Error) - 10)
+ /*!< Supplied buffer is larger than I2C supports */
+#define VL53L1_ERROR_GPIO_NOT_EXISTING ((VL53L1_Error) - 11)
+ /*!< User tried to setup a non-existing GPIO pin */
+#define VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ((VL53L1_Error) - 12)
+ /*!< unsupported GPIO functionality */
+#define VL53L1_ERROR_CONTROL_INTERFACE ((VL53L1_Error) - 13)
+ /*!< error reported from IO functions */
+#define VL53L1_ERROR_INVALID_COMMAND ((VL53L1_Error) - 14)
+ /*!< The command is not allowed in the current device state
+ * (power down)
+ */
+#define VL53L1_ERROR_DIVISION_BY_ZERO ((VL53L1_Error) - 15)
+ /*!< In the function a division by zero occurs */
+#define VL53L1_ERROR_REF_SPAD_INIT ((VL53L1_Error) - 16)
+ /*!< Error during reference SPAD initialization */
+#define VL53L1_ERROR_GPH_SYNC_CHECK_FAIL ((VL53L1_Error) - 17)
+ /*!< GPH sync interrupt check fail - API out of sync with device*/
+#define VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 18)
+ /*!< Stream count check fail - API out of sync with device */
+#define VL53L1_ERROR_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 19)
+ /*!< GPH ID check fail - API out of sync with device */
+#define VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 20)
+ /*!< Zone dynamic config stream count check failed - API out of sync */
+#define VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 21)
+ /*!< Zone dynamic config GPH ID check failed - API out of sync */
+
+#define VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL ((VL53L1_Error) - 22)
+ /*!< Thrown when run_xtalk_extraction fn has 0 succesful samples
+ * when using the full array to sample the xtalk. In this case there is
+ * not enough information to generate new Xtalk parm info. The function
+ * will exit and leave the current xtalk parameters unaltered
+ */
+#define VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL ((VL53L1_Error) - 23)
+ /*!< Thrown when run_xtalk_extraction fn has found that the
+ * avg sigma estimate of the full array xtalk sample is > than the
+ * maximal limit allowed. In this case the xtalk sample is too noisy for
+ * measurement. The function will exit and leave the current xtalk
+ * parameters unaltered.
+ */
+
+
+#define VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 24)
+ /*!< Thrown if there one of stages has no valid offset calibration
+ * samples. A fatal error calibration not valid
+ */
+#define VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL ((VL53L1_Error) - 25)
+ /*!< Thrown if there one of stages has zero effective SPADS
+ * Traps the case when MM1 SPADs is zero.
+ * A fatal error calibration not valid
+ */
+#define VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 26)
+ /*!< Thrown if then some of the zones have no valid samples
+ * A fatal error calibration not valid
+ */
+
+#define VL53L1_ERROR_TUNING_PARM_KEY_MISMATCH ((VL53L1_Error) - 27)
+ /*!< Thrown if the tuning file key table version does not match with
+ * expected value. The driver expects the key table version to match
+ * the compiled default version number in the define
+ * #VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT
+ */
+
+#define VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS ((VL53L1_Error) - 28)
+ /*!< Thrown if there are less than 5 good SPADs are available. */
+#define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH ((VL53L1_Error) - 29)
+ /*!< Thrown if the final reference rate is greater than
+ * the upper reference rate limit - default is 40 Mcps.
+ * Implies a minimum Q3 (x10) SPAD (5) selected
+ */
+#define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW ((VL53L1_Error) - 30)
+ /*!< Thrown if the final reference rate is less than
+ * the lower reference rate limit - default is 10 Mcps.
+ * Implies maximum Q1 (x1) SPADs selected
+ */
+
+
+#define VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES ((VL53L1_Error) - 31)
+ /*!< Thrown if there is less than the requested number of
+ * valid samples.
+ */
+#define VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 32)
+ /*!< Thrown if the offset calibration range sigma estimate is greater
+ * than 8.0 mm. This is the recommended min value to yield a stable
+ * offset measurement
+ */
+#define VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 33)
+ /*!< Thrown when VL53L1_run_offset_calibration() peak rate is greater
+ * than that 50.0Mcps. This is the recommended max rate to avoid
+ * pile-up influencing the offset measurement
+ */
+#define VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW ((VL53L1_Error) - 34)
+ /*!< Thrown when VL53L1_run_offset_calibration() when one of stages
+ * range has less that 5.0 effective SPADS. This is the recommended
+ * min value to yield a stable offset
+ */
+
+
+#define VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES ((VL53L1_Error) - 35)
+ /*!< Thrown if one of more of the zones have less than
+ * the requested number of valid samples
+ */
+#define VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 36)
+ /*!< Thrown if one or more zones have sigma estimate value greater
+ * than 8.0 mm. This is the recommended min value to yield a stable
+ * offset measurement
+ */
+#define VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 37)
+ /*!< Thrown if one of more zones have peak rate higher than
+ * that 50.0Mcps. This is the recommended max rate to avoid
+ * pile-up influencing the offset measurement
+ */
+
+
+#define VL53L1_WARNING_XTALK_MISSING_SAMPLES ((VL53L1_Error) - 38)
+ /*!< Thrown to notify that some of the xtalk samples did not yield
+ * valid ranging pulse data while attempting to measure
+ * the xtalk signal in vl53l1_run_xtalk_extract(). This can signify any
+ * of the zones are missing samples, for further debug information the
+ * xtalk_results struct should be referred to. This warning is for
+ * notification only, xtalk pulse and shape have still been generated
+ */
+#define VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT ((VL53L1_Error) - 39)
+ /*!< Thrown to notify that some of teh xtalk samples used for gradient
+ * generation did not yield valid ranging pulse data while attempting to
+ * measure the xtalk signal in vl53l1_run_xtalk_extract(). This can
+ * signify that any one of the zones 0-3 yielded no successful samples.
+ * xtalk_results struct should be referred to for further debug info.
+ * This warning is for notification only, the xtalk pulse and shape
+ * have still been generated.
+ */
+#define VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT ((VL53L1_Error) - 40)
+ /*!< Thrown to notify that some of the xtalk samples used for gradient
+ * generation did not pass the sigma limit check while attempting to
+ * measure the xtalk signal in vl53l1_run_xtalk_extract(). This can
+ * signify that any one of the zones 0-3 yielded an avg sigma_mm
+ * value > the limit. The xtalk_results struct should be referred to for
+ * further debug info.
+ * This warning is for notification only, the xtalk pulse and shape
+ * have still been generated.
+ */
+
+#define VL53L1_ERROR_NOT_IMPLEMENTED ((VL53L1_Error) - 41)
+ /*!< Tells requested functionality has not been implemented yet or
+ * not compatible with the device
+ */
+#define VL53L1_ERROR_PLATFORM_SPECIFIC_START ((VL53L1_Error) - 60)
+ /*!< Tells the starting code for platform */
+/** @} VL53L1_define_Error_group */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _VL53L1_ERROR_CODES_H_ */
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_exceptions.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_exceptions.h
new file mode 100644
index 000000000000..8fd8a7edd9f4
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_exceptions.h
@@ -0,0 +1,126 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_ERROR_EXCEPTIONS_H_
+#define _VL53L1_ERROR_EXCEPTIONS_H_
+
+#define IGNORE_DIVISION_BY_ZERO 0
+
+#define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL 0
+#define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL 0
+#define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FOR_GRADIENT_WARN 0
+#define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FOR_GRADIENT_WARN 0
+#define IGNORE_XTALK_EXTRACTION_MISSING_SAMPLES_WARN 0
+
+#define IGNORE_REF_SPAD_CHAR_NOT_ENOUGH_SPADS 0
+#define IGNORE_REF_SPAD_CHAR_RATE_TOO_HIGH 0
+#define IGNORE_REF_SPAD_CHAR_RATE_TOO_LOW 0
+
+#define IGNORE_OFFSET_CAL_MISSING_SAMPLES 0
+#define IGNORE_OFFSET_CAL_SIGMA_TOO_HIGH 0
+#define IGNORE_OFFSET_CAL_RATE_TOO_HIGH 0
+#define IGNORE_OFFSET_CAL_SPAD_COUNT_TOO_LOW 0
+
+#define IGNORE_ZONE_CAL_MISSING_SAMPLES 0
+#define IGNORE_ZONE_CAL_SIGMA_TOO_HIGH 0
+#define IGNORE_ZONE_CAL_RATE_TOO_HIGH 0
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_strings.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_strings.h
new file mode 100644
index 000000000000..7eab1fec2536
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_error_strings.h
@@ -0,0 +1,244 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef VL53L1_ERROR_STRINGS_H_
+#define VL53L1_ERROR_STRINGS_H_
+
+#include "vl53l1_error_codes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_pal_error_string(
+ VL53L1_Error PalErrorCode,
+ char *pPalErrorString);
+
+
+#ifndef VL53L1_USE_EMPTY_STRING
+
+
+
+ #define VL53L1_STRING_ERROR_NONE \
+ "No Error"
+ #define VL53L1_STRING_ERROR_CALIBRATION_WARNING \
+ "Calibration Warning Error"
+ #define VL53L1_STRING_ERROR_MIN_CLIPPED \
+ "Min clipped error"
+ #define VL53L1_STRING_ERROR_UNDEFINED \
+ "Undefined error"
+ #define VL53L1_STRING_ERROR_INVALID_PARAMS \
+ "Invalid parameters error"
+ #define VL53L1_STRING_ERROR_NOT_SUPPORTED \
+ "Not supported error"
+ #define VL53L1_STRING_ERROR_RANGE_ERROR \
+ "Range error"
+ #define VL53L1_STRING_ERROR_TIME_OUT \
+ "Time out error"
+ #define VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED \
+ "Mode not supported error"
+ #define VL53L1_STRING_ERROR_BUFFER_TOO_SMALL \
+ "Buffer too small"
+ #define VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL \
+ "Comms Buffer too small"
+ #define VL53L1_STRING_ERROR_GPIO_NOT_EXISTING \
+ "GPIO not existing"
+ #define VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \
+ "GPIO funct not supported"
+ #define VL53L1_STRING_ERROR_CONTROL_INTERFACE \
+ "Control Interface Error"
+ #define VL53L1_STRING_ERROR_INVALID_COMMAND \
+ "Invalid Command Error"
+ #define VL53L1_STRING_ERROR_DIVISION_BY_ZERO \
+ "Division by zero Error"
+ #define VL53L1_STRING_ERROR_REF_SPAD_INIT \
+ "Reference Spad Init Error"
+ #define VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL \
+ "GPH Sync Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL \
+ "Stream Count Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL \
+ "GPH ID Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL \
+ "Zone Stream Count Check Fail - API out of sync"
+ #define VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL \
+ "Zone GPH ID Check Fail - API out of sync"
+
+ #define VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL \
+ "No Xtalk using full array - Xtalk Extract Fail"
+ #define VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL \
+ "Xtalk does not meet required VL53L1_p_011 limit - Xtalk Extract Fail"
+
+ #define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL \
+ "Offset Cal - one of more stages with no valid samples - fatal"
+ #define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL \
+ "Offset Cal - one of more stages with no SPADS enables - fatal"
+ #define VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL \
+ "Zone Cal - one of more zones with no valid samples - fatal"
+
+ #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS \
+ "Ref SPAD Char - Not Enough Good SPADs"
+ #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH \
+ "Ref SPAD Char - Final Ref Rate too high"
+ #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW \
+ "Ref SPAD Char - Final Ref Rate too low"
+
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES \
+ "Offset Cal - Less than the requested number of valid samples"
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH \
+ "Offset Cal - Sigma estimate value too high - offset not stable"
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH \
+ "Offset Cal - Rate too high - in pile up"
+ #define VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW \
+ "Offset Cal - Insufficient SPADs - offset may not be stable"
+
+ #define VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES \
+ "Zone Cal - One or more zone with less than requested valid samples"
+ #define VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH \
+ "Zone Cal - One of more zones the VL53L1_p_011 estimate too high"
+ #define VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH \
+ "Zone Cal - One of more zones with rate too high - in pile up"
+
+ #define VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT \
+ "Xtalk - Gradient sample num = 0"
+ #define VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT \
+ "Xtalk - Gradient Sigma > Limit"
+ #define VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES \
+ "Xtalk - Some missing and invalid samples"
+
+ #define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD \
+ "Device Firmware too old"
+ #define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW \
+ "Device Firmware too new"
+ #define VL53L1_STRING_ERROR_UNIT_TEST_FAIL \
+ "Unit Test Fail"
+ #define VL53L1_STRING_ERROR_FILE_READ_FAIL \
+ "File Read Fail"
+ #define VL53L1_STRING_ERROR_FILE_WRITE_FAIL \
+ "File Write Fail"
+
+ #define VL53L1_STRING_ERROR_NOT_IMPLEMENTED \
+ "Not implemented error"
+ #define VL53L1_STRING_UNKNOW_ERROR_CODE \
+ "Unknown Error Code"
+
+#endif
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_char.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_char.h
new file mode 100644
index 000000000000..6c509aadc7f2
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_char.h
@@ -0,0 +1,176 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_HIST_CHAR_H_
+#define _VL53L1_HIST_CHAR_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_calib_config(
+ VL53L1_DEV Dev,
+ uint8_t vcsel_delay__a0,
+ uint8_t calib_1,
+ uint8_t calib_2,
+ uint8_t calib_3,
+ uint8_t calib_2__a0,
+ uint8_t spad_readout);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_hist_calib_pulse_delay(
+ VL53L1_DEV Dev,
+ uint8_t calib_delay);
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_disable_calib_pulse_delay(
+ VL53L1_DEV Dev);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_map.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_map.h
new file mode 100644
index 000000000000..d3703c1616b4
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_map.h
@@ -0,0 +1,156 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_HIST_MAP_H_
+#define _VL53L1_HIST_MAP_H_
+
+#include "vl53l1_register_map.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_0 \
+ VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_PULSE_WIDTH_NS
+
+#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_1 \
+ VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_AMBIENT_WIDTH_NS
+
+#define VL53L1_HISTOGRAM_CONFIG__OPCODE_SEQUENCE_2 \
+ VL53L1_SIGMA_ESTIMATOR__SIGMA_REF_MM
+
+#define VL53L1_HISTOGRAM_CONFIG__AMB_THRESH_HIGH \
+ VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS
+
+
+
+
+
+#define VL53L1_RESULT__HISTOGRAM_BIN_0_2 0x008E
+#define VL53L1_RESULT__HISTOGRAM_BIN_0_1 0x008F
+#define VL53L1_RESULT__HISTOGRAM_BIN_0_0 0x0090
+
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_2 0x00D3
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_1 0x00D4
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_0 0x00D5
+
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_0_MSB 0x00D9
+#define VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB 0x00DA
+
+
+
+
+#define VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX \
+ VL53L1_RESULT__INTERRUPT_STATUS
+#define VL53L1_HISTOGRAM_BIN_DATA_I2C_SIZE_BYTES \
+ (VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB - \
+ VL53L1_RESULT__INTERRUPT_STATUS + 1)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_structs.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_structs.h
new file mode 100644
index 000000000000..08aefabba7c8
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_hist_structs.h
@@ -0,0 +1,515 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_HIST_STRUCTS_H_
+#define _VL53L1_HIST_STRUCTS_H_
+
+#include "vl53l1_ll_device.h"
+#include "vl53l1_dmax_structs.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define VL53L1_MAX_BIN_SEQUENCE_LENGTH 6
+#define VL53L1_MAX_BIN_SEQUENCE_CODE 15
+#define VL53L1_HISTOGRAM_BUFFER_SIZE 24
+#define VL53L1_XTALK_HISTO_BINS 12
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t histogram_config__spad_array_selection;
+
+ uint8_t histogram_config__low_amb_even_bin_0_1;
+ uint8_t histogram_config__low_amb_even_bin_2_3;
+ uint8_t histogram_config__low_amb_even_bin_4_5;
+
+ uint8_t histogram_config__low_amb_odd_bin_0_1;
+ uint8_t histogram_config__low_amb_odd_bin_2_3;
+ uint8_t histogram_config__low_amb_odd_bin_4_5;
+
+ uint8_t histogram_config__mid_amb_even_bin_0_1;
+ uint8_t histogram_config__mid_amb_even_bin_2_3;
+ uint8_t histogram_config__mid_amb_even_bin_4_5;
+
+ uint8_t histogram_config__mid_amb_odd_bin_0_1;
+ uint8_t histogram_config__mid_amb_odd_bin_2;
+ uint8_t histogram_config__mid_amb_odd_bin_3_4;
+ uint8_t histogram_config__mid_amb_odd_bin_5;
+
+ uint8_t histogram_config__user_bin_offset;
+
+ uint8_t histogram_config__high_amb_even_bin_0_1;
+ uint8_t histogram_config__high_amb_even_bin_2_3;
+ uint8_t histogram_config__high_amb_even_bin_4_5;
+
+ uint8_t histogram_config__high_amb_odd_bin_0_1;
+ uint8_t histogram_config__high_amb_odd_bin_2_3;
+ uint8_t histogram_config__high_amb_odd_bin_4_5;
+
+ uint16_t histogram_config__amb_thresh_low;
+
+
+
+ uint16_t histogram_config__amb_thresh_high;
+
+
+
+
+} VL53L1_histogram_config_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_HistAlgoSelect hist_algo_select;
+
+
+
+ VL53L1_HistTargetOrder hist_target_order;
+
+
+
+
+
+ uint8_t filter_woi0;
+
+
+
+ uint8_t filter_woi1;
+
+
+
+
+ VL53L1_HistAmbEstMethod hist_amb_est_method;
+
+
+ uint8_t ambient_thresh_sigma0;
+
+
+
+ uint8_t ambient_thresh_sigma1;
+
+
+
+
+
+ uint16_t ambient_thresh_events_scaler;
+
+
+
+
+
+
+ int32_t min_ambient_thresh_events;
+
+
+ uint16_t noise_threshold;
+
+
+
+ int32_t signal_total_events_limit;
+
+
+ uint8_t sigma_estimator__sigma_ref_mm;
+
+
+ uint16_t sigma_thresh;
+
+
+ int16_t range_offset_mm;
+
+
+ uint16_t gain_factor;
+
+
+
+ uint8_t valid_phase_low;
+
+
+
+ uint8_t valid_phase_high;
+
+
+
+ uint8_t algo__consistency_check__phase_tolerance;
+
+
+
+ uint8_t algo__consistency_check__event_sigma;
+
+
+
+
+
+
+ uint16_t algo__consistency_check__event_min_spad_count;
+
+
+
+
+
+
+ uint16_t algo__consistency_check__min_max_tolerance;
+
+
+
+ uint8_t algo__crosstalk_compensation_enable;
+
+
+ uint32_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+ int16_t algo__crosstalk_detect_min_valid_range_mm;
+
+
+ int16_t algo__crosstalk_detect_max_valid_range_mm;
+
+
+ uint16_t algo__crosstalk_detect_max_valid_rate_kcps;
+
+
+
+ uint16_t algo__crosstalk_detect_max_sigma_mm;
+
+
+
+
+
+
+ uint8_t algo__crosstalk_detect_event_sigma;
+
+
+
+
+
+
+ uint16_t algo__crosstalk_detect_min_max_tolerance;
+
+
+
+
+} VL53L1_hist_post_process_config_t;
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+
+ uint8_t zone_id;
+
+
+ uint32_t time_stamp;
+
+
+
+ uint8_t VL53L1_p_022;
+
+
+ uint8_t VL53L1_p_023;
+
+
+ uint8_t VL53L1_p_024;
+
+
+
+ uint8_t number_of_ambient_bins;
+
+
+
+ uint8_t bin_seq[VL53L1_MAX_BIN_SEQUENCE_LENGTH];
+
+
+ uint8_t bin_rep[VL53L1_MAX_BIN_SEQUENCE_LENGTH];
+
+
+
+
+ int32_t bin_data[VL53L1_HISTOGRAM_BUFFER_SIZE];
+
+
+
+ uint8_t result__interrupt_status;
+
+
+ uint8_t result__range_status;
+
+
+ uint8_t result__report_status;
+
+
+ uint8_t result__stream_count;
+
+
+ uint16_t result__dss_actual_effective_spads;
+
+
+
+ uint16_t phasecal_result__reference_phase;
+
+
+ uint8_t phasecal_result__vcsel_start;
+
+
+ uint8_t cal_config__vcsel_start;
+
+
+ uint16_t vcsel_width;
+
+
+ uint8_t VL53L1_p_009;
+
+
+ uint16_t VL53L1_p_019;
+
+
+ uint32_t total_periods_elapsed;
+
+
+
+ uint32_t peak_duration_us;
+
+
+ uint32_t woi_duration_us;
+
+
+
+ int32_t min_bin_value;
+
+
+ int32_t max_bin_value;
+
+
+
+ uint16_t zero_distance_phase;
+
+
+ uint8_t number_of_ambient_samples;
+
+
+ int32_t ambient_events_sum;
+
+
+ int32_t VL53L1_p_004;
+
+
+
+ uint8_t roi_config__user_roi_centre_spad;
+
+
+ uint8_t roi_config__user_roi_requested_global_xy_size;
+
+
+
+} VL53L1_histogram_bin_data_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ uint8_t zone_id;
+
+
+ uint32_t time_stamp;
+
+
+
+ uint8_t VL53L1_p_022;
+
+
+ uint8_t VL53L1_p_023;
+
+
+ uint8_t VL53L1_p_024;
+
+
+ uint32_t bin_data[VL53L1_XTALK_HISTO_BINS];
+
+
+
+
+ uint16_t phasecal_result__reference_phase;
+
+
+ uint8_t phasecal_result__vcsel_start;
+
+
+ uint8_t cal_config__vcsel_start;
+
+
+ uint16_t vcsel_width;
+
+
+ uint16_t VL53L1_p_019;
+
+
+ uint16_t zero_distance_phase;
+
+
+
+} VL53L1_xtalk_histogram_shape_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_xtalk_histogram_shape_t xtalk_shape;
+
+
+ VL53L1_histogram_bin_data_t xtalk_hist_removed;
+
+} VL53L1_xtalk_histogram_data_t;
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_ll_def.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_ll_def.h
new file mode 100644
index 000000000000..4e6653cade3b
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_ll_def.h
@@ -0,0 +1,2781 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_LL_DEF_H_
+#define _VL53L1_LL_DEF_H_
+
+#include "vl53l1_error_codes.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_platform_user_config.h"
+#include "vl53l1_platform_user_defines.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_dmax_structs.h"
+#include "vl53l1_error_exceptions.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_MAJOR 1
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_MINOR 1
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_SUB 48
+
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_REVISION 12224
+
+#define VL53L1_LL_API_IMPLEMENTATION_VER_STRING "1.1.48.12224"
+
+
+
+#define VL53L1_FIRMWARE_VER_MINIMUM 398
+#define VL53L1_FIRMWARE_VER_MAXIMUM 400
+
+
+
+
+
+
+
+#define VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION 0xECAB0102
+
+
+
+
+
+
+#define VL53L1_LL_ZONE_CALIBRATION_DATA_STRUCT_VERSION 0xECAE0101
+
+
+
+
+
+
+
+
+#define VL53L1_BIN_REC_SIZE 6
+
+
+#define VL53L1_TIMING_CONF_A_B_SIZE 2
+
+
+#define VL53L1_FRAME_WAIT_EVENT 6
+
+
+
+
+
+#define VL53L1_MAX_XTALK_RANGE_RESULTS 5
+
+
+
+
+
+
+#define VL53L1_MAX_OFFSET_RANGE_RESULTS 3
+
+
+
+
+
+#define VL53L1_NVM_MAX_FMT_RANGE_DATA 4
+
+
+
+#define VL53L1_NVM_PEAK_RATE_MAP_SAMPLES 25
+
+
+#define VL53L1_NVM_PEAK_RATE_MAP_WIDTH 5
+
+
+#define VL53L1_NVM_PEAK_RATE_MAP_HEIGHT 5
+
+
+
+
+
+
+
+
+
+#define VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD ((VL53L1_Error) - 80)
+
+
+#define VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW ((VL53L1_Error) - 85)
+
+
+#define VL53L1_ERROR_UNIT_TEST_FAIL ((VL53L1_Error) - 90)
+
+
+#define VL53L1_ERROR_FILE_READ_FAIL ((VL53L1_Error) - 95)
+
+
+#define VL53L1_ERROR_FILE_WRITE_FAIL ((VL53L1_Error) - 96)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t ll_revision;
+
+ uint8_t ll_major;
+
+ uint8_t ll_minor;
+
+ uint8_t ll_build;
+
+} VL53L1_ll_version_t;
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t device_test_mode;
+
+ uint8_t VL53L1_p_009;
+
+ uint32_t timeout_us;
+
+ uint16_t target_count_rate_mcps;
+
+
+ uint16_t min_count_rate_limit_mcps;
+
+
+ uint16_t max_count_rate_limit_mcps;
+
+
+
+} VL53L1_refspadchar_config_t;
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+ uint32_t phasecal_config_timeout_us;
+
+
+ uint32_t mm_config_timeout_us;
+
+
+ uint32_t range_config_timeout_us;
+
+
+ uint8_t num_of_samples;
+
+
+ int16_t algo__crosstalk_extract_min_valid_range_mm;
+
+
+ int16_t algo__crosstalk_extract_max_valid_range_mm;
+
+
+ uint16_t algo__crosstalk_extract_max_valid_rate_kcps;
+
+
+
+ uint16_t algo__crosstalk_extract_max_sigma_mm;
+
+
+
+
+
+} VL53L1_xtalkextract_config_t;
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+
+ uint32_t phasecal_config_timeout_us;
+
+
+
+ uint32_t range_config_timeout_us;
+
+
+
+ uint32_t mm_config_timeout_us;
+
+
+
+
+ uint8_t pre_num_of_samples;
+
+
+
+ uint8_t mm1_num_of_samples;
+
+
+
+ uint8_t mm2_num_of_samples;
+
+
+
+
+} VL53L1_offsetcal_config_t;
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+
+ uint32_t phasecal_config_timeout_us;
+
+
+
+ uint32_t mm_config_timeout_us;
+
+
+
+ uint32_t range_config_timeout_us;
+
+
+
+ uint16_t phasecal_num_of_samples;
+
+
+
+ uint16_t zone_num_of_samples;
+
+
+
+
+} VL53L1_zonecal_config_t;
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceSscArray array_select;
+
+
+
+
+ uint8_t VL53L1_p_009;
+
+
+ uint8_t vcsel_start;
+
+
+ uint8_t vcsel_width;
+
+
+ uint32_t timeout_us;
+
+
+ uint16_t rate_limit_mcps;
+
+
+
+
+
+} VL53L1_ssc_config_t;
+
+
+
+
+
+
+typedef struct {
+
+
+ uint32_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+ uint32_t nvm_default__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t nvm_default__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t nvm_default__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+ uint8_t global_crosstalk_compensation_enable;
+
+
+ int16_t histogram_mode_crosstalk_margin_kcps;
+
+
+
+
+
+
+ int16_t lite_mode_crosstalk_margin_kcps;
+
+
+
+
+
+
+ uint8_t crosstalk_range_ignore_threshold_mult;
+
+
+ uint16_t crosstalk_range_ignore_threshold_rate_mcps;
+
+
+
+
+ int16_t algo__crosstalk_detect_min_valid_range_mm;
+
+
+ int16_t algo__crosstalk_detect_max_valid_range_mm;
+
+
+ uint16_t algo__crosstalk_detect_max_valid_rate_kcps;
+
+
+
+ uint16_t algo__crosstalk_detect_max_sigma_mm;
+
+
+
+
+
+
+} VL53L1_xtalk_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+ uint16_t tp_tuning_parm_version;
+
+
+
+ uint16_t tp_tuning_parm_key_table_version;
+
+
+
+
+ uint16_t tp_tuning_parm_lld_version;
+
+
+
+
+ uint8_t tp_init_phase_rtn_lite_long;
+
+
+
+
+ uint8_t tp_init_phase_rtn_lite_med;
+
+
+
+
+ uint8_t tp_init_phase_rtn_lite_short;
+
+
+
+
+ uint8_t tp_init_phase_ref_lite_long;
+
+
+
+
+ uint8_t tp_init_phase_ref_lite_med;
+
+
+
+
+ uint8_t tp_init_phase_ref_lite_short;
+
+
+
+
+
+ uint8_t tp_init_phase_rtn_hist_long;
+
+
+
+
+ uint8_t tp_init_phase_rtn_hist_med;
+
+
+
+
+ uint8_t tp_init_phase_rtn_hist_short;
+
+
+
+
+ uint8_t tp_init_phase_ref_hist_long;
+
+
+
+
+ uint8_t tp_init_phase_ref_hist_med;
+
+
+
+
+ uint8_t tp_init_phase_ref_hist_short;
+
+
+
+
+
+ uint8_t tp_consistency_lite_phase_tolerance;
+
+
+
+
+ uint8_t tp_phasecal_target;
+
+
+
+
+ uint16_t tp_cal_repeat_rate;
+
+
+
+
+ uint8_t tp_lite_min_clip;
+
+
+
+
+
+ uint16_t tp_lite_long_sigma_thresh_mm;
+
+
+
+
+ uint16_t tp_lite_med_sigma_thresh_mm;
+
+
+
+
+ uint16_t tp_lite_short_sigma_thresh_mm;
+
+
+
+
+
+ uint16_t tp_lite_long_min_count_rate_rtn_mcps;
+
+
+
+
+ uint16_t tp_lite_med_min_count_rate_rtn_mcps;
+
+
+
+
+ uint16_t tp_lite_short_min_count_rate_rtn_mcps;
+
+
+
+
+
+ uint8_t tp_lite_sigma_est_pulse_width_ns;
+
+
+
+ uint8_t tp_lite_sigma_est_amb_width_ns;
+
+
+
+ uint8_t tp_lite_sigma_ref_mm;
+
+
+
+ uint8_t tp_lite_seed_cfg;
+
+
+
+ uint8_t tp_timed_seed_cfg;
+
+
+
+
+ uint8_t tp_lite_quantifier;
+
+
+
+ uint8_t tp_lite_first_order_select;
+
+
+
+
+ uint16_t tp_dss_target_lite_mcps;
+
+
+
+ uint16_t tp_dss_target_histo_mcps;
+
+
+
+ uint16_t tp_dss_target_histo_mz_mcps;
+
+
+
+ uint16_t tp_dss_target_timed_mcps;
+
+
+
+ uint16_t tp_dss_target_very_short_mcps;
+
+
+
+
+ uint32_t tp_phasecal_timeout_lite_us;
+
+
+
+ uint32_t tp_phasecal_timeout_hist_long_us;
+
+
+
+ uint32_t tp_phasecal_timeout_hist_med_us;
+
+
+
+ uint32_t tp_phasecal_timeout_hist_short_us;
+
+
+
+
+ uint32_t tp_phasecal_timeout_mz_long_us;
+
+
+
+ uint32_t tp_phasecal_timeout_mz_med_us;
+
+
+
+ uint32_t tp_phasecal_timeout_mz_short_us;
+
+
+
+ uint32_t tp_phasecal_timeout_timed_us;
+
+
+
+
+ uint32_t tp_mm_timeout_lite_us;
+
+
+
+ uint32_t tp_mm_timeout_histo_us;
+
+
+
+ uint32_t tp_mm_timeout_mz_us;
+
+
+
+ uint32_t tp_mm_timeout_timed_us;
+
+
+
+ uint32_t tp_mm_timeout_lpa_us;
+
+
+
+
+ uint32_t tp_range_timeout_lite_us;
+
+
+
+ uint32_t tp_range_timeout_histo_us;
+
+
+
+ uint32_t tp_range_timeout_mz_us;
+
+
+
+ uint32_t tp_range_timeout_timed_us;
+
+
+
+ uint32_t tp_range_timeout_lpa_us;
+
+
+
+ uint32_t tp_phasecal_patch_power;
+
+
+
+ uint32_t tp_hist_merge;
+
+
+
+ uint32_t tp_reset_merge_threshold;
+
+
+
+ uint32_t tp_hist_merge_max_size;
+
+
+
+
+} VL53L1_tuning_parm_storage_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t x_centre;
+
+ uint8_t y_centre;
+
+
+} VL53L1_optical_centre_t;
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t x_centre;
+
+ uint8_t y_centre;
+
+ uint8_t width;
+
+ uint8_t height;
+
+
+} VL53L1_user_zone_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+ uint8_t active_zones;
+
+
+
+
+
+
+
+
+
+VL53L1_histogram_config_t multizone_hist_cfg;
+
+ VL53L1_user_zone_t user_zones[VL53L1_MAX_USER_ZONES];
+
+
+
+ uint8_t bin_config[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_config_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_GPIO_Interrupt_Mode intr_mode_distance;
+
+
+
+ VL53L1_GPIO_Interrupt_Mode intr_mode_rate;
+
+
+
+
+
+ uint8_t intr_new_measure_ready;
+
+
+
+ uint8_t intr_no_target;
+
+
+
+
+
+
+ uint8_t intr_combined_mode;
+
+
+
+
+
+
+
+
+
+
+ uint16_t threshold_distance_high;
+
+
+
+ uint16_t threshold_distance_low;
+
+
+
+ uint16_t threshold_rate_high;
+
+
+
+ uint16_t threshold_rate_low;
+
+} VL53L1_GPIO_interrupt_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+
+
+ uint8_t vhv_loop_bound;
+
+
+
+ uint8_t is_low_power_auto_mode;
+
+
+
+
+ uint8_t low_power_auto_range_count;
+
+
+
+ uint8_t saved_interrupt_config;
+
+
+
+ uint8_t saved_vhv_init;
+
+
+
+ uint8_t saved_vhv_timeout;
+
+
+
+ uint8_t first_run_phasecal_result;
+
+
+
+ uint32_t dss__total_rate_per_spad_mcps;
+
+
+
+ uint16_t dss__required_spads;
+
+} VL53L1_low_power_auto_data_t;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ uint8_t smudge_corr_enabled;
+
+
+
+ uint8_t smudge_corr_apply_enabled;
+
+
+
+ uint8_t smudge_corr_single_apply;
+
+
+
+
+
+
+ uint16_t smudge_margin;
+
+
+
+ uint32_t noise_margin;
+
+
+
+
+ uint32_t user_xtalk_offset_limit;
+
+
+
+
+ uint8_t user_xtalk_offset_limit_hi;
+
+
+
+
+ uint32_t sample_limit;
+
+
+
+
+ uint32_t single_xtalk_delta;
+
+
+
+
+ uint32_t averaged_xtalk_delta;
+
+
+
+
+ uint32_t smudge_corr_clip_limit;
+
+
+
+
+ uint32_t smudge_corr_ambient_threshold;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t scaler_calc_method;
+
+
+
+
+
+
+ int16_t x_gradient_scaler;
+
+
+
+
+
+
+ int16_t y_gradient_scaler;
+
+
+
+
+
+
+ uint8_t user_scaler_set;
+
+
+
+
+ uint32_t nodetect_ambient_threshold;
+
+
+
+
+ uint32_t nodetect_sample_limit;
+
+
+
+
+ uint32_t nodetect_xtalk_offset;
+
+
+
+
+ uint16_t nodetect_min_range_mm;
+
+
+} VL53L1_smudge_corrector_config_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ uint32_t current_samples;
+
+
+
+ uint32_t required_samples;
+
+
+
+ uint64_t accumulator;
+
+
+
+ uint32_t nodetect_counter;
+
+} VL53L1_smudge_corrector_internals_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+
+
+
+
+ uint8_t smudge_corr_valid;
+
+
+
+ uint8_t smudge_corr_clipped;
+
+
+
+
+
+
+
+
+ uint8_t single_xtalk_delta_flag;
+
+
+
+
+
+
+
+
+ uint8_t averaged_xtalk_delta_flag;
+
+
+
+ uint8_t sample_limit_exceeded_flag;
+
+
+
+
+
+
+ uint8_t gradient_zero_flag;
+
+
+
+ uint8_t new_xtalk_applied_flag;
+
+
+
+ uint32_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+} VL53L1_smudge_corrector_data_t;
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+
+ uint8_t range_id;
+
+
+ uint32_t time_stamp;
+
+
+ uint8_t VL53L1_p_015;
+
+
+ uint8_t VL53L1_p_022;
+
+
+ uint8_t VL53L1_p_025;
+
+
+ uint8_t VL53L1_p_026;
+
+
+ uint8_t VL53L1_p_016;
+
+
+ uint8_t VL53L1_p_027;
+
+
+
+ uint16_t width;
+
+
+ uint8_t VL53L1_p_030;
+
+
+
+
+ uint16_t fast_osc_frequency;
+
+
+ uint16_t zero_distance_phase;
+
+
+ uint16_t VL53L1_p_006;
+
+
+
+ uint32_t total_periods_elapsed;
+
+
+
+ uint32_t peak_duration_us;
+
+
+
+ uint32_t woi_duration_us;
+
+
+
+
+
+
+
+ uint32_t VL53L1_p_020;
+
+
+ uint32_t VL53L1_p_021;
+
+
+
+ int32_t VL53L1_p_013;
+
+
+
+
+
+
+
+ uint16_t peak_signal_count_rate_mcps;
+
+
+ uint16_t avg_signal_count_rate_mcps;
+
+
+ uint16_t ambient_count_rate_mcps;
+
+
+ uint16_t total_rate_per_spad_mcps;
+
+
+ uint32_t VL53L1_p_012;
+
+
+
+
+
+
+ uint16_t VL53L1_p_005;
+
+
+
+
+
+
+ uint16_t VL53L1_p_028;
+
+
+
+ uint16_t VL53L1_p_014;
+
+
+ uint16_t VL53L1_p_029;
+
+
+
+
+
+
+
+ int16_t min_range_mm;
+
+
+
+
+
+ int16_t median_range_mm;
+
+
+
+
+ int16_t max_range_mm;
+
+
+
+
+
+
+
+
+
+ uint8_t range_status;
+
+} VL53L1_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+ uint8_t zone_id;
+
+
+ uint8_t stream_count;
+
+
+
+ int16_t VL53L1_p_007[VL53L1_MAX_AMBIENT_DMAX_VALUES];
+
+
+
+
+ int16_t wrap_dmax_mm;
+
+
+
+ uint8_t device_status;
+
+
+
+ uint8_t max_results;
+
+
+
+ uint8_t active_results;
+
+
+ VL53L1_range_data_t VL53L1_p_002[VL53L1_MAX_RANGE_RESULTS];
+
+
+ VL53L1_range_data_t xmonitor;
+
+
+ VL53L1_smudge_corrector_data_t smudge_corrector_data;
+
+
+
+
+} VL53L1_range_results_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t no_of_samples;
+
+
+ uint32_t rate_per_spad_kcps_sum;
+
+
+
+ uint32_t rate_per_spad_kcps_avg;
+
+
+ int32_t signal_total_events_sum;
+
+
+
+ int32_t signal_total_events_avg;
+
+
+
+ uint32_t sigma_mm_sum;
+
+
+
+ uint32_t sigma_mm_avg;
+
+
+ uint32_t median_phase_sum;
+
+
+
+
+ uint32_t median_phase_avg;
+
+
+
+
+} VL53L1_xtalk_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_Error cal_status;
+
+
+ uint8_t num_of_samples_status;
+
+
+
+
+
+
+
+
+ uint8_t zero_samples_status;
+
+
+
+
+
+
+
+
+ uint8_t max_sigma_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t max_results;
+
+
+
+ uint8_t active_results;
+
+
+
+ VL53L1_xtalk_range_data_t
+ VL53L1_p_002[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+ VL53L1_histogram_bin_data_t central_histogram_sum;
+
+
+
+ VL53L1_histogram_bin_data_t central_histogram_avg;
+
+
+
+ uint8_t central_histogram__window_start;
+
+
+
+ uint8_t central_histogram__window_end;
+
+
+
+ VL53L1_histogram_bin_data_t
+ histogram_avg_1[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+
+ VL53L1_histogram_bin_data_t
+ histogram_avg_2[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+
+ VL53L1_histogram_bin_data_t
+ xtalk_avg[VL53L1_MAX_XTALK_RANGE_RESULTS];
+
+
+
+
+} VL53L1_xtalk_range_results_t;
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t preset_mode;
+
+
+ uint8_t dss_config__roi_mode_control;
+
+
+ uint16_t dss_config__manual_effective_spads_select;
+
+
+ uint8_t no_of_samples;
+
+
+ uint32_t effective_spads;
+
+
+ uint32_t peak_rate_mcps;
+
+
+ uint32_t VL53L1_p_005;
+
+
+ int32_t median_range_mm;
+
+
+
+ int32_t range_mm_offset;
+
+
+
+} VL53L1_offset_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ int16_t cal_distance_mm;
+
+
+ uint16_t cal_reflectance_pc;
+
+
+ VL53L1_Error cal_status;
+
+
+ uint8_t cal_report;
+
+
+ uint8_t max_results;
+
+
+
+ uint8_t active_results;
+
+
+ VL53L1_offset_range_data_t
+ VL53L1_p_002[VL53L1_MAX_OFFSET_RANGE_RESULTS];
+
+
+
+} VL53L1_offset_range_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t result__mm_inner_actual_effective_spads;
+
+
+ uint16_t result__mm_outer_actual_effective_spads;
+
+
+ uint16_t result__mm_inner_peak_signal_count_rtn_mcps;
+
+
+ uint16_t result__mm_outer_peak_signal_count_rtn_mcps;
+
+
+
+} VL53L1_additional_offset_cal_data_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+ int16_t short_a_offset_mm;
+ int16_t short_b_offset_mm;
+ int16_t medium_a_offset_mm;
+ int16_t medium_b_offset_mm;
+ int16_t long_a_offset_mm;
+ int16_t long_b_offset_mm;
+} VL53L1_per_vcsel_period_offset_cal_data_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t VL53L1_p_020;
+
+
+ uint32_t VL53L1_p_021;
+
+
+
+ uint16_t VL53L1_p_014;
+
+
+ uint8_t range_status;
+
+
+
+} VL53L1_object_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+ uint8_t zone_id;
+
+
+ uint8_t stream_count;
+
+
+ uint8_t max_objects;
+
+
+
+ uint8_t active_objects;
+
+
+ VL53L1_object_data_t VL53L1_p_002[VL53L1_MAX_RANGE_RESULTS];
+
+
+
+ VL53L1_object_data_t xmonitor;
+
+
+
+} VL53L1_zone_objects_t;
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_objects_t VL53L1_p_002[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_results_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState rd_device_state;
+
+
+
+ uint8_t number_of_ambient_bins;
+
+
+
+
+ uint16_t result__dss_actual_effective_spads;
+
+
+ uint8_t VL53L1_p_009;
+
+
+ uint32_t total_periods_elapsed;
+
+
+
+ int32_t ambient_events_sum;
+
+
+
+} VL53L1_zone_hist_info_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_hist_info_t VL53L1_p_002[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_histograms_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t no_of_samples;
+
+
+ uint32_t effective_spads;
+
+
+ uint32_t peak_rate_mcps;
+
+
+ uint32_t VL53L1_p_014;
+
+
+ uint32_t VL53L1_p_005;
+
+
+
+ int32_t median_range_mm;
+
+
+
+ int32_t range_mm_offset;
+
+
+
+} VL53L1_zone_calibration_data_t;
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t struct_version;
+
+
+ VL53L1_DevicePresetModes preset_mode;
+
+
+ VL53L1_DeviceZonePreset zone_preset;
+
+
+ int16_t cal_distance_mm;
+
+
+ uint16_t cal_reflectance_pc;
+
+
+ uint16_t phasecal_result__reference_phase;
+
+
+ uint16_t zero_distance_phase;
+
+
+ VL53L1_Error cal_status;
+
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_calibration_data_t VL53L1_p_002[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_calibration_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ int16_t cal_distance_mm;
+
+
+ uint16_t cal_reflectance_pc;
+
+
+ uint16_t max_samples;
+
+
+ uint16_t width;
+
+
+ uint16_t height;
+
+
+ uint16_t peak_rate_mcps[VL53L1_NVM_PEAK_RATE_MAP_SAMPLES];
+
+
+
+} VL53L1_cal_peak_rate_map_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t expected_stream_count;
+
+
+ uint8_t expected_gph_id;
+
+
+ uint8_t dss_mode;
+
+
+ uint16_t dss_requested_effective_spad_count;
+
+
+
+ uint8_t seed_cfg;
+
+
+ uint8_t initial_phase_seed;
+
+
+
+ uint8_t roi_config__user_roi_centre_spad;
+
+
+ uint8_t roi_config__user_roi_requested_global_xy_size;
+
+
+
+} VL53L1_zone_private_dyn_cfg_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t max_zones;
+
+
+
+ uint8_t active_zones;
+
+
+ VL53L1_zone_private_dyn_cfg_t VL53L1_p_002[VL53L1_MAX_USER_ZONES];
+
+
+
+} VL53L1_zone_private_dyn_cfgs_t;
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+ uint32_t algo__xtalk_cpo_HistoMerge_kcps[VL53L1_BIN_REC_SIZE];
+
+
+
+} VL53L1_xtalk_calibration_results_t;
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ uint32_t sample_count;
+
+
+
+ uint32_t pll_period_mm;
+
+
+
+ uint32_t peak_duration_us_sum;
+
+
+
+ uint32_t effective_spad_count_sum;
+
+
+
+ uint32_t zero_distance_phase_sum;
+
+
+
+ uint32_t zero_distance_phase_avg;
+
+
+
+ int32_t event_scaler_sum;
+
+
+
+ int32_t event_scaler_avg;
+
+
+
+ int32_t signal_events_sum;
+
+
+
+ uint32_t xtalk_rate_kcps_per_spad;
+
+
+
+ int32_t xtalk_start_phase;
+
+
+
+ int32_t xtalk_end_phase;
+
+
+
+ int32_t xtalk_width_phase;
+
+
+
+ int32_t target_start_phase;
+
+
+
+ int32_t target_end_phase;
+
+
+
+ int32_t target_width_phase;
+
+
+
+ int32_t effective_width;
+
+
+
+ int32_t event_scaler;
+
+
+
+ uint8_t VL53L1_p_015;
+
+
+
+ uint8_t VL53L1_p_016;
+
+
+
+ uint8_t target_start;
+
+
+
+ int32_t max_shape_value;
+
+
+
+ int32_t bin_data_sums[VL53L1_XTALK_HISTO_BINS];
+
+} VL53L1_hist_xtalk_extract_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t standard_ranging_gain_factor;
+
+
+ uint16_t histogram_ranging_gain_factor;
+
+
+
+} VL53L1_gain_calibration_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DeviceState cfg_device_state;
+
+
+ uint8_t cfg_stream_count;
+
+
+
+ uint8_t cfg_internal_stream_count;
+
+
+ uint8_t cfg_internal_stream_count_val;
+
+
+ uint8_t cfg_gph_id;
+
+
+ uint8_t cfg_timing_status;
+
+
+ uint8_t cfg_zone_id;
+
+
+
+ VL53L1_DeviceState rd_device_state;
+
+
+ uint8_t rd_stream_count;
+
+
+ uint8_t rd_internal_stream_count;
+
+
+ uint8_t rd_internal_stream_count_val;
+
+
+ uint8_t rd_gph_id;
+
+
+ uint8_t rd_timing_status;
+
+
+ uint8_t rd_zone_id;
+
+
+
+} VL53L1_ll_driver_state_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t wait_method;
+
+
+ VL53L1_DevicePresetModes preset_mode;
+
+
+ VL53L1_DeviceZonePreset zone_preset;
+
+
+ VL53L1_DeviceMeasurementModes measurement_mode;
+
+
+ VL53L1_OffsetCalibrationMode offset_calibration_mode;
+
+
+ VL53L1_OffsetCorrectionMode offset_correction_mode;
+
+
+ VL53L1_DeviceDmaxMode dmax_mode;
+
+
+ uint32_t phasecal_config_timeout_us;
+
+
+ uint32_t mm_config_timeout_us;
+
+
+ uint32_t range_config_timeout_us;
+
+
+ uint32_t inter_measurement_period_ms;
+
+
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+
+ uint32_t fw_ready_poll_duration_ms;
+
+
+ uint8_t fw_ready;
+
+
+ uint8_t debug_mode;
+
+
+
+
+
+ VL53L1_ll_version_t version;
+
+
+
+ VL53L1_ll_driver_state_t ll_state;
+
+
+
+ VL53L1_GPIO_interrupt_config_t gpio_interrupt_config;
+
+
+
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
+ VL53L1_additional_offset_cal_data_t add_off_cal_data;
+ VL53L1_dmax_calibration_data_t fmt_dmax_cal;
+ VL53L1_dmax_calibration_data_t cust_dmax_cal;
+ VL53L1_gain_calibration_data_t gain_cal;
+ VL53L1_user_zone_t mm_roi;
+ VL53L1_optical_centre_t optical_centre;
+ VL53L1_zone_config_t zone_cfg;
+
+
+
+ VL53L1_tuning_parm_storage_t tuning_parms;
+
+
+
+ uint8_t rtn_good_spads[VL53L1_RTN_SPAD_BUFFER_SIZE];
+
+
+
+ VL53L1_refspadchar_config_t refspadchar;
+ VL53L1_ssc_config_t ssc_cfg;
+ VL53L1_hist_post_process_config_t histpostprocess;
+ VL53L1_hist_gen3_dmax_config_t dmax_cfg;
+ VL53L1_xtalkextract_config_t xtalk_extract_cfg;
+ VL53L1_xtalk_config_t xtalk_cfg;
+ VL53L1_offsetcal_config_t offsetcal_cfg;
+ VL53L1_zonecal_config_t zonecal_cfg;
+
+
+
+ VL53L1_static_nvm_managed_t stat_nvm;
+ VL53L1_histogram_config_t hist_cfg;
+ VL53L1_static_config_t stat_cfg;
+ VL53L1_general_config_t gen_cfg;
+ VL53L1_timing_config_t tim_cfg;
+ VL53L1_dynamic_config_t dyn_cfg;
+ VL53L1_system_control_t sys_ctrl;
+ VL53L1_system_results_t sys_results;
+ VL53L1_nvm_copy_data_t nvm_copy_data;
+
+
+
+ VL53L1_histogram_bin_data_t hist_data;
+ VL53L1_histogram_bin_data_t hist_xtalk;
+
+
+
+ VL53L1_xtalk_histogram_data_t xtalk_shapes;
+ VL53L1_xtalk_range_results_t xtalk_results;
+ VL53L1_xtalk_calibration_results_t xtalk_cal;
+ VL53L1_hist_xtalk_extract_data_t xtalk_extract;
+
+
+
+ VL53L1_offset_range_results_t offset_results;
+
+
+
+ VL53L1_core_results_t core_results;
+ VL53L1_debug_results_t dbg_results;
+
+ VL53L1_smudge_corrector_config_t smudge_correct_config;
+
+
+ VL53L1_smudge_corrector_internals_t smudge_corrector_internals;
+
+
+
+
+
+
+
+ VL53L1_low_power_auto_data_t low_power_auto_data;
+
+
+
+#ifdef PAL_EXTENDED
+
+
+ VL53L1_patch_results_t patch_results;
+ VL53L1_shadow_core_results_t shadow_core_results;
+ VL53L1_shadow_system_results_t shadow_sys_results;
+ VL53L1_prev_shadow_core_results_t prev_shadow_core_results;
+ VL53L1_prev_shadow_system_results_t prev_shadow_sys_results;
+#endif
+ uint8_t wArea1[1536];
+ uint8_t wArea2[512];
+ VL53L1_per_vcsel_period_offset_cal_data_t per_vcsel_cal_data;
+
+
+ uint8_t bin_rec_pos;
+
+
+ uint8_t pos_before_next_recom;
+
+
+ int32_t multi_bins_rec[VL53L1_BIN_REC_SIZE]
+ [VL53L1_TIMING_CONF_A_B_SIZE][VL53L1_HISTOGRAM_BUFFER_SIZE];
+
+
+
+} VL53L1_LLDriverData_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+
+
+ VL53L1_range_results_t range_results;
+
+
+
+ VL53L1_zone_private_dyn_cfgs_t zone_dyn_cfgs;
+
+
+
+ VL53L1_zone_results_t zone_results;
+ VL53L1_zone_histograms_t zone_hists;
+ VL53L1_zone_calibration_results_t zone_cal;
+
+} VL53L1_LLDriverResults_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint32_t struct_version;
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_dmax_calibration_data_t fmt_dmax_cal;
+ VL53L1_dmax_calibration_data_t cust_dmax_cal;
+ VL53L1_additional_offset_cal_data_t add_off_cal_data;
+ VL53L1_optical_centre_t optical_centre;
+ VL53L1_xtalk_histogram_data_t xtalkhisto;
+ VL53L1_gain_calibration_data_t gain_cal;
+ VL53L1_cal_peak_rate_map_t cal_peak_rate_map;
+ VL53L1_per_vcsel_period_offset_cal_data_t per_vcsel_cal_data;
+
+} VL53L1_calibration_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_xtalkextract_config_t xtalk_extract_cfg;
+ VL53L1_xtalk_config_t xtalk_cfg;
+ VL53L1_histogram_bin_data_t hist_data;
+ VL53L1_xtalk_histogram_data_t xtalk_shapes;
+ VL53L1_xtalk_range_results_t xtalk_results;
+
+} VL53L1_xtalk_debug_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_customer_nvm_managed_t customer;
+ VL53L1_dmax_calibration_data_t fmt_dmax_cal;
+ VL53L1_dmax_calibration_data_t cust_dmax_cal;
+ VL53L1_additional_offset_cal_data_t add_off_cal_data;
+ VL53L1_offset_range_results_t offset_results;
+
+} VL53L1_offset_debug_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint16_t vl53l1_tuningparm_version;
+ uint16_t vl53l1_tuningparm_key_table_version;
+ uint16_t vl53l1_tuningparm_lld_version;
+ uint8_t vl53l1_tuningparm_hist_algo_select;
+ uint8_t vl53l1_tuningparm_hist_target_order;
+ uint8_t vl53l1_tuningparm_hist_filter_woi_0;
+ uint8_t vl53l1_tuningparm_hist_filter_woi_1;
+ uint8_t vl53l1_tuningparm_hist_amb_est_method;
+ uint8_t vl53l1_tuningparm_hist_amb_thresh_sigma_0;
+ uint8_t vl53l1_tuningparm_hist_amb_thresh_sigma_1;
+ int32_t vl53l1_tuningparm_hist_min_amb_thresh_events;
+ uint16_t vl53l1_tuningparm_hist_amb_events_scaler;
+ uint16_t vl53l1_tuningparm_hist_noise_threshold;
+ int32_t vl53l1_tuningparm_hist_signal_total_events_limit;
+ uint8_t vl53l1_tuningparm_hist_sigma_est_ref_mm;
+ uint16_t vl53l1_tuningparm_hist_sigma_thresh_mm;
+ uint16_t vl53l1_tuningparm_hist_gain_factor;
+ uint8_t vl53l1_tuningparm_consistency_hist_phase_tolerance;
+ uint16_t vl53l1_tuningparm_consistency_hist_min_max_tolerance_mm;
+ uint8_t vl53l1_tuningparm_consistency_hist_event_sigma;
+ uint16_t vl53l1_tuningparm_consistency_hist_event_sigma_min_spad_limit;
+ uint8_t vl53l1_tuningparm_initial_phase_rtn_histo_long_range;
+ uint8_t vl53l1_tuningparm_initial_phase_rtn_histo_med_range;
+ uint8_t vl53l1_tuningparm_initial_phase_rtn_histo_short_range;
+ uint8_t vl53l1_tuningparm_initial_phase_ref_histo_long_range;
+ uint8_t vl53l1_tuningparm_initial_phase_ref_histo_med_range;
+ uint8_t vl53l1_tuningparm_initial_phase_ref_histo_short_range;
+ int16_t vl53l1_tuningparm_xtalk_detect_min_valid_range_mm;
+ int16_t vl53l1_tuningparm_xtalk_detect_max_valid_range_mm;
+ uint16_t vl53l1_tuningparm_xtalk_detect_max_sigma_mm;
+ uint16_t vl53l1_tuningparm_xtalk_detect_min_max_tolerance;
+ uint16_t vl53l1_tuningparm_xtalk_detect_max_valid_rate_kcps;
+ uint8_t vl53l1_tuningparm_xtalk_detect_event_sigma;
+ int16_t vl53l1_tuningparm_hist_xtalk_margin_kcps;
+ uint8_t vl53l1_tuningparm_consistency_lite_phase_tolerance;
+ uint8_t vl53l1_tuningparm_phasecal_target;
+ uint16_t vl53l1_tuningparm_lite_cal_repeat_rate;
+ uint16_t vl53l1_tuningparm_lite_ranging_gain_factor;
+ uint8_t vl53l1_tuningparm_lite_min_clip_mm;
+ uint16_t vl53l1_tuningparm_lite_long_sigma_thresh_mm;
+ uint16_t vl53l1_tuningparm_lite_med_sigma_thresh_mm;
+ uint16_t vl53l1_tuningparm_lite_short_sigma_thresh_mm;
+ uint16_t vl53l1_tuningparm_lite_long_min_count_rate_rtn_mcps;
+ uint16_t vl53l1_tuningparm_lite_med_min_count_rate_rtn_mcps;
+ uint16_t vl53l1_tuningparm_lite_short_min_count_rate_rtn_mcps;
+ uint8_t vl53l1_tuningparm_lite_sigma_est_pulse_width;
+ uint8_t vl53l1_tuningparm_lite_sigma_est_amb_width_ns;
+ uint8_t vl53l1_tuningparm_lite_sigma_ref_mm;
+ uint8_t vl53l1_tuningparm_lite_rit_mult;
+ uint8_t vl53l1_tuningparm_lite_seed_config;
+ uint8_t vl53l1_tuningparm_lite_quantifier;
+ uint8_t vl53l1_tuningparm_lite_first_order_select;
+ int16_t vl53l1_tuningparm_lite_xtalk_margin_kcps;
+ uint8_t vl53l1_tuningparm_initial_phase_rtn_lite_long_range;
+ uint8_t vl53l1_tuningparm_initial_phase_rtn_lite_med_range;
+ uint8_t vl53l1_tuningparm_initial_phase_rtn_lite_short_range;
+ uint8_t vl53l1_tuningparm_initial_phase_ref_lite_long_range;
+ uint8_t vl53l1_tuningparm_initial_phase_ref_lite_med_range;
+ uint8_t vl53l1_tuningparm_initial_phase_ref_lite_short_range;
+ uint8_t vl53l1_tuningparm_timed_seed_config;
+ uint8_t vl53l1_tuningparm_dmax_cfg_signal_thresh_sigma;
+ uint16_t vl53l1_tuningparm_dmax_cfg_reflectance_array_0;
+ uint16_t vl53l1_tuningparm_dmax_cfg_reflectance_array_1;
+ uint16_t vl53l1_tuningparm_dmax_cfg_reflectance_array_2;
+ uint16_t vl53l1_tuningparm_dmax_cfg_reflectance_array_3;
+ uint16_t vl53l1_tuningparm_dmax_cfg_reflectance_array_4;
+ uint8_t vl53l1_tuningparm_vhv_loopbound;
+ uint8_t vl53l1_tuningparm_refspadchar_device_test_mode;
+ uint8_t vl53l1_tuningparm_refspadchar_vcsel_period;
+ uint32_t vl53l1_tuningparm_refspadchar_phasecal_timeout_us;
+ uint16_t vl53l1_tuningparm_refspadchar_target_count_rate_mcps;
+ uint16_t vl53l1_tuningparm_refspadchar_min_countrate_limit_mcps;
+ uint16_t vl53l1_tuningparm_refspadchar_max_countrate_limit_mcps;
+ uint8_t vl53l1_tuningparm_xtalk_extract_num_of_samples;
+ int16_t vl53l1_tuningparm_xtalk_extract_min_filter_thresh_mm;
+ int16_t vl53l1_tuningparm_xtalk_extract_max_filter_thresh_mm;
+ uint16_t vl53l1_tuningparm_xtalk_extract_dss_rate_mcps;
+ uint32_t vl53l1_tuningparm_xtalk_extract_phasecal_timeout_us;
+ uint16_t vl53l1_tuningparm_xtalk_extract_max_valid_rate_kcps;
+ uint16_t vl53l1_tuningparm_xtalk_extract_sigma_threshold_mm;
+ uint32_t vl53l1_tuningparm_xtalk_extract_dss_timeout_us;
+ uint32_t vl53l1_tuningparm_xtalk_extract_bin_timeout_us;
+ uint16_t vl53l1_tuningparm_offset_cal_dss_rate_mcps;
+ uint32_t vl53l1_tuningparm_offset_cal_phasecal_timeout_us;
+ uint32_t vl53l1_tuningparm_offset_cal_mm_timeout_us;
+ uint32_t vl53l1_tuningparm_offset_cal_range_timeout_us;
+ uint8_t vl53l1_tuningparm_offset_cal_pre_samples;
+ uint8_t vl53l1_tuningparm_offset_cal_mm1_samples;
+ uint8_t vl53l1_tuningparm_offset_cal_mm2_samples;
+ uint16_t vl53l1_tuningparm_zone_cal_dss_rate_mcps;
+ uint32_t vl53l1_tuningparm_zone_cal_phasecal_timeout_us;
+ uint32_t vl53l1_tuningparm_zone_cal_dss_timeout_us;
+ uint16_t vl53l1_tuningparm_zone_cal_phasecal_num_samples;
+ uint32_t vl53l1_tuningparm_zone_cal_range_timeout_us;
+ uint16_t vl53l1_tuningparm_zone_cal_zone_num_samples;
+ uint8_t vl53l1_tuningparm_spadmap_vcsel_period;
+ uint8_t vl53l1_tuningparm_spadmap_vcsel_start;
+ uint16_t vl53l1_tuningparm_spadmap_rate_limit_mcps;
+ uint16_t vl53l1_tuningparm_lite_dss_config_target_total_rate_mcps;
+ uint16_t vl53l1_tuningparm_ranging_dss_config_target_total_rate_mcps;
+ uint16_t vl53l1_tuningparm_mz_dss_config_target_total_rate_mcps;
+ uint16_t vl53l1_tuningparm_timed_dss_config_target_total_rate_mcps;
+ uint32_t vl53l1_tuningparm_lite_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_ranging_long_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_ranging_med_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_ranging_short_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_mz_long_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_mz_med_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_mz_short_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_timed_phasecal_config_timeout_us;
+ uint32_t vl53l1_tuningparm_lite_mm_config_timeout_us;
+ uint32_t vl53l1_tuningparm_ranging_mm_config_timeout_us;
+ uint32_t vl53l1_tuningparm_mz_mm_config_timeout_us;
+ uint32_t vl53l1_tuningparm_timed_mm_config_timeout_us;
+ uint32_t vl53l1_tuningparm_lite_range_config_timeout_us;
+ uint32_t vl53l1_tuningparm_ranging_range_config_timeout_us;
+ uint32_t vl53l1_tuningparm_mz_range_config_timeout_us;
+ uint32_t vl53l1_tuningparm_timed_range_config_timeout_us;
+ uint16_t vl53l1_tuningparm_dynxtalk_smudge_margin;
+ uint32_t vl53l1_tuningparm_dynxtalk_noise_margin;
+ uint32_t vl53l1_tuningparm_dynxtalk_xtalk_offset_limit;
+ uint8_t vl53l1_tuningparm_dynxtalk_xtalk_offset_limit_hi;
+ uint32_t vl53l1_tuningparm_dynxtalk_sample_limit;
+ uint32_t vl53l1_tuningparm_dynxtalk_single_xtalk_delta;
+ uint32_t vl53l1_tuningparm_dynxtalk_averaged_xtalk_delta;
+ uint32_t vl53l1_tuningparm_dynxtalk_clip_limit;
+ uint8_t vl53l1_tuningparm_dynxtalk_scaler_calc_method;
+ int16_t vl53l1_tuningparm_dynxtalk_xgradient_scaler;
+ int16_t vl53l1_tuningparm_dynxtalk_ygradient_scaler;
+ uint8_t vl53l1_tuningparm_dynxtalk_user_scaler_set;
+ uint8_t vl53l1_tuningparm_dynxtalk_smudge_cor_single_apply;
+ uint32_t vl53l1_tuningparm_dynxtalk_xtalk_amb_threshold;
+ uint32_t vl53l1_tuningparm_dynxtalk_nodetect_amb_threshold_kcps;
+ uint32_t vl53l1_tuningparm_dynxtalk_nodetect_sample_limit;
+ uint32_t vl53l1_tuningparm_dynxtalk_nodetect_xtalk_offset_kcps;
+ uint16_t vl53l1_tuningparm_dynxtalk_nodetect_min_range_mm;
+ uint8_t vl53l1_tuningparm_lowpowerauto_vhv_loop_bound;
+ uint32_t vl53l1_tuningparm_lowpowerauto_mm_config_timeout_us;
+ uint32_t vl53l1_tuningparm_lowpowerauto_range_config_timeout_us;
+ uint16_t vl53l1_tuningparm_very_short_dss_rate_mcps;
+ uint32_t vl53l1_tuningparm_phasecal_patch_power;
+} VL53L1_tuning_parameters_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t target_reflectance_for_dmax[VL53L1_MAX_AMBIENT_DMAX_VALUES];
+
+} VL53L1_dmax_reflectance_array_t;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t spad_type;
+
+
+ uint16_t VL53L1_p_023;
+
+
+ uint16_t rate_data[VL53L1_NO_OF_SPAD_ENABLES];
+
+
+ uint16_t no_of_values;
+
+
+ uint8_t fractional_bits;
+
+
+ uint8_t error_status;
+
+
+
+} VL53L1_spad_rate_data_t;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ VL53L1_DevicePresetModes preset_mode;
+
+
+ VL53L1_DeviceZonePreset zone_preset;
+
+
+ VL53L1_DeviceMeasurementModes measurement_mode;
+
+
+ VL53L1_OffsetCalibrationMode offset_calibration_mode;
+
+
+ VL53L1_OffsetCorrectionMode offset_correction_mode;
+
+
+ VL53L1_DeviceDmaxMode dmax_mode;
+
+
+
+ uint32_t phasecal_config_timeout_us;
+
+
+ uint32_t mm_config_timeout_us;
+
+
+ uint32_t range_config_timeout_us;
+
+
+ uint32_t inter_measurement_period_ms;
+
+
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+
+ VL53L1_histogram_bin_data_t VL53L1_p_010;
+
+
+
+} VL53L1_additional_data_t;
+
+
+
+
+
+
+
+
+
+
+#define SUPPRESS_UNUSED_WARNING(x) \
+ ((void) (x))
+
+
+#define IGNORE_STATUS(__FUNCTION_ID__, __ERROR_STATUS_CHECK__, __STATUS__) \
+ do { \
+ DISABLE_WARNINGS(); \
+ if (__FUNCTION_ID__) { \
+ if (__STATUS__ == __ERROR_STATUS_CHECK__) { \
+ __STATUS__ = VL53L1_ERROR_NONE; \
+ WARN_OVERRIDE_STATUS(__FUNCTION_ID__); \
+ } \
+ } \
+ ENABLE_WARNINGS(); \
+ } \
+ while (0)
+
+#define VL53L1_COPYSTRING(str, ...) \
+ (strncpy(str, ##__VA_ARGS__, VL53L1_MAX_STRING_LENGTH-1))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_ll_device.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_ll_device.h
new file mode 100644
index 000000000000..587efb61b87c
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_ll_device.h
@@ -0,0 +1,1296 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_LL_DEVICE_H_
+#define _VL53L1_LL_DEVICE_H_
+
+#include "vl53l1_types.h"
+#include "vl53l1_platform_user_config.h"
+
+#define VL53L1_I2C 0x01
+#define VL53L1_SPI 0x00
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_WaitMethod;
+
+#define VL53L1_WAIT_METHOD_BLOCKING ((VL53L1_WaitMethod) 0)
+#define VL53L1_WAIT_METHOD_NON_BLOCKING ((VL53L1_WaitMethod) 1)
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceState;
+
+#define VL53L1_DEVICESTATE_POWERDOWN ((VL53L1_DeviceState) 0)
+#define VL53L1_DEVICESTATE_HW_STANDBY ((VL53L1_DeviceState) 1)
+#define VL53L1_DEVICESTATE_FW_COLDBOOT ((VL53L1_DeviceState) 2)
+#define VL53L1_DEVICESTATE_SW_STANDBY ((VL53L1_DeviceState) 3)
+#define VL53L1_DEVICESTATE_RANGING_DSS_AUTO ((VL53L1_DeviceState) 4)
+#define VL53L1_DEVICESTATE_RANGING_DSS_MANUAL ((VL53L1_DeviceState) 5)
+#define VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC ((VL53L1_DeviceState) 6)
+#define VL53L1_DEVICESTATE_RANGING_GATHER_DATA ((VL53L1_DeviceState) 7)
+#define VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA ((VL53L1_DeviceState) 8)
+
+#define VL53L1_DEVICESTATE_UNKNOWN ((VL53L1_DeviceState) 98)
+#define VL53L1_DEVICESTATE_ERROR ((VL53L1_DeviceState) 99)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceZonePreset;
+
+#define VL53L1_DEVICEZONEPRESET_NONE \
+ ((VL53L1_DeviceZonePreset) 0)
+
+#define VL53L1_DEVICEZONEPRESET_XTALK_PLANAR \
+ ((VL53L1_DeviceZonePreset) 1)
+#define VL53L1_DEVICEZONEPRESET_1X1_SIZE_16X16 \
+ ((VL53L1_DeviceZonePreset) 2)
+#define VL53L1_DEVICEZONEPRESET_1X2_SIZE_16X8 \
+ ((VL53L1_DeviceZonePreset) 3)
+#define VL53L1_DEVICEZONEPRESET_2X1_SIZE_8X16 \
+ ((VL53L1_DeviceZonePreset) 4)
+#define VL53L1_DEVICEZONEPRESET_2X2_SIZE_8X8 \
+ ((VL53L1_DeviceZonePreset) 5)
+#define VL53L1_DEVICEZONEPRESET_3X3_SIZE_5X5 \
+ ((VL53L1_DeviceZonePreset) 6)
+#define VL53L1_DEVICEZONEPRESET_4X4_SIZE_4X4 \
+ ((VL53L1_DeviceZonePreset) 7)
+#define VL53L1_DEVICEZONEPRESET_5X5_SIZE_4X4 \
+ ((VL53L1_DeviceZonePreset) 8)
+#define VL53L1_DEVICEZONEPRESET_11X11_SIZE_5X5 \
+ ((VL53L1_DeviceZonePreset) 9)
+#define VL53L1_DEVICEZONEPRESET_13X13_SIZE_4X4 \
+ ((VL53L1_DeviceZonePreset) 10)
+
+#define VL53L1_DEVICEZONEPRESET_1X1_SIZE_4X4_POS_8X8 \
+ ((VL53L1_DeviceZonePreset) 11)
+
+#define VL53L1_DEVICEZONEPRESET_CUSTOM \
+ ((VL53L1_DeviceZonePreset) 255)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DevicePresetModes;
+
+#define VL53L1_DEVICEPRESETMODE_NONE \
+ ((VL53L1_DevicePresetModes) 0)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING \
+ ((VL53L1_DevicePresetModes) 1)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE \
+ ((VL53L1_DevicePresetModes) 2)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE \
+ ((VL53L1_DevicePresetModes) 3)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL \
+ ((VL53L1_DevicePresetModes) 4)
+#define VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL \
+ ((VL53L1_DevicePresetModes) 5)
+#define VL53L1_DEVICEPRESETMODE_TIMED_RANGING \
+ ((VL53L1_DevicePresetModes) 6)
+#define VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE \
+ ((VL53L1_DevicePresetModes) 7)
+#define VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE \
+ ((VL53L1_DevicePresetModes) 8)
+#define VL53L1_DEVICEPRESETMODE_NEAR_FARRANGING \
+ ((VL53L1_DevicePresetModes) 9)
+#define VL53L1_DEVICEPRESETMODE_QUADRANT_RANGING \
+ ((VL53L1_DevicePresetModes) 10)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING \
+ ((VL53L1_DevicePresetModes) 11)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_SHORT_TIMING \
+ ((VL53L1_DevicePresetModes) 12)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_CHARACTERISATION \
+ ((VL53L1_DevicePresetModes) 13)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR \
+ ((VL53L1_DevicePresetModes) 14)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM1 \
+ ((VL53L1_DevicePresetModes) 15)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM2 \
+ ((VL53L1_DevicePresetModes) 16)
+#define VL53L1_DEVICEPRESETMODE_OLT \
+ ((VL53L1_DevicePresetModes) 17)
+#define VL53L1_DEVICEPRESETMODE_SINGLESHOT_RANGING \
+ ((VL53L1_DevicePresetModes) 18)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_REF_ARRAY \
+ ((VL53L1_DevicePresetModes) 19)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM1 \
+ ((VL53L1_DevicePresetModes) 20)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM2 \
+ ((VL53L1_DevicePresetModes) 21)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL \
+ ((VL53L1_DevicePresetModes) 22)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL \
+ ((VL53L1_DevicePresetModes) 23)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE \
+ ((VL53L1_DevicePresetModes) 24)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE \
+ ((VL53L1_DevicePresetModes) 25)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE \
+ ((VL53L1_DevicePresetModes) 26)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE \
+ ((VL53L1_DevicePresetModes) 27)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM1 \
+ ((VL53L1_DevicePresetModes) 28)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM2 \
+ ((VL53L1_DevicePresetModes) 29)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE \
+ ((VL53L1_DevicePresetModes) 30)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM1 \
+ ((VL53L1_DevicePresetModes) 31)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM2 \
+ ((VL53L1_DevicePresetModes) 32)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE \
+ ((VL53L1_DevicePresetModes) 33)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM1 \
+ ((VL53L1_DevicePresetModes) 34)
+#define VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM2 \
+ ((VL53L1_DevicePresetModes) 35)
+#define VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_SHORT_RANGE \
+ ((VL53L1_DevicePresetModes) 36)
+#define VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_MEDIUM_RANGE \
+ ((VL53L1_DevicePresetModes) 37)
+#define VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_LONG_RANGE \
+ ((VL53L1_DevicePresetModes) 38)
+#define VL53L1_DEVICEPRESETMODE_SPECIAL_HISTOGRAM_SHORT_RANGE \
+ ((VL53L1_DevicePresetModes) 39)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceMeasurementModes;
+
+#define VL53L1_DEVICEMEASUREMENTMODE_STOP \
+ ((VL53L1_DeviceMeasurementModes) 0x00)
+#define VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT \
+ ((VL53L1_DeviceMeasurementModes) 0x10)
+#define VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK \
+ ((VL53L1_DeviceMeasurementModes) 0x20)
+#define VL53L1_DEVICEMEASUREMENTMODE_TIMED \
+ ((VL53L1_DeviceMeasurementModes) 0x40)
+#define VL53L1_DEVICEMEASUREMENTMODE_ABORT \
+ ((VL53L1_DeviceMeasurementModes) 0x80)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_OffsetCalibrationMode;
+
+#define VL53L1_OFFSETCALIBRATIONMODE__NONE \
+ ((VL53L1_OffsetCalibrationMode) 0)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD \
+ ((VL53L1_OffsetCalibrationMode) 1)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM \
+ ((VL53L1_OffsetCalibrationMode) 2)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY \
+ ((VL53L1_OffsetCalibrationMode) 3)
+#define VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY \
+ ((VL53L1_OffsetCalibrationMode) 4)
+#define VL53L1_OFFSETCALIBRATIONMODE__PER_ZONE \
+ ((VL53L1_OffsetCalibrationMode) 5)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_OffsetCorrectionMode;
+
+#define VL53L1_OFFSETCORRECTIONMODE__NONE \
+ ((VL53L1_OffsetCorrectionMode) 0)
+#define VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS \
+ ((VL53L1_OffsetCorrectionMode) 1)
+#define VL53L1_OFFSETCORRECTIONMODE__PER_ZONE_OFFSETS \
+ ((VL53L1_OffsetCorrectionMode) 2)
+#define VL53L1_OFFSETCORRECTIONMODE__PER_VCSEL_OFFSETS \
+ ((VL53L1_OffsetCorrectionMode) 3)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceDmaxMode;
+
+#define VL53L1_DEVICEDMAXMODE__NONE \
+ ((VL53L1_DeviceDmaxMode) 0)
+#define VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA \
+ ((VL53L1_DeviceDmaxMode) 1)
+#define VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA \
+ ((VL53L1_DeviceDmaxMode) 2)
+#define VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA \
+ ((VL53L1_DeviceDmaxMode) 3)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceSequenceConfig;
+
+#define VL53L1_DEVICESEQUENCECONFIG_VHV \
+ ((VL53L1_DeviceSequenceConfig) 0)
+#define VL53L1_DEVICESEQUENCECONFIG_PHASECAL \
+ ((VL53L1_DeviceSequenceConfig) 1)
+#define VL53L1_DEVICESEQUENCECONFIG_REFERENCE_PHASE \
+ ((VL53L1_DeviceSequenceConfig) 2)
+#define VL53L1_DEVICESEQUENCECONFIG_DSS1 \
+ ((VL53L1_DeviceSequenceConfig) 3)
+#define VL53L1_DEVICESEQUENCECONFIG_DSS2 \
+ ((VL53L1_DeviceSequenceConfig) 4)
+#define VL53L1_DEVICESEQUENCECONFIG_MM1 \
+ ((VL53L1_DeviceSequenceConfig) 5)
+#define VL53L1_DEVICESEQUENCECONFIG_MM2 \
+ ((VL53L1_DeviceSequenceConfig) 6)
+#define VL53L1_DEVICESEQUENCECONFIG_RANGE \
+ ((VL53L1_DeviceSequenceConfig) 7)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceInterruptPolarity;
+
+#define VL53L1_DEVICEINTERRUPTPOLARITY_ACTIVE_HIGH \
+ ((VL53L1_DeviceInterruptPolarity) 0x00)
+#define VL53L1_DEVICEINTERRUPTPOLARITY_ACTIVE_LOW \
+ ((VL53L1_DeviceInterruptPolarity) 0x10)
+#define VL53L1_DEVICEINTERRUPTPOLARITY_BIT_MASK \
+ ((VL53L1_DeviceInterruptPolarity) 0x10)
+#define VL53L1_DEVICEINTERRUPTPOLARITY_CLEAR_MASK \
+ ((VL53L1_DeviceInterruptPolarity) 0xEF)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceGpioMode;
+
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_CONSTANT_ZERO \
+ ((VL53L1_DeviceGpioMode) 0x00)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_RANGE_AND_ERROR_INTERRUPTS \
+ ((VL53L1_DeviceGpioMode) 0x01)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_TIMIER_INTERRUPTS \
+ ((VL53L1_DeviceGpioMode) 0x02)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_RANGE_MODE_INTERRUPT_STATUS \
+ ((VL53L1_DeviceGpioMode) 0x03)
+#define VL53L1_DEVICEGPIOMODE_OUTPUT_SLOW_OSCILLATOR_CLOCK \
+ ((VL53L1_DeviceGpioMode) 0x04)
+#define VL53L1_DEVICEGPIOMODE_BIT_MASK \
+ ((VL53L1_DeviceGpioMode) 0x0F)
+#define VL53L1_DEVICEGPIOMODE_CLEAR_MASK \
+ ((VL53L1_DeviceGpioMode) 0xF0)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceError;
+
+#define VL53L1_DEVICEERROR_NOUPDATE \
+ ((VL53L1_DeviceError) 0)
+
+
+#define VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE \
+ ((VL53L1_DeviceError) 1)
+#define VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE \
+ ((VL53L1_DeviceError) 2)
+#define VL53L1_DEVICEERROR_NOVHVVALUEFOUND \
+ ((VL53L1_DeviceError) 3)
+#define VL53L1_DEVICEERROR_MSRCNOTARGET \
+ ((VL53L1_DeviceError) 4)
+#define VL53L1_DEVICEERROR_RANGEPHASECHECK \
+ ((VL53L1_DeviceError) 5)
+#define VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK \
+ ((VL53L1_DeviceError) 6)
+#define VL53L1_DEVICEERROR_PHASECONSISTENCY \
+ ((VL53L1_DeviceError) 7)
+#define VL53L1_DEVICEERROR_MINCLIP \
+ ((VL53L1_DeviceError) 8)
+#define VL53L1_DEVICEERROR_RANGECOMPLETE \
+ ((VL53L1_DeviceError) 9)
+#define VL53L1_DEVICEERROR_ALGOUNDERFLOW \
+ ((VL53L1_DeviceError) 10)
+#define VL53L1_DEVICEERROR_ALGOOVERFLOW \
+ ((VL53L1_DeviceError) 11)
+#define VL53L1_DEVICEERROR_RANGEIGNORETHRESHOLD \
+ ((VL53L1_DeviceError) 12)
+#define VL53L1_DEVICEERROR_USERROICLIP \
+ ((VL53L1_DeviceError) 13)
+#define VL53L1_DEVICEERROR_REFSPADCHARNOTENOUGHDPADS \
+ ((VL53L1_DeviceError) 14)
+#define VL53L1_DEVICEERROR_REFSPADCHARMORETHANTARGET \
+ ((VL53L1_DeviceError) 15)
+#define VL53L1_DEVICEERROR_REFSPADCHARLESSTHANTARGET \
+ ((VL53L1_DeviceError) 16)
+#define VL53L1_DEVICEERROR_MULTCLIPFAIL \
+ ((VL53L1_DeviceError) 17)
+#define VL53L1_DEVICEERROR_GPHSTREAMCOUNT0READY \
+ ((VL53L1_DeviceError) 18)
+#define VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK \
+ ((VL53L1_DeviceError) 19)
+#define VL53L1_DEVICEERROR_EVENTCONSISTENCY \
+ ((VL53L1_DeviceError) 20)
+#define VL53L1_DEVICEERROR_MINSIGNALEVENTCHECK \
+ ((VL53L1_DeviceError) 21)
+#define VL53L1_DEVICEERROR_RANGECOMPLETE_MERGED_PULSE \
+ ((VL53L1_DeviceError) 22)
+
+
+
+#define VL53L1_DEVICEERROR_PREV_RANGE_NO_TARGETS \
+ ((VL53L1_DeviceError) 23)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceReportStatus;
+
+#define VL53L1_DEVICEREPORTSTATUS_NOUPDATE \
+ ((VL53L1_DeviceReportStatus) 0)
+
+
+#define VL53L1_DEVICEREPORTSTATUS_ROI_SETUP \
+ ((VL53L1_DeviceReportStatus) 1)
+#define VL53L1_DEVICEREPORTSTATUS_VHV \
+ ((VL53L1_DeviceReportStatus) 2)
+#define VL53L1_DEVICEREPORTSTATUS_PHASECAL \
+ ((VL53L1_DeviceReportStatus) 3)
+#define VL53L1_DEVICEREPORTSTATUS_REFERENCE_PHASE \
+ ((VL53L1_DeviceReportStatus) 4)
+#define VL53L1_DEVICEREPORTSTATUS_DSS1 \
+ ((VL53L1_DeviceReportStatus) 5)
+#define VL53L1_DEVICEREPORTSTATUS_DSS2 \
+ ((VL53L1_DeviceReportStatus) 6)
+#define VL53L1_DEVICEREPORTSTATUS_MM1 \
+ ((VL53L1_DeviceReportStatus) 7)
+#define VL53L1_DEVICEREPORTSTATUS_MM2 \
+ ((VL53L1_DeviceReportStatus) 8)
+#define VL53L1_DEVICEREPORTSTATUS_RANGE \
+ ((VL53L1_DeviceReportStatus) 9)
+#define VL53L1_DEVICEREPORTSTATUS_HISTOGRAM \
+ ((VL53L1_DeviceReportStatus) 10)
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceDssMode;
+
+#define VL53L1_DEVICEDSSMODE__DISABLED \
+ ((VL53L1_DeviceDssMode) 0)
+#define VL53L1_DEVICEDSSMODE__TARGET_RATE \
+ ((VL53L1_DeviceDssMode) 1)
+#define VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS \
+ ((VL53L1_DeviceDssMode) 2)
+#define VL53L1_DEVICEDSSMODE__BLOCK_SELECT \
+ ((VL53L1_DeviceDssMode) 3)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistAlgoSelect;
+
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN1 \
+ ((VL53L1_HistAlgoSelect) 1)
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN2 \
+ ((VL53L1_HistAlgoSelect) 2)
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN3 \
+ ((VL53L1_HistAlgoSelect) 3)
+#define VL53L1_HIST_ALGO_SELECT__PW_HIST_GEN4 \
+ ((VL53L1_HistAlgoSelect) 4)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistTargetOrder;
+
+#define VL53L1_HIST_TARGET_ORDER__INCREASING_DISTANCE \
+ ((VL53L1_HistTargetOrder) 1)
+#define VL53L1_HIST_TARGET_ORDER__STRONGEST_FIRST \
+ ((VL53L1_HistTargetOrder) 2)
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistAmbEstMethod;
+
+#define VL53L1_HIST_AMB_EST_METHOD__AMBIENT_BINS \
+ ((VL53L1_HistAmbEstMethod) 1)
+#define VL53L1_HIST_AMB_EST_METHOD__THRESHOLDED_BINS \
+ ((VL53L1_HistAmbEstMethod) 2)
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_HistXtalkCompEnable;
+
+#define VL53L1_HIST_XTALK_COMP__DIS \
+ ((VL53L1_HistXtalkCompEnable) 0)
+#define VL53L1_HIST_XTALK_COMP__EN \
+ ((VL53L1_HistXtalkCompEnable) 1)
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceConfigLevel;
+
+#define VL53L1_DEVICECONFIGLEVEL_SYSTEM_CONTROL \
+ ((VL53L1_DeviceConfigLevel) 0)
+
+
+#define VL53L1_DEVICECONFIGLEVEL_DYNAMIC_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 1)
+
+
+#define VL53L1_DEVICECONFIGLEVEL_TIMING_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 2)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 3)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_STATIC_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 4)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS \
+ ((VL53L1_DeviceConfigLevel) 5)
+
+
+
+#define VL53L1_DEVICECONFIGLEVEL_FULL \
+ ((VL53L1_DeviceConfigLevel) 6)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceResultsLevel;
+
+#define VL53L1_DEVICERESULTSLEVEL_SYSTEM_RESULTS \
+ ((VL53L1_DeviceResultsLevel) 0)
+
+
+#define VL53L1_DEVICERESULTSLEVEL_UPTO_CORE \
+ ((VL53L1_DeviceResultsLevel) 1)
+
+
+#define VL53L1_DEVICERESULTSLEVEL_FULL \
+ ((VL53L1_DeviceResultsLevel) 2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceTestMode;
+
+#define VL53L1_DEVICETESTMODE_NONE \
+ ((VL53L1_DeviceTestMode) 0x00)
+
+
+#define VL53L1_DEVICETESTMODE_NVM_ZERO \
+ ((VL53L1_DeviceTestMode) 0x01)
+
+
+#define VL53L1_DEVICETESTMODE_NVM_COPY \
+ ((VL53L1_DeviceTestMode) 0x02)
+
+
+#define VL53L1_DEVICETESTMODE_PATCH \
+ ((VL53L1_DeviceTestMode) 0x03)
+
+
+#define VL53L1_DEVICETESTMODE_DCR \
+ ((VL53L1_DeviceTestMode) 0x04)
+
+
+#define VL53L1_DEVICETESTMODE_LCR_VCSEL_OFF \
+ ((VL53L1_DeviceTestMode) 0x05)
+
+
+
+#define VL53L1_DEVICETESTMODE_LCR_VCSEL_ON \
+ ((VL53L1_DeviceTestMode) 0x06)
+
+
+
+#define VL53L1_DEVICETESTMODE_SPOT_CENTRE_LOCATE \
+ ((VL53L1_DeviceTestMode) 0x07)
+
+
+#define VL53L1_DEVICETESTMODE_REF_SPAD_CHAR_WITH_PRE_VHV \
+ ((VL53L1_DeviceTestMode) 0x08)
+
+
+#define VL53L1_DEVICETESTMODE_REF_SPAD_CHAR_ONLY \
+ ((VL53L1_DeviceTestMode) 0x09)
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_DeviceSscArray;
+
+#define VL53L1_DEVICESSCARRAY_RTN ((VL53L1_DeviceSscArray) 0x00)
+
+
+#define VL53L1_DEVICETESTMODE_REF ((VL53L1_DeviceSscArray) 0x01)
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RETURN_ARRAY_ONLY 0x01
+
+
+#define VL53L1_REFERENCE_ARRAY_ONLY 0x10
+
+
+#define VL53L1_BOTH_RETURN_AND_REFERENCE_ARRAYS 0x11
+
+
+#define VL53L1_NEITHER_RETURN_AND_REFERENCE_ARRAYS 0x00
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH 0x00
+
+
+#define VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_LOW 0x10
+
+
+#define VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK 0x10
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_POLLING_DELAY_US 1000
+
+
+#define VL53L1_SOFTWARE_RESET_DURATION_US 100
+
+
+#define VL53L1_FIRMWARE_BOOT_TIME_US 1200
+
+
+
+#define VL53L1_ENABLE_POWERFORCE_SETTLING_TIME_US 250
+
+
+
+
+#define VL53L1_SPAD_ARRAY_WIDTH 16
+
+
+#define VL53L1_SPAD_ARRAY_HEIGHT 16
+
+
+#define VL53L1_NVM_SIZE_IN_BYTES 512
+
+
+#define VL53L1_NO_OF_SPAD_ENABLES 256
+
+
+#define VL53L1_RTN_SPAD_BUFFER_SIZE 32
+
+
+#define VL53L1_REF_SPAD_BUFFER_SIZE 6
+
+
+#define VL53L1_AMBIENT_WINDOW_VCSEL_PERIODS 256
+
+
+#define VL53L1_RANGING_WINDOW_VCSEL_PERIODS 2048
+
+
+#define VL53L1_MACRO_PERIOD_VCSEL_PERIODS \
+ (VL53L1_AMBIENT_WINDOW_VCSEL_PERIODS + \
+ VL53L1_RANGING_WINDOW_VCSEL_PERIODS)
+
+
+#define VL53L1_MAX_ALLOWED_PHASE 0xFFFF
+
+
+
+#define VL53L1_RTN_SPAD_UNITY_TRANSMISSION 0x0100
+
+
+#define VL53L1_RTN_SPAD_APERTURE_TRANSMISSION 0x0038
+
+
+
+
+
+#define VL53L1_SPAD_TOTAL_COUNT_MAX ((0x01 << 29) - 1)
+
+
+#define VL53L1_SPAD_TOTAL_COUNT_RES_THRES (0x01 << 24)
+
+
+#define VL53L1_COUNT_RATE_INTERNAL_MAX ((0x01 << 24) - 1)
+
+
+#define VL53L1_SPEED_OF_LIGHT_IN_AIR 299704
+
+
+#define VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8 (299704 >> 3)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_ZoneConfig_BinConfig_select;
+
+#define VL53L1_ZONECONFIG_BINCONFIG__LOWAMB \
+ ((VL53L1_ZoneConfig_BinConfig_select) 1)
+#define VL53L1_ZONECONFIG_BINCONFIG__MIDAMB \
+ ((VL53L1_ZoneConfig_BinConfig_select) 2)
+#define VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB \
+ ((VL53L1_ZoneConfig_BinConfig_select) 3)
+
+
+
+
+
+
+
+
+
+
+typedef uint8_t VL53L1_GPIO_Interrupt_Mode;
+
+#define VL53L1_GPIOINTMODE_LEVEL_LOW \
+ ((VL53L1_GPIO_Interrupt_Mode) 0)
+
+
+#define VL53L1_GPIOINTMODE_LEVEL_HIGH \
+ ((VL53L1_GPIO_Interrupt_Mode) 1)
+
+
+#define VL53L1_GPIOINTMODE_OUT_OF_WINDOW \
+ ((VL53L1_GPIO_Interrupt_Mode) 2)
+
+
+#define VL53L1_GPIOINTMODE_IN_WINDOW \
+ ((VL53L1_GPIO_Interrupt_Mode) 3)
+
+
+
+
+
+
+
+
+
+
+
+
+
+typedef uint16_t VL53L1_TuningParms;
+
+#define VL53L1_TUNINGPARMS_LLD_PUBLIC_MIN_ADDRESS \
+ ((VL53L1_TuningParms) VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS)
+#define VL53L1_TUNINGPARMS_LLD_PUBLIC_MAX_ADDRESS \
+ ((VL53L1_TuningParms) VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE)
+
+#define VL53L1_TUNINGPARMS_LLD_PRIVATE_MIN_ADDRESS \
+ ((VL53L1_TuningParms) VL53L1_TUNINGPARM_PRIVATE_PAGE_BASE_ADDRESS)
+#define VL53L1_TUNINGPARMS_LLD_PRIVATE_MAX_ADDRESS \
+ ((VL53L1_TuningParms) VL53L1_TUNINGPARMS_LLD_PRIVATE_MIN_ADDRESS)
+
+#define VL53L1_TUNINGPARM_VERSION \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 0))
+#define VL53L1_TUNINGPARM_KEY_TABLE_VERSION \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 1))
+#define VL53L1_TUNINGPARM_LLD_VERSION \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 2))
+#define VL53L1_TUNINGPARM_HIST_ALGO_SELECT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 3))
+#define VL53L1_TUNINGPARM_HIST_TARGET_ORDER \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 4))
+#define VL53L1_TUNINGPARM_HIST_FILTER_WOI_0 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 5))
+#define VL53L1_TUNINGPARM_HIST_FILTER_WOI_1 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 6))
+#define VL53L1_TUNINGPARM_HIST_AMB_EST_METHOD \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 7))
+#define VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_0 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 8))
+#define VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_1 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 9))
+#define VL53L1_TUNINGPARM_HIST_MIN_AMB_THRESH_EVENTS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 10))
+#define VL53L1_TUNINGPARM_HIST_AMB_EVENTS_SCALER \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 11))
+#define VL53L1_TUNINGPARM_HIST_NOISE_THRESHOLD \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 12))
+#define VL53L1_TUNINGPARM_HIST_SIGNAL_TOTAL_EVENTS_LIMIT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 13))
+#define VL53L1_TUNINGPARM_HIST_SIGMA_EST_REF_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 14))
+#define VL53L1_TUNINGPARM_HIST_SIGMA_THRESH_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 15))
+#define VL53L1_TUNINGPARM_HIST_GAIN_FACTOR \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 16))
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_PHASE_TOLERANCE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 17))
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_MIN_MAX_TOLERANCE_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 18))
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 19))
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_MIN_SPAD_LIMIT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 20))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_LONG_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 21))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_MED_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 22))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_SHORT_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 23))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_LONG_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 24))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_MED_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 25))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_SHORT_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 26))
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MIN_VALID_RANGE_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 27))
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RANGE_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 28))
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_SIGMA_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 29))
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MIN_MAX_TOLERANCE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 30))
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RATE_KCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 31))
+#define VL53L1_TUNINGPARM_XTALK_DETECT_EVENT_SIGMA \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 32))
+#define VL53L1_TUNINGPARM_HIST_XTALK_MARGIN_KCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 33))
+#define VL53L1_TUNINGPARM_CONSISTENCY_LITE_PHASE_TOLERANCE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 34))
+#define VL53L1_TUNINGPARM_PHASECAL_TARGET \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 35))
+#define VL53L1_TUNINGPARM_LITE_CAL_REPEAT_RATE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 36))
+#define VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 37))
+#define VL53L1_TUNINGPARM_LITE_MIN_CLIP_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 38))
+#define VL53L1_TUNINGPARM_LITE_LONG_SIGMA_THRESH_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 39))
+#define VL53L1_TUNINGPARM_LITE_MED_SIGMA_THRESH_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 40))
+#define VL53L1_TUNINGPARM_LITE_SHORT_SIGMA_THRESH_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 41))
+#define VL53L1_TUNINGPARM_LITE_LONG_MIN_COUNT_RATE_RTN_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 42))
+#define VL53L1_TUNINGPARM_LITE_MED_MIN_COUNT_RATE_RTN_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 43))
+#define VL53L1_TUNINGPARM_LITE_SHORT_MIN_COUNT_RATE_RTN_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 44))
+#define VL53L1_TUNINGPARM_LITE_SIGMA_EST_PULSE_WIDTH \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 45))
+#define VL53L1_TUNINGPARM_LITE_SIGMA_EST_AMB_WIDTH_NS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 46))
+#define VL53L1_TUNINGPARM_LITE_SIGMA_REF_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 47))
+#define VL53L1_TUNINGPARM_LITE_RIT_MULT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 48))
+#define VL53L1_TUNINGPARM_LITE_SEED_CONFIG \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 49))
+#define VL53L1_TUNINGPARM_LITE_QUANTIFIER \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 50))
+#define VL53L1_TUNINGPARM_LITE_FIRST_ORDER_SELECT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 51))
+#define VL53L1_TUNINGPARM_LITE_XTALK_MARGIN_KCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 52))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_LONG_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 53))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_MED_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 54))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_SHORT_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 55))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_LONG_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 56))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_MED_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 57))
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_SHORT_RANGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 58))
+#define VL53L1_TUNINGPARM_TIMED_SEED_CONFIG \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 59))
+#define VL53L1_TUNINGPARM_DMAX_CFG_SIGNAL_THRESH_SIGMA \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 60))
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_0 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 61))
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_1 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 62))
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_2 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 63))
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_3 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 64))
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_4 \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 65))
+#define VL53L1_TUNINGPARM_VHV_LOOPBOUND \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 66))
+#define VL53L1_TUNINGPARM_REFSPADCHAR_DEVICE_TEST_MODE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 67))
+#define VL53L1_TUNINGPARM_REFSPADCHAR_VCSEL_PERIOD \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 68))
+#define VL53L1_TUNINGPARM_REFSPADCHAR_PHASECAL_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 69))
+#define VL53L1_TUNINGPARM_REFSPADCHAR_TARGET_COUNT_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 70))
+#define VL53L1_TUNINGPARM_REFSPADCHAR_MIN_COUNTRATE_LIMIT_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 71))
+#define VL53L1_TUNINGPARM_REFSPADCHAR_MAX_COUNTRATE_LIMIT_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 72))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_NUM_OF_SAMPLES \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 73))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MIN_FILTER_THRESH_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 74))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_FILTER_THRESH_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 75))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 76))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_PHASECAL_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 77))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_VALID_RATE_KCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 78))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_SIGMA_THRESHOLD_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 79))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 80))
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_BIN_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 81))
+#define VL53L1_TUNINGPARM_OFFSET_CAL_DSS_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 82))
+#define VL53L1_TUNINGPARM_OFFSET_CAL_PHASECAL_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 83))
+#define VL53L1_TUNINGPARM_OFFSET_CAL_MM_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 84))
+#define VL53L1_TUNINGPARM_OFFSET_CAL_RANGE_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 85))
+#define VL53L1_TUNINGPARM_OFFSET_CAL_PRE_SAMPLES \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 86))
+#define VL53L1_TUNINGPARM_OFFSET_CAL_MM1_SAMPLES \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 87))
+#define VL53L1_TUNINGPARM_OFFSET_CAL_MM2_SAMPLES \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 88))
+#define VL53L1_TUNINGPARM_ZONE_CAL_DSS_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 89))
+#define VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 90))
+#define VL53L1_TUNINGPARM_ZONE_CAL_DSS_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 91))
+#define VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_NUM_SAMPLES \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 92))
+#define VL53L1_TUNINGPARM_ZONE_CAL_RANGE_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 93))
+#define VL53L1_TUNINGPARM_ZONE_CAL_ZONE_NUM_SAMPLES \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 94))
+#define VL53L1_TUNINGPARM_SPADMAP_VCSEL_PERIOD \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 95))
+#define VL53L1_TUNINGPARM_SPADMAP_VCSEL_START \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 96))
+#define VL53L1_TUNINGPARM_SPADMAP_RATE_LIMIT_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 97))
+#define VL53L1_TUNINGPARM_LITE_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 98))
+#define VL53L1_TUNINGPARM_RANGING_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 99))
+#define VL53L1_TUNINGPARM_MZ_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 100))
+#define VL53L1_TUNINGPARM_TIMED_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 101))
+#define VL53L1_TUNINGPARM_LITE_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 102))
+#define VL53L1_TUNINGPARM_RANGING_LONG_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 103))
+#define VL53L1_TUNINGPARM_RANGING_MED_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 104))
+#define VL53L1_TUNINGPARM_RANGING_SHORT_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 105))
+#define VL53L1_TUNINGPARM_MZ_LONG_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 106))
+#define VL53L1_TUNINGPARM_MZ_MED_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 107))
+#define VL53L1_TUNINGPARM_MZ_SHORT_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 108))
+#define VL53L1_TUNINGPARM_TIMED_PHASECAL_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 109))
+#define VL53L1_TUNINGPARM_LITE_MM_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 110))
+#define VL53L1_TUNINGPARM_RANGING_MM_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 111))
+#define VL53L1_TUNINGPARM_MZ_MM_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 112))
+#define VL53L1_TUNINGPARM_TIMED_MM_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 113))
+#define VL53L1_TUNINGPARM_LITE_RANGE_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 114))
+#define VL53L1_TUNINGPARM_RANGING_RANGE_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 115))
+#define VL53L1_TUNINGPARM_MZ_RANGE_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 116))
+#define VL53L1_TUNINGPARM_TIMED_RANGE_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 117))
+#define VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_MARGIN \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 118))
+#define VL53L1_TUNINGPARM_DYNXTALK_NOISE_MARGIN \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 119))
+#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 120))
+#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_HI \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 121))
+#define VL53L1_TUNINGPARM_DYNXTALK_SAMPLE_LIMIT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 122))
+#define VL53L1_TUNINGPARM_DYNXTALK_SINGLE_XTALK_DELTA \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 123))
+#define VL53L1_TUNINGPARM_DYNXTALK_AVERAGED_XTALK_DELTA \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 124))
+#define VL53L1_TUNINGPARM_DYNXTALK_CLIP_LIMIT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 125))
+#define VL53L1_TUNINGPARM_DYNXTALK_SCALER_CALC_METHOD \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 126))
+#define VL53L1_TUNINGPARM_DYNXTALK_XGRADIENT_SCALER \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 127))
+#define VL53L1_TUNINGPARM_DYNXTALK_YGRADIENT_SCALER \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 128))
+#define VL53L1_TUNINGPARM_DYNXTALK_USER_SCALER_SET \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 129))
+#define VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_COR_SINGLE_APPLY \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 130))
+#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_AMB_THRESHOLD \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 131))
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_AMB_THRESHOLD_KCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 132))
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_SAMPLE_LIMIT \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 133))
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 134))
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_MIN_RANGE_MM \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 135))
+#define VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 136))
+#define VL53L1_TUNINGPARM_LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 137))
+#define VL53L1_TUNINGPARM_LOWPOWERAUTO_RANGE_CONFIG_TIMEOUT_US \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 138))
+#define VL53L1_TUNINGPARM_VERY_SHORT_DSS_RATE_MCPS \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 139))
+#define VL53L1_TUNINGPARM_PHASECAL_PATCH_POWER \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 140))
+#define VL53L1_TUNINGPARM_HIST_MERGE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 141))
+#define VL53L1_TUNINGPARM_RESET_MERGE_THRESHOLD \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 142))
+#define VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE \
+((VL53L1_TuningParms) (VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS + 143))
+
+
+
+
+
+
+#endif
+
+
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm.h
new file mode 100644
index 000000000000..fc297c7f046e
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm.h
@@ -0,0 +1,459 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_H_
+#define _VL53L1_NVM_H_
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define VL53L1_NVM_POWER_UP_DELAY_US 50
+#define VL53L1_NVM_READ_TRIGGER_DELAY_US 5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_enable(
+ VL53L1_DEV Dev,
+ uint16_t nvm_ctrl_pulse_width,
+ int32_t nvm_power_up_delay_us);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_read(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_disable(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_format_decode(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_optical_centre(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_optical_centre_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_cal_peak_rate_map(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_cal_peak_rate_map_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_additional_offset_cal_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_additional_offset_cal_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_range_results_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_info_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_nvm_decode_ews_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_ews_info_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_nvm_format_encode(
+ VL53L1_decoded_nvm_data_t *pnvm_info,
+ uint8_t *pnvm_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_raw_data(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pnvm_raw_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm(
+ VL53L1_DEV Dev,
+ uint8_t nvm_format,
+ VL53L1_decoded_nvm_data_t *pnvm_info);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_optical_centre(
+ VL53L1_DEV Dev,
+ VL53L1_optical_centre_t *pcentre);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_cal_peak_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_cal_peak_rate_map_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_additional_offset_cal_data(
+ VL53L1_DEV Dev,
+ VL53L1_additional_offset_cal_data_t *pcal_data);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_read_nvm_fmt_range_results_data(
+ VL53L1_DEV Dev,
+ uint16_t range_results_select,
+ VL53L1_decoded_nvm_fmt_range_data_t *prange_data);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_debug.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_debug.h
new file mode 100644
index 000000000000..755fc76cb835
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_debug.h
@@ -0,0 +1,202 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_DEBUG_H_
+#define _VL53L1_NVM_DEBUG_H_
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_nvm_structs.h"
+
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_nvm_raw_data(
+ uint8_t *pnvm_raw_data,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_data(
+ VL53L1_decoded_nvm_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_fmt_range_data(
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_fmt_info(
+ VL53L1_decoded_nvm_fmt_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+
+
+
+
+
+
+
+
+
+
+void VL53L1_print_decoded_nvm_ews_info(
+ VL53L1_decoded_nvm_ews_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags);
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_map.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_map.h
new file mode 100644
index 000000000000..b79219dc2c94
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_map.h
@@ -0,0 +1,3254 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_MAP_H_
+#define _VL53L1_NVM_MAP_H_
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__MODEL_ID 0x0008
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__MODULE_TYPE 0x000C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__REVISION_ID 0x000D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__IDENTIFICATION__MODULE_ID 0x000E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__I2C_VALID 0x0010
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__I2C_SLAVE__DEVICE_ADDRESS 0x0011
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__OSC_MEASURED__FAST_OSC_FREQUENCY 0x0014
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__FAST_OSC_TRIM_MAX 0x0016
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__FAST_OSC_FREQ_SET 0x0017
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SLOW_OSC_CALIBRATION 0x0018
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__OSC_MEASURED__FAST_OSC_FREQUENCY 0x001C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FAST_OSC_TRIM_MAX 0x001E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FAST_OSC_FREQ_SET 0x001F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SLOW_OSC_CALIBRATION 0x0020
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG_UNLOCK 0x0028
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__REF_SELVDDPIX 0x0029
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__REF_SELVQUENCH 0x002A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL 0x002B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x002C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__COUNT_THRESH 0x002D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__OFFSET 0x002E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__VHV_CONFIG__INIT 0x002F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LL 0x0030
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LL 0x0031
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LL 0x0032
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__MULT_LL 0x0034
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__CLIP_LL 0x0035
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LD 0x0038
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LD 0x0039
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LD 0x003A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__MULT_LD 0x003C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY__CLIP_LD 0x003D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY_LOCK_BYTE 0x0040
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__LASER_SAFETY_UNLOCK_BYTE 0x0044
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_0_ 0x0048
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_1_ 0x0049
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_2_ 0x004A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_3_ 0x004B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_4_ 0x004C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_5_ 0x004D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_6_ 0x004E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_7_ 0x004F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_8_ 0x0050
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_9_ 0x0051
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_10_ 0x0052
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_11_ 0x0053
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_12_ 0x0054
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_13_ 0x0055
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_14_ 0x0056
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_15_ 0x0057
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_16_ 0x0058
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_17_ 0x0059
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_18_ 0x005A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_19_ 0x005B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_20_ 0x005C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_21_ 0x005D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_22_ 0x005E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_23_ 0x005F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_24_ 0x0060
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_25_ 0x0061
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_26_ 0x0062
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_27_ 0x0063
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_28_ 0x0064
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_29_ 0x0065
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_30_ 0x0066
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_RTN_31_ 0x0067
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_0_ 0x0068
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_1_ 0x0069
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_2_ 0x006A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_3_ 0x006B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_4_ 0x006C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_5_ 0x006D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_0_ 0x0070
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_1_ 0x0071
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_2_ 0x0072
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_3_ 0x0073
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_4_ 0x0074
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_5_ 0x0075
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_0_ 0x0078
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_1_ 0x0079
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_2_ 0x007A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_3_ 0x007B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_4_ 0x007C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_5_ 0x007D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_0_ 0x0080
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_1_ 0x0081
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_2_ 0x0082
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_3_ 0x0083
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_4_ 0x0084
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_5_ 0x0085
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_6_ 0x0086
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_7_ 0x0087
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_8_ 0x0088
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_9_ 0x0089
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_10_ 0x008A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_11_ 0x008B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_12_ 0x008C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_13_ 0x008D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_14_ 0x008E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_15_ 0x008F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_16_ 0x0090
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_17_ 0x0091
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_18_ 0x0092
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_19_ 0x0093
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_20_ 0x0094
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_21_ 0x0095
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_22_ 0x0096
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_23_ 0x0097
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_24_ 0x0098
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_25_ 0x0099
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_26_ 0x009A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_27_ 0x009B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_28_ 0x009C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_29_ 0x009D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_30_ 0x009E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_RTN_31_ 0x009F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_0_ 0x00A0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_1_ 0x00A1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_2_ 0x00A2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_3_ 0x00A3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_4_ 0x00A4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_5_ 0x00A5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_0_ 0x00A8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_1_ 0x00A9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_2_ 0x00AA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_3_ 0x00AB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_4_ 0x00AC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_5_ 0x00AD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_0_ 0x00B0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_1_ 0x00B1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_2_ 0x00B2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_3_ 0x00B3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_4_ 0x00B4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_5_ 0x00B5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x00B8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE 0x00B9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD 0x00BC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__REF_SPAD_MAN__REF_LOCATION 0x00BD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__MM_CONFIG__INNER_OFFSET_MM 0x00C0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__MM_CONFIG__OUTER_OFFSET_MM 0x00C2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x00C4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x00C8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS \
+ 0x00CA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS \
+ 0x00CC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0 0x00CE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1 0x00CF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUSTOMER_NVM_SPACE_PROGRAMMED 0x00E0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__I2C_SLAVE__DEVICE_ADDRESS 0x00E4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD 0x00E8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__REF_SPAD_MAN__REF_LOCATION 0x00E9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__MM_CONFIG__INNER_OFFSET_MM 0x00EC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__MM_CONFIG__OUTER_OFFSET_MM 0x00EE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x00F0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x00F4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS \
+ 0x00F6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS \
+ 0x00F8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0 0x00FA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1 0x00FB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_0 0x01DC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_1 0x01DD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_2 0x01DE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_3 0x01DF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_4 0x01E0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_5 0x01E1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_6 0x01E2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_7 0x01E3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_8 0x01E4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_9 0x01E5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_10 0x01E6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_11 0x01E7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_12 0x01E8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_13 0x01E9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_14 0x01EA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__FGC__BYTE_15 0x01EB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR 0x01EC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__MAP_MAJOR_MINOR 0x01ED
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__YEAR_MONTH 0x01EE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE 0x01EF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__TIME 0x01F0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__TESTER_ID 0x01F2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__SITE_ID 0x01F3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR 0x01F4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR 0x01F5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__TESTER_ID 0x01F6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_0 0x01F8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_1 0x01F9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_2 0x01FA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_3 0x01FB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_4 0x01FC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__LOT__BYTE_5 0x01FD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__WAFER 0x01FD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__XCOORD 0x01FE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__EWS__YCOORD 0x01FF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_INDEX 0x00B8
+#define VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE 4
+
+#define VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX 0x015C
+#define VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE 56
+
+#define VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX 0x0194
+#define VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE 8
+
+#define VL53L1_NVM__FMT__RANGE_RESULTS__140MM_MM_PRE_RANGE 0x019C
+#define VL53L1_NVM__FMT__RANGE_RESULTS__140MM_DARK 0x01AC
+#define VL53L1_NVM__FMT__RANGE_RESULTS__400MM_DARK 0x01BC
+#define VL53L1_NVM__FMT__RANGE_RESULTS__400MM_AMBIENT 0x01CC
+#define VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES 16
+
+
+
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_structs.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_structs.h
new file mode 100644
index 000000000000..782f2d808650
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_nvm_structs.h
@@ -0,0 +1,809 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_NVM_STRUCTS_H_
+#define _VL53L1_NVM_STRUCTS_H_
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "vl53l1_platform.h"
+#include "vl53l1_ll_def.h"
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint16_t result__actual_effective_rtn_spads;
+
+
+ uint8_t ref_spad_array__num_requested_ref_spads;
+
+
+ uint8_t ref_spad_array__ref_location;
+
+
+ uint16_t result__peak_signal_count_rate_rtn_mcps;
+
+
+ uint16_t result__ambient_count_rate_rtn_mcps;
+
+
+ uint16_t result__peak_signal_count_rate_ref_mcps;
+
+
+ uint16_t result__ambient_count_rate_ref_mcps;
+
+
+ uint16_t measured_distance_mm;
+
+
+ uint16_t measured_distance_stdev_mm;
+
+
+
+} VL53L1_decoded_nvm_fmt_range_data_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ char nvm__fmt__fgc[19];
+
+
+ uint8_t nvm__fmt__test_program_major;
+
+
+
+
+
+ uint8_t nvm__fmt__test_program_minor;
+
+
+
+
+
+ uint8_t nvm__fmt__map_major;
+
+
+
+
+
+ uint8_t nvm__fmt__map_minor;
+
+
+
+
+
+ uint8_t nvm__fmt__year;
+
+
+
+
+
+ uint8_t nvm__fmt__month;
+
+
+
+
+
+ uint8_t nvm__fmt__day;
+
+
+
+
+
+ uint8_t nvm__fmt__module_date_phase;
+
+
+
+
+
+ uint16_t nvm__fmt__time;
+
+
+
+
+
+ uint8_t nvm__fmt__tester_id;
+
+
+
+
+
+ uint8_t nvm__fmt__site_id;
+
+
+
+
+
+ uint8_t nvm__ews__test_program_major;
+
+
+
+
+
+ uint8_t nvm__ews__test_program_minor;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_major;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_minor;
+
+
+
+
+
+ uint8_t nvm__ews__tester_id;
+
+
+
+
+
+
+ char nvm__ews__lot[8];
+
+
+ uint8_t nvm__ews__wafer;
+
+
+
+
+
+ uint8_t nvm__ews__xcoord;
+
+
+
+
+
+ uint8_t nvm__ews__ycoord;
+
+
+
+
+
+} VL53L1_decoded_nvm_fmt_info_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+
+ uint8_t nvm__ews__test_program_major;
+
+
+
+
+
+ uint8_t nvm__ews__test_program_minor;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_major;
+
+
+
+
+
+ uint8_t nvm__ews__probe_card_minor;
+
+
+
+
+
+ uint8_t nvm__ews__tester_id;
+
+
+
+
+
+
+ char nvm__ews__lot[8];
+
+
+ uint8_t nvm__ews__wafer;
+
+
+
+
+
+ uint8_t nvm__ews__xcoord;
+
+
+
+
+
+ uint8_t nvm__ews__ycoord;
+
+
+
+
+
+
+} VL53L1_decoded_nvm_ews_info_t;
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t nvm__identification_model_id;
+
+
+
+
+
+ uint8_t nvm__identification_module_type;
+
+
+
+
+
+ uint8_t nvm__identification_revision_id;
+
+
+
+
+
+ uint16_t nvm__identification_module_id;
+
+
+
+
+
+ uint8_t nvm__i2c_valid;
+
+
+
+
+
+ uint8_t nvm__i2c_device_address_ews;
+
+
+
+
+
+ uint16_t nvm__ews__fast_osc_frequency;
+
+
+
+
+
+ uint8_t nvm__ews__fast_osc_trim_max;
+
+
+
+
+
+ uint8_t nvm__ews__fast_osc_freq_set;
+
+
+
+
+
+ uint16_t nvm__ews__slow_osc_calibration;
+
+
+
+
+
+ uint16_t nvm__fmt__fast_osc_frequency;
+
+
+
+
+
+ uint8_t nvm__fmt__fast_osc_trim_max;
+
+
+
+
+
+ uint8_t nvm__fmt__fast_osc_freq_set;
+
+
+
+
+
+ uint16_t nvm__fmt__slow_osc_calibration;
+
+
+
+
+
+ uint8_t nvm__vhv_config_unlock;
+
+
+
+
+
+ uint8_t nvm__ref_selvddpix;
+
+
+
+
+
+ uint8_t nvm__ref_selvquench;
+
+
+
+
+
+ uint8_t nvm__regavdd1v2_sel;
+
+
+
+
+
+ uint8_t nvm__regdvdd1v2_sel;
+
+
+
+
+
+ uint8_t nvm__vhv_timeout__macrop;
+
+
+
+
+
+ uint8_t nvm__vhv_loop_bound;
+
+
+
+
+
+ uint8_t nvm__vhv_count_threshold;
+
+
+
+
+
+ uint8_t nvm__vhv_offset;
+
+
+
+
+
+ uint8_t nvm__vhv_init_enable;
+
+
+
+
+
+ uint8_t nvm__vhv_init_value;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_trim_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_max_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_mult_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_clip_ll;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_trim_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_vcsel_selion_max_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_mult_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_clip_ld;
+
+
+
+
+
+ uint8_t nvm__laser_safety_lock_byte;
+
+
+
+
+
+ uint8_t nvm__laser_safety_unlock_byte;
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_rtn[VL53L1_RTN_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_ref__loc1[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_ref__loc2[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__ews__spad_enables_ref__loc3[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_rtn[VL53L1_RTN_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_ref__loc1[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_ref__loc2[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__spad_enables_ref__loc3[VL53L1_REF_SPAD_BUFFER_SIZE];
+
+
+
+
+
+ uint8_t nvm__fmt__roi_config__mode_roi_centre_spad;
+
+
+
+
+
+ uint8_t nvm__fmt__roi_config__mode_roi_x_size;
+
+
+
+
+
+ uint8_t nvm__fmt__roi_config__mode_roi_y_size;
+
+
+
+
+
+ uint8_t nvm__fmt__ref_spad_apply__num_requested_ref_spad;
+
+
+
+
+
+ uint8_t nvm__fmt__ref_spad_man__ref_location;
+
+
+
+
+
+ uint16_t nvm__fmt__mm_config__inner_offset_mm;
+
+
+
+
+
+ uint16_t nvm__fmt__mm_config__outer_offset_mm;
+
+
+
+
+
+ uint16_t nvm__fmt__algo_part_to_part_range_offset_mm;
+
+
+
+
+
+ uint16_t nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps;
+
+
+
+
+
+ uint16_t nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+
+
+
+ uint16_t nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+
+ uint8_t nvm__fmt__spare__host_config__nvm_config_spare_0;
+
+
+
+
+
+ uint8_t nvm__fmt__spare__host_config__nvm_config_spare_1;
+
+
+
+
+
+ uint8_t nvm__customer_space_programmed;
+
+
+
+
+
+ uint8_t nvm__cust__i2c_device_address;
+
+
+
+
+
+ uint8_t nvm__cust__ref_spad_apply__num_requested_ref_spad;
+
+
+
+
+
+ uint8_t nvm__cust__ref_spad_man__ref_location;
+
+
+
+
+
+ uint16_t nvm__cust__mm_config__inner_offset_mm;
+
+
+
+
+
+ uint16_t nvm__cust__mm_config__outer_offset_mm;
+
+
+
+
+
+ uint16_t nvm__cust__algo_part_to_part_range_offset_mm;
+
+
+
+
+
+ uint16_t nvm__cust__algo__crosstalk_compensation_plane_offset_kcps;
+
+
+
+
+
+ uint16_t nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+
+
+
+ uint16_t nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+
+ uint8_t nvm__cust__spare__host_config__nvm_config_spare_0;
+
+
+
+
+
+ uint8_t nvm__cust__spare__host_config__nvm_config_spare_1;
+
+
+
+
+
+
+ VL53L1_optical_centre_t fmt_optical_centre;
+ VL53L1_cal_peak_rate_map_t fmt_peak_rate_map;
+ VL53L1_additional_offset_cal_data_t fmt_add_offset_data;
+
+ VL53L1_decoded_nvm_fmt_range_data_t
+ fmt_range_data[VL53L1_NVM_MAX_FMT_RANGE_DATA];
+
+ VL53L1_decoded_nvm_fmt_info_t fmt_info;
+ VL53L1_decoded_nvm_ews_info_t ews_info;
+
+} VL53L1_decoded_nvm_data_t;
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_preset_setup.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_preset_setup.h
new file mode 100644
index 000000000000..f8f949a9d53a
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_preset_setup.h
@@ -0,0 +1,125 @@
+
+/******************************************************************************
+ * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+ ******************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+ *******************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+ *******************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones mentioned above :
+
+ *******************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+ *******************************************************************************
+ */
+
+#ifndef _VL53L1_PRESET_SETUP_H_
+#define _VL53L1_PRESET_SETUP_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* indexes for the bare driver tuning setting API function */
+enum VL53L1_Tuning_t {
+ VL53L1_TUNING_VERSION = 0,
+ VL53L1_TUNING_PROXY_MIN,
+ VL53L1_TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM,
+ VL53L1_TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER,
+ VL53L1_TUNING_MIN_AMBIENT_DMAX_VALID,
+ VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER,
+ VL53L1_TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM,
+ VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT,
+ VL53L1_TUNING_XTALK_FULL_ROI_MAX_THRESHOLD,
+ VL53L1_TUNING_XTALK_FULL_ROI_BIN_SUM_MARGIN,
+ VL53L1_TUNING_XTALK_FULL_ROI_DEFAULT_OFFSET,
+ VL53L1_TUNING_ZERO_DISTANCE_OFFSET_NON_LINEAR_FACTOR,
+ VL53L1_TUNING_MAX_TUNABLE_KEY
+};
+
+/* default values for the tuning settings parameters */
+#define TUNING_VERSION 0x0006
+
+#define TUNING_PROXY_MIN -30 /* min distance in mm */
+#define TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM 600
+/* Target distance in mm for single target Xtalk */
+#define TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER 50
+/* Number of sample used for single target Xtalk */
+#define TUNING_MIN_AMBIENT_DMAX_VALID 8
+/* Minimum ambient level to state the Dmax returned by the device is valid */
+#define TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER 10
+/* Maximum loops to perform simple offset calibration */
+#define TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM 600
+/* Target distance in mm for target Xtalk from Bins method*/
+#define TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT 3
+/* Number of loops done during the simple offset calibration*/
+#define TUNING_ZERO_DISTANCE_OFFSET_NON_LINEAR_FACTOR_DEFAULT 9
+/* zero distance offset calibration non linear compensation default value */
+
+/* The 3 following settings are related to the fix for ticket EwokP #558410 */
+#define TUNING_XTALK_FULL_ROI_MAX_THRESHOLD 262144
+/* Maximum possible plane offset (262144 stands for 512 kcps in 7.9 format) */
+#define TUNING_XTALK_FULL_ROI_BIN_SUM_MARGIN 24
+/* Acceptance margin for the xtalk_shape bin_data sum computation */
+#define TUNING_XTALK_FULL_ROI_DEFAULT_OFFSET 50
+/* Recovery value for Xtalk compensation plane offset in kcps */
+/* 50 stands for ~0.10 kcps cover glass in 7.9 format */
+/* End of settings related to the fix for ticket EwokP #558410 */
+
+/* the following table should actually be defined as static and shall be part
+ * of the VL53L1_StaticInit() function code
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VL53L1_PRESET_SETUP_H_ */
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_funcs.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_funcs.h
new file mode 100644
index 000000000000..881aea81c009
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_funcs.h
@@ -0,0 +1,1694 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_FUNCS_H_
+#define _VL53L1_REGISTER_FUNCS_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_static_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_customer_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_customer_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_static_config(
+ VL53L1_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_general_config(
+ VL53L1_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_timing_config(
+ VL53L1_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_dynamic_config(
+ VL53L1_dynamic_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_dynamic_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_dynamic_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_system_control(
+ VL53L1_system_control_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_system_control(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_control_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_system_results(
+ VL53L1_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_core_results(
+ VL53L1_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_debug_results(
+ VL53L1_debug_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_debug_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_debug_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_nvm_copy_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_nvm_copy_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_system_results(
+ VL53L1_prev_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_core_results(
+ VL53L1_prev_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_debug(
+ VL53L1_patch_debug_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_debug(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_debug_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_general_config(
+ VL53L1_gph_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_static_config(
+ VL53L1_gph_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_timing_config(
+ VL53L1_gph_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_fw_internal(
+ VL53L1_fw_internal_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_fw_internal(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_fw_internal_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_results(
+ VL53L1_patch_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_system_results(
+ VL53L1_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_core_results(
+ VL53L1_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_map.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_map.h
new file mode 100644
index 000000000000..288c80b9af20
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_map.h
@@ -0,0 +1,13151 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_MAP_H_
+#define _VL53L1_REGISTER_MAP_H_
+
+
+
+
+
+
+
+#define VL53L1_SOFT_RESET 0x0000
+
+
+
+
+
+
+
+#define VL53L1_I2C_SLAVE__DEVICE_ADDRESS 0x0001
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VHV_REF_SEL_VDDPIX 0x0002
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VHV_REF_SEL_VQUENCH 0x0003
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__REG_AVDD1V2_SEL 0x0004
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__TRIM 0x0005
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_OSC_MEASURED__FAST_OSC__FREQUENCY 0x0006
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_OSC_MEASURED__FAST_OSC__FREQUENCY_HI 0x0006
+
+
+
+
+
+
+
+#define VL53L1_OSC_MEASURED__FAST_OSC__FREQUENCY_LO 0x0007
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND 0x0008
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__COUNT_THRESH 0x0009
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__OFFSET 0x000A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_CONFIG__INIT 0x000B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0 0x000D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_1 0x000E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_2 0x000F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_3 0x0010
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_4 0x0011
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_5 0x0012
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__REF_EN_START_SELECT 0x0013
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_MAN__NUM_REQUESTED_REF_SPADS 0x0014
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_MAN__REF_LOCATION 0x0015
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS 0x0016
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS_HI 0x0016
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS_LO 0x0017
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS 0x0018
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS_HI 0x0018
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS_LO 0x0019
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS 0x001A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS_HI 0x001A
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS_LO 0x001B
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS 0x001C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS_HI 0x001C
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS_LO 0x001D
+
+
+
+
+
+
+
+#define VL53L1_ALGO__PART_TO_PART_RANGE_OFFSET_MM 0x001E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__PART_TO_PART_RANGE_OFFSET_MM_HI 0x001E
+
+
+
+
+
+
+
+#define VL53L1_ALGO__PART_TO_PART_RANGE_OFFSET_MM_LO 0x001F
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__INNER_OFFSET_MM 0x0020
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__INNER_OFFSET_MM_HI 0x0020
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__INNER_OFFSET_MM_LO 0x0021
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__OUTER_OFFSET_MM 0x0022
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__OUTER_OFFSET_MM_HI 0x0022
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__OUTER_OFFSET_MM_LO 0x0023
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS 0x0024
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS_HI 0x0024
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS_LO 0x0025
+
+
+
+
+
+
+
+#define VL53L1_DEBUG__CTRL 0x0026
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_TEST_MODE__CTRL 0x0027
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CLK_GATING__CTRL 0x0028
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__CTRL 0x0029
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__NUM_NVM_WORDS 0x002A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__START_ADDRESS 0x002B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_HOST_IF__STATUS 0x002C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_I2C_HV__CONFIG 0x002D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_I2C_HV__EXTSUP_CONFIG 0x002E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_HV_PAD__CTRL 0x002F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_HV_MUX__CTRL 0x0030
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO__TIO_HV_STATUS 0x0031
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO__FIO_HV_STATUS 0x0032
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__SPAD_SEL_PSWIDTH 0x0033
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_PULSE_WIDTH_OFFSET 0x0034
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__CONFIG_CTRL 0x0035
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_PULSE_WIDTH_NS 0x0036
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR__EFFECTIVE_AMBIENT_WIDTH_NS 0x0037
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR__SIGMA_REF_MM 0x0038
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CROSSTALK_COMPENSATION_VALID_HEIGHT_MM 0x0039
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SPARE_HOST_CONFIG__STATIC_CONFIG_SPARE_0 0x003A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SPARE_HOST_CONFIG__STATIC_CONFIG_SPARE_1 0x003B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS 0x003C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS_HI 0x003C
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_THRESHOLD_MCPS_LO 0x003D
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_IGNORE_VALID_HEIGHT_MM 0x003E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__RANGE_MIN_CLIP 0x003F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ALGO__CONSISTENCY_CHECK__TOLERANCE 0x0040
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SPARE_HOST_CONFIG__STATIC_CONFIG_SPARE_2 0x0041
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__RESET_STAGES_MSB 0x0042
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__RESET_STAGES_LSB 0x0043
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE 0x0044
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__STREAM_DIVIDER 0x0045
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERRUPT_CONFIG_GPIO 0x0046
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__VCSEL_START 0x0047
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__REPEAT_RATE 0x0048
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__REPEAT_RATE_HI 0x0048
+
+
+
+
+
+
+
+#define VL53L1_CAL_CONFIG__REPEAT_RATE_LO 0x0049
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__VCSEL_WIDTH 0x004A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_CONFIG__TIMEOUT_MACROP 0x004B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_CONFIG__TARGET 0x004C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_CONFIG__OVERRIDE 0x004D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__ROI_MODE_CONTROL 0x004F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_HIGH 0x0050
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_HIGH_HI 0x0050
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_HIGH_LO 0x0051
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_LOW 0x0052
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_LOW_HI 0x0052
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_RATE_LOW_LO 0x0053
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT 0x0054
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_HI 0x0054
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_LO 0x0055
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MANUAL_BLOCK_SELECT 0x0056
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__APERTURE_ATTENUATION 0x0057
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MAX_SPADS_LIMIT 0x0058
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CONFIG__MIN_SPADS_LIMIT 0x0059
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI 0x005A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_LO 0x005B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_B_HI 0x005C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_CONFIG__TIMEOUT_MACROP_B_LO 0x005D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x005E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_A_LO 0x005F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VCSEL_PERIOD_A 0x0060
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0061
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0062
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VCSEL_PERIOD_B 0x0063
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__SIGMA_THRESH 0x0064
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__SIGMA_THRESH_HI 0x0064
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__SIGMA_THRESH_LO 0x0065
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0066
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_HI 0x0066
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_LO 0x0067
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VALID_PHASE_LOW 0x0068
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_CONFIG__VALID_PHASE_HIGH 0x0069
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD 0x006C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_3 0x006C
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_2 0x006D
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_1 0x006E
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERMEASUREMENT_PERIOD_0 0x006F
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__FRACTIONAL_ENABLE 0x0070
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0 0x0071
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_HIGH 0x0072
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_HIGH_HI 0x0072
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_HIGH_LO 0x0073
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_LOW 0x0074
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_LOW_HI 0x0074
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__THRESH_LOW_LO 0x0075
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__ENABLE_XTALK_PER_QUADRANT 0x0076
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__SEED_CONFIG 0x0077
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__WOI_SD0 0x0078
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__WOI_SD1 0x0079
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__INITIAL_PHASE_SD0 0x007A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__INITIAL_PHASE_SD1 0x007B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_1 0x007C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__FIRST_ORDER_SELECT 0x007D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SD_CONFIG__QUANTIFIER 0x007E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x007F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x0080
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__SEQUENCE_CONFIG 0x0081
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD 0x0082
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE 0x0083
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__STREAM_COUNT_CTRL 0x0084
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__ENABLE 0x0085
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERRUPT_CLEAR 0x0086
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__MODE_START 0x0087
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__INTERRUPT_STATUS 0x0088
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__RANGE_STATUS 0x0089
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__REPORT_STATUS 0x008A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__STREAM_COUNT 0x008B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x008C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x008C
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x008D
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0 0x008E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x008E
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x008F
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0 0x0090
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_HI 0x0090
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_LO 0x0091
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD0 0x0092
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD0_HI 0x0092
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD0_LO 0x0093
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD0 0x0094
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD0_HI 0x0094
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD0_LO 0x0095
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0096
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_HI 0x0096
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_LO 0x0097
+
+
+
+
+
+
+
+#define VL53L1_PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0098
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_HI 0x0098
+
+
+
+
+
+
+
+#define VL53L1___PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_LO 0x0099
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0 0x009A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x009A
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x009B
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0 0x009C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x009C
+
+
+
+
+
+
+
+#define VL53L1_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x009D
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0 0x009E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x009E
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x009F
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1 0x00A0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_HI 0x00A0
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_LO 0x00A1
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1 0x00A2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_HI 0x00A2
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_LO 0x00A3
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1 0x00A4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_HI 0x00A4
+
+
+
+
+
+
+
+#define VL53L1_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_LO 0x00A5
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD1 0x00A6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD1_HI 0x00A6
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SIGMA_SD1_LO 0x00A7
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD1 0x00A8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD1_HI 0x00A8
+
+
+
+
+
+
+
+#define VL53L1_RESULT__PHASE_SD1_LO 0x00A9
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1 0x00AA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_HI 0x00AA
+
+
+
+
+
+
+
+#define VL53L1_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_LO 0x00AB
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_0_SD1 0x00AC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_0_SD1_HI 0x00AC
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_0_SD1_LO 0x00AD
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_1_SD1 0x00AE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_1_SD1_HI 0x00AE
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_1_SD1_LO 0x00AF
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_2_SD1 0x00B0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_2_SD1_HI 0x00B0
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_2_SD1_LO 0x00B1
+
+
+
+
+
+
+
+#define VL53L1_RESULT__SPARE_3_SD1 0x00B2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__THRESH_INFO 0x00B3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0 0x00B4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_3 0x00B4
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_2 0x00B5
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_1 0x00B6
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_0 0x00B7
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0 0x00B8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_3 0x00B8
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_2 0x00B9
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_1 0x00BA
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_0 0x00BB
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0 0x00BC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_3 0x00BC
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_2 0x00BD
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_1 0x00BE
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_0 0x00BF
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0 0x00C0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_3 0x00C0
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_2 0x00C1
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_1 0x00C2
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_0 0x00C3
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1 0x00C4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_3 0x00C4
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_2 0x00C5
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_1 0x00C6
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_0 0x00C7
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1 0x00C8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_3 0x00C8
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_2 0x00C9
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_1 0x00CA
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_0 0x00CB
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1 0x00CC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_3 0x00CC
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_2 0x00CD
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_1 0x00CE
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_0 0x00CF
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1 0x00D0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_3 0x00D0
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_2 0x00D1
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_1 0x00D2
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_0 0x00D3
+
+
+
+
+
+
+
+#define VL53L1_RESULT_CORE__SPARE_0 0x00D4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__REFERENCE_PHASE 0x00D6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__REFERENCE_PHASE_HI 0x00D6
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__REFERENCE_PHASE_LO 0x00D7
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__VCSEL_START 0x00D8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR_RESULT__NUM_ACTUAL_REF_SPADS 0x00D9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_REF_SPAD_CHAR_RESULT__REF_LOCATION 0x00DA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__COLDBOOT_STATUS 0x00DB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SEARCH_RESULT 0x00DC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__LATEST_SETTING 0x00DD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__OSC_CALIBRATE_VAL 0x00DE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__OSC_CALIBRATE_VAL_HI 0x00DE
+
+
+
+
+
+
+
+#define VL53L1_RESULT__OSC_CALIBRATE_VAL_LO 0x00DF
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__POWERDOWN_GO1 0x00E0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__REF_BG_CTRL 0x00E1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__REGDVDD1V2_CTRL 0x00E2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__OSC_SLOW_CTRL 0x00E3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_TEST_MODE__STATUS 0x00E4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__SYSTEM_STATUS 0x00E5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__MODE_STATUS 0x00E6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__SECONDARY_MODE_STATUS 0x00E7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__CAL_REPEAT_RATE_COUNTER 0x00E8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__CAL_REPEAT_RATE_COUNTER_HI 0x00E8
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__CAL_REPEAT_RATE_COUNTER_LO 0x00E9
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__HISTOGRAM_BIN 0x00EA
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_HIGH 0x00EC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_HIGH_HI 0x00EC
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_HIGH_LO 0x00ED
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_LOW 0x00EE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_LOW_HI 0x00EE
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_LOW_LO 0x00EF
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__ENABLE_XTALK_PER_QUADRANT 0x00F0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SPARE_0 0x00F1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__WOI_SD0 0x00F2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__WOI_SD1 0x00F3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__INITIAL_PHASE_SD0 0x00F4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__INITIAL_PHASE_SD1 0x00F5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__FIRST_ORDER_SELECT 0x00F6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SD_CONFIG__QUANTIFIER 0x00F7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__ROI_CONFIG__USER_ROI_CENTRE_SPAD 0x00F8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE 0x00F9
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__SEQUENCE_CONFIG 0x00FA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__GPH_ID 0x00FB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SYSTEM__INTERRUPT_SET 0x00FC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_MANAGER__ENABLES 0x00FD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_MANAGER__CLEAR 0x00FE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_MANAGER__STATUS 0x00FF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_TO_HOST_BANK__WR_ACCESS_EN 0x0100
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_POWER_MANAGEMENT__GO1_RESET_STATUS 0x0101
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_STARTUP_MODE__VALUE_RO 0x0102
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_STARTUP_MODE__VALUE_CTRL 0x0103
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US 0x0104
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_3 0x0104
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_2 0x0105
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_1 0x0106
+
+
+
+
+
+
+
+#define VL53L1_PLL_PERIOD_US_0 0x0107
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT 0x0108
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_3 0x0108
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_2 0x0109
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_1 0x010A
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_SCHEDULER__DATA_OUT_0 0x010B
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__COMPLETE 0x010C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_NVM_BIST__STATUS 0x010D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODEL_ID 0x010F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_TYPE 0x0110
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__REVISION_ID 0x0111
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_ID 0x0112
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_ID_HI 0x0112
+
+
+
+
+
+
+
+#define VL53L1_IDENTIFICATION__MODULE_ID_LO 0x0113
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__TRIM_MAX 0x0114
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__FAST_OSC__FREQ_SET 0x0115
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_TRIM 0x0116
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_SELION 0x0117
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ANA_CONFIG__VCSEL_SELION_MAX 0x0118
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PROTECTED_LASER_SAFETY__LOCK_BIT 0x0119
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__KEY 0x011A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__KEY_RO 0x011B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__CLIP 0x011C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_LASER_SAFETY__MULT 0x011D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_0 0x011E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_1 0x011F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_2 0x0120
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_3 0x0121
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_4 0x0122
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_5 0x0123
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_6 0x0124
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_7 0x0125
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_8 0x0126
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_9 0x0127
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_10 0x0128
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_11 0x0129
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_12 0x012A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_13 0x012B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_14 0x012C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_15 0x012D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_16 0x012E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_17 0x012F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_18 0x0130
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_19 0x0131
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_20 0x0132
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_21 0x0133
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_22 0x0134
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_23 0x0135
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_24 0x0136
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_25 0x0137
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_26 0x0138
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_27 0x0139
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_28 0x013A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_29 0x013B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_30 0x013C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_RTN_31 0x013D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__MODE_ROI_CENTRE_SPAD 0x013E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_ROI_CONFIG__MODE_ROI_XY_SIZE 0x013F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GO2_HOST_BANK_ACCESS__OVERRIDE 0x0300
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND 0x0400
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_3 0x0400
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_2 0x0401
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_1 0x0402
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLICAND_0 0x0403
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER 0x0404
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_3 0x0404
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_2 0x0405
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_1 0x0406
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__MULTIPLIER_0 0x0407
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI 0x0408
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_3 0x0408
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_2 0x0409
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_1 0x040A
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_HI_0 0x040B
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO 0x040C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_3 0x040C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_2 0x040D
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_1 0x040E
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__PRODUCT_LO_0 0x040F
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__START 0x0410
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_MULTIPLIER__STATUS 0x0411
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__START 0x0412
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__STATUS 0x0413
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND 0x0414
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_3 0x0414
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_2 0x0415
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_1 0x0416
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVIDEND_0 0x0417
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR 0x0418
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_3 0x0418
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_2 0x0419
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_1 0x041A
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__DIVISOR_0 0x041B
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT 0x041C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_3 0x041C
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_2 0x041D
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_1 0x041E
+
+
+
+
+
+
+
+#define VL53L1_MCU_UTIL_DIVIDER__QUOTIENT_0 0x041F
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN 0x0420
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_3 0x0420
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_2 0x0421
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_1 0x0422
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__VALUE_IN_0 0x0423
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN 0x0424
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_3 0x0424
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_2 0x0425
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_1 0x0426
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__VALUE_IN_0 0x0427
+
+
+
+
+
+
+
+#define VL53L1_TIMER0__CTRL 0x0428
+
+
+
+
+
+
+
+#define VL53L1_TIMER1__CTRL 0x0429
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_0 0x042C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_1 0x042D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_2 0x042E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_GENERAL_PURPOSE__GP_3 0x042F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__CONFIG 0x0430
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__OFFSET_CORRECTED_RANGE 0x0432
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__OFFSET_CORRECTED_RANGE_HI 0x0432
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__OFFSET_CORRECTED_RANGE_LO 0x0433
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4 0x0434
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_3 0x0434
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_2 0x0435
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_1 0x0436
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_4_0 0x0437
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_DURATION_PRE_CALC 0x0438
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_DURATION_PRE_CALC_HI 0x0438
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_DURATION_PRE_CALC_LO 0x0439
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_VCSEL_PERIOD 0x043C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_5 0x043D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_TOTAL_PERIODS 0x043E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_TOTAL_PERIODS_HI 0x043E
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_TOTAL_PERIODS_LO 0x043F
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE 0x0440
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_3 0x0440
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_2 0x0441
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_1 0x0442
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ACCUM_PHASE_0 0x0443
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS 0x0444
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_3 0x0444
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_2 0x0445
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_1 0x0446
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_SIGNAL_EVENTS_0 0x0447
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS 0x0448
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_3 0x0448
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_2 0x0449
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_1 0x044A
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_AMBIENT_EVENTS_0 0x044B
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_6 0x044C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_6_HI 0x044C
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_6_LO 0x044D
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ADJUST_VCSEL_PERIOD 0x044E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ADJUST_VCSEL_PERIOD_HI 0x044E
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__ALGO_ADJUST_VCSEL_PERIOD_LO 0x044F
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__NUM_SPADS 0x0450
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__NUM_SPADS_HI 0x0450
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__NUM_SPADS_LO 0x0451
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PHASE_OUTPUT 0x0452
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PHASE_OUTPUT_HI 0x0452
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PHASE_OUTPUT_LO 0x0453
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS 0x0454
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_3 0x0454
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_2 0x0455
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_1 0x0456
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__RATE_PER_SPAD_MCPS_0 0x0457
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_7 0x0458
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_8 0x0459
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_MCPS 0x045A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_MCPS_HI 0x045A
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_MCPS_LO 0x045B
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AVG_SIGNAL_RATE_MCPS 0x045C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AVG_SIGNAL_RATE_MCPS_HI 0x045C
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AVG_SIGNAL_RATE_MCPS_LO 0x045D
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_RATE_MCPS 0x045E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_RATE_MCPS_HI 0x045E
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__AMBIENT_RATE_MCPS_LO 0x045F
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__XTALK 0x0460
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__XTALK_HI 0x0460
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__XTALK_LO 0x0461
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__CALC_STATUS 0x0462
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__DEBUG 0x0463
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_XTALK_CORR_MCPS 0x0464
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_XTALK_CORR_MCPS_HI 0x0464
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__PEAK_SIGNAL_RATE_XTALK_CORR_MCPS_LO 0x0465
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_0 0x0468
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_1 0x0469
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_2 0x046A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_RANGE_CALC__SPARE_3 0x046B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PATCH__CTRL 0x0470
+
+
+
+
+
+
+
+#define VL53L1_PATCH__JMP_ENABLES 0x0472
+
+
+
+
+
+
+
+#define VL53L1_PATCH__JMP_ENABLES_HI 0x0472
+
+
+
+
+
+
+
+#define VL53L1_PATCH__JMP_ENABLES_LO 0x0473
+
+
+
+
+
+
+
+#define VL53L1_PATCH__DATA_ENABLES 0x0474
+
+
+
+
+
+
+
+#define VL53L1_PATCH__DATA_ENABLES_HI 0x0474
+
+
+
+
+
+
+
+#define VL53L1_PATCH__DATA_ENABLES_LO 0x0475
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_0 0x0476
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_0_HI 0x0476
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_0_LO 0x0477
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_1 0x0478
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_1_HI 0x0478
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_1_LO 0x0479
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_2 0x047A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_2_HI 0x047A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_2_LO 0x047B
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_3 0x047C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_3_HI 0x047C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_3_LO 0x047D
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_4 0x047E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_4_HI 0x047E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_4_LO 0x047F
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_5 0x0480
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_5_HI 0x0480
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_5_LO 0x0481
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_6 0x0482
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_6_HI 0x0482
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_6_LO 0x0483
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_7 0x0484
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_7_HI 0x0484
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_7_LO 0x0485
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_8 0x0486
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_8_HI 0x0486
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_8_LO 0x0487
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_9 0x0488
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_9_HI 0x0488
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_9_LO 0x0489
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_10 0x048A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_10_HI 0x048A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_10_LO 0x048B
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_11 0x048C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_11_HI 0x048C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_11_LO 0x048D
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_12 0x048E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_12_HI 0x048E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_12_LO 0x048F
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_13 0x0490
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_13_HI 0x0490
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_13_LO 0x0491
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_14 0x0492
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_14_HI 0x0492
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_14_LO 0x0493
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_15 0x0494
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_15_HI 0x0494
+
+
+
+
+
+
+
+#define VL53L1_PATCH__OFFSET_15_LO 0x0495
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_0 0x0496
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_0_HI 0x0496
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_0_LO 0x0497
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_1 0x0498
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_1_HI 0x0498
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_1_LO 0x0499
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_2 0x049A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_2_HI 0x049A
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_2_LO 0x049B
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_3 0x049C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_3_HI 0x049C
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_3_LO 0x049D
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_4 0x049E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_4_HI 0x049E
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_4_LO 0x049F
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_5 0x04A0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_5_HI 0x04A0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_5_LO 0x04A1
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_6 0x04A2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_6_HI 0x04A2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_6_LO 0x04A3
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_7 0x04A4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_7_HI 0x04A4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_7_LO 0x04A5
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_8 0x04A6
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_8_HI 0x04A6
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_8_LO 0x04A7
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_9 0x04A8
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_9_HI 0x04A8
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_9_LO 0x04A9
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_10 0x04AA
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_10_HI 0x04AA
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_10_LO 0x04AB
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_11 0x04AC
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_11_HI 0x04AC
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_11_LO 0x04AD
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_12 0x04AE
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_12_HI 0x04AE
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_12_LO 0x04AF
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_13 0x04B0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_13_HI 0x04B0
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_13_LO 0x04B1
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_14 0x04B2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_14_HI 0x04B2
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_14_LO 0x04B3
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_15 0x04B4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_15_HI 0x04B4
+
+
+
+
+
+
+
+#define VL53L1_PATCH__ADDRESS_15_LO 0x04B5
+
+
+
+
+
+
+
+#define VL53L1_SPI_ASYNC_MUX__CTRL 0x04C0
+
+
+
+
+
+
+
+#define VL53L1_CLK__CONFIG 0x04C4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_LV_MUX__CTRL 0x04CC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPIO_LV_PAD__CTRL 0x04CD
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PAD_I2C_LV__CONFIG 0x04D0
+
+
+
+
+
+
+
+#define VL53L1_PAD_STARTUP_MODE__VALUE_RO_GO1 0x04D4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_HOST_IF__STATUS_GO1 0x04D5
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MCU_CLK_GATING__CTRL 0x04D8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_CTRL 0x04E0
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_RESULT 0x04E1
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_MCU_SIG 0x04E2
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_MCU_SIG_HI 0x04E2
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_ROM_MCU_SIG_LO 0x04E3
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_RAM_CTRL 0x04E4
+
+
+
+
+
+
+
+#define VL53L1_TEST__BIST_RAM_RESULT 0x04E5
+
+
+
+
+
+
+
+#define VL53L1_TEST__TMC 0x04E8
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MIN_THRESHOLD 0x04F0
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MIN_THRESHOLD_HI 0x04F0
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MIN_THRESHOLD_LO 0x04F1
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MAX_THRESHOLD 0x04F2
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MAX_THRESHOLD_HI 0x04F2
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_MAX_THRESHOLD_LO 0x04F3
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_COUNT_OUT 0x04F4
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_COUNT_OUT_HI 0x04F4
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_COUNT_OUT_LO 0x04F5
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_GONOGO 0x04F6
+
+
+
+
+
+
+
+#define VL53L1_TEST__PLL_BIST_CTRL 0x04F7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__DEVICE_ID 0x0680
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REVISION_ID 0x0681
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CLK_CTRL1 0x0683
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CLK_CTRL2 0x0684
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__WOI_1 0x0685
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__WOI_REF_1 0x0686
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__START_RANGING 0x0687
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LOW_LIMIT_1 0x0690
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__HIGH_LIMIT_1 0x0691
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LOW_LIMIT_REF_1 0x0692
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__HIGH_LIMIT_REF_1 0x0693
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_1_MSB 0x0694
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_1_LSB 0x0695
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_REF_1_MSB 0x0696
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__QUANTIFIER_REF_1_LSB 0x0697
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_1_MSB 0x0698
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_1_LSB 0x0699
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_REF_1_MSB 0x069A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_OFFSET_REF_1_LSB 0x069B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FILTER_STRENGTH_1 0x069C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FILTER_STRENGTH_REF_1 0x069D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_1_MSB 0x069E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_1_LSB 0x069F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_REF_1_MSB 0x06A0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_EVENT_LIMIT_REF_1_LSB 0x06A1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TIMEOUT_OVERALL_PERIODS_MSB 0x06A4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TIMEOUT_OVERALL_PERIODS_LSB 0x06A5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INVERT_HW 0x06A6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_HW 0x06A7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_HW_VALUE 0x06A8
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_CONTINUOUS_AMBIENT 0x06A9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TEST_PHASE_SELECT_TO_FILTER 0x06AA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TEST_PHASE_SELECT_TO_TIMING_GEN 0x06AB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INITIAL_PHASE_VALUE_1 0x06AC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INITIAL_PHASE_VALUE_REF_1 0x06AD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_UP_IN 0x06AE
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__FORCE_DN_IN 0x06AF
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_UP_VALUE_1 0x06B0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_UP_VALUE_REF_1 0x06B1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_DN_VALUE_1 0x06B2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATIC_DN_VALUE_REF_1 0x06B3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__MONITOR_UP_DN 0x06B4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INVERT_UP_DN 0x06B5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_1 0x06B6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_2 0x06B7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_3 0x06B8
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__OSC_1 0x06B9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__PLL_1 0x06BB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__PLL_2 0x06BC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_1 0x06BD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_3 0x06BF
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_4 0x06C0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_5 0x06C1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REGAVDD1V2 0x06C3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_1 0x06C4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_2 0x06C5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_3 0x06C6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX_SEL1 0x06C9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX_SEL2 0x06CA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX 0x06CB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__GPIO_OUT_TESTMUX 0x06CC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CUSTOM_FE 0x06CD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CUSTOM_FE_2 0x06CE
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT 0x06CF
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT_1 0x06D0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT_2 0x06D1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_PS 0x06D2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LASER_SAFETY_2 0x06D4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__MODE 0x0780
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PDN 0x0781
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PROGN 0x0782
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__READN 0x0783
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PULSE_WIDTH_MSB 0x0784
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__PULSE_WIDTH_LSB 0x0785
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_RISE_MSB 0x0786
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_RISE_LSB 0x0787
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_FALL_MSB 0x0788
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__HV_FALL_LSB 0x0789
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__TST 0x078A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__TESTREAD 0x078B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_MMM 0x078C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_LMM 0x078D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_LLM 0x078E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAIN_LLL 0x078F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_MMM 0x0790
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_LMM 0x0791
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_LLM 0x0792
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_LLL 0x0793
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__ADDR 0x0794
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_ECC 0x0795
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_0 0x0796
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_1 0x0797
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_2 0x0798
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_3 0x0799
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_4 0x079A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_5 0x079B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_6 0x079C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_7 0x079D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_8 0x079E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_9 0x079F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_10 0x07A0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_11 0x07A1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_12 0x07A2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_13 0x07A3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_14 0x07A4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_15 0x07A5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_16 0x07A6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_17 0x07A7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_SHIFT_EN 0x07BA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_DISABLE_CTRL 0x07BB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_EN_SHIFT_OUT_DEBUG 0x07BC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPI_MODE 0x07BD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__GPIO_DIR 0x07BE
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_PERIOD 0x0880
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_START 0x0881
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_STOP 0x0882
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_1 0x0885
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_STATUS 0x088D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATUS 0x0980
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__LASER_CONTINUITY_STATE 0x0981
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_MMM 0x0982
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_LMM 0x0983
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_LLM 0x0984
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_1_LLL 0x0985
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_MMM 0x0986
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_LMM 0x0987
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_LLM 0x0988
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGE_REF_1_LLL 0x0989
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_MMM 0x098A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_LMM 0x098B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_LLM 0x098C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_1_LLL 0x098D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_MMM 0x098E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_LMM 0x098F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_LLM 0x0990
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_1_LLL 0x0991
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_MMM 0x0992
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_LMM 0x0993
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_LLM 0x0994
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_1_LLL 0x0995
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_1_MM 0x0996
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_1_LM 0x0997
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_1_LL 0x0998
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_MM 0x0999
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_LM 0x099A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_LL 0x099B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_MMM 0x099C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_LMM 0x099D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_LLM 0x099E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_WINDOW_EVENTS_REF_1_LLL 0x099F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_MMM 0x09A0
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_LMM 0x09A1
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_LLM 0x09A2
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RANGING_TOTAL_EVENTS_REF_1_LLL 0x09A3
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_MMM 0x09A4
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_LMM 0x09A5
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_LLM 0x09A6
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SIGNAL_TOTAL_EVENTS_REF_1_LLL 0x09A7
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_REF_1_MM 0x09A8
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_REF_1_LM 0x09A9
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TOTAL_PERIODS_ELAPSED_REF_1_LL 0x09AA
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_REF_MM 0x09AB
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_REF_LM 0x09AC
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__AMBIENT_MISMATCH_REF_LL 0x09AD
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__GPIO_CONFIG__A0 0x0A00
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RESET_CONTROL__A0 0x0A01
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__INTR_MANAGER__A0 0x0A02
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__POWER_FSM_TIME_OSC__A0 0x0A06
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_ATEST__A0 0x0A07
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_PERIOD_CLIPPED__A0 0x0A08
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_STOP_CLIPPED__A0 0x0A09
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CALIB_2__A0 0x0A0A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STOP_CONDITION__A0 0x0A0B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__STATUS_RESET__A0 0x0A0C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__READOUT_CFG__A0 0x0A0D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__WINDOW_SETTING__A0 0x0A0E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_DELAY__A0 0x0A1A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REFERENCE_2__A0 0x0A1B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REGAVDD1V2__A0 0x0A1D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__TST_MUX__A0 0x0A1F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CUSTOM_FE_2__A0 0x0A20
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT__A0 0x0A21
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__CPUMP_1__A0 0x0A22
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPARE_REGISTER__A0 0x0A23
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__VCSEL_CONT_STAGE5_BYPASS__A0 0x0A24
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_18 0x0A25
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_19 0x0A26
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_20 0x0A27
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_21 0x0A28
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_22 0x0A29
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_23 0x0A2A
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_24 0x0A2B
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_25 0x0A2C
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_26 0x0A2D
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_27 0x0A2E
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_28 0x0A2F
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_29 0x0A30
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_30 0x0A31
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__RET_SPAD_EN_31 0x0A32
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_0__EWOK 0x0A33
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_1__EWOK 0x0A34
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_2__EWOK 0x0A35
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_3__EWOK 0x0A36
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_4__EWOK 0x0A37
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_SPAD_EN_5__EWOK 0x0A38
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REF_EN_START_SELECT 0x0A39
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__REGDVDD1V2_ATEST__EWOK 0x0A41
+
+
+
+
+
+
+
+#define VL53L1_SOFT_RESET_GO1 0x0B00
+
+
+
+
+
+
+
+#define VL53L1_PRIVATE__PATCH_BASE_ADDR_RSLV 0x0E00
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS 0x0ED0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__RANGE_STATUS 0x0ED1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__REPORT_STATUS 0x0ED2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__STREAM_COUNT 0x0ED3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x0ED4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0ED4
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0ED5
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0 0x0ED6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0ED6
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0ED7
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0 0x0ED8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_HI 0x0ED8
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_LO 0x0ED9
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD0 0x0EDA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD0_HI 0x0EDA
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD0_LO 0x0EDB
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD0 0x0EDC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD0_HI 0x0EDC
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD0_LO 0x0EDD
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0EDE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_HI 0x0EDE
+
+
+
+
+
+
+
+#define VL53L1_PREV__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_LO 0x0EDF
+
+
+
+
+
+
+
+#define VL53L1_PREV__PEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0EE0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PPEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_HI 0x0EE0
+
+
+
+
+
+
+
+#define VL53L1_PPEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_LO 0x0EE1
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0EE2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0EE2
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0EE3
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0EE4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0EE4
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0EE5
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0 0x0EE6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0EE6
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0EE7
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1 0x0EE8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_HI 0x0EE8
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_LO 0x0EE9
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1 0x0EEA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_HI 0x0EEA
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_LO 0x0EEB
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1 0x0EEC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_HI 0x0EEC
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_LO 0x0EED
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD1 0x0EEE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD1_HI 0x0EEE
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SIGMA_SD1_LO 0x0EEF
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD1 0x0EF0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD1_HI 0x0EF0
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__PHASE_SD1_LO 0x0EF1
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1 0x0EF2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PFINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_HI 0x0EF2
+
+
+
+
+
+
+
+#define VL53L1_PFINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_LO 0x0EF3
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_0_SD1 0x0EF4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_0_SD1_HI 0x0EF4
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_0_SD1_LO 0x0EF5
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_1_SD1 0x0EF6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_1_SD1_HI 0x0EF6
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_1_SD1_LO 0x0EF7
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_2_SD1 0x0EF8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_2_SD1_HI 0x0EF8
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_2_SD1_LO 0x0EF9
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_3_SD1 0x0EFA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_3_SD1_HI 0x0EFA
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT__SPARE_3_SD1_LO 0x0EFB
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0 0x0EFC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_3 0x0EFC
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_2 0x0EFD
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_1 0x0EFE
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_0 0x0EFF
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0 0x0F00
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_3 0x0F00
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_2 0x0F01
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_1 0x0F02
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_0 0x0F03
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0 0x0F04
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_3 0x0F04
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_2 0x0F05
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_1 0x0F06
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_0 0x0F07
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0 0x0F08
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_3 0x0F08
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_2 0x0F09
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_1 0x0F0A
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_0 0x0F0B
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1 0x0F0C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_3 0x0F0C
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_2 0x0F0D
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_1 0x0F0E
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_0 0x0F0F
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1 0x0F10
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_3 0x0F10
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_2 0x0F11
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_1 0x0F12
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_0 0x0F13
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1 0x0F14
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_3 0x0F14
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_2 0x0F15
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_1 0x0F16
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_0 0x0F17
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1 0x0F18
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_3 0x0F18
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_2 0x0F19
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_1 0x0F1A
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_0 0x0F1B
+
+
+
+
+
+
+
+#define VL53L1_PREV_SHADOW_RESULT_CORE__SPARE_0 0x0F1C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DEBUG_STATUS 0x0F20
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RESULT__DEBUG_STAGE 0x0F21
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH 0x0F24
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH_HI 0x0F24
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH_LO 0x0F25
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_LOW 0x0F26
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_LOW_HI 0x0F26
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__THRESH_RATE_LOW_LO 0x0F27
+
+
+
+
+
+
+
+#define VL53L1_GPH__SYSTEM__INTERRUPT_CONFIG_GPIO 0x0F28
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL 0x0F2F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT 0x0F30
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_HI 0x0F30
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_EFFECTIVE_SPADS_SELECT_LO 0x0F31
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MANUAL_BLOCK_SELECT 0x0F32
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MAX_SPADS_LIMIT 0x0F33
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__DSS_CONFIG__MIN_SPADS_LIMIT 0x0F34
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI 0x0F36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_LO 0x0F37
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_B_HI 0x0F38
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_B_LO 0x0F39
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_A_HI 0x0F3A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_A_LO 0x0F3B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VCSEL_PERIOD_A 0x0F3C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VCSEL_PERIOD_B 0x0F3D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_B_HI 0x0F3E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__TIMEOUT_MACROP_B_LO 0x0F3F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__SIGMA_THRESH 0x0F40
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__SIGMA_THRESH_HI 0x0F40
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__SIGMA_THRESH_LO 0x0F41
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS 0x0F42
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_HI 0x0F42
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS_LO 0x0F43
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VALID_PHASE_LOW 0x0F44
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_GPH__RANGE_CONFIG__VALID_PHASE_HIGH 0x0F45
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV 0x0F46
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_FIRMWARE__INTERNAL_STREAM_COUNTER_VAL 0x0F47
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__ROI_CTRL 0x0F54
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_1 0x0F55
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_2 0x0F56
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_3 0x0F57
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_4 0x0F58
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_5 0x0F59
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_6 0x0F5A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__SPARE_7 0x0F5B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_0 0x0F5C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_1 0x0F5D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_2 0x0F5E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_3 0x0F5F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_4 0x0F60
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_5 0x0F61
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_6 0x0F62
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_7 0x0F63
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_8 0x0F64
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_9 0x0F65
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_10 0x0F66
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_11 0x0F67
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_12 0x0F68
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_13 0x0F69
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_14 0x0F6A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_15 0x0F6B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_16 0x0F6C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_17 0x0F6D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_18 0x0F6E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_19 0x0F6F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_20 0x0F70
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_21 0x0F71
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_22 0x0F72
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_23 0x0F73
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_24 0x0F74
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_25 0x0F75
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_26 0x0F76
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_27 0x0F77
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_28 0x0F78
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_29 0x0F79
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_30 0x0F7A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_SPAD_EN_31 0x0F7B
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_0 0x0F7C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__USER_ROI_1 0x0F7D
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__MODE_ROI_0 0x0F7E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_CALC__MODE_ROI_1 0x0F7F
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SIGMA_ESTIMATOR_CALC__SPARE_0 0x0F80
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__PEAK_SIGNAL_RATE_MCPS 0x0F82
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__PEAK_SIGNAL_RATE_MCPS_HI 0x0F82
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__PEAK_SIGNAL_RATE_MCPS_LO 0x0F83
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF 0x0F84
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_3 0x0F84
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_2 0x0F85
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_1 0x0F86
+
+
+
+
+
+
+
+#define VL53L1_VHV_RESULT__SIGNAL_TOTAL_EVENTS_REF_0 0x0F87
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__PHASE_OUTPUT_REF 0x0F88
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__PHASE_OUTPUT_REF_HI 0x0F88
+
+
+
+
+
+
+
+#define VL53L1_PHASECAL_RESULT__PHASE_OUTPUT_REF_LO 0x0F89
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__TOTAL_RATE_PER_SPAD 0x0F8A
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__TOTAL_RATE_PER_SPAD_HI 0x0F8A
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__TOTAL_RATE_PER_SPAD_LO 0x0F8B
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__ENABLED_BLOCKS 0x0F8C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__NUM_REQUESTED_SPADS 0x0F8E
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__NUM_REQUESTED_SPADS_HI 0x0F8E
+
+
+
+
+
+
+
+#define VL53L1_DSS_RESULT__NUM_REQUESTED_SPADS_LO 0x0F8F
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__INNER_INTERSECTION_RATE 0x0F92
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__INNER_INTERSECTION_RATE_HI 0x0F92
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__INNER_INTERSECTION_RATE_LO 0x0F93
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__OUTER_COMPLEMENT_RATE 0x0F94
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__OUTER_COMPLEMENT_RATE_HI 0x0F94
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__OUTER_COMPLEMENT_RATE_LO 0x0F95
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__TOTAL_OFFSET 0x0F96
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__TOTAL_OFFSET_HI 0x0F96
+
+
+
+
+
+
+
+#define VL53L1_MM_RESULT__TOTAL_OFFSET_LO 0x0F97
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS 0x0F98
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_3 0x0F98
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_2 0x0F99
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_1 0x0F9A
+
+
+
+
+
+
+
+#define VL53L1_XTALK_CALC__XTALK_FOR_ENABLED_SPADS_0 0x0F9B
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS 0x0F9C
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_3 0x0F9C
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_2 0x0F9D
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_1 0x0F9E
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_USER_ROI_KCPS_0 0x0F9F
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS 0x0FA0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_3 0x0FA0
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_2 0x0FA1
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_1 0x0FA2
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_INNER_ROI_KCPS_0 0x0FA3
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS 0x0FA4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_3 0x0FA4
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_2 0x0FA5
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_1 0x0FA6
+
+
+
+
+
+
+
+#define VL53L1_XTALK_RESULT__AVG_XTALK_MM_OUTER_ROI_KCPS_0 0x0FA7
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE 0x0FA8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_3 0x0FA8
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_2 0x0FA9
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_1 0x0FAA
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__ACCUM_PHASE_0 0x0FAB
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__OFFSET_CORRECTED_RANGE 0x0FAC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__OFFSET_CORRECTED_RANGE_HI 0x0FAC
+
+
+
+
+
+
+
+#define VL53L1_RANGE_RESULT__OFFSET_CORRECTED_RANGE_LO 0x0FAD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START 0x0FAE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__INTERRUPT_STATUS 0x0FB0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__RANGE_STATUS 0x0FB1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__REPORT_STATUS 0x0FB2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__STREAM_COUNT 0x0FB3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0 0x0FB4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0FB4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0FB5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0 0x0FB6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0FB6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0FB7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0 0x0FB8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_HI 0x0FB8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD0_LO 0x0FB9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD0 0x0FBA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD0_HI 0x0FBA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD0_LO 0x0FBB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD0 0x0FBC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD0_HI 0x0FBC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD0_LO 0x0FBD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 0x0FBE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_HI 0x0FBE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0_LO 0x0FBF
+
+
+
+
+
+
+
+#define VL53L1_SHPEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0 0x0FC0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHPEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_HI 0x0FC0
+
+
+
+
+
+
+
+#define VL53L1_SHPEAK_SIGNAL_COUNT_RATE_CROSSTALK_CORRECTED_MCPS_SD0_LO 0x0FC1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0FC2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0FC2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_INNER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0FC3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0 0x0FC4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_HI 0x0FC4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__MM_OUTER_ACTUAL_EFFECTIVE_SPADS_SD0_LO 0x0FC5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0 0x0FC6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_HI 0x0FC6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AVG_SIGNAL_COUNT_RATE_MCPS_SD0_LO 0x0FC7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1 0x0FC8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_HI 0x0FC8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__DSS_ACTUAL_EFFECTIVE_SPADS_SD1_LO 0x0FC9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1 0x0FCA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_HI 0x0FCA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PEAK_SIGNAL_COUNT_RATE_MCPS_SD1_LO 0x0FCB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1 0x0FCC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_HI 0x0FCC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__AMBIENT_COUNT_RATE_MCPS_SD1_LO 0x0FCD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD1 0x0FCE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD1_HI 0x0FCE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SIGMA_SD1_LO 0x0FCF
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD1 0x0FD0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD1_HI 0x0FD0
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__PHASE_SD1_LO 0x0FD1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1 0x0FD2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_HI 0x0FD2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD1_LO 0x0FD3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_0_SD1 0x0FD4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_0_SD1_HI 0x0FD4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_0_SD1_LO 0x0FD5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_1_SD1 0x0FD6
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_1_SD1_HI 0x0FD6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_1_SD1_LO 0x0FD7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_2_SD1 0x0FD8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_2_SD1_HI 0x0FD8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_2_SD1_LO 0x0FD9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__SPARE_3_SD1 0x0FDA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT__THRESH_INFO 0x0FDB
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0 0x0FDC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_3 0x0FDC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_2 0x0FDD
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_1 0x0FDE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0_0 0x0FDF
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0 0x0FE0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_3 0x0FE0
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_2 0x0FE1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_1 0x0FE2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD0_0 0x0FE3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0 0x0FE4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_3 0x0FE4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_2 0x0FE5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_1 0x0FE6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD0_0 0x0FE7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0 0x0FE8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_3 0x0FE8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_2 0x0FE9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_1 0x0FEA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD0_0 0x0FEB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1 0x0FEC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_3 0x0FEC
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_2 0x0FED
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_1 0x0FEE
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD1_0 0x0FEF
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1 0x0FF0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_3 0x0FF0
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_2 0x0FF1
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_1 0x0FF2
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__RANGING_TOTAL_EVENTS_SD1_0 0x0FF3
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1 0x0FF4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_3 0x0FF4
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_2 0x0FF5
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_1 0x0FF6
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SIGNAL_TOTAL_EVENTS_SD1_0 0x0FF7
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1 0x0FF8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_3 0x0FF8
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_2 0x0FF9
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_1 0x0FFA
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__TOTAL_PERIODS_ELAPSED_SD1_0 0x0FFB
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_RESULT_CORE__SPARE_0 0x0FFC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_PHASECAL_RESULT__REFERENCE_PHASE_HI 0x0FFE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_SHADOW_PHASECAL_RESULT__REFERENCE_PHASE_LO 0x0FFF
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_settings.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_settings.h
new file mode 100644
index 000000000000..22bb9ef0fa67
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_settings.h
@@ -0,0 +1,274 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_SETTINGS_H_
+#define _VL53L1_REGISTER_SETTINGS_H_
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO 0x00
+#define VL53L1_DEVICESCHEDULERMODE_STREAMING 0x01
+#define VL53L1_DEVICESCHEDULERMODE_HISTOGRAM 0x02
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICEREADOUTMODE_SINGLE_SD (0x00 << 2)
+#define VL53L1_DEVICEREADOUTMODE_DUAL_SD (0x01 << 2)
+#define VL53L1_DEVICEREADOUTMODE_SPLIT_READOUT (0x02 << 2)
+#define VL53L1_DEVICEREADOUTMODE_SPLIT_MANUAL (0x03 << 2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK 0xF0
+#define VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK 0x0F
+
+#define VL53L1_GROUPEDPARAMETERHOLD_ID_MASK 0x02
+
+
+
+
+#define VL53L1_EWOK_I2C_DEV_ADDR_DEFAULT 0x29
+
+
+#define VL53L1_OSC_FREQUENCY 0x00
+#define VL53L1_OSC_TRIM_DEFAULT 0x00
+#define VL53L1_OSC_FREQ_SET_DEFAULT 0x00
+
+#define VL53L1_RANGE_HISTOGRAM_REF 0x08
+#define VL53L1_RANGE_HISTOGRAM_RET 0x10
+#define VL53L1_RANGE_HISTOGRAM_BOTH 0x18
+#define VL53L1_RANGE_HISTOGRAM_INIT 0x20
+#define VL53L1_RANGE_VHV_INIT 0x40
+
+
+
+#define VL53L1_RESULT_RANGE_STATUS 0x1F
+
+
+
+#define VL53L1_SYSTEM__SEED_CONFIG__MANUAL 0x00
+#define VL53L1_SYSTEM__SEED_CONFIG__STANDARD 0x01
+#define VL53L1_SYSTEM__SEED_CONFIG__EVEN_UPDATE_ONLY 0x02
+
+
+
+#define VL53L1_INTERRUPT_CONFIG_LEVEL_LOW 0x00
+#define VL53L1_INTERRUPT_CONFIG_LEVEL_HIGH 0x01
+#define VL53L1_INTERRUPT_CONFIG_OUT_OF_WINDOW 0x02
+#define VL53L1_INTERRUPT_CONFIG_IN_WINDOW 0x03
+#define VL53L1_INTERRUPT_CONFIG_NEW_SAMPLE_READY 0x20
+
+
+
+#define VL53L1_CLEAR_RANGE_INT 0x01
+#define VL53L1_CLEAR_ERROR_INT 0x02
+
+
+
+#define VL53L1_SEQUENCE_VHV_EN 0x01
+#define VL53L1_SEQUENCE_PHASECAL_EN 0x02
+#define VL53L1_SEQUENCE_REFERENCE_PHASE_EN 0x04
+#define VL53L1_SEQUENCE_DSS1_EN 0x08
+#define VL53L1_SEQUENCE_DSS2_EN 0x10
+#define VL53L1_SEQUENCE_MM1_EN 0x20
+#define VL53L1_SEQUENCE_MM2_EN 0x40
+#define VL53L1_SEQUENCE_RANGE_EN 0x80
+
+
+
+#define VL53L1_DSS_CONTROL__ROI_SUBTRACT 0x20
+#define VL53L1_DSS_CONTROL__ROI_INTERSECT 0x10
+
+#define VL53L1_DSS_CONTROL__MODE_DISABLED 0x00
+#define VL53L1_DSS_CONTROL__MODE_TARGET_RATE 0x01
+#define VL53L1_DSS_CONTROL__MODE_EFFSPADS 0x02
+#define VL53L1_DSS_CONTROL__MODE_BLOCKSELECT 0x03
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD 0x45
+#define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_ARRAY_ONLY 0x05
+#define VL53L1_RANGING_CORE__SPAD_READOUT__REFERENCE_ARRAY_ONLY 0x55
+#define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_SPLIT_ARRAY 0x25
+#define VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES 0xF5
+
+
+#define VL53L1_LASER_SAFETY__KEY_VALUE 0x6C
+
+
+
+
+
+
+
+
+
+
+#define VL53L1_RANGE_STATUS__RANGE_STATUS_MASK 0x1F
+#define VL53L1_RANGE_STATUS__MAX_THRESHOLD_HIT_MASK 0x20
+#define VL53L1_RANGE_STATUS__MIN_THRESHOLD_HIT_MASK 0x40
+#define VL53L1_RANGE_STATUS__GPH_ID_RANGE_STATUS_MASK 0x80
+
+
+
+
+
+
+
+
+
+#define VL53L1_INTERRUPT_STATUS__INT_STATUS_MASK 0x07
+#define VL53L1_INTERRUPT_STATUS__INT_ERROR_STATUS_MASK 0x18
+#define VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK 0x20
+
+
+
+
+
+#endif
+
+
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_structs.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_structs.h
new file mode 100644
index 000000000000..f928566a883d
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_register_structs.h
@@ -0,0 +1,4872 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_REGISTER_STRUCTS_H_
+#define _VL53L1_REGISTER_STRUCTS_H_
+
+#include "vl53l1_types.h"
+#include "vl53l1_register_map.h"
+
+#define VL53L1_STATIC_NVM_MANAGED_I2C_INDEX \
+ VL53L1_I2C_SLAVE__DEVICE_ADDRESS
+#define VL53L1_CUSTOMER_NVM_MANAGED_I2C_INDEX \
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0
+#define VL53L1_STATIC_CONFIG_I2C_INDEX \
+ VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS
+#define VL53L1_GENERAL_CONFIG_I2C_INDEX \
+ VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE
+#define VL53L1_TIMING_CONFIG_I2C_INDEX \
+ VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI
+#define VL53L1_DYNAMIC_CONFIG_I2C_INDEX \
+ VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0
+#define VL53L1_SYSTEM_CONTROL_I2C_INDEX \
+ VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE
+#define VL53L1_SYSTEM_RESULTS_I2C_INDEX \
+ VL53L1_RESULT__INTERRUPT_STATUS
+#define VL53L1_CORE_RESULTS_I2C_INDEX \
+ VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0
+#define VL53L1_DEBUG_RESULTS_I2C_INDEX \
+ VL53L1_PHASECAL_RESULT__REFERENCE_PHASE
+#define VL53L1_NVM_COPY_DATA_I2C_INDEX \
+ VL53L1_IDENTIFICATION__MODEL_ID
+#define VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_INDEX \
+ VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS
+#define VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_INDEX \
+ VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0
+#define VL53L1_PATCH_DEBUG_I2C_INDEX \
+ VL53L1_RESULT__DEBUG_STATUS
+#define VL53L1_GPH_GENERAL_CONFIG_I2C_INDEX \
+ VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH
+#define VL53L1_GPH_STATIC_CONFIG_I2C_INDEX \
+ VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL
+#define VL53L1_GPH_TIMING_CONFIG_I2C_INDEX \
+ VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI
+#define VL53L1_FW_INTERNAL_I2C_INDEX \
+ VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV
+#define VL53L1_PATCH_RESULTS_I2C_INDEX \
+ VL53L1_DSS_CALC__ROI_CTRL
+#define VL53L1_SHADOW_SYSTEM_RESULTS_I2C_INDEX \
+ VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START
+#define VL53L1_SHADOW_CORE_RESULTS_I2C_INDEX \
+ VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0
+
+#define VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES 11
+#define VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES 23
+#define VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES 32
+#define VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES 22
+#define VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES 23
+#define VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES 18
+#define VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES 5
+#define VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES 44
+#define VL53L1_CORE_RESULTS_I2C_SIZE_BYTES 33
+#define VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES 56
+#define VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES 49
+#define VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES 44
+#define VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES 33
+#define VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES 2
+#define VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES 5
+#define VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES 6
+#define VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES 16
+#define VL53L1_FW_INTERNAL_I2C_SIZE_BYTES 2
+#define VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES 90
+#define VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES 82
+#define VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES 33
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t i2c_slave__device_address;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vhv_ref_sel_vddpix;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vhv_ref_sel_vquench;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__reg_avdd1v2_sel;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__trim;
+
+
+
+
+
+
+
+
+
+
+ uint16_t osc_measured__fast_osc__frequency;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__timeout_macrop_loop_bound;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__count_thresh;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__offset;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_config__init;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_static_nvm_managed_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t global_config__spad_enables_ref_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_ref_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__ref_en_start_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_man__num_requested_ref_spads;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_man__ref_location;
+
+
+
+
+
+
+
+
+
+
+ uint16_t algo__crosstalk_compensation_plane_offset_kcps;
+
+
+
+
+
+
+
+
+
+
+ int16_t algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+
+
+
+
+
+
+
+
+
+ int16_t algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint16_t ref_spad_char__total_rate_target_mcps;
+
+
+
+
+
+
+
+
+
+
+ int16_t algo__part_to_part_range_offset_mm;
+
+
+
+
+
+
+
+
+
+
+ int16_t mm_config__inner_offset_mm;
+
+
+
+
+
+
+
+
+
+
+ int16_t mm_config__outer_offset_mm;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_customer_nvm_managed_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint16_t dss_config__target_total_rate_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t debug__ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t test_mode__ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t clk_gating__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__num_nvm_words;
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__start_address;
+
+
+
+
+
+
+
+
+
+
+ uint8_t host_if__status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_i2c_hv__config;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_i2c_hv__extsup_config;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio_hv_pad__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio_hv_mux__ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio__tio_hv_status;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gpio__fio_hv_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__spad_sel_pswidth;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_pulse_width_offset;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__config_ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator__effective_pulse_width_ns;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator__effective_ambient_width_ns;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator__sigma_ref_mm;
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__crosstalk_compensation_valid_height_mm;
+
+
+
+
+
+
+
+
+
+
+ uint8_t spare_host_config__static_config_spare_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t spare_host_config__static_config_spare_1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t algo__range_ignore_threshold_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__range_ignore_valid_height_mm;
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__range_min_clip;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t algo__consistency_check__tolerance;
+
+
+
+
+
+
+
+
+
+
+ uint8_t spare_host_config__static_config_spare_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__reset_stages_msb;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__reset_stages_lsb;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_static_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t gph_config__stream_count_update_value;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__stream_divider;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__interrupt_config_gpio;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t cal_config__vcsel_start;
+
+
+
+
+
+
+
+
+
+
+ uint16_t cal_config__repeat_rate;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__vcsel_width;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_config__timeout_macrop;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_config__target;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_config__override;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__roi_mode_control;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_rate_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_rate_low;
+
+
+
+
+
+
+
+
+
+
+ uint16_t dss_config__manual_effective_spads_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__manual_block_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__aperture_attenuation;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__max_spads_limit;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_config__min_spads_limit;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_general_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t mm_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t mm_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t mm_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t mm_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__vcsel_period_a;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__vcsel_period_b;
+
+
+
+
+
+
+
+
+
+
+ uint16_t range_config__sigma_thresh;
+
+
+
+
+
+
+
+
+
+
+ uint16_t range_config__min_count_rate_rtn_limit_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__valid_phase_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t range_config__valid_phase_high;
+
+
+
+
+
+
+
+
+
+
+ uint32_t system__intermeasurement_period;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__fractional_enable;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_timing_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t system__grouped_parameter_hold_0;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t system__thresh_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__enable_xtalk_per_quadrant;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__seed_config;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__woi_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__woi_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__initial_phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__initial_phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__grouped_parameter_hold_1;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__first_order_select;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t sd_config__quantifier;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__user_roi_centre_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__user_roi_requested_global_xy_size;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__sequence_config;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__grouped_parameter_hold;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_dynamic_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t power_management__go1_power_force;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__stream_count_ctrl;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__enable;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__interrupt_clear;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__mode_start;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_system_control_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t result__interrupt_status;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__range_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__report_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__stream_count;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__dss_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__peak_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__ambient_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__sigma_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__final_crosstalk_corrected_range_mm_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__mm_inner_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__mm_outer_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__avg_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__dss_actual_effective_spads_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__peak_signal_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__ambient_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__sigma_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__final_crosstalk_corrected_range_mm_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__spare_0_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__spare_1_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__spare_2_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__spare_3_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__thresh_info;
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_system_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t result_core__ambient_window_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__ranging_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ int32_t result_core__signal_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__total_periods_elapsed_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__ambient_window_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__ranging_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ int32_t result_core__signal_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t result_core__total_periods_elapsed_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result_core__spare_0;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_core_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint16_t phasecal_result__reference_phase;
+
+
+
+
+
+
+
+
+
+
+ uint8_t phasecal_result__vcsel_start;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_char_result__num_actual_ref_spads;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ref_spad_char_result__ref_location;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_result__coldboot_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_result__search_result;
+
+
+
+
+
+
+
+
+
+
+ uint8_t vhv_result__latest_setting;
+
+
+
+
+
+
+
+
+
+
+ uint16_t result__osc_calibrate_val;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__powerdown_go1;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__ref_bg_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__regdvdd1v2_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__osc_slow_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t test_mode__status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__system_status;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__mode_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__secondary_mode_status;
+
+
+
+
+
+
+
+
+
+
+ uint16_t firmware__cal_repeat_rate_counter;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__system__thresh_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__system__thresh_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__system__enable_xtalk_per_quadrant;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__spare_0;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__woi_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__woi_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__initial_phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__initial_phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__first_order_select;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__sd_config__quantifier;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__roi_config__user_roi_centre_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__roi_config__user_roi_requested_global_xy_size;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__system__sequence_config;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__gph_id;
+
+
+
+
+
+
+
+
+
+
+ uint8_t system__interrupt_set;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t interrupt_manager__enables;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t interrupt_manager__clear;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t interrupt_manager__status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t mcu_to_host_bank__wr_access_en;
+
+
+
+
+
+
+
+
+
+
+ uint8_t power_management__go1_reset_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_startup_mode__value_ro;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t pad_startup_mode__value_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint32_t pll_period_us;
+
+
+
+
+
+
+
+
+
+
+ uint32_t interrupt_scheduler__data_out;
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__complete;
+
+
+
+
+
+
+
+
+
+
+ uint8_t nvm_bist__status;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_debug_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t identification__model_id;
+
+
+
+
+
+
+
+
+
+
+ uint8_t identification__module_type;
+
+
+
+
+
+
+
+
+
+
+ uint8_t identification__revision_id;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t identification__module_id;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__trim_max;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__fast_osc__freq_set;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_trim;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_selion;
+
+
+
+
+
+
+
+
+
+
+ uint8_t ana_config__vcsel_selion_max;
+
+
+
+
+
+
+
+
+
+
+ uint8_t protected_laser_safety__lock_bit;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__key;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__key_ro;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__clip;
+
+
+
+
+
+
+
+
+
+
+ uint8_t laser_safety__mult;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_6;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_7;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_8;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_9;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_10;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_11;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_12;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_13;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_14;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_15;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_16;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_17;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_18;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_19;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_20;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_21;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_22;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_23;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_24;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_25;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_26;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_27;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_28;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_29;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_30;
+
+
+
+
+
+
+
+
+
+
+ uint8_t global_config__spad_enables_rtn_31;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__mode_roi_centre_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t roi_config__mode_roi_xy_size;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_nvm_copy_data_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t prev_shadow_result__interrupt_status;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result__range_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result__report_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result__stream_count;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__dss_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__peak_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__ambient_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__sigma_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__final_crosstalk_corrected_range_mm_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t
+ psr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__mm_inner_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__mm_outer_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__avg_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__dss_actual_effective_spads_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__peak_signal_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__ambient_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__sigma_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__final_crosstalk_corrected_range_mm_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_0_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_1_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_2_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t prev_shadow_result__spare_3_sd1;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_prev_shadow_system_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t prev_shadow_result_core__ambient_window_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__ranging_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ int32_t prev_shadow_result_core__signal_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__total_periods_elapsed_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__ambient_window_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__ranging_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ int32_t prev_shadow_result_core__signal_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t prev_shadow_result_core__total_periods_elapsed_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t prev_shadow_result_core__spare_0;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_prev_shadow_core_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t result__debug_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t result__debug_stage;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_patch_debug_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint16_t gph__system__thresh_rate_high;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__system__thresh_rate_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__system__interrupt_config_gpio;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+} VL53L1_gph_general_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t gph__dss_config__roi_mode_control;
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__dss_config__manual_effective_spads_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__dss_config__manual_block_select;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__dss_config__max_spads_limit;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__dss_config__min_spads_limit;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_gph_static_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t gph__mm_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__mm_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__mm_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__mm_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_a_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_a_lo;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__vcsel_period_a;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__vcsel_period_b;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_b_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__timeout_macrop_b_lo;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__range_config__sigma_thresh;
+
+
+
+
+
+
+
+
+
+
+ uint16_t gph__range_config__min_count_rate_rtn_limit_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__valid_phase_low;
+
+
+
+
+
+
+
+
+
+
+ uint8_t gph__range_config__valid_phase_high;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_gph_timing_config_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t firmware__internal_stream_count_div;
+
+
+
+
+
+
+
+
+
+
+ uint8_t firmware__internal_stream_counter_val;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_fw_internal_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t dss_calc__roi_ctrl;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_6;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__spare_7;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_2;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_3;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_4;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_5;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_6;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_7;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_8;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_9;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_10;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_11;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_12;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_13;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_14;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_15;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_16;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_17;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_18;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_19;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_20;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_21;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_22;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_23;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_24;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_25;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_26;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_27;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_28;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_29;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_30;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_spad_en_31;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__user_roi_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__mode_roi_0;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_calc__mode_roi_1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t sigma_estimator_calc__spare_0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t vhv_result__peak_signal_rate_mcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t vhv_result__signal_total_events_ref;
+
+
+
+
+
+
+
+
+
+
+ uint16_t phasecal_result__phase_output_ref;
+
+
+
+
+
+
+
+
+
+
+ uint16_t dss_result__total_rate_per_spad;
+
+
+
+
+
+
+
+
+
+
+ uint8_t dss_result__enabled_blocks;
+
+
+
+
+
+
+
+
+
+
+ uint16_t dss_result__num_requested_spads;
+
+
+
+
+
+
+
+
+
+
+ uint16_t mm_result__inner_intersection_rate;
+
+
+
+
+
+
+
+
+
+
+ uint16_t mm_result__outer_complement_rate;
+
+
+
+
+
+
+
+
+
+
+ uint16_t mm_result__total_offset;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_calc__xtalk_for_enabled_spads;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_result__avg_xtalk_user_roi_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_result__avg_xtalk_mm_inner_roi_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t xtalk_result__avg_xtalk_mm_outer_roi_kcps;
+
+
+
+
+
+
+
+
+
+
+ uint32_t range_result__accum_phase;
+
+
+
+
+
+
+
+
+
+
+ uint16_t range_result__offset_corrected_range;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_patch_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint8_t shadow_phasecal_result__vcsel_start;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__interrupt_status;
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__range_status;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__report_status;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__stream_count;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__dss_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__peak_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__ambient_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__sigma_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__phase_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__final_crosstalk_corrected_range_mm_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t
+ shr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__mm_inner_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__mm_outer_actual_effective_spads_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__avg_signal_count_rate_mcps_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__dss_actual_effective_spads_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__peak_signal_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__ambient_count_rate_mcps_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__sigma_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__phase_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__final_crosstalk_corrected_range_mm_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__spare_0_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__spare_1_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint16_t shadow_result__spare_2_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__spare_3_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result__thresh_info;
+
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_phasecal_result__reference_phase_hi;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_phasecal_result__reference_phase_lo;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_shadow_system_results_t;
+
+
+
+
+
+
+
+
+
+
+
+
+typedef struct {
+ uint32_t shadow_result_core__ambient_window_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__ranging_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ int32_t shadow_result_core__signal_total_events_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__total_periods_elapsed_sd0;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__ambient_window_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__ranging_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ int32_t shadow_result_core__signal_total_events_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint32_t shadow_result_core__total_periods_elapsed_sd1;
+
+
+
+
+
+
+
+
+
+
+ uint8_t shadow_result_core__spare_0;
+
+
+
+
+
+
+
+
+
+
+} VL53L1_shadow_core_results_t;
+
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_silicon_core.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_silicon_core.h
new file mode 100644
index 000000000000..d48393e143cd
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_silicon_core.h
@@ -0,0 +1,134 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_SILICON_CORE_H_
+#define _VL53L1_SILICON_CORE_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_firmware_ready_silicon(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_tuning_parm_defaults.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_tuning_parm_defaults.h
new file mode 100644
index 000000000000..b0753e2f0971
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_tuning_parm_defaults.h
@@ -0,0 +1,418 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_TUNING_PARM_DEFAULTS_H_
+#define _VL53L1_TUNING_PARM_DEFAULTS_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+#define VL53L1_TUNINGPARM_VERSION_DEFAULT \
+((uint16_t) 28)
+#define VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT \
+((uint16_t) 14)
+#define VL53L1_TUNINGPARM_LLD_VERSION_DEFAULT \
+((uint16_t) 12180)
+#define VL53L1_TUNINGPARM_HIST_ALGO_SELECT_DEFAULT \
+((uint8_t) 4)
+#define VL53L1_TUNINGPARM_HIST_TARGET_ORDER_DEFAULT \
+((uint8_t) 1)
+#define VL53L1_TUNINGPARM_HIST_FILTER_WOI_0_DEFAULT \
+((uint8_t) 1)
+#define VL53L1_TUNINGPARM_HIST_FILTER_WOI_1_DEFAULT \
+((uint8_t) 2)
+#define VL53L1_TUNINGPARM_HIST_AMB_EST_METHOD_DEFAULT \
+((uint8_t) 1)
+#define VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_0_DEFAULT \
+((uint8_t) 80)
+#define VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_1_DEFAULT \
+((uint8_t) 100)
+#define VL53L1_TUNINGPARM_HIST_MIN_AMB_THRESH_EVENTS_DEFAULT \
+((int32_t) 16)
+#define VL53L1_TUNINGPARM_HIST_AMB_EVENTS_SCALER_DEFAULT \
+((uint16_t) 4157)
+#define VL53L1_TUNINGPARM_HIST_NOISE_THRESHOLD_DEFAULT \
+((uint16_t) 50)
+#define VL53L1_TUNINGPARM_HIST_SIGNAL_TOTAL_EVENTS_LIMIT_DEFAULT \
+((int32_t) 100)
+#define VL53L1_TUNINGPARM_HIST_SIGMA_EST_REF_MM_DEFAULT \
+((uint8_t) 1)
+#define VL53L1_TUNINGPARM_HIST_SIGMA_THRESH_MM_DEFAULT \
+((uint16_t) 180)
+#define VL53L1_TUNINGPARM_HIST_GAIN_FACTOR_DEFAULT \
+((uint16_t) 1987)
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_PHASE_TOLERANCE_DEFAULT \
+((uint8_t) 8)
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_MIN_MAX_TOLERANCE_MM_DEFAULT \
+((uint16_t) 0)
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_DEFAULT \
+((uint8_t) 0)
+#define VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_MIN_SPAD_LIMIT_DEFAULT \
+((uint16_t) 2048)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_LONG_RANGE_DEFAULT \
+((uint8_t) 9)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_MED_RANGE_DEFAULT \
+((uint8_t) 5)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_SHORT_RANGE_DEFAULT \
+((uint8_t) 3)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_LONG_RANGE_DEFAULT \
+((uint8_t) 6)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_MED_RANGE_DEFAULT \
+((uint8_t) 6)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_SHORT_RANGE_DEFAULT \
+((uint8_t) 6)
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MIN_VALID_RANGE_MM_DEFAULT \
+((int16_t) -50)
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RANGE_MM_DEFAULT \
+((int16_t) 50)
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_SIGMA_MM_DEFAULT \
+((uint16_t) 140)
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MIN_MAX_TOLERANCE_DEFAULT \
+((uint16_t) 50)
+#define VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RATE_KCPS_DEFAULT \
+((uint16_t) 400)
+#define VL53L1_TUNINGPARM_XTALK_DETECT_EVENT_SIGMA_DEFAULT \
+((uint8_t) 80)
+#define VL53L1_TUNINGPARM_HIST_XTALK_MARGIN_KCPS_DEFAULT \
+((int16_t) 0)
+#define VL53L1_TUNINGPARM_CONSISTENCY_LITE_PHASE_TOLERANCE_DEFAULT \
+((uint8_t) 2)
+#define VL53L1_TUNINGPARM_PHASECAL_TARGET_DEFAULT \
+((uint8_t) 33)
+#define VL53L1_TUNINGPARM_LITE_CAL_REPEAT_RATE_DEFAULT \
+((uint16_t) 0)
+#define VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR_DEFAULT \
+((uint16_t) 2011)
+#define VL53L1_TUNINGPARM_LITE_MIN_CLIP_MM_DEFAULT \
+((uint8_t) 0)
+#define VL53L1_TUNINGPARM_LITE_LONG_SIGMA_THRESH_MM_DEFAULT \
+((uint16_t) 60)
+#define VL53L1_TUNINGPARM_LITE_MED_SIGMA_THRESH_MM_DEFAULT \
+((uint16_t) 60)
+#define VL53L1_TUNINGPARM_LITE_SHORT_SIGMA_THRESH_MM_DEFAULT \
+((uint16_t) 60)
+#define VL53L1_TUNINGPARM_LITE_LONG_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \
+((uint16_t) 128)
+#define VL53L1_TUNINGPARM_LITE_MED_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \
+((uint16_t) 128)
+#define VL53L1_TUNINGPARM_LITE_SHORT_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \
+((uint16_t) 128)
+#define VL53L1_TUNINGPARM_LITE_SIGMA_EST_PULSE_WIDTH_DEFAULT \
+((uint8_t) 8)
+#define VL53L1_TUNINGPARM_LITE_SIGMA_EST_AMB_WIDTH_NS_DEFAULT \
+((uint8_t) 16)
+#define VL53L1_TUNINGPARM_LITE_SIGMA_REF_MM_DEFAULT \
+((uint8_t) 1)
+#define VL53L1_TUNINGPARM_LITE_RIT_MULT_DEFAULT \
+((uint8_t) 64)
+#define VL53L1_TUNINGPARM_LITE_SEED_CONFIG_DEFAULT \
+((uint8_t) 2)
+#define VL53L1_TUNINGPARM_LITE_QUANTIFIER_DEFAULT \
+((uint8_t) 2)
+#define VL53L1_TUNINGPARM_LITE_FIRST_ORDER_SELECT_DEFAULT \
+((uint8_t) 0)
+#define VL53L1_TUNINGPARM_LITE_XTALK_MARGIN_KCPS_DEFAULT \
+((int16_t) 0)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_LONG_RANGE_DEFAULT \
+((uint8_t) 14)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_MED_RANGE_DEFAULT \
+((uint8_t) 10)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_SHORT_RANGE_DEFAULT \
+((uint8_t) 6)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_LONG_RANGE_DEFAULT \
+((uint8_t) 14)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_MED_RANGE_DEFAULT \
+((uint8_t) 10)
+#define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_SHORT_RANGE_DEFAULT \
+((uint8_t) 6)
+#define VL53L1_TUNINGPARM_TIMED_SEED_CONFIG_DEFAULT \
+((uint8_t) 1)
+#define VL53L1_TUNINGPARM_DMAX_CFG_SIGNAL_THRESH_SIGMA_DEFAULT \
+((uint8_t) 32)
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_0_DEFAULT \
+((uint16_t) 15)
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_1_DEFAULT \
+((uint16_t) 52)
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_2_DEFAULT \
+((uint16_t) 200)
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_3_DEFAULT \
+((uint16_t) 364)
+#define VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_4_DEFAULT \
+((uint16_t) 400)
+#define VL53L1_TUNINGPARM_VHV_LOOPBOUND_DEFAULT \
+((uint8_t) 129)
+#define VL53L1_TUNINGPARM_REFSPADCHAR_DEVICE_TEST_MODE_DEFAULT \
+((uint8_t) 8)
+#define VL53L1_TUNINGPARM_REFSPADCHAR_VCSEL_PERIOD_DEFAULT \
+((uint8_t) 11)
+#define VL53L1_TUNINGPARM_REFSPADCHAR_PHASECAL_TIMEOUT_US_DEFAULT \
+((uint32_t) 1000)
+#define VL53L1_TUNINGPARM_REFSPADCHAR_TARGET_COUNT_RATE_MCPS_DEFAULT \
+((uint16_t) 2560)
+#define VL53L1_TUNINGPARM_REFSPADCHAR_MIN_COUNTRATE_LIMIT_MCPS_DEFAULT \
+((uint16_t) 1280)
+#define VL53L1_TUNINGPARM_REFSPADCHAR_MAX_COUNTRATE_LIMIT_MCPS_DEFAULT \
+((uint16_t) 5120)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_NUM_OF_SAMPLES_DEFAULT \
+((uint8_t) 7)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MIN_FILTER_THRESH_MM_DEFAULT \
+((int16_t) -70)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_FILTER_THRESH_MM_DEFAULT \
+((int16_t) 70)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_RATE_MCPS_DEFAULT \
+((uint16_t) 5120)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_PHASECAL_TIMEOUT_US_DEFAULT \
+((uint32_t) 15000)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_VALID_RATE_KCPS_DEFAULT \
+((uint16_t) 640)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_SIGMA_THRESHOLD_MM_DEFAULT \
+((uint16_t) 140)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_TIMEOUT_US_DEFAULT \
+((uint32_t) 2000)
+#define VL53L1_TUNINGPARM_XTALK_EXTRACT_BIN_TIMEOUT_US_DEFAULT \
+((uint32_t) 10000)
+#define VL53L1_TUNINGPARM_OFFSET_CAL_DSS_RATE_MCPS_DEFAULT \
+((uint16_t) 2560)
+#define VL53L1_TUNINGPARM_OFFSET_CAL_PHASECAL_TIMEOUT_US_DEFAULT \
+((uint32_t) 15000)
+#define VL53L1_TUNINGPARM_OFFSET_CAL_MM_TIMEOUT_US_DEFAULT \
+((uint32_t) 13000)
+#define VL53L1_TUNINGPARM_OFFSET_CAL_RANGE_TIMEOUT_US_DEFAULT \
+((uint32_t) 13000)
+#define VL53L1_TUNINGPARM_OFFSET_CAL_PRE_SAMPLES_DEFAULT \
+((uint8_t) 8)
+#define VL53L1_TUNINGPARM_OFFSET_CAL_MM1_SAMPLES_DEFAULT \
+((uint8_t) 40)
+#define VL53L1_TUNINGPARM_OFFSET_CAL_MM2_SAMPLES_DEFAULT \
+((uint8_t) 9)
+#define VL53L1_TUNINGPARM_ZONE_CAL_DSS_RATE_MCPS_DEFAULT \
+((uint16_t) 5120)
+#define VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_TIMEOUT_US_DEFAULT \
+((uint32_t) 15000)
+#define VL53L1_TUNINGPARM_ZONE_CAL_DSS_TIMEOUT_US_DEFAULT \
+((uint32_t) 2000)
+#define VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_NUM_SAMPLES_DEFAULT \
+((uint16_t) 16)
+#define VL53L1_TUNINGPARM_ZONE_CAL_RANGE_TIMEOUT_US_DEFAULT \
+((uint32_t) 1000)
+#define VL53L1_TUNINGPARM_ZONE_CAL_ZONE_NUM_SAMPLES_DEFAULT \
+((uint16_t) 8)
+#define VL53L1_TUNINGPARM_SPADMAP_VCSEL_PERIOD_DEFAULT \
+((uint8_t) 18)
+#define VL53L1_TUNINGPARM_SPADMAP_VCSEL_START_DEFAULT \
+((uint8_t) 15)
+#define VL53L1_TUNINGPARM_SPADMAP_RATE_LIMIT_MCPS_DEFAULT \
+((uint16_t) 12)
+#define VL53L1_TUNINGPARM_LITE_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
+((uint16_t) 2560)
+#define VL53L1_TUNINGPARM_RANGING_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
+((uint16_t) 5120)
+#define VL53L1_TUNINGPARM_MZ_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
+((uint16_t) 5120)
+#define VL53L1_TUNINGPARM_TIMED_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \
+((uint16_t) 2560)
+#define VL53L1_TUNINGPARM_LITE_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 1000)
+#define VL53L1_TUNINGPARM_RANGING_LONG_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 15000)
+#define VL53L1_TUNINGPARM_RANGING_MED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 9000)
+#define VL53L1_TUNINGPARM_RANGING_SHORT_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 6000)
+#define VL53L1_TUNINGPARM_MZ_LONG_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 15000)
+#define VL53L1_TUNINGPARM_MZ_MED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 9000)
+#define VL53L1_TUNINGPARM_MZ_SHORT_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 6000)
+#define VL53L1_TUNINGPARM_TIMED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 1000)
+#define VL53L1_TUNINGPARM_LITE_MM_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 2000)
+#define VL53L1_TUNINGPARM_RANGING_MM_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 2000)
+#define VL53L1_TUNINGPARM_MZ_MM_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 2000)
+#define VL53L1_TUNINGPARM_TIMED_MM_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 2000)
+#define VL53L1_TUNINGPARM_LITE_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 63000)
+#define VL53L1_TUNINGPARM_RANGING_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 2500)
+#define VL53L1_TUNINGPARM_MZ_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 2500)
+#define VL53L1_TUNINGPARM_TIMED_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 13000)
+#define VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_MARGIN_DEFAULT \
+((uint16_t) 0)
+#define VL53L1_TUNINGPARM_DYNXTALK_NOISE_MARGIN_DEFAULT \
+((uint32_t) 100)
+#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_DEFAULT \
+((uint32_t) 0)
+#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_HI_DEFAULT \
+((uint8_t) 0)
+#define VL53L1_TUNINGPARM_DYNXTALK_SAMPLE_LIMIT_DEFAULT \
+((uint32_t) 200)
+#define VL53L1_TUNINGPARM_DYNXTALK_SINGLE_XTALK_DELTA_DEFAULT \
+((uint32_t) 2048)
+#define VL53L1_TUNINGPARM_DYNXTALK_AVERAGED_XTALK_DELTA_DEFAULT \
+((uint32_t) 308)
+#define VL53L1_TUNINGPARM_DYNXTALK_CLIP_LIMIT_DEFAULT \
+((uint32_t) 10240)
+#define VL53L1_TUNINGPARM_DYNXTALK_SCALER_CALC_METHOD_DEFAULT \
+((uint8_t) 0)
+#define VL53L1_TUNINGPARM_DYNXTALK_XGRADIENT_SCALER_DEFAULT \
+((int16_t) 256)
+#define VL53L1_TUNINGPARM_DYNXTALK_YGRADIENT_SCALER_DEFAULT \
+((int16_t) 256)
+#define VL53L1_TUNINGPARM_DYNXTALK_USER_SCALER_SET_DEFAULT \
+((uint8_t) 0)
+#define VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_COR_SINGLE_APPLY_DEFAULT \
+((uint8_t) 0)
+#define VL53L1_TUNINGPARM_DYNXTALK_XTALK_AMB_THRESHOLD_DEFAULT \
+((uint32_t) 128)
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_AMB_THRESHOLD_KCPS_DEFAULT \
+((uint32_t) 57671680)
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_SAMPLE_LIMIT_DEFAULT \
+((uint32_t) 40)
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS_DEFAULT \
+((uint32_t) 410)
+#define VL53L1_TUNINGPARM_DYNXTALK_NODETECT_MIN_RANGE_MM_DEFAULT \
+((uint16_t) 900)
+#define VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND_DEFAULT \
+((uint8_t) 3)
+#define VL53L1_TUNINGPARM_LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 1)
+#define VL53L1_TUNINGPARM_LOWPOWERAUTO_RANGE_CONFIG_TIMEOUT_US_DEFAULT \
+((uint32_t) 8000)
+#define VL53L1_TUNINGPARM_VERY_SHORT_DSS_RATE_MCPS_DEFAULT \
+((uint16_t) 10240)
+#define VL53L1_TUNINGPARM_PHASECAL_PATCH_POWER_DEFAULT \
+((uint32_t) 0)
+#define VL53L1_TUNINGPARM_HIST_MERGE_DEFAULT \
+((uint32_t) 1)
+#define VL53L1_TUNINGPARM_RESET_MERGE_THRESHOLD_DEFAULT \
+((uint32_t) 15000)
+#define VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE_DEFAULT \
+((uint32_t) 6)
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_wait.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_wait.h
new file mode 100644
index 000000000000..c76cb5ad050f
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_wait.h
@@ -0,0 +1,319 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_WAIT_H_
+#define _VL53L1_WAIT_H_
+
+#include "vl53l1_platform.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_boot_completion(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_firmware_ready(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_range_completion(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_wait_for_test_completion(
+ VL53L1_DEV Dev);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_boot_complete(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_firmware_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_is_new_data_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_poll_for_boot_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_poll_for_firmware_ready(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_poll_for_range_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/inc/vl53l1_zone_presets.h b/drivers/input/misc/vl53L1/kona/inc/vl53l1_zone_presets.h
new file mode 100644
index 000000000000..68c8c4712a7e
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/inc/vl53l1_zone_presets.h
@@ -0,0 +1,183 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifndef _VL53L1_ZONE_PRESETS_H_
+#define _VL53L1_ZONE_PRESETS_H_
+
+#include "vl53l1_ll_def.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_zone_config_structure(
+ uint8_t x_off,
+ uint8_t x_inc,
+ uint8_t x_zones,
+ uint8_t y_off,
+ uint8_t y_inc,
+ uint8_t y_zones,
+ uint8_t width,
+ uint8_t height,
+ VL53L1_zone_config_t *pdata);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_zone_preset_xtalk_planar(
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_zone_config_t *pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_init_zone_config_histogram_bins(
+ VL53L1_zone_config_t *pdata);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/drivers/input/misc/vl53L1/kona/ipp/ipp_linux.c b/drivers/input/misc/vl53L1/kona/ipp/ipp_linux.c
new file mode 100644
index 000000000000..d220186fc10f
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/ipp/ipp_linux.c
@@ -0,0 +1,356 @@
+/**************************************************************************
+ * Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ****************************************************************************/
+
+/**
+ * @file ipp_linux.c kernel side implementation of vl53l1 protected processing
+ *
+ * @date Sep 1, 2016
+ * @author : imaging
+ *
+ * @ingroup ipp_dev
+ */
+
+#include "stmvl53l1.h"
+
+#define IPP_ERR_CODE (VL53L1_ERROR_PLATFORM_SPECIFIC_START-1)
+
+static int stmvl53l1_ipp_do_wrapper(struct stmvl53l1_data *data,
+ struct ipp_work_t *pin, struct ipp_work_t *pout, int payload_out)
+{
+ int rc;
+
+ if (data->ipp.buzy) {
+ vl53l1_errmsg("try exec new ipp but still buzy on previous");
+ /* TODO shall we discard it and push new ? */
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ WARN_ON(pin->payload > IPP_WORK_MAX_PAYLOAD);
+ stmvl531_ipp_tim_start(data);
+ rc = stmvl53l1_ipp_do(data, pin, pout);
+ if (rc != 0) {
+ vl53l1_errmsg("stmvl53l1_ipp_do err %d\n", rc);
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ //vl53l1_dbgmsg("ipp ok \n");
+ /* check what we got back if valid answer error etc */
+ if (pout->status) {
+ vl53l1_errmsg("ipp error status %d from user", pout->status);
+ if (pout->status >= stmvl53l1_ipp_status_proc_code)
+ rc = pout->status & (stmvl53l1_ipp_status_proc_code-1);
+ else
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ WARN_ON(pout->payload > IPP_WORK_MAX_PAYLOAD);
+ if (pout->payload != payload_out) {
+ /* bad formated answer */
+ vl53l1_errmsg("bad payload %d != %d in ipp work back",
+ pout->payload, payload_out);
+ rc = IPP_ERR_CODE;
+ goto done;
+ }
+ stmvl531_ipp_tim_stop(data);
+ stmvl531_ipp_stat(data, "ipp #%5x to=%3d fm=%3d in %5ld us",
+ pin->xfer_id, pin->payload,
+ pout->payload,
+ stmvl531_ipp_time(data));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @file vl53l1_platform_ipp.h
+ *
+ * @brief EwokPlus25 IPP Wrapper Functions
+ */
+
+/**
+ * @brief IPP Wrapper call for histogram post processing
+ *
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] pdmax_cal : DMAX calibration data
+ * @param[in] pdmax_cfg : DMAX configuration data
+ * @param[in] ppost_cfg : VL53L1_hist_post_process_config_t
+ * @param[in] pbins : Input histogram raw bin data
+ * @param[in] pxtalk : Cross talk histogram data
+ * @param[in] pArea1 : Extern. allocated to save stack
+ * @param[in] pArea1 : Extern. allocated to save stack
+ * @param[out] presults : Output VL53L1_range_results_t
+ * structure
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ipp_hist_process_data(
+ VL53L1_DEV dev,
+ VL53L1_dmax_calibration_data_t *pdmax_cal,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg,
+ VL53L1_hist_post_process_config_t *ppost_cfg,
+ VL53L1_histogram_bin_data_t *pbins,
+ VL53L1_xtalk_histogram_data_t *pxtalk,
+ uint8_t *pArea1,
+ uint8_t *pArea2,
+ uint8_t *phisto_merge_nb,
+ VL53L1_range_results_t *presults)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ VL53L1_range_results_t *presults_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* These external workspace input params are useless with IPP managed in
+ * the daemon because the histogram processing function is actually
+ * allocating its data in USER stack within the daemon not the kernel one
+ */
+ (void)pArea1;
+ (void)pArea2;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 6);
+ IPP_SET_ARG_PTR(pin->data, 0, pdmax_cal);
+ IPP_SET_ARG_PTR(pin->data, 1, pdmax_cfg);
+ IPP_SET_ARG_PTR(pin->data, 2, ppost_cfg);
+ IPP_SET_ARG_PTR(pin->data, 3, pbins);
+ IPP_SET_ARG_PTR(pin->data, 4, pxtalk);
+ IPP_SET_ARG_PTR(pin->data, 5, phisto_merge_nb);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_cal_hist;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 1);
+ IPP_OUT_ARG_PTR(pout->data, 0, presults_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(presults, presults_ipp, sizeof(*presults));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @brief IPP Wrapper call for histogram ambient dmax calc
+ *
+ * The target reflectance in percent for the DMAX calculation
+ * is set by target_reflectance input
+ *
+ * The fixed point format is 7.2
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] target_reflectance : target reflectance to report ambient DMAX
+ * Percentage in 7.2 fixed point format
+ * @param[in] pdmax_cal : DMAX calibration data
+ * @param[in] pdmax_cfg : DMAX configuration data
+ * @param[in] pbins : Input histogram raw bin data
+ * @param[out] pambient_dmax_mm : Output ambient DMAX distance in [mm]
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ipp_hist_ambient_dmax(
+ VL53L1_DEV dev,
+ uint16_t target_reflectance,
+ VL53L1_dmax_calibration_data_t *pdmax_cal,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg,
+ VL53L1_histogram_bin_data_t *pbins,
+ int16_t *pambient_dmax_mm)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ int16_t *pambient_dmax_mm_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 4);
+ IPP_SET_ARG(pin->data, 0, target_reflectance);
+ IPP_SET_ARG_PTR(pin->data, 1, pdmax_cal);
+ IPP_SET_ARG_PTR(pin->data, 2, pdmax_cfg);
+ IPP_SET_ARG_PTR(pin->data, 3, pbins);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_hist_ambient_dmax;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 1);
+ IPP_OUT_ARG_PTR(pout->data, 0, pambient_dmax_mm_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(pambient_dmax_mm, pambient_dmax_mm_ipp,
+ sizeof(*pambient_dmax_mm));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @brief IPP Wrapper call for xtalk calibration post processing
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] pxtalk_ranges : Input VL53L1_xtalk_range_results_t
+ * Must contain 5 ranges, 4 quadrants + 1
+ * full FoV
+ * @param[out] pxtalk_shape : Output normalised Cross talk histogram
+ * shape
+ * @param[out] pxtalk_cal : Output VL53L1_xtalk_calibration_results_t
+ * structure
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+VL53L1_Error VL53L1_ipp_xtalk_calibration_process_data(
+ VL53L1_DEV dev,
+ VL53L1_xtalk_range_results_t *pxtalk_ranges,
+ VL53L1_xtalk_histogram_data_t *pxtalk_shape,
+ VL53L1_xtalk_calibration_results_t *pxtalk_cal)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ VL53L1_xtalk_histogram_data_t *pxtalk_shape_ipp;
+ VL53L1_xtalk_calibration_results_t *pxtalk_cal_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 1);
+ IPP_SET_ARG_PTR(pin->data, 0, pxtalk_ranges);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_xtalk_calibration;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 2);
+ IPP_OUT_ARG_PTR(pout->data, 0, pxtalk_shape_ipp);
+ IPP_OUT_ARG_PTR(pout->data, 1, pxtalk_cal_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(pxtalk_shape, pxtalk_shape_ipp, sizeof(*pxtalk_shape));
+ memcpy(pxtalk_cal, pxtalk_cal_ipp, sizeof(*pxtalk_cal));
+
+ rc = 0;
+done:
+
+ return rc;
+}
+
+/**
+ * @brief IPP Wrapper call for Generating Xtalk data from dual reflectance
+ * histogram data
+ *
+ * @param[in] Dev : Device handle
+ * @param[in] pxtalk_results : Pointer to xtalk_results structure
+ * containing dual reflectance
+ * histogram data
+ * @param[in] expected_target_distance_mm : User input of true target distance
+ * @param[in] higher_reflectance : User input detailing which
+ * histogram data 1 or 2 has the
+ * highest reflectance.
+ * @param[out] pxtalk_avg_samples : Pointer to output xtalk histogram
+ * data
+ *
+ * @return VL53L1_ERROR_NONE Success
+ * @return "Other error code" See ::VL53L1_Error
+ */
+
+VL53L1_Error VL53L1_ipp_generate_dual_reflectance_xtalk_samples(
+ VL53L1_DEV dev,
+ VL53L1_xtalk_range_results_t *pxtalk_results,
+ uint16_t expected_target_distance_mm,
+ uint8_t higher_reflectance,
+ VL53L1_histogram_bin_data_t *pxtalk_avg_samples)
+{
+ struct stmvl53l1_data *data = (struct stmvl53l1_data *)
+ container_of(dev, struct stmvl53l1_data, stdev);
+ struct ipp_work_t *pout = &data->ipp.work_out;
+ struct ipp_work_t *pin = &data->ipp.work;
+ int rc;
+ VL53L1_histogram_bin_data_t *pxtalk_avg_samples_ipp;
+
+ IPP_SERIALIZE_VAR;
+
+ /* setup pin */
+ IPP_SERIALIZE_START(pin->data, 3);
+ IPP_SET_ARG_PTR(pin->data, 0, pxtalk_results);
+ IPP_SET_ARG(pin->data, 1, expected_target_distance_mm);
+ IPP_SET_ARG(pin->data, 2, higher_reflectance);
+ pin->payload = IPP_SERIALIZE_PAYLAOD();
+ pin->process_no = stmvl53l1_ipp_generate_dual_reflectance_xtalk_samples;
+
+ /* setup pout */
+ IPP_SERIALIZE_START(pout->data, 1);
+ IPP_OUT_ARG_PTR(pout->data, 0, pxtalk_avg_samples_ipp);
+
+ /* do ipp */
+ rc = stmvl53l1_ipp_do_wrapper(data, pin, pout, IPP_SERIALIZE_PAYLAOD());
+ if (rc)
+ goto done;
+
+ /* copy output */
+ memcpy(pxtalk_avg_samples, pxtalk_avg_samples_ipp,
+ sizeof(*pxtalk_avg_samples));
+
+ rc = 0;
+done:
+
+ return rc;
+}
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_api.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_api.c
new file mode 100644
index 000000000000..9f366925573b
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_api.c
@@ -0,0 +1,4063 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_api.h"
+#include "vl53l1_api_strings.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_register_funcs.h"
+#include "vl53l1_core.h"
+#include "vl53l1_api_calibration.h"
+#include "vl53l1_wait.h"
+#include "vl53l1_preset_setup.h"
+#include "vl53l1_api_debug.h"
+#include "vl53l1_api_core.h"
+#include "vl53l1_nvm.h"
+
+
+
+#define ZONE_CHECK VL53L1_MAX_USER_ZONES
+
+#if ZONE_CHECK < 5
+#error Must define at least 5 zones in MAX_USER_ZONES constant
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, \
+ fmt, ##__VA_ARGS__)
+
+#ifdef VL53L1_LOG_ENABLE
+#define trace_print(level, ...) trace_print_module_function(\
+ VL53L1_TRACE_MODULE_API, level, VL53L1_TRACE_FUNCTION_NONE, \
+ ##__VA_ARGS__)
+#endif
+
+#ifndef MIN
+#define MIN(v1, v2) ((v1) < (v2) ? (v1) : (v2))
+#endif
+#ifndef MAX
+#define MAX(v1, v2) ((v1) < (v2) ? (v2) : (v1))
+#endif
+
+#define DMAX_REFLECTANCE_IDX 2
+
+
+
+
+
+
+
+#define LOWPOWER_AUTO_VHV_LOOP_DURATION_US 245
+#define LOWPOWER_AUTO_OVERHEAD_BEFORE_A_RANGING 1448
+#define LOWPOWER_AUTO_OVERHEAD_BETWEEN_A_B_RANGING 2100
+
+#define FDA_MAX_TIMING_BUDGET_US 550000
+
+
+
+
+
+
+
+
+
+static int32_t BDTable[VL53L1_TUNING_MAX_TUNABLE_KEY] = {
+ TUNING_VERSION,
+ TUNING_PROXY_MIN,
+ TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM,
+ TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER,
+ TUNING_MIN_AMBIENT_DMAX_VALID,
+ TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER,
+ TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM,
+ TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT,
+ TUNING_XTALK_FULL_ROI_MAX_THRESHOLD,
+ TUNING_XTALK_FULL_ROI_BIN_SUM_MARGIN,
+ TUNING_XTALK_FULL_ROI_DEFAULT_OFFSET,
+ TUNING_ZERO_DISTANCE_OFFSET_NON_LINEAR_FACTOR_DEFAULT
+};
+
+
+
+static VL53L1_Error SingleTargetXTalkCalibration(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ uint32_t sum_ranging = 0;
+ uint32_t sum_spads = 0;
+ FixPoint1616_t sum_signalRate = 0;
+ FixPoint1616_t total_count = 0;
+ uint8_t xtalk_meas = 0;
+ uint8_t xtalk_measmax =
+ BDTable[VL53L1_TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER];
+ VL53L1_RangingMeasurementData_t RMData;
+ FixPoint1616_t xTalkStoredMeanSignalRate;
+ FixPoint1616_t xTalkStoredMeanRange;
+ FixPoint1616_t xTalkStoredMeanRtnSpads;
+ uint32_t xTalkStoredMeanRtnSpadsAsInt;
+ uint32_t xTalkCalDistanceAsInt;
+ FixPoint1616_t XTalkCompensationRateMegaCps;
+ uint32_t signalXTalkTotalPerSpad;
+ VL53L1_PresetModes PresetMode;
+ VL53L1_CalibrationData_t CalibrationData;
+ VL53L1_CustomerNvmManaged_t *pC;
+
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+ PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode);
+
+ if ((PresetMode != VL53L1_PRESETMODE_AUTONOMOUS) &&
+ (PresetMode != VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS) &&
+ (PresetMode != VL53L1_PRESETMODE_LITE_RANGING)) {
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ goto ENDFUNC;
+ }
+
+
+
+ Status = VL53L1_disable_xtalk_compensation(Dev);
+
+ if (Status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+ Status = VL53L1_StartMeasurement(Dev);
+
+ if (Status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+
+
+ VL53L1_WaitMeasurementDataReady(Dev);
+ VL53L1_GetRangingMeasurementData(Dev, &RMData);
+ VL53L1_ClearInterruptAndStartMeasurement(Dev);
+
+ sum_ranging = 0;
+ sum_spads = 0;
+ sum_signalRate = 0;
+ total_count = 0;
+ for (xtalk_meas = 0; xtalk_meas < xtalk_measmax; xtalk_meas++) {
+ VL53L1_WaitMeasurementDataReady(Dev);
+ VL53L1_GetRangingMeasurementData(Dev, &RMData);
+ VL53L1_ClearInterruptAndStartMeasurement(Dev);
+ if (RMData.RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) {
+ sum_ranging += RMData.RangeMilliMeter;
+ sum_signalRate += RMData.SignalRateRtnMegaCps;
+ sum_spads += RMData.EffectiveSpadRtnCount / 256;
+ total_count++;
+ }
+ }
+ Status = VL53L1_StopMeasurement(Dev);
+
+ if (total_count > 0) {
+
+
+ xTalkStoredMeanSignalRate = sum_signalRate / total_count;
+ xTalkStoredMeanRange = (FixPoint1616_t)(sum_ranging << 16);
+ xTalkStoredMeanRange /= total_count;
+ xTalkStoredMeanRtnSpads = (FixPoint1616_t)(sum_spads << 16);
+ xTalkStoredMeanRtnSpads /= total_count;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xTalkStoredMeanRtnSpadsAsInt = (xTalkStoredMeanRtnSpads +
+ 0x8000) >> 16;
+
+
+
+
+
+
+ xTalkCalDistanceAsInt = ((uint32_t)BDTable[
+ VL53L1_TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM]);
+ if (xTalkStoredMeanRtnSpadsAsInt == 0 ||
+ xTalkCalDistanceAsInt == 0 ||
+ xTalkStoredMeanRange >= (xTalkCalDistanceAsInt << 16)) {
+ XTalkCompensationRateMegaCps = 0;
+ } else {
+
+
+
+
+
+
+ signalXTalkTotalPerSpad = (xTalkStoredMeanSignalRate) /
+ xTalkStoredMeanRtnSpadsAsInt;
+
+
+
+
+
+
+
+ signalXTalkTotalPerSpad *= (((uint32_t)1 << 16) -
+ (xTalkStoredMeanRange / xTalkCalDistanceAsInt));
+
+
+
+ XTalkCompensationRateMegaCps = (signalXTalkTotalPerSpad
+ + 0x8000) >> 16;
+ }
+
+
+ Status = VL53L1_GetCalibrationData(Dev, &CalibrationData);
+
+ if (Status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+ pC = &CalibrationData.customer;
+
+ pC->algo__crosstalk_compensation_plane_offset_kcps =
+ (uint32_t)(1000 * ((XTalkCompensationRateMegaCps +
+ ((uint32_t)1<<6)) >> (16-9)));
+
+ Status = VL53L1_SetCalibrationData(Dev, &CalibrationData);
+
+ if (Status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+ Status = VL53L1_enable_xtalk_compensation(Dev);
+
+ } else
+
+
+ Status = VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL;
+
+ENDFUNC:
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+
+
+
+
+
+
+
+
+
+static VL53L1_Error CheckValidRectRoi(VL53L1_UserRoi_t ROI)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ if ((ROI.TopLeftX > 15) || (ROI.TopLeftY > 15) ||
+ (ROI.BotRightX > 15) || (ROI.BotRightY > 15))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ if ((ROI.TopLeftX > ROI.BotRightX) || (ROI.TopLeftY < ROI.BotRightY))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static VL53L1_GPIO_Interrupt_Mode ConvertModeToLLD(VL53L1_Error *pStatus,
+ VL53L1_ThresholdMode CrossMode)
+{
+ VL53L1_GPIO_Interrupt_Mode Mode;
+
+ switch (CrossMode) {
+ case VL53L1_THRESHOLD_CROSSED_LOW:
+ Mode = VL53L1_GPIOINTMODE_LEVEL_LOW;
+ break;
+ case VL53L1_THRESHOLD_CROSSED_HIGH:
+ Mode = VL53L1_GPIOINTMODE_LEVEL_HIGH;
+ break;
+ case VL53L1_THRESHOLD_OUT_OF_WINDOW:
+ Mode = VL53L1_GPIOINTMODE_OUT_OF_WINDOW;
+ break;
+ case VL53L1_THRESHOLD_IN_WINDOW:
+ Mode = VL53L1_GPIOINTMODE_IN_WINDOW;
+ break;
+ default:
+
+
+ Mode = VL53L1_GPIOINTMODE_LEVEL_HIGH;
+ *pStatus = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ return Mode;
+}
+
+static VL53L1_ThresholdMode ConvertModeFromLLD(VL53L1_Error *pStatus,
+ VL53L1_GPIO_Interrupt_Mode CrossMode)
+{
+ VL53L1_ThresholdMode Mode;
+
+ switch (CrossMode) {
+ case VL53L1_GPIOINTMODE_LEVEL_LOW:
+ Mode = VL53L1_THRESHOLD_CROSSED_LOW;
+ break;
+ case VL53L1_GPIOINTMODE_LEVEL_HIGH:
+ Mode = VL53L1_THRESHOLD_CROSSED_HIGH;
+ break;
+ case VL53L1_GPIOINTMODE_OUT_OF_WINDOW:
+ Mode = VL53L1_THRESHOLD_OUT_OF_WINDOW;
+ break;
+ case VL53L1_GPIOINTMODE_IN_WINDOW:
+ Mode = VL53L1_THRESHOLD_IN_WINDOW;
+ break;
+ default:
+
+
+ Mode = VL53L1_THRESHOLD_CROSSED_HIGH;
+ *pStatus = VL53L1_ERROR_UNDEFINED;
+ }
+ return Mode;
+}
+
+
+
+
+VL53L1_Error VL53L1_GetVersion(VL53L1_Version_t *pVersion)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ pVersion->major = VL53L1_IMPLEMENTATION_VER_MAJOR;
+ pVersion->minor = VL53L1_IMPLEMENTATION_VER_MINOR;
+ pVersion->build = VL53L1_IMPLEMENTATION_VER_SUB;
+
+ pVersion->revision = VL53L1_IMPLEMENTATION_VER_REVISION;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetProductRevision(VL53L1_DEV Dev,
+ uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t revision_id;
+ VL53L1_LLDriverData_t *pLLData;
+
+ LOG_FUNCTION_START("");
+
+ pLLData = VL53L1DevStructGetLLDriverHandle(Dev);
+ revision_id = pLLData->nvm_copy_data.identification__revision_id;
+ *pProductRevisionMajor = 1;
+ *pProductRevisionMinor = (revision_id & 0xF0) >> 4;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L1_Error VL53L1_GetDeviceInfo(VL53L1_DEV Dev,
+ VL53L1_DeviceInfo_t *pVL53L1_DeviceInfo)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t revision_id;
+ VL53L1_LLDriverData_t *pLLData;
+
+ LOG_FUNCTION_START("");
+
+ pLLData = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ strncpy(pVL53L1_DeviceInfo->ProductId, "",
+ VL53L1_DEVINFO_STRLEN-1);
+ pVL53L1_DeviceInfo->ProductType =
+ pLLData->nvm_copy_data.identification__module_type;
+
+ revision_id = pLLData->nvm_copy_data.identification__revision_id;
+ pVL53L1_DeviceInfo->ProductRevisionMajor = 1;
+ pVL53L1_DeviceInfo->ProductRevisionMinor = (revision_id & 0xF0) >> 4;
+
+#ifndef VL53L1_USE_EMPTY_STRING
+ if (pVL53L1_DeviceInfo->ProductRevisionMinor == 0)
+ strncpy(pVL53L1_DeviceInfo->Name,
+ VL53L1_STRING_DEVICE_INFO_NAME0,
+ VL53L1_DEVINFO_STRLEN-1);
+ else
+ strncpy(pVL53L1_DeviceInfo->Name,
+ VL53L1_STRING_DEVICE_INFO_NAME1,
+ VL53L1_DEVINFO_STRLEN-1);
+ strncpy(pVL53L1_DeviceInfo->Type,
+ VL53L1_STRING_DEVICE_INFO_TYPE,
+ VL53L1_DEVINFO_STRLEN-1);
+
+
+ if (pVL53L1_DeviceInfo->ProductType == 0xAA) {
+ pVL53L1_DeviceInfo->Name[5] = '3';
+ pVL53L1_DeviceInfo->Type[5] = '3';
+ }
+#else
+ pVL53L1_DeviceInfo->Name[0] = 0;
+ pVL53L1_DeviceInfo->Type[0] = 0;
+#endif
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetUID(VL53L1_DEV Dev, uint64_t *pUid)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t fmtdata[8];
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_read_nvm_raw_data(Dev,
+ (uint8_t)(0x1F8 >> 2),
+ (uint8_t)(8 >> 2),
+ fmtdata);
+ memcpy(pUid, fmtdata, sizeof(uint64_t));
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetRangeStatusString(uint8_t RangeStatus,
+ char *pRangeStatusString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_range_status_string(RangeStatus,
+ pRangeStatusString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetPalErrorString(VL53L1_Error PalErrorCode,
+ char *pPalErrorString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_pal_error_string(PalErrorCode, pPalErrorString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetPalStateString(VL53L1_State PalStateCode,
+ char *pPalStateString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_pal_state_string(PalStateCode, pPalStateString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetPalState(VL53L1_DEV Dev, VL53L1_State *pPalState)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pPalState = VL53L1DevDataGet(Dev, PalState);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_SetDeviceAddress(VL53L1_DEV Dev, uint8_t DeviceAddress)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_WrByte(Dev, VL53L1_I2C_SLAVE__DEVICE_ADDRESS,
+ DeviceAddress / 2);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_DataInit(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t i;
+ VL53L1_LLDriverData_t *pdev;
+
+ LOG_FUNCTION_START("");
+
+
+
+#ifdef USE_I2C_2V8
+ Status = VL53L1_RdByte(Dev, VL53L1_PAD_I2C_HV__EXTSUP_CONFIG, &i);
+ if (Status == VL53L1_ERROR_NONE) {
+ i = (i & 0xfe) | 0x01;
+ Status = VL53L1_WrByte(Dev, VL53L1_PAD_I2C_HV__EXTSUP_CONFIG,
+ i);
+ }
+#endif
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_data_init(Dev, 1);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ memset(&pdev->per_vcsel_cal_data, 0,
+ sizeof(pdev->per_vcsel_cal_data));
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_WAIT_STATICINIT);
+ VL53L1DevDataSet(Dev, CurrentParameters.PresetMode,
+ VL53L1_PRESETMODE_RANGING);
+ }
+
+
+
+ for (i = 0; i < VL53L1_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
+ if (Status == VL53L1_ERROR_NONE)
+ Status |= VL53L1_SetLimitCheckEnable(Dev, i, 1);
+ else
+ break;
+
+ }
+
+
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_set_dmax_mode(Dev,
+ VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA);
+ }
+
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_StaticInit(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t measurement_mode;
+
+ LOG_FUNCTION_START("");
+
+ VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_IDLE);
+
+ measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ VL53L1DevDataSet(Dev, LLData.measurement_mode, measurement_mode);
+
+ VL53L1DevDataSet(Dev, CurrentParameters.DistanceMode,
+ VL53L1_DISTANCEMODE_LONG);
+
+ VL53L1DevDataSet(Dev, CurrentParameters.OutputMode,
+ VL53L1_OUTPUTMODE_NEAREST);
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_WaitDeviceBooted(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_poll_for_boot_completion(Dev,
+ VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+static VL53L1_Error ComputeDevicePresetMode(
+ VL53L1_PresetModes PresetMode,
+ VL53L1_DistanceModes DistanceMode,
+ VL53L1_DevicePresetModes *pDevicePresetMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ uint8_t DistIdx;
+ VL53L1_DevicePresetModes LightModes[3] = {
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE,
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING,
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE};
+
+ VL53L1_DevicePresetModes RangingModes[3] = {
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE};
+
+ VL53L1_DevicePresetModes ScanningModes[3] = {
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE};
+
+ VL53L1_DevicePresetModes TimedModes[3] = {
+ VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE,
+ VL53L1_DEVICEPRESETMODE_TIMED_RANGING,
+ VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE};
+
+ VL53L1_DevicePresetModes LowPowerTimedModes[3] = {
+ VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_SHORT_RANGE,
+ VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_MEDIUM_RANGE,
+ VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_LONG_RANGE};
+
+ *pDevicePresetMode = VL53L1_DEVICEPRESETMODE_STANDARD_RANGING;
+
+ switch (DistanceMode) {
+ case VL53L1_DISTANCEMODE_SHORT:
+ DistIdx = 0;
+ break;
+ case VL53L1_DISTANCEMODE_MEDIUM:
+ DistIdx = 1;
+ break;
+ default:
+ DistIdx = 2;
+ }
+
+ switch (PresetMode) {
+ case VL53L1_PRESETMODE_LITE_RANGING:
+ *pDevicePresetMode = LightModes[DistIdx];
+ break;
+
+ case VL53L1_PRESETMODE_RANGING:
+ *pDevicePresetMode = RangingModes[DistIdx];
+ break;
+
+ case VL53L1_PRESETMODE_MULTIZONES_SCANNING:
+ *pDevicePresetMode = ScanningModes[DistIdx];
+ break;
+
+ case VL53L1_PRESETMODE_AUTONOMOUS:
+ *pDevicePresetMode = TimedModes[DistIdx];
+ break;
+
+ case VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS:
+ *pDevicePresetMode = LowPowerTimedModes[DistIdx];
+ break;
+ case VL53L1_PRESETMODE_OLT:
+ *pDevicePresetMode = VL53L1_DEVICEPRESETMODE_OLT;
+ break;
+ case VL53L1_PRESETMODE_PROXY_RANGING_MODE:
+ *pDevicePresetMode =
+ VL53L1_DEVICEPRESETMODE_SPECIAL_HISTOGRAM_SHORT_RANGE;
+ break;
+
+ default:
+
+
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ return Status;
+}
+
+static VL53L1_Error SetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes PresetMode,
+ VL53L1_DistanceModes DistanceMode,
+ uint32_t inter_measurement_period_ms)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_DevicePresetModes device_preset_mode;
+ uint8_t measurement_mode;
+ uint16_t dss_config__target_total_rate_mcps;
+ uint32_t phasecal_config_timeout_us;
+ uint32_t mm_config_timeout_us;
+ uint32_t lld_range_config_timeout_us;
+
+ LOG_FUNCTION_START("%d", (int)PresetMode);
+
+ if ((PresetMode == VL53L1_PRESETMODE_AUTONOMOUS) ||
+ (PresetMode == VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS))
+ measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ else
+ measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+
+ Status = ComputeDevicePresetMode(PresetMode, DistanceMode,
+ &device_preset_mode);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_preset_mode_timing_cfg(Dev,
+ device_preset_mode,
+ &dss_config__target_total_rate_mcps,
+ &phasecal_config_timeout_us,
+ &mm_config_timeout_us,
+ &lld_range_config_timeout_us);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_preset_mode(
+ Dev,
+ device_preset_mode,
+ dss_config__target_total_rate_mcps,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ lld_range_config_timeout_us,
+ inter_measurement_period_ms);
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1DevDataSet(Dev, LLData.measurement_mode,
+ measurement_mode);
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1DevDataSet(Dev, CurrentParameters.PresetMode, PresetMode);
+
+ VL53L1DevDataSet(Dev, CurrentParameters.OutputMode,
+ VL53L1_OUTPUTMODE_NEAREST);
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetPresetMode(VL53L1_DEV Dev, VL53L1_PresetModes PresetMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_DistanceModes DistanceMode = VL53L1_DISTANCEMODE_LONG;
+
+ LOG_FUNCTION_START("%d", (int)PresetMode);
+
+
+
+ Status = VL53L1_low_power_auto_data_init(Dev);
+
+ if (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE)
+ DistanceMode = VL53L1_DISTANCEMODE_SHORT;
+ Status = SetPresetMode(Dev,
+ PresetMode,
+ DistanceMode,
+ 1000);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ if ((PresetMode == VL53L1_PRESETMODE_LITE_RANGING) ||
+ (PresetMode == VL53L1_PRESETMODE_AUTONOMOUS) ||
+ (PresetMode == VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS))
+ Status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(
+ Dev, 41000);
+ else
+
+
+ Status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(
+ Dev, 33333);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+
+ Status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev,
+ 1000);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetPresetMode(VL53L1_DEV Dev,
+ VL53L1_PresetModes *pPresetMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pPresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes DistanceMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_PresetModes PresetMode;
+ uint32_t inter_measurement_period_ms;
+ uint32_t TimingBudget;
+ uint32_t MmTimeoutUs;
+ uint32_t PhaseCalTimeoutUs;
+ VL53L1_zone_config_t zone_config;
+
+ LOG_FUNCTION_START("%d", (int)DistanceMode);
+
+ PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode);
+
+
+
+
+
+
+
+ if ((PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE) &&
+ (DistanceMode != VL53L1_DISTANCEMODE_SHORT))
+ return VL53L1_ERROR_INVALID_PARAMS;
+ if ((DistanceMode != VL53L1_DISTANCEMODE_SHORT) &&
+ (DistanceMode != VL53L1_DISTANCEMODE_MEDIUM) &&
+ (DistanceMode != VL53L1_DISTANCEMODE_LONG))
+ return VL53L1_ERROR_INVALID_PARAMS;
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_zone_config(Dev, &zone_config);
+
+ inter_measurement_period_ms = VL53L1DevDataGet(Dev,
+ LLData.inter_measurement_period_ms);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_timeouts_us(Dev, &PhaseCalTimeoutUs,
+ &MmTimeoutUs, &TimingBudget);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = SetPresetMode(Dev,
+ PresetMode,
+ DistanceMode,
+ inter_measurement_period_ms);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1DevDataSet(Dev, CurrentParameters.DistanceMode,
+ DistanceMode);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_set_timeouts_us(Dev, PhaseCalTimeoutUs,
+ MmTimeoutUs, TimingBudget);
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1DevDataSet(Dev, LLData.range_config_timeout_us,
+ TimingBudget);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_zone_config(Dev, &zone_config);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetDistanceMode(VL53L1_DEV Dev,
+ VL53L1_DistanceModes *pDistanceMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pDistanceMode = VL53L1DevDataGet(Dev, CurrentParameters.DistanceMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes OutputMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if ((OutputMode != VL53L1_OUTPUTMODE_NEAREST) &&
+ (OutputMode != VL53L1_OUTPUTMODE_STRONGEST))
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ else
+ VL53L1DevDataSet(Dev, CurrentParameters.OutputMode, OutputMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetOutputMode(VL53L1_DEV Dev,
+ VL53L1_OutputModes *pOutputMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pOutputMode = VL53L1DevDataGet(Dev, CurrentParameters.OutputMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+VL53L1_Error VL53L1_SetMeasurementTimingBudgetMicroSeconds(VL53L1_DEV Dev,
+ uint32_t MeasurementTimingBudgetMicroSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Mm1Enabled;
+ uint8_t Mm2Enabled;
+ uint32_t TimingGuard;
+ uint32_t divisor;
+ uint32_t TimingBudget;
+ uint32_t MmTimeoutUs;
+ VL53L1_PresetModes PresetMode;
+ uint32_t PhaseCalTimeoutUs;
+ uint32_t vhv;
+ int32_t vhv_loops;
+ uint32_t FDAMaxTimingBudgetUs = FDA_MAX_TIMING_BUDGET_US;
+
+ LOG_FUNCTION_START("");
+
+
+
+ if (MeasurementTimingBudgetMicroSeconds > 10000000)
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM1, &Mm1Enabled);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM2, &Mm2Enabled);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_timeouts_us(Dev,
+ &PhaseCalTimeoutUs,
+ &MmTimeoutUs,
+ &TimingBudget);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PresetMode = VL53L1DevDataGet(Dev,
+ CurrentParameters.PresetMode);
+
+ TimingGuard = 0;
+ divisor = 1;
+ switch (PresetMode) {
+ case VL53L1_PRESETMODE_LITE_RANGING:
+ if ((Mm1Enabled == 1) || (Mm2Enabled == 1))
+ TimingGuard = 5000;
+ else
+ TimingGuard = 1000;
+ break;
+
+ case VL53L1_PRESETMODE_AUTONOMOUS:
+ FDAMaxTimingBudgetUs *= 2;
+ if ((Mm1Enabled == 1) || (Mm2Enabled == 1))
+ TimingGuard = 26600;
+ else
+ TimingGuard = 21600;
+ divisor = 2;
+ break;
+
+ case VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS:
+ FDAMaxTimingBudgetUs *= 2;
+ vhv = LOWPOWER_AUTO_VHV_LOOP_DURATION_US;
+ VL53L1_get_tuning_parm(Dev,
+ VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND,
+ &vhv_loops);
+ if (vhv_loops > 0) {
+ vhv += vhv_loops *
+ LOWPOWER_AUTO_VHV_LOOP_DURATION_US;
+ }
+ TimingGuard = LOWPOWER_AUTO_OVERHEAD_BEFORE_A_RANGING +
+ LOWPOWER_AUTO_OVERHEAD_BETWEEN_A_B_RANGING +
+ vhv;
+ divisor = 2;
+ break;
+
+ case VL53L1_PRESETMODE_RANGING:
+ case VL53L1_PRESETMODE_MULTIZONES_SCANNING:
+ case VL53L1_PRESETMODE_PROXY_RANGING_MODE:
+ TimingGuard = 1700;
+ divisor = 6;
+ break;
+
+ case VL53L1_PRESETMODE_OLT:
+ TimingGuard = MmTimeoutUs + 5000;
+ break;
+ default:
+
+
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ }
+
+ if (MeasurementTimingBudgetMicroSeconds <= TimingGuard)
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ else {
+ TimingBudget = (MeasurementTimingBudgetMicroSeconds
+ - TimingGuard);
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ if (TimingBudget > FDAMaxTimingBudgetUs)
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ else {
+ TimingBudget /= divisor;
+ Status = VL53L1_set_timeouts_us(
+ Dev,
+ PhaseCalTimeoutUs,
+ MmTimeoutUs,
+ TimingBudget);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1DevDataSet(Dev,
+ LLData.range_config_timeout_us,
+ TimingBudget);
+ }
+ }
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1DevDataSet(Dev,
+ CurrentParameters.MeasurementTimingBudgetMicroSeconds,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetMeasurementTimingBudgetMicroSeconds(VL53L1_DEV Dev,
+ uint32_t *pMeasurementTimingBudgetMicroSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Mm1Enabled = 0;
+ uint8_t Mm2Enabled = 0;
+ uint32_t MmTimeoutUs = 0;
+ uint32_t RangeTimeoutUs = 0;
+ uint32_t MeasTimingBdg = 0;
+ uint32_t PhaseCalTimeoutUs = 0;
+ VL53L1_PresetModes PresetMode;
+ uint32_t TimingGuard;
+ uint32_t vhv;
+ int32_t vhv_loops;
+
+ LOG_FUNCTION_START("");
+
+ *pMeasurementTimingBudgetMicroSeconds = 0;
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM1, &Mm1Enabled);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_GetSequenceStepEnable(Dev,
+ VL53L1_SEQUENCESTEP_MM2, &Mm2Enabled);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_timeouts_us(Dev,
+ &PhaseCalTimeoutUs,
+ &MmTimeoutUs,
+ &RangeTimeoutUs);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PresetMode = VL53L1DevDataGet(Dev,
+ CurrentParameters.PresetMode);
+
+ switch (PresetMode) {
+ case VL53L1_PRESETMODE_LITE_RANGING:
+ if ((Mm1Enabled == 1) || (Mm2Enabled == 1))
+ MeasTimingBdg = RangeTimeoutUs + 5000;
+ else
+ MeasTimingBdg = RangeTimeoutUs + 1000;
+
+ break;
+
+ case VL53L1_PRESETMODE_AUTONOMOUS:
+ if ((Mm1Enabled == 1) || (Mm2Enabled == 1))
+ MeasTimingBdg = 2 * RangeTimeoutUs + 26600;
+ else
+ MeasTimingBdg = 2 * RangeTimeoutUs + 21600;
+
+ break;
+
+ case VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS:
+ vhv = LOWPOWER_AUTO_VHV_LOOP_DURATION_US;
+ VL53L1_get_tuning_parm(Dev,
+ VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND,
+ &vhv_loops);
+ if (vhv_loops > 0) {
+ vhv += vhv_loops *
+ LOWPOWER_AUTO_VHV_LOOP_DURATION_US;
+ }
+ TimingGuard = LOWPOWER_AUTO_OVERHEAD_BEFORE_A_RANGING +
+ LOWPOWER_AUTO_OVERHEAD_BETWEEN_A_B_RANGING +
+ vhv;
+ MeasTimingBdg = 2 * RangeTimeoutUs + TimingGuard;
+ break;
+
+ case VL53L1_PRESETMODE_RANGING:
+ case VL53L1_PRESETMODE_MULTIZONES_SCANNING:
+ case VL53L1_PRESETMODE_PROXY_RANGING_MODE:
+ MeasTimingBdg = (6 * RangeTimeoutUs) + 1700;
+ break;
+
+ case VL53L1_PRESETMODE_OLT:
+ MeasTimingBdg = RangeTimeoutUs + MmTimeoutUs + 5000;
+ break;
+ default:
+
+
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ }
+ }
+ if (Status == VL53L1_ERROR_NONE)
+ *pMeasurementTimingBudgetMicroSeconds = MeasTimingBdg;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+VL53L1_Error VL53L1_SetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev,
+ uint32_t InterMeasurementPeriodMilliSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint32_t adjustedIMP;
+
+ LOG_FUNCTION_START("");
+
+
+
+ adjustedIMP = InterMeasurementPeriodMilliSeconds;
+ adjustedIMP += (adjustedIMP * 64) / 1000;
+
+
+ Status = VL53L1_set_inter_measurement_period_ms(Dev,
+ adjustedIMP);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev,
+ uint32_t *pInterMeasurementPeriodMilliSeconds)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint32_t adjustedIMP;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_inter_measurement_period_ms(Dev, &adjustedIMP);
+
+
+ adjustedIMP -= (adjustedIMP * 64) / 1000;
+ *pInterMeasurementPeriodMilliSeconds = adjustedIMP;
+
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t DmaxReflectance)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_dmax_reflectance_array_t dmax_reflectances;
+
+ LOG_FUNCTION_START("");
+
+ if (DmaxReflectance > 100*65536)
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_dmax_reflectance_values(Dev,
+ &dmax_reflectances);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ dmax_reflectances.target_reflectance_for_dmax[
+ DMAX_REFLECTANCE_IDX] =
+ VL53L1_FIXPOINT1616TOFIXPOINT72(DmaxReflectance);
+ Status = VL53L1_set_dmax_reflectance_values(Dev,
+ &dmax_reflectances);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetDmaxReflectance(VL53L1_DEV Dev,
+ FixPoint1616_t *pDmaxReflectance)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_dmax_reflectance_array_t dmax_reflectances;
+ uint16_t r;
+
+ LOG_FUNCTION_START("");
+ Status = VL53L1_get_dmax_reflectance_values(Dev, &dmax_reflectances);
+ if (Status == VL53L1_ERROR_NONE) {
+ r = dmax_reflectances.target_reflectance_for_dmax[
+ DMAX_REFLECTANCE_IDX];
+ *pDmaxReflectance = VL53L1_FIXPOINT72TOFIXPOINT1616(r);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_SetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes DmaxMode)
+{
+
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_DeviceDmaxMode dmax_mode;
+
+ LOG_FUNCTION_START("");
+
+ switch (DmaxMode) {
+ case VL53L1_DMAXMODE_FMT_CAL_DATA:
+ dmax_mode = VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA;
+ break;
+ case VL53L1_DMAXMODE_CUSTCAL_DATA:
+ dmax_mode = VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA;
+ break;
+ case VL53L1_DMAXMODE_PER_ZONE_CAL_DATA:
+ dmax_mode = VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+ }
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_dmax_mode(Dev, dmax_mode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetDmaxMode(VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxModes *pDmaxMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_DeviceDmaxMode dmax_mode;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_dmax_mode(Dev, &dmax_mode);
+ if (Status == VL53L1_ERROR_NONE) {
+ switch (dmax_mode) {
+ case VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA:
+ *pDmaxMode = VL53L1_DMAXMODE_FMT_CAL_DATA;
+ break;
+ case VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA:
+ *pDmaxMode = VL53L1_DMAXMODE_CUSTCAL_DATA;
+ break;
+ case VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA:
+ *pDmaxMode = VL53L1_DMAXMODE_PER_ZONE_CAL_DATA;
+ break;
+ default:
+
+
+ *pDmaxMode = VL53L1_ERROR_NOT_IMPLEMENTED;
+ break;
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_GetNumberOfLimitCheck(uint16_t *pNumberOfLimitCheck)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ *pNumberOfLimitCheck = VL53L1_CHECKENABLE_NUMBER_OF_CHECKS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckInfo(uint16_t LimitCheckId,
+ char *pLimitCheckString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_limit_check_info(LimitCheckId,
+ pLimitCheckString);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckStatus(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ uint8_t *pLimitCheckStatus)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ LimitCheckId, Temp8);
+ *pLimitCheckStatus = Temp8;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static VL53L1_Error SetLimitValue(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t value)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint16_t tmpuint16;
+
+
+ LOG_FUNCTION_START("");
+
+ switch (LimitCheckId) {
+ case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
+ tmpuint16 = VL53L1_FIXPOINT1616TOFIXPOINT142(value);
+ VL53L1_set_lite_sigma_threshold(Dev, tmpuint16);
+ break;
+ case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ tmpuint16 = VL53L1_FIXPOINT1616TOFIXPOINT97(value);
+ VL53L1_set_lite_min_count_rate(Dev, tmpuint16);
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_SetLimitCheckEnable(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ uint8_t LimitCheckEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ FixPoint1616_t TempFix1616 = 0;
+
+ LOG_FUNCTION_START("");
+
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+
+
+ if (LimitCheckEnable == 0)
+ TempFix1616 = 0;
+ else
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, TempFix1616);
+
+ Status = SetLimitValue(Dev, LimitCheckId, TempFix1616);
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable,
+ LimitCheckId,
+ ((LimitCheckEnable == 0) ? 0 : 1));
+
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckEnable(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ uint8_t *pLimitCheckEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Temp8;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ *pLimitCheckEnable = 0;
+ } else {
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId, Temp8);
+ *pLimitCheckEnable = Temp8;
+ }
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetLimitCheckValue(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t LimitCheckValue)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t LimitChecksEnable;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
+ LimitCheckId,
+ LimitChecksEnable);
+
+ if (LimitChecksEnable == 0) {
+
+
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
+ LimitCheckId, LimitCheckValue);
+ } else {
+
+ Status = SetLimitValue(Dev, LimitCheckId,
+ LimitCheckValue);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue,
+ LimitCheckId, LimitCheckValue);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetLimitCheckValue(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckValue)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint16_t MinCountRate;
+ FixPoint1616_t TempFix1616;
+ uint16_t SigmaThresh;
+
+ LOG_FUNCTION_START("");
+
+ switch (LimitCheckId) {
+ case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
+ Status = VL53L1_get_lite_sigma_threshold(Dev, &SigmaThresh);
+ TempFix1616 = VL53L1_FIXPOINT142TOFIXPOINT1616(SigmaThresh);
+ break;
+ case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ Status = VL53L1_get_lite_min_count_rate(Dev, &MinCountRate);
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(MinCountRate);
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+ if (TempFix1616 == 0) {
+
+
+ VL53L1_GETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue, LimitCheckId,
+ TempFix1616);
+ *pLimitCheckValue = TempFix1616;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable, LimitCheckId, 0);
+ } else {
+ *pLimitCheckValue = TempFix1616;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksValue, LimitCheckId,
+ TempFix1616);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksEnable, LimitCheckId, 1);
+ }
+ }
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L1_Error VL53L1_GetLimitCheckCurrent(VL53L1_DEV Dev, uint16_t LimitCheckId,
+ FixPoint1616_t *pLimitCheckCurrent)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ FixPoint1616_t TempFix1616 = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ } else {
+ VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksCurrent,
+ LimitCheckId, TempFix1616);
+ *pLimitCheckCurrent = TempFix1616;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_GetMaxNumberOfROI(VL53L1_DEV Dev,
+ uint8_t *pMaxNumberOfROI)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_PresetModes PresetMode;
+
+ LOG_FUNCTION_START("");
+
+ PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode);
+
+
+
+ if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING)
+ *pMaxNumberOfROI = VL53L1_MAX_USER_ZONES;
+ else
+ *pMaxNumberOfROI = 1;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_PresetModes PresetMode;
+ uint8_t MaxNumberOfROI = 1;
+ VL53L1_zone_config_t zone_cfg;
+ VL53L1_UserRoi_t CurrROI;
+ uint8_t i;
+ uint8_t x_centre;
+ uint8_t y_centre;
+ uint8_t width, height;
+
+ LOG_FUNCTION_START("");
+
+
+
+ PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode);
+
+
+
+ if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING)
+ MaxNumberOfROI = VL53L1_MAX_USER_ZONES;
+
+ if ((pRoiConfig->NumberOfRoi > MaxNumberOfROI) ||
+ (pRoiConfig->NumberOfRoi < 1))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+
+
+ zone_cfg.max_zones = MaxNumberOfROI;
+ zone_cfg.active_zones = pRoiConfig->NumberOfRoi - 1;
+
+ for (i = 0; i < pRoiConfig->NumberOfRoi; i++) {
+ CurrROI = pRoiConfig->UserRois[i];
+
+
+
+
+
+
+
+
+
+ Status = CheckValidRectRoi(CurrROI);
+ if (Status != VL53L1_ERROR_NONE)
+ break;
+
+ x_centre = (CurrROI.BotRightX + CurrROI.TopLeftX + 1)
+ / 2;
+ y_centre = (CurrROI.TopLeftY + CurrROI.BotRightY + 1)
+ / 2;
+ width = (CurrROI.BotRightX - CurrROI.TopLeftX);
+ height = (CurrROI.TopLeftY - CurrROI.BotRightY);
+ if ((width < 3) || (height < 3)) {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+ }
+ zone_cfg.user_zones[i].x_centre = x_centre;
+ zone_cfg.user_zones[i].y_centre = y_centre;
+ zone_cfg.user_zones[i].width = width;
+ zone_cfg.user_zones[i].height = height;
+ }
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_zone_config(Dev, &zone_cfg);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetROI(VL53L1_DEV Dev,
+ VL53L1_RoiConfig_t *pRoiConfig)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_zone_config_t zone_cfg;
+ uint8_t i;
+ uint8_t TopLeftX;
+ uint8_t TopLeftY;
+ uint8_t BotRightX;
+ uint8_t BotRightY;
+
+ LOG_FUNCTION_START("");
+
+ VL53L1_get_zone_config(Dev, &zone_cfg);
+
+ pRoiConfig->NumberOfRoi = zone_cfg.active_zones + 1;
+
+ for (i = 0; i < pRoiConfig->NumberOfRoi; i++) {
+ TopLeftX = (2 * zone_cfg.user_zones[i].x_centre -
+ zone_cfg.user_zones[i].width) >> 1;
+ TopLeftY = (2 * zone_cfg.user_zones[i].y_centre +
+ zone_cfg.user_zones[i].height) >> 1;
+ BotRightX = (2 * zone_cfg.user_zones[i].x_centre +
+ zone_cfg.user_zones[i].width) >> 1;
+ BotRightY = (2 * zone_cfg.user_zones[i].y_centre -
+ zone_cfg.user_zones[i].height) >> 1;
+ pRoiConfig->UserRois[i].TopLeftX = TopLeftX;
+ pRoiConfig->UserRois[i].TopLeftY = TopLeftY;
+ pRoiConfig->UserRois[i].BotRightX = BotRightX;
+ pRoiConfig->UserRois[i].BotRightY = BotRightY;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_GetNumberOfSequenceSteps(VL53L1_DEV Dev,
+ uint8_t *pNumberOfSequenceSteps)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ SUPPRESS_UNUSED_WARNING(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pNumberOfSequenceSteps = VL53L1_SEQUENCESTEP_NUMBER_OF_ITEMS;
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetSequenceStepsInfo(VL53L1_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_sequence_steps_info(
+ SequenceStepId,
+ pSequenceStepsString);
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint32_t MeasurementTimingBudgetMicroSeconds;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ Status = VL53L1_set_sequence_config_bit(Dev,
+ (VL53L1_DeviceSequenceConfig)SequenceStepId,
+ SequenceStepEnabled);
+
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+
+
+ MeasurementTimingBudgetMicroSeconds = VL53L1DevDataGet(Dev,
+ CurrentParameters.MeasurementTimingBudgetMicroSeconds);
+
+ VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev,
+ MeasurementTimingBudgetMicroSeconds);
+ }
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetSequenceStepEnable(VL53L1_DEV Dev,
+ VL53L1_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_sequence_config_bit(Dev,
+ (VL53L1_DeviceSequenceConfig)SequenceStepId,
+ pSequenceStepEnabled);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev)
+{
+#define TIMED_MODE_TIMING_GUARD_MILLISECONDS 4
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t DeviceMeasurementMode;
+ VL53L1_State CurrPalState;
+ VL53L1_Error lStatus;
+ uint32_t MTBus, IMPms;
+
+ LOG_FUNCTION_START("");
+
+ //VL53L1_load_patch(Dev);
+
+ CurrPalState = VL53L1DevDataGet(Dev, PalState);
+ switch (CurrPalState) {
+ case VL53L1_STATE_IDLE:
+ Status = VL53L1_ERROR_NONE;
+ break;
+ case VL53L1_STATE_POWERDOWN:
+ case VL53L1_STATE_WAIT_STATICINIT:
+ case VL53L1_STATE_STANDBY:
+ case VL53L1_STATE_RUNNING:
+ case VL53L1_STATE_RESET:
+ case VL53L1_STATE_UNKNOWN:
+ case VL53L1_STATE_ERROR:
+ Status = VL53L1_ERROR_INVALID_COMMAND;
+ break;
+ default:
+ Status = VL53L1_ERROR_UNDEFINED;
+ }
+
+ DeviceMeasurementMode = VL53L1DevDataGet(Dev, LLData.measurement_mode);
+
+
+
+
+ if ((Status == VL53L1_ERROR_NONE) &&
+ (DeviceMeasurementMode == VL53L1_DEVICEMEASUREMENTMODE_TIMED)) {
+ lStatus = VL53L1_GetMeasurementTimingBudgetMicroSeconds(Dev,
+ &MTBus);
+
+
+ MTBus /= 1000;
+ lStatus = VL53L1_GetInterMeasurementPeriodMilliSeconds(Dev,
+ &IMPms);
+
+
+ SUPPRESS_UNUSED_WARNING(lStatus);
+ if (IMPms < MTBus + TIMED_MODE_TIMING_GUARD_MILLISECONDS)
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_init_and_start_range(
+ Dev,
+ DeviceMeasurementMode,
+ VL53L1_DEVICECONFIGLEVEL_FULL);
+
+
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_RUNNING);
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_StopMeasurement(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_stop_range(Dev);
+
+ //VL53L1_unload_patch(Dev);
+
+
+
+ if (Status == VL53L1_ERROR_NONE)
+ VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_IDLE);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_ClearInterruptAndStartMeasurement(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t DeviceMeasurementMode;
+
+ LOG_FUNCTION_START("");
+
+ DeviceMeasurementMode = VL53L1DevDataGet(Dev, LLData.measurement_mode);
+
+ Status = VL53L1_clear_interrupt_and_enable_next_range(Dev,
+ DeviceMeasurementMode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetMeasurementDataReady(VL53L1_DEV Dev,
+ uint8_t *pMeasurementDataReady)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_is_new_data_ready(Dev, pMeasurementDataReady);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_WaitMeasurementDataReady(VL53L1_DEV Dev)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ Status = VL53L1_poll_for_range_completion(Dev,
+ VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static void GenNewPresetMode(int16_t RefRange,
+ VL53L1_DistanceModes InternalDistanceMode,
+ VL53L1_DistanceModes *pNewDistanceMode)
+{
+ uint16_t HRLI = 600;
+ uint16_t HRLH = 700;
+ uint16_t MRLI = 1400;
+ uint16_t MRLH = 1500;
+
+ switch (InternalDistanceMode) {
+ case VL53L1_DISTANCEMODE_SHORT:
+
+
+
+
+
+ if (RefRange > MRLH)
+ *pNewDistanceMode = VL53L1_DISTANCEMODE_LONG;
+ else if (RefRange > HRLH)
+ *pNewDistanceMode = VL53L1_DISTANCEMODE_MEDIUM;
+ break;
+ case VL53L1_DISTANCEMODE_MEDIUM:
+
+
+
+
+
+ if (RefRange > MRLH)
+ *pNewDistanceMode = VL53L1_DISTANCEMODE_LONG;
+ else if (RefRange < HRLI)
+ *pNewDistanceMode = VL53L1_DISTANCEMODE_SHORT;
+ break;
+ default:
+
+
+
+
+
+
+ if (RefRange < HRLI)
+ *pNewDistanceMode = VL53L1_DISTANCEMODE_SHORT;
+ else if (RefRange < MRLI)
+ *pNewDistanceMode = VL53L1_DISTANCEMODE_MEDIUM;
+ break;
+ }
+}
+
+static void CheckAndChangeDistanceMode(VL53L1_DEV Dev,
+ VL53L1_TargetRangeData_t *pRangeData,
+ int16_t Ambient100DmaxMm,
+ VL53L1_DistanceModes *pNewDistanceMode
+)
+{
+ VL53L1_DistanceModes DistanceMode;
+ uint8_t RangeStatus = pRangeData->RangeStatus;
+ uint8_t DmaxValid;
+ int32_t MinAmbient = BDTable[VL53L1_TUNING_MIN_AMBIENT_DMAX_VALID];
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ int32_t tmpint32;
+
+
+
+ switch (RangeStatus) {
+ case VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL:
+ case VL53L1_RANGESTATUS_WRAP_TARGET_FAIL:
+ case VL53L1_RANGESTATUS_RANGE_VALID_MERGED_PULSE:
+ case VL53L1_RANGESTATUS_TARGET_PRESENT_LACK_OF_SIGNAL:
+ case VL53L1_RANGESTATUS_SYNCRONISATION_INT:
+ case VL53L1_RANGESTATUS_NONE:
+ return;
+ default:
+
+
+ break;
+ }
+
+ DmaxValid = 1;
+ tmpint32 = pdev->hist_data.VL53L1_p_004;
+ if ((tmpint32 < MinAmbient) || (Ambient100DmaxMm == 0))
+ DmaxValid = 0;
+
+ DistanceMode = VL53L1DevDataGet(Dev,
+ CurrentParameters.DistanceMode);
+
+ *pNewDistanceMode = DistanceMode;
+
+ if (RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID)
+ GenNewPresetMode(pRangeData->RangeMilliMeter,
+ DistanceMode, pNewDistanceMode);
+ else {
+ if (DmaxValid)
+ GenNewPresetMode(Ambient100DmaxMm,
+ DistanceMode, pNewDistanceMode);
+ else
+ *pNewDistanceMode = VL53L1_DISTANCEMODE_LONG;
+ }
+}
+
+static uint8_t ComputeRQL(uint8_t active_results,
+ uint8_t FilteredRangeStatus,
+ VL53L1_range_data_t *presults_data)
+{
+ int16_t T_Wide = 150;
+ int16_t SRL = 300;
+ uint16_t SRAS = 30;
+ FixPoint1616_t RAS;
+ FixPoint1616_t SRQL;
+ FixPoint1616_t GI = 7713587;
+
+ FixPoint1616_t GGm = 3198157;
+
+ FixPoint1616_t LRAP = 6554;
+
+ FixPoint1616_t partial;
+ uint8_t finalvalue;
+ uint8_t returnvalue;
+
+ if (active_results == 0)
+ returnvalue = 0;
+ else if (((presults_data->max_range_mm -
+ presults_data->min_range_mm) >= T_Wide) ||
+ (FilteredRangeStatus == VL53L1_DEVICEERROR_PHASECONSISTENCY))
+ returnvalue = 50;
+ else {
+ if (presults_data->median_range_mm < SRL)
+ RAS = SRAS * 65536;
+ else
+ RAS = LRAP * presults_data->median_range_mm;
+
+
+
+ if (RAS != 0) {
+ partial = (GGm * presults_data->VL53L1_p_005);
+ partial = partial + (RAS >> 1);
+ partial = partial / RAS;
+ partial = partial * 65536;
+ if (partial <= GI)
+ SRQL = GI - partial;
+ else
+ SRQL = 50 * 65536;
+ } else
+ SRQL = 100 * 65536;
+
+ finalvalue = (uint8_t)(SRQL >> 16);
+ returnvalue = MAX(50, MIN(100, finalvalue));
+ }
+
+ return returnvalue;
+}
+
+
+static uint8_t ConvertStatusLite(uint8_t FilteredRangeStatus)
+{
+ uint8_t RangeStatus;
+
+ switch (FilteredRangeStatus) {
+ case VL53L1_DEVICEERROR_GPHSTREAMCOUNT0READY:
+ RangeStatus = VL53L1_RANGESTATUS_SYNCRONISATION_INT;
+ break;
+ case VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK:
+ RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_RANGEPHASECHECK:
+ RangeStatus = VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_MSRCNOTARGET:
+ RangeStatus = VL53L1_RANGESTATUS_SIGNAL_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK:
+ RangeStatus = VL53L1_RANGESTATUS_SIGMA_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_PHASECONSISTENCY:
+ RangeStatus = VL53L1_RANGESTATUS_WRAP_TARGET_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_RANGEIGNORETHRESHOLD:
+ RangeStatus = VL53L1_RANGESTATUS_XTALK_SIGNAL_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_MINCLIP:
+ RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_MIN_RANGE_CLIPPED;
+ break;
+ case VL53L1_DEVICEERROR_RANGECOMPLETE:
+ RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID;
+ break;
+ default:
+ RangeStatus = VL53L1_RANGESTATUS_NONE;
+ }
+
+ return RangeStatus;
+}
+
+
+static uint8_t ConvertStatusHisto(uint8_t FilteredRangeStatus)
+{
+ uint8_t RangeStatus;
+
+ switch (FilteredRangeStatus) {
+ case VL53L1_DEVICEERROR_RANGEPHASECHECK:
+ RangeStatus = VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK:
+ RangeStatus = VL53L1_RANGESTATUS_SIGMA_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK:
+ RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_PHASECONSISTENCY:
+ RangeStatus = VL53L1_RANGESTATUS_WRAP_TARGET_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_PREV_RANGE_NO_TARGETS:
+ RangeStatus = VL53L1_RANGESTATUS_TARGET_PRESENT_LACK_OF_SIGNAL;
+ break;
+ case VL53L1_DEVICEERROR_EVENTCONSISTENCY:
+ RangeStatus = VL53L1_RANGESTATUS_WRAP_TARGET_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_RANGECOMPLETE_MERGED_PULSE:
+ RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_MERGED_PULSE;
+ break;
+ case VL53L1_DEVICEERROR_RANGECOMPLETE:
+ RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID;
+ break;
+ default:
+ RangeStatus = VL53L1_RANGESTATUS_NONE;
+ }
+
+ return RangeStatus;
+}
+
+static VL53L1_Error SetSimpleData(VL53L1_DEV Dev,
+ uint8_t active_results, uint8_t device_status,
+ VL53L1_range_data_t *presults_data,
+ VL53L1_RangingMeasurementData_t *pRangeData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t FilteredRangeStatus;
+ uint8_t SigmaLimitflag;
+ uint8_t SignalLimitflag;
+ uint8_t Temp8Enable;
+ uint8_t Temp8;
+ FixPoint1616_t AmbientRate;
+ FixPoint1616_t SignalRate;
+ FixPoint1616_t TempFix1616;
+ FixPoint1616_t LimitCheckValue;
+ VL53L1_PresetModes PresetMode;
+ int16_t Range;
+
+ pRangeData->TimeStamp = presults_data->time_stamp;
+
+ FilteredRangeStatus = presults_data->range_status & 0x1F;
+
+ pRangeData->RangeQualityLevel = ComputeRQL(active_results,
+ FilteredRangeStatus,
+ presults_data);
+
+ SignalRate = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->peak_signal_count_rate_mcps);
+ pRangeData->SignalRateRtnMegaCps
+ = SignalRate;
+
+ AmbientRate = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->ambient_count_rate_mcps);
+ pRangeData->AmbientRateRtnMegaCps = AmbientRate;
+
+ pRangeData->EffectiveSpadRtnCount =
+ presults_data->VL53L1_p_006;
+
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->VL53L1_p_005);
+
+ pRangeData->SigmaMilliMeter = TempFix1616;
+
+ pRangeData->RangeMilliMeter = presults_data->median_range_mm;
+
+ pRangeData->RangeFractionalPart = 0;
+
+
+
+ switch (device_status) {
+ case VL53L1_DEVICEERROR_MULTCLIPFAIL:
+ case VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE:
+ case VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE:
+ case VL53L1_DEVICEERROR_NOVHVVALUEFOUND:
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_HARDWARE_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_USERROICLIP:
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_MIN_RANGE_FAIL;
+ break;
+ default:
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID;
+ }
+
+
+
+ if (pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) {
+ PresetMode = VL53L1DevDataGet(Dev,
+ CurrentParameters.PresetMode);
+ if ((PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) ||
+ (PresetMode == VL53L1_PRESETMODE_RANGING) ||
+ (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE))
+ pRangeData->RangeStatus =
+ ConvertStatusHisto(FilteredRangeStatus);
+ else
+ pRangeData->RangeStatus =
+ ConvertStatusLite(FilteredRangeStatus);
+ }
+
+
+
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->VL53L1_p_005);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksCurrent, VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ TempFix1616);
+
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->peak_signal_count_rate_mcps);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksCurrent, VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ TempFix1616);
+
+
+
+
+
+ VL53L1_GetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &LimitCheckValue);
+
+ SigmaLimitflag = (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK)
+ ? 1 : 0;
+
+ VL53L1_GetLimitCheckEnable(Dev,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &Temp8Enable);
+
+ Temp8 = ((Temp8Enable == 1) && (SigmaLimitflag == 1)) ? 1 : 0;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, Temp8);
+
+
+
+ VL53L1_GetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &LimitCheckValue);
+
+ SignalLimitflag = (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_MSRCNOTARGET)
+ ? 1 : 0;
+
+ VL53L1_GetLimitCheckEnable(Dev,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &Temp8Enable);
+
+ Temp8 = ((Temp8Enable == 1) && (SignalLimitflag == 1)) ? 1 : 0;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, Temp8);
+
+ Range = pRangeData->RangeMilliMeter;
+ if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) &&
+ (Range < 0)) {
+ if (Range < BDTable[VL53L1_TUNING_PROXY_MIN])
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_RANGE_INVALID;
+ else
+ pRangeData->RangeMilliMeter = 0;
+ }
+
+ return Status;
+}
+
+static VL53L1_Error SetTargetData(VL53L1_DEV Dev,
+ uint8_t active_results, uint8_t device_status,
+ VL53L1_range_data_t *presults_data,
+ VL53L1_TargetRangeData_t *pRangeData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t FilteredRangeStatus;
+ uint8_t SigmaLimitflag;
+ uint8_t SignalLimitflag;
+ uint8_t Temp8Enable;
+ uint8_t Temp8;
+ FixPoint1616_t AmbientRate;
+ FixPoint1616_t SignalRate;
+ FixPoint1616_t TempFix1616;
+ FixPoint1616_t LimitCheckValue;
+ VL53L1_PresetModes PresetMode;
+ int16_t Range;
+
+ FilteredRangeStatus = presults_data->range_status & 0x1F;
+
+ pRangeData->RangeQualityLevel = ComputeRQL(active_results,
+ FilteredRangeStatus,
+ presults_data);
+
+ SignalRate = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->peak_signal_count_rate_mcps);
+ pRangeData->SignalRateRtnMegaCps
+ = SignalRate;
+
+ AmbientRate = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->ambient_count_rate_mcps);
+ pRangeData->AmbientRateRtnMegaCps = AmbientRate;
+
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->VL53L1_p_005);
+
+ pRangeData->SigmaMilliMeter = TempFix1616;
+
+ pRangeData->RangeMilliMeter = presults_data->median_range_mm;
+ pRangeData->RangeMaxMilliMeter = presults_data->max_range_mm;
+ pRangeData->RangeMinMilliMeter = presults_data->min_range_mm;
+
+ pRangeData->RangeFractionalPart = 0;
+
+
+
+ switch (device_status) {
+ case VL53L1_DEVICEERROR_MULTCLIPFAIL:
+ case VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE:
+ case VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE:
+ case VL53L1_DEVICEERROR_NOVHVVALUEFOUND:
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_HARDWARE_FAIL;
+ break;
+ case VL53L1_DEVICEERROR_USERROICLIP:
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_MIN_RANGE_FAIL;
+ break;
+ default:
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID;
+ }
+
+ if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) &&
+ (active_results == 0)) {
+ pRangeData->RangeStatus = VL53L1_RANGESTATUS_NONE;
+ pRangeData->SignalRateRtnMegaCps = 0;
+ pRangeData->SigmaMilliMeter = 0;
+ pRangeData->RangeMilliMeter = 8191;
+ pRangeData->RangeMaxMilliMeter = 8191;
+ pRangeData->RangeMinMilliMeter = 8191;
+ }
+
+ if (pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) {
+ PresetMode = VL53L1DevDataGet(Dev,
+ CurrentParameters.PresetMode);
+ if ((PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) ||
+ (PresetMode == VL53L1_PRESETMODE_RANGING) ||
+ (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE))
+ pRangeData->RangeStatus =
+ ConvertStatusHisto(FilteredRangeStatus);
+ else
+ pRangeData->RangeStatus =
+ ConvertStatusLite(FilteredRangeStatus);
+ }
+
+
+
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->VL53L1_p_005);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksCurrent, VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ TempFix1616);
+
+ TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(
+ presults_data->peak_signal_count_rate_mcps);
+ VL53L1_SETARRAYPARAMETERFIELD(Dev,
+ LimitChecksCurrent, VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ TempFix1616);
+
+
+
+
+
+ VL53L1_GetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &LimitCheckValue);
+
+ SigmaLimitflag = (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK)
+ ? 1 : 0;
+
+ VL53L1_GetLimitCheckEnable(Dev,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE,
+ &Temp8Enable);
+
+ Temp8 = ((Temp8Enable == 1) && (SigmaLimitflag == 1)) ? 1 : 0;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, Temp8);
+
+
+
+ VL53L1_GetLimitCheckValue(Dev,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &LimitCheckValue);
+
+ SignalLimitflag = (FilteredRangeStatus ==
+ VL53L1_DEVICEERROR_MSRCNOTARGET)
+ ? 1 : 0;
+
+ VL53L1_GetLimitCheckEnable(Dev,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
+ &Temp8Enable);
+
+ Temp8 = ((Temp8Enable == 1) && (SignalLimitflag == 1)) ? 1 : 0;
+ VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
+ VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, Temp8);
+
+ Range = pRangeData->RangeMilliMeter;
+ if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) &&
+ (Range < 0)) {
+ if (Range < BDTable[VL53L1_TUNING_PROXY_MIN])
+ pRangeData->RangeStatus =
+ VL53L1_RANGESTATUS_RANGE_INVALID;
+ else
+ pRangeData->RangeMilliMeter = 0;
+ }
+
+ return Status;
+}
+
+static uint8_t GetOutputDataIndex(VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults)
+{
+ uint8_t i;
+ uint8_t index = 0;
+ VL53L1_OutputModes OutputMode;
+
+ OutputMode = VL53L1DevDataGet(Dev, CurrentParameters.OutputMode);
+
+
+
+
+ if (OutputMode == VL53L1_OUTPUTMODE_NEAREST)
+ return 0;
+
+
+
+
+
+ for (i = 1; i < presults->active_results; i++) {
+ if (presults->VL53L1_p_002[i].peak_signal_count_rate_mcps >
+ presults->VL53L1_p_002[index].peak_signal_count_rate_mcps)
+ index = i;
+ }
+
+ return index;
+}
+
+VL53L1_Error VL53L1_GetRangingMeasurementData(VL53L1_DEV Dev,
+ VL53L1_RangingMeasurementData_t *pRangingMeasurementData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_range_results_t *presults =
+ (VL53L1_range_results_t *) pdev->wArea1;
+ VL53L1_range_data_t *presults_data;
+ VL53L1_PresetModes PresetMode;
+ uint8_t index = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+ PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode);
+
+ if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) {
+ Status = VL53L1_ERROR_MODE_NOT_SUPPORTED;
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+
+
+ memset(pRangingMeasurementData, 0xFF,
+ sizeof(VL53L1_RangingMeasurementData_t));
+
+
+
+ Status = VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ presults);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ pRangingMeasurementData->StreamCount = presults->stream_count;
+
+
+
+
+
+ index = GetOutputDataIndex(Dev, presults);
+ presults_data = &(presults->VL53L1_p_002[index]);
+ Status = SetSimpleData(Dev, presults->active_results,
+ presults->device_status,
+ presults_data,
+ pRangingMeasurementData);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+static VL53L1_Error SetMeasurementData(VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults,
+ VL53L1_MultiRangingData_t *pMultiRangingData)
+{
+ uint8_t i;
+ uint8_t iteration;
+ VL53L1_TargetRangeData_t *pRangeData;
+ VL53L1_range_data_t *presults_data;
+ int16_t dmax_min;
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ uint8_t Furthest_idx = 0;
+ int16_t Furthest_range = 0;
+ uint8_t ActiveResults;
+
+ pMultiRangingData->NumberOfObjectsFound = presults->active_results;
+ pMultiRangingData->RoiNumber = presults->zone_id;
+ pMultiRangingData->HasXtalkValueChanged =
+ presults->smudge_corrector_data.new_xtalk_applied_flag;
+ dmax_min = MIN(presults->wrap_dmax_mm,
+ presults->VL53L1_p_007[DMAX_REFLECTANCE_IDX]);
+ pMultiRangingData->DmaxMilliMeter = dmax_min;
+
+
+
+
+
+ pMultiRangingData->TimeStamp = 0;
+
+ pMultiRangingData->StreamCount = presults->stream_count;
+
+ pMultiRangingData->RecommendedDistanceMode =
+ VL53L1DevDataGet(Dev, CurrentParameters.DistanceMode);
+ ActiveResults = presults->active_results;
+ if (ActiveResults < 1)
+
+
+
+
+ iteration = 1;
+ else
+ iteration = ActiveResults;
+ for (i = 0; i < iteration; i++) {
+ pRangeData = &(pMultiRangingData->RangeData[i]);
+
+ presults_data = &(presults->VL53L1_p_002[i]);
+ if (Status == VL53L1_ERROR_NONE)
+ Status = SetTargetData(Dev, ActiveResults,
+ presults->device_status,
+ presults_data,
+ pRangeData);
+
+ pMultiRangingData->EffectiveSpadRtnCount =
+ presults_data->VL53L1_p_006;
+
+ if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID)
+ && (pRangeData->RangeMilliMeter > Furthest_range)) {
+ Furthest_range = pRangeData->RangeMilliMeter;
+ Furthest_idx = i;
+ }
+
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ if (ActiveResults > 0) {
+ pRangeData = &(pMultiRangingData->RangeData[Furthest_idx]);
+ CheckAndChangeDistanceMode(Dev, pRangeData,
+ presults->VL53L1_p_007[VL53L1_MAX_AMBIENT_DMAX_VALUES-1],
+ &pMultiRangingData->RecommendedDistanceMode);
+ }
+ }
+
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetMultiRangingData(VL53L1_DEV Dev,
+ VL53L1_MultiRangingData_t *pMultiRangingData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_range_results_t *presults =
+ (VL53L1_range_results_t *) pdev->wArea1;
+
+ LOG_FUNCTION_START("");
+
+
+
+ memset(pMultiRangingData, 0xFF,
+ sizeof(VL53L1_MultiRangingData_t));
+
+
+
+ Status = VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ presults);
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+ switch (presults->rd_device_state) {
+ case VL53L1_DEVICESTATE_RANGING_GATHER_DATA:
+ pMultiRangingData->RoiStatus =
+ VL53L1_ROISTATUS_VALID_NOT_LAST;
+ break;
+ case VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA:
+ pMultiRangingData->RoiStatus =
+ VL53L1_ROISTATUS_VALID_LAST;
+ break;
+ default:
+ pMultiRangingData->RoiStatus =
+ VL53L1_ROISTATUS_NOT_VALID;
+ }
+
+ Status = SetMeasurementData(Dev,
+ presults,
+ pMultiRangingData);
+
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetAdditionalData(VL53L1_DEV Dev,
+ VL53L1_AdditionalData_t *pAdditionalData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_additional_data(Dev, pAdditionalData);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_SetTuningParameter(VL53L1_DEV Dev,
+ uint16_t TuningParameterId, int32_t TuningParameterValue)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+ if (TuningParameterId ==
+ VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS)
+ return VL53L1_ERROR_INVALID_PARAMS;
+
+
+ if (TuningParameterId >= 32768)
+ Status = VL53L1_set_tuning_parm(Dev,
+ TuningParameterId,
+ TuningParameterValue);
+ else {
+ if (TuningParameterId < VL53L1_TUNING_MAX_TUNABLE_KEY)
+ BDTable[TuningParameterId] = TuningParameterValue;
+ else
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetTuningParameter(VL53L1_DEV Dev,
+ uint16_t TuningParameterId, int32_t *pTuningParameterValue)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (TuningParameterId >= 32768)
+ Status = VL53L1_get_tuning_parm(Dev,
+ TuningParameterId,
+ pTuningParameterValue);
+ else {
+ if (TuningParameterId < VL53L1_TUNING_MAX_TUNABLE_KEY)
+ *pTuningParameterValue = BDTable[TuningParameterId];
+ else
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_PerformRefSpadManagement(VL53L1_DEV Dev)
+{
+#ifdef VL53L1_NOCALIB
+ VL53L1_Error Status = VL53L1_ERROR_NOT_SUPPORTED;
+
+ SUPPRESS_UNUSED_WARNING(Dev);
+
+ LOG_FUNCTION_START("");
+#else
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_Error RawStatus;
+ uint8_t dcrbuffer[24];
+ uint8_t *commbuf;
+ uint8_t numloc[2] = {5, 3};
+ VL53L1_LLDriverData_t *pdev;
+ VL53L1_customer_nvm_managed_t *pc;
+ VL53L1_PresetModes PresetMode;
+
+ LOG_FUNCTION_START("");
+
+ pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ pc = &pdev->customer;
+
+ if (Status == VL53L1_ERROR_NONE) {
+ PresetMode = VL53L1DevDataGet(Dev,
+ CurrentParameters.PresetMode);
+ Status = VL53L1_run_ref_spad_char(Dev, &RawStatus);
+
+
+
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_SetPresetMode(Dev, PresetMode);
+ }
+
+ if (Status == VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH) {
+
+
+
+
+ Status = VL53L1_read_nvm_raw_data(Dev,
+ (uint8_t)(0xA0 >> 2),
+ (uint8_t)(24 >> 2),
+ dcrbuffer);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_WriteMulti(Dev,
+ VL53L1_REF_SPAD_MAN__NUM_REQUESTED_REF_SPADS,
+ numloc, 2);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ pc->ref_spad_man__num_requested_ref_spads = numloc[0];
+ pc->ref_spad_man__ref_location = numloc[1];
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ commbuf = &dcrbuffer[16];
+
+
+
+
+
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_WriteMulti(Dev,
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0,
+ commbuf, 6);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ pc->global_config__spad_enables_ref_0 = commbuf[0];
+ pc->global_config__spad_enables_ref_1 = commbuf[1];
+ pc->global_config__spad_enables_ref_2 = commbuf[2];
+ pc->global_config__spad_enables_ref_3 = commbuf[3];
+ pc->global_config__spad_enables_ref_4 = commbuf[4];
+ pc->global_config__spad_enables_ref_5 = commbuf[5];
+ }
+
+
+ }
+
+#endif
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SmudgeCorrectionEnable(VL53L1_DEV Dev,
+ VL53L1_SmudgeCorrectionModes Mode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_Error s1 = VL53L1_ERROR_NONE;
+ VL53L1_Error s2 = VL53L1_ERROR_NONE;
+ VL53L1_Error s3 = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ switch (Mode) {
+ case VL53L1_SMUDGE_CORRECTION_NONE:
+ s1 = VL53L1_dynamic_xtalk_correction_disable(Dev);
+ s2 = VL53L1_dynamic_xtalk_correction_apply_disable(Dev);
+ s3 = VL53L1_dynamic_xtalk_correction_single_apply_disable(Dev);
+ break;
+ case VL53L1_SMUDGE_CORRECTION_CONTINUOUS:
+ s1 = VL53L1_dynamic_xtalk_correction_enable(Dev);
+ s2 = VL53L1_dynamic_xtalk_correction_apply_enable(Dev);
+ s3 = VL53L1_dynamic_xtalk_correction_single_apply_disable(Dev);
+ break;
+ case VL53L1_SMUDGE_CORRECTION_SINGLE:
+ s1 = VL53L1_dynamic_xtalk_correction_enable(Dev);
+ s2 = VL53L1_dynamic_xtalk_correction_apply_enable(Dev);
+ s3 = VL53L1_dynamic_xtalk_correction_single_apply_enable(Dev);
+ break;
+ case VL53L1_SMUDGE_CORRECTION_DEBUG:
+ s1 = VL53L1_dynamic_xtalk_correction_enable(Dev);
+ s2 = VL53L1_dynamic_xtalk_correction_apply_disable(Dev);
+ s3 = VL53L1_dynamic_xtalk_correction_single_apply_disable(Dev);
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+ }
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = s1;
+ if (Status == VL53L1_ERROR_NONE)
+ Status = s2;
+ if (Status == VL53L1_ERROR_NONE)
+ Status = s3;
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetXTalkCompensationEnable(VL53L1_DEV Dev,
+ uint8_t XTalkCompensationEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (XTalkCompensationEnable == 0)
+ Status = VL53L1_disable_xtalk_compensation(Dev);
+ else
+ Status = VL53L1_enable_xtalk_compensation(Dev);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetXTalkCompensationEnable(VL53L1_DEV Dev,
+ uint8_t *pXTalkCompensationEnable)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ VL53L1_get_xtalk_compensation_enable(
+ Dev,
+ pXTalkCompensationEnable);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_PerformXTalkCalibration(VL53L1_DEV Dev,
+ uint8_t CalibrationOption)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_Error UStatus;
+ int16_t CalDistanceMm;
+ VL53L1_xtalk_calibration_results_t xtalk;
+
+
+ VL53L1_CalibrationData_t caldata;
+ VL53L1_LLDriverData_t *pLLData;
+ int i;
+ uint32_t *pPlaneOffsetKcps;
+ uint32_t HugePlaneOffsetKcps =
+ BDTable[VL53L1_TUNING_XTALK_FULL_ROI_MAX_THRESHOLD];
+ uint32_t Margin =
+ BDTable[VL53L1_TUNING_XTALK_FULL_ROI_BIN_SUM_MARGIN];
+ uint32_t DefaultOffset =
+ BDTable[VL53L1_TUNING_XTALK_FULL_ROI_DEFAULT_OFFSET];
+ uint32_t *pLLDataPlaneOffsetKcps;
+ uint32_t sum = 0;
+ uint8_t binok = 0;
+ int32_t merge;
+
+
+ LOG_FUNCTION_START("");
+
+ pPlaneOffsetKcps =
+ &caldata.customer.algo__crosstalk_compensation_plane_offset_kcps;
+ pLLData = VL53L1DevStructGetLLDriverHandle(Dev);
+ pLLDataPlaneOffsetKcps =
+ &pLLData->xtalk_cal.algo__crosstalk_compensation_plane_offset_kcps;
+ VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, &merge);
+
+
+ VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, 0);
+ switch (CalibrationOption) {
+ case VL53L1_XTALKCALIBRATIONMODE_NO_TARGET:
+ Status = VL53L1_run_xtalk_extraction(Dev, &UStatus);
+
+
+ if (Status == VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL)
+ VL53L1_xtalk_cal_data_init(Dev);
+ break;
+ case VL53L1_XTALKCALIBRATIONMODE_SINGLE_TARGET:
+ Status = SingleTargetXTalkCalibration(Dev);
+ break;
+ case VL53L1_XTALKCALIBRATIONMODE_FULL_ROI:
+ CalDistanceMm = (int16_t)
+ BDTable[VL53L1_TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM];
+
+
+ VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, merge);
+ Status = VL53L1_run_hist_xtalk_extraction(Dev, CalDistanceMm,
+ &UStatus);
+
+
+ VL53L1_GetCalibrationData(Dev, &caldata);
+ for (i = 0; i < VL53L1_XTALK_HISTO_BINS; i++) {
+ sum += caldata.xtalkhisto.xtalk_shape.bin_data[i];
+ if (caldata.xtalkhisto.xtalk_shape.bin_data[i] > 0)
+ binok++;
+ }
+ if ((UStatus == VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL)
+ || (*pPlaneOffsetKcps > HugePlaneOffsetKcps) ||
+ (sum > (1024 + Margin)) || (sum < (1024 - Margin)) ||
+ (binok < 3)) {
+ *pPlaneOffsetKcps = DefaultOffset;
+ *pLLDataPlaneOffsetKcps = DefaultOffset;
+ caldata.xtalkhisto.xtalk_shape.bin_data[0] = 307;
+ caldata.xtalkhisto.xtalk_shape.bin_data[1] = 410;
+ caldata.xtalkhisto.xtalk_shape.bin_data[2] = 410;
+ caldata.xtalkhisto.xtalk_shape.bin_data[3] = 307;
+ for (i = 4; i < VL53L1_XTALK_HISTO_BINS; i++)
+ caldata.xtalkhisto.xtalk_shape.bin_data[i] = 0;
+ for (i = 0; i < VL53L1_BIN_REC_SIZE; i++)
+ caldata.algo__xtalk_cpo_HistoMerge_kcps[i] =
+ DefaultOffset + DefaultOffset * i;
+ VL53L1_SetCalibrationData(Dev, &caldata);
+ }
+
+
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, merge);
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Status = VL53L1_get_current_xtalk_settings(Dev, &xtalk);
+ Status = VL53L1_set_tuning_parm(Dev,
+ VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS,
+ xtalk.algo__crosstalk_compensation_plane_offset_kcps);
+ }
+
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetOffsetCalibrationMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationModes OffsetCalibrationMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_OffsetCalibrationMode offset_cal_mode;
+
+ LOG_FUNCTION_START("");
+
+ if (OffsetCalibrationMode == VL53L1_OFFSETCALIBRATIONMODE_STANDARD) {
+ offset_cal_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD;
+ } else if (OffsetCalibrationMode ==
+ VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY) {
+ offset_cal_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY;
+ } else if (OffsetCalibrationMode ==
+ VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE) {
+ offset_cal_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__PER_ZONE;
+ } else {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_offset_calibration_mode(Dev,
+ offset_cal_mode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetOffsetCorrectionMode(VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionModes OffsetCorrectionMode)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_OffsetCorrectionMode offset_cor_mode;
+
+ LOG_FUNCTION_START("");
+
+ if (OffsetCorrectionMode == VL53L1_OFFSETCORRECTIONMODE_STANDARD) {
+ offset_cor_mode =
+ VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS;
+ } else if (OffsetCorrectionMode ==
+ VL53L1_OFFSETCORRECTIONMODE_PERZONE) {
+ offset_cor_mode =
+ VL53L1_OFFSETCORRECTIONMODE__PER_ZONE_OFFSETS;
+ } else if (OffsetCorrectionMode ==
+ VL53L1_OFFSETCORRECTIONMODE_PERVCSEL) {
+ offset_cor_mode =
+ VL53L1_OFFSETCORRECTIONMODE__PER_VCSEL_OFFSETS;
+ } else {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_set_offset_correction_mode(Dev,
+ offset_cor_mode);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_PerformOffsetCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter, FixPoint1616_t CalReflectancePercent)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_Error UnfilteredStatus;
+ VL53L1_OffsetCalibrationMode offset_cal_mode;
+ uint16_t CalReflectancePercent_int;
+
+
+ VL53L1_DevicePresetModes device_preset_mode;
+ VL53L1_DeviceZonePreset zone_preset;
+ VL53L1_zone_config_t zone_cfg;
+
+ LOG_FUNCTION_START("");
+
+ CalReflectancePercent_int =
+ VL53L1_FIXPOINT1616TOFIXPOINT72(CalReflectancePercent);
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_get_offset_calibration_mode(Dev,
+ &offset_cal_mode);
+
+ if (Status != VL53L1_ERROR_NONE) {
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+
+ if ((offset_cal_mode ==
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD) ||
+ (offset_cal_mode ==
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY
+ )) {
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_run_offset_calibration(
+ Dev,
+ (int16_t)CalDistanceMilliMeter,
+ CalReflectancePercent_int,
+ &UnfilteredStatus);
+
+ } else if (offset_cal_mode ==
+ VL53L1_OFFSETCALIBRATIONMODE__PER_ZONE) {
+ device_preset_mode =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE;
+ zone_preset = VL53L1_DEVICEZONEPRESET_CUSTOM;
+
+ Status = VL53L1_get_zone_config(Dev, &zone_cfg);
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_run_zone_calibration(
+ Dev,
+ device_preset_mode,
+ zone_preset,
+ &zone_cfg,
+ (int16_t)CalDistanceMilliMeter,
+ CalReflectancePercent_int,
+ &UnfilteredStatus);
+
+ } else {
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_PerformOffsetSimpleCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ int32_t sum_ranging;
+ uint8_t offset_meas;
+ int16_t Max, UnderMax, OverMax, Repeat;
+ int32_t total_count, inloopcount;
+ int32_t IncRounding;
+ int16_t meanDistance_mm;
+ int16_t offset;
+ VL53L1_RangingMeasurementData_t RangingMeasurementData;
+ VL53L1_LLDriverData_t *pdev;
+ uint8_t goodmeas;
+ VL53L1_Error SmudgeStatus = VL53L1_ERROR_NONE;
+ uint8_t smudge_corr_en;
+
+ LOG_FUNCTION_START("");
+
+ pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+
+ smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled;
+ SmudgeStatus = VL53L1_dynamic_xtalk_correction_disable(Dev);
+
+
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+ pdev->customer.mm_config__inner_offset_mm = 0;
+ pdev->customer.mm_config__outer_offset_mm = 0;
+ memset(&pdev->per_vcsel_cal_data, 0, sizeof(pdev->per_vcsel_cal_data));
+ Repeat = BDTable[VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT];
+ Max = BDTable[
+ VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER];
+ UnderMax = 1 + (Max / 2);
+ OverMax = Max + (Max / 2);
+ sum_ranging = 0;
+ total_count = 0;
+
+ while ((Repeat > 0) && (Status == VL53L1_ERROR_NONE)) {
+ Status = VL53L1_StartMeasurement(Dev);
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1_WaitMeasurementDataReady(Dev);
+ VL53L1_GetRangingMeasurementData(Dev, &RangingMeasurementData);
+ VL53L1_ClearInterruptAndStartMeasurement(Dev);
+ }
+
+
+ inloopcount = 0;
+ offset_meas = 0;
+ while ((Status == VL53L1_ERROR_NONE) && (inloopcount < Max) &&
+ (offset_meas < OverMax)) {
+ Status = VL53L1_WaitMeasurementDataReady(Dev);
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_GetRangingMeasurementData(Dev,
+ &RangingMeasurementData);
+ goodmeas = (RangingMeasurementData.RangeStatus ==
+ VL53L1_RANGESTATUS_RANGE_VALID);
+ if ((Status == VL53L1_ERROR_NONE) && goodmeas) {
+ sum_ranging = sum_ranging +
+ RangingMeasurementData.RangeMilliMeter;
+ inloopcount++;
+ }
+ Status = VL53L1_ClearInterruptAndStartMeasurement(Dev);
+ offset_meas++;
+ }
+ total_count += inloopcount;
+
+
+
+ if (inloopcount < UnderMax)
+ Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL;
+
+ VL53L1_StopMeasurement(Dev);
+
+ Repeat--;
+
+ }
+
+
+ if ((SmudgeStatus == VL53L1_ERROR_NONE) && (smudge_corr_en == 1))
+ SmudgeStatus = VL53L1_dynamic_xtalk_correction_enable(Dev);
+
+
+ if ((sum_ranging < 0) ||
+ (sum_ranging > ((int32_t) total_count * 0xffff)))
+ Status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH;
+
+ if ((Status == VL53L1_ERROR_NONE) && (total_count > 0)) {
+ IncRounding = total_count / 2;
+ meanDistance_mm = (int16_t)((sum_ranging + IncRounding)
+ / total_count);
+ offset = (int16_t)CalDistanceMilliMeter - meanDistance_mm;
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+ pdev->customer.mm_config__inner_offset_mm = offset;
+ pdev->customer.mm_config__outer_offset_mm = offset;
+
+ Status = VL53L1_set_customer_nvm_managed(Dev,
+ &(pdev->customer));
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_PerformOffsetZeroDistanceCalibration(VL53L1_DEV Dev)
+ {
+ #define START_OFFSET 50
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ int32_t sum_ranging;
+ uint8_t offset_meas;
+ int16_t Max, UnderMax, OverMax, Repeat;
+ int32_t total_count, inloopcount;
+ int32_t IncRounding;
+ int16_t meanDistance_mm;
+ int16_t offset, ZeroDistanceOffset;
+ VL53L1_RangingMeasurementData_t RangingMeasurementData;
+ VL53L1_LLDriverData_t *pdev;
+ uint8_t goodmeas;
+ VL53L1_Error SmudgeStatus = VL53L1_ERROR_NONE;
+ uint8_t smudge_corr_en;
+
+ LOG_FUNCTION_START("");
+
+ pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled;
+ SmudgeStatus = VL53L1_dynamic_xtalk_correction_disable(Dev);
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+ pdev->customer.mm_config__inner_offset_mm = START_OFFSET;
+ pdev->customer.mm_config__outer_offset_mm = START_OFFSET;
+ memset(&pdev->per_vcsel_cal_data, 0, sizeof(pdev->per_vcsel_cal_data));
+ ZeroDistanceOffset = BDTable[
+ VL53L1_TUNING_ZERO_DISTANCE_OFFSET_NON_LINEAR_FACTOR];
+ Repeat = BDTable[VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT];
+ Max = BDTable[VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER];
+ UnderMax = 1 + (Max / 2);
+ OverMax = Max + (Max / 2);
+ sum_ranging = 0;
+ total_count = 0;
+
+ while ((Repeat > 0) && (Status == VL53L1_ERROR_NONE)) {
+ Status = VL53L1_StartMeasurement(Dev);
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1_WaitMeasurementDataReady(Dev);
+ VL53L1_GetRangingMeasurementData(Dev, &RangingMeasurementData);
+ VL53L1_ClearInterruptAndStartMeasurement(Dev);
+ }
+ inloopcount = 0;
+ offset_meas = 0;
+ while ((Status == VL53L1_ERROR_NONE) && (inloopcount < Max) &&
+ (offset_meas < OverMax)) {
+ Status = VL53L1_WaitMeasurementDataReady(Dev);
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_GetRangingMeasurementData(Dev,
+ &RangingMeasurementData);
+ goodmeas = (RangingMeasurementData.RangeStatus ==
+ VL53L1_RANGESTATUS_RANGE_VALID);
+ if ((Status == VL53L1_ERROR_NONE) && goodmeas) {
+ sum_ranging = sum_ranging +
+ RangingMeasurementData.RangeMilliMeter;
+ inloopcount++;
+ }
+ Status = VL53L1_ClearInterruptAndStartMeasurement(Dev);
+ offset_meas++;
+ }
+ total_count += inloopcount;
+ if (inloopcount < UnderMax)
+ Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL;
+ VL53L1_StopMeasurement(Dev);
+ Repeat--;
+ }
+ if ((SmudgeStatus == VL53L1_ERROR_NONE) && (smudge_corr_en == 1))
+ SmudgeStatus = VL53L1_dynamic_xtalk_correction_enable(Dev);
+ if ((sum_ranging < 0) ||
+ (sum_ranging > ((int32_t) total_count * 0xffff)))
+ Status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH;
+
+ if ((Status == VL53L1_ERROR_NONE) && (total_count > 0)) {
+ IncRounding = total_count / 2;
+ meanDistance_mm = (int16_t)((sum_ranging + IncRounding) / total_count);
+ offset = START_OFFSET - meanDistance_mm + ZeroDistanceOffset;
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+ pdev->customer.mm_config__inner_offset_mm = offset;
+ pdev->customer.mm_config__outer_offset_mm = offset;
+ Status = VL53L1_set_customer_nvm_managed(Dev, &(pdev->customer));
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_SetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_CustomerNvmManaged_t *pC;
+ VL53L1_calibration_data_t cal_data;
+ uint32_t x;
+ VL53L1_xtalk_calibration_results_t xtalk;
+
+ LOG_FUNCTION_START("");
+
+ cal_data.struct_version = pCalibrationData->struct_version -
+ VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION;
+
+
+
+
+
+
+ memcpy(
+ &(cal_data.fmt_dmax_cal),
+ &(pCalibrationData->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(cal_data.cust_dmax_cal),
+ &(pCalibrationData->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+
+ memcpy(
+ &(cal_data.add_off_cal_data),
+ &(pCalibrationData->add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+
+
+ memcpy(
+ &(cal_data.optical_centre),
+ &(pCalibrationData->optical_centre),
+ sizeof(VL53L1_optical_centre_t));
+
+
+
+ memcpy(
+ &(cal_data.xtalkhisto),
+ &(pCalibrationData->xtalkhisto),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+
+
+ memcpy(
+ &(cal_data.gain_cal),
+ &(pCalibrationData->gain_cal),
+ sizeof(VL53L1_gain_calibration_data_t));
+
+
+
+ memcpy(
+ &(cal_data.cal_peak_rate_map),
+ &(pCalibrationData->cal_peak_rate_map),
+ sizeof(VL53L1_cal_peak_rate_map_t));
+
+
+
+ memcpy(
+ &(cal_data.per_vcsel_cal_data),
+ &(pCalibrationData->per_vcsel_cal_data),
+ sizeof(VL53L1_per_vcsel_period_offset_cal_data_t));
+
+ pC = &pCalibrationData->customer;
+ x = pC->algo__crosstalk_compensation_plane_offset_kcps;
+ cal_data.customer.algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)(x&0x0000FFFF);
+
+ cal_data.customer.global_config__spad_enables_ref_0 =
+ pC->global_config__spad_enables_ref_0;
+ cal_data.customer.global_config__spad_enables_ref_1 =
+ pC->global_config__spad_enables_ref_1;
+ cal_data.customer.global_config__spad_enables_ref_2 =
+ pC->global_config__spad_enables_ref_2;
+ cal_data.customer.global_config__spad_enables_ref_3 =
+ pC->global_config__spad_enables_ref_3;
+ cal_data.customer.global_config__spad_enables_ref_4 =
+ pC->global_config__spad_enables_ref_4;
+ cal_data.customer.global_config__spad_enables_ref_5 =
+ pC->global_config__spad_enables_ref_5;
+ cal_data.customer.global_config__ref_en_start_select =
+ pC->global_config__ref_en_start_select;
+ cal_data.customer.ref_spad_man__num_requested_ref_spads =
+ pC->ref_spad_man__num_requested_ref_spads;
+ cal_data.customer.ref_spad_man__ref_location =
+ pC->ref_spad_man__ref_location;
+ cal_data.customer.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ cal_data.customer.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ cal_data.customer.ref_spad_char__total_rate_target_mcps =
+ pC->ref_spad_char__total_rate_target_mcps;
+ cal_data.customer.algo__part_to_part_range_offset_mm =
+ pC->algo__part_to_part_range_offset_mm;
+ cal_data.customer.mm_config__inner_offset_mm =
+ pC->mm_config__inner_offset_mm;
+ cal_data.customer.mm_config__outer_offset_mm =
+ pC->mm_config__outer_offset_mm;
+
+ Status = VL53L1_set_part_to_part_data(Dev, &cal_data);
+ if (Status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+ Status = VL53L1_get_current_xtalk_settings(Dev, &xtalk);
+
+ if (Status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+ xtalk.algo__crosstalk_compensation_plane_offset_kcps = x;
+
+
+ Status = VL53L1_set_tuning_parm(Dev,
+ VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS,
+ x);
+
+
+
+ memcpy(
+ &(xtalk.algo__xtalk_cpo_HistoMerge_kcps[0]),
+ &(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps[0]),
+ sizeof(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps));
+
+ Status = VL53L1_set_current_xtalk_settings(Dev, &xtalk);
+
+ENDFUNC:
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L1_Error VL53L1_GetCalibrationData(VL53L1_DEV Dev,
+ VL53L1_CalibrationData_t *pCalibrationData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_calibration_data_t cal_data;
+ VL53L1_CustomerNvmManaged_t *pC;
+ VL53L1_customer_nvm_managed_t *pC2;
+ VL53L1_xtalk_calibration_results_t xtalk;
+ uint32_t tmp;
+ VL53L1_PresetModes PresetMode;
+
+ LOG_FUNCTION_START("");
+
+
+
+ Status = VL53L1_get_part_to_part_data(Dev, &cal_data);
+
+ pCalibrationData->struct_version = cal_data.struct_version +
+ VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION;
+
+
+
+ memcpy(
+ &(pCalibrationData->fmt_dmax_cal),
+ &(cal_data.fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pCalibrationData->cust_dmax_cal),
+ &(cal_data.cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pCalibrationData->add_off_cal_data),
+ &(cal_data.add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+
+
+ memcpy(
+ &(pCalibrationData->optical_centre),
+ &(cal_data.optical_centre),
+ sizeof(VL53L1_optical_centre_t));
+
+
+
+ memcpy(
+ &(pCalibrationData->xtalkhisto),
+ &(cal_data.xtalkhisto),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+
+ memcpy(
+ &(pCalibrationData->gain_cal),
+ &(cal_data.gain_cal),
+ sizeof(VL53L1_gain_calibration_data_t));
+
+
+
+ memcpy(
+ &(pCalibrationData->cal_peak_rate_map),
+ &(cal_data.cal_peak_rate_map),
+ sizeof(VL53L1_cal_peak_rate_map_t));
+
+
+
+ memcpy(
+ &(pCalibrationData->per_vcsel_cal_data),
+ &(cal_data.per_vcsel_cal_data),
+ sizeof(VL53L1_per_vcsel_period_offset_cal_data_t));
+
+ pC = &pCalibrationData->customer;
+ pC2 = &cal_data.customer;
+ pC->global_config__spad_enables_ref_0 =
+ pC2->global_config__spad_enables_ref_0;
+ pC->global_config__spad_enables_ref_1 =
+ pC2->global_config__spad_enables_ref_1;
+ pC->global_config__spad_enables_ref_2 =
+ pC2->global_config__spad_enables_ref_2;
+ pC->global_config__spad_enables_ref_3 =
+ pC2->global_config__spad_enables_ref_3;
+ pC->global_config__spad_enables_ref_4 =
+ pC2->global_config__spad_enables_ref_4;
+ pC->global_config__spad_enables_ref_5 =
+ pC2->global_config__spad_enables_ref_5;
+ pC->global_config__ref_en_start_select =
+ pC2->global_config__ref_en_start_select;
+ pC->ref_spad_man__num_requested_ref_spads =
+ pC2->ref_spad_man__num_requested_ref_spads;
+ pC->ref_spad_man__ref_location =
+ pC2->ref_spad_man__ref_location;
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pC2->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pC2->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ pC->ref_spad_char__total_rate_target_mcps =
+ pC2->ref_spad_char__total_rate_target_mcps;
+ pC->algo__part_to_part_range_offset_mm =
+ pC2->algo__part_to_part_range_offset_mm;
+ pC->mm_config__inner_offset_mm =
+ pC2->mm_config__inner_offset_mm;
+ pC->mm_config__outer_offset_mm =
+ pC2->mm_config__outer_offset_mm;
+
+ pC->algo__crosstalk_compensation_plane_offset_kcps =
+ (uint32_t)(
+ pC2->algo__crosstalk_compensation_plane_offset_kcps);
+
+
+ PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode);
+
+ if ((PresetMode == VL53L1_PRESETMODE_RANGING) ||
+ (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) ||
+ (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE)
+ ) {
+
+ Status = VL53L1_get_current_xtalk_settings(Dev, &xtalk);
+
+ if (Status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+ tmp = xtalk.algo__crosstalk_compensation_plane_offset_kcps;
+ pC->algo__crosstalk_compensation_plane_offset_kcps = tmp;
+ tmp = xtalk.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps = tmp;
+ tmp = xtalk.algo__crosstalk_compensation_y_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps = tmp;
+
+ memcpy(&(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps[0]),
+ &(xtalk.algo__xtalk_cpo_HistoMerge_kcps[0]),
+ sizeof(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps));
+ }
+ENDFUNC:
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_SetZoneCalibrationData(VL53L1_DEV Dev,
+ VL53L1_ZoneCalibrationData_t *pZoneCalibrationData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_set_zone_calibration_data(Dev, pZoneCalibrationData);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+
+}
+
+VL53L1_Error VL53L1_GetZoneCalibrationData(VL53L1_DEV Dev,
+ VL53L1_ZoneCalibrationData_t *pZoneCalibrationData)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_zone_calibration_data(Dev, pZoneCalibrationData);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+VL53L1_Error VL53L1_GetOpticalCenter(VL53L1_DEV Dev,
+ FixPoint1616_t *pOpticalCenterX,
+ FixPoint1616_t *pOpticalCenterY)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_calibration_data_t CalibrationData;
+
+ LOG_FUNCTION_START("");
+
+ *pOpticalCenterX = 0;
+ *pOpticalCenterY = 0;
+ Status = VL53L1_get_part_to_part_data(Dev, &CalibrationData);
+ if (Status == VL53L1_ERROR_NONE) {
+ *pOpticalCenterX = VL53L1_FIXPOINT44TOFIXPOINT1616(
+ CalibrationData.optical_centre.x_centre);
+ *pOpticalCenterY = VL53L1_FIXPOINT44TOFIXPOINT1616(
+ CalibrationData.optical_centre.y_centre);
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_SetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig)
+{
+#define BADTHRESBOUNDS(T) \
+ (((T.CrossMode == VL53L1_THRESHOLD_OUT_OF_WINDOW) || \
+ (T.CrossMode == VL53L1_THRESHOLD_IN_WINDOW)) && (T.Low > T.High))
+
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_GPIO_interrupt_config_t Cfg;
+ uint16_t g;
+ FixPoint1616_t gain, high1616, low1616;
+ VL53L1_LLDriverData_t *pdev;
+
+ LOG_FUNCTION_START("");
+
+ pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ Status = VL53L1_get_GPIO_interrupt_config(Dev, &Cfg);
+ if (Status == VL53L1_ERROR_NONE) {
+ if (pConfig->DetectionMode == VL53L1_DETECTION_NORMAL_RUN) {
+ Cfg.intr_new_measure_ready = 1;
+ Status = VL53L1_set_GPIO_interrupt_config_struct(Dev,
+ Cfg);
+ } else {
+ if (BADTHRESBOUNDS(pConfig->Distance))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ if ((Status == VL53L1_ERROR_NONE) &&
+ (BADTHRESBOUNDS(pConfig->Rate)))
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ if (Status == VL53L1_ERROR_NONE) {
+ Cfg.intr_new_measure_ready = 0;
+ Cfg.intr_no_target = pConfig->IntrNoTarget;
+
+
+
+ g = pdev->gain_cal.standard_ranging_gain_factor;
+ if (g != 0) {
+
+
+ gain = (FixPoint1616_t) ((uint32_t)g << 5);
+ high1616 = (FixPoint1616_t) ((uint32_t)
+ pConfig->Distance.High << 16);
+ low1616 = (FixPoint1616_t) ((uint32_t)
+ pConfig->Distance.Low << 16);
+
+
+ high1616 = (high1616 + 32768) / gain;
+ low1616 = (low1616 + 32768) / gain;
+ Cfg.threshold_distance_high = (uint16_t)
+ (high1616 & 0xFFFF);
+ Cfg.threshold_distance_low = (uint16_t)
+ (low1616 & 0xFFFF);
+ }
+
+
+ Cfg.threshold_rate_high =
+ VL53L1_FIXPOINT1616TOFIXPOINT97(
+ pConfig->Rate.High);
+ Cfg.threshold_rate_low =
+ VL53L1_FIXPOINT1616TOFIXPOINT97(
+ pConfig->Rate.Low);
+
+ Cfg.intr_mode_distance = ConvertModeToLLD(
+ &Status,
+ pConfig->Distance.CrossMode);
+ if (Status == VL53L1_ERROR_NONE)
+ Cfg.intr_mode_rate = ConvertModeToLLD(
+ &Status,
+ pConfig->Rate.CrossMode);
+ }
+
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ Cfg.intr_combined_mode = 1;
+ switch (pConfig->DetectionMode) {
+ case VL53L1_DETECTION_DISTANCE_ONLY:
+ Cfg.threshold_rate_high = 0;
+ Cfg.threshold_rate_low = 0;
+ break;
+ case VL53L1_DETECTION_RATE_ONLY:
+ Cfg.threshold_distance_high = 0;
+ Cfg.threshold_distance_low = 0;
+ break;
+ case VL53L1_DETECTION_DISTANCE_OR_RATE:
+
+
+
+
+ break;
+ case VL53L1_DETECTION_DISTANCE_AND_RATE:
+ Cfg.intr_combined_mode = 0;
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+ }
+
+ if (Status == VL53L1_ERROR_NONE)
+ Status =
+ VL53L1_set_GPIO_interrupt_config_struct(Dev,
+ Cfg);
+
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+VL53L1_Error VL53L1_GetThresholdConfig(VL53L1_DEV Dev,
+ VL53L1_DetectionConfig_t *pConfig)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ VL53L1_GPIO_interrupt_config_t Cfg;
+
+ LOG_FUNCTION_START("");
+
+ Status = VL53L1_get_GPIO_interrupt_config(Dev, &Cfg);
+
+ if (Status != VL53L1_ERROR_NONE) {
+ LOG_FUNCTION_END(Status);
+ return Status;
+ }
+
+ pConfig->IntrNoTarget = Cfg.intr_no_target;
+ pConfig->Distance.High = Cfg.threshold_distance_high;
+ pConfig->Distance.Low = Cfg.threshold_distance_low;
+ pConfig->Rate.High =
+ VL53L1_FIXPOINT97TOFIXPOINT1616(
+ Cfg.threshold_rate_high);
+ pConfig->Rate.Low =
+ VL53L1_FIXPOINT97TOFIXPOINT1616(Cfg.threshold_rate_low);
+ pConfig->Distance.CrossMode =
+ ConvertModeFromLLD(&Status, Cfg.intr_mode_distance);
+ if (Status == VL53L1_ERROR_NONE)
+ pConfig->Rate.CrossMode =
+ ConvertModeFromLLD(&Status, Cfg.intr_mode_rate);
+
+ if (Cfg.intr_new_measure_ready == 1) {
+ pConfig->DetectionMode = VL53L1_DETECTION_NORMAL_RUN;
+ } else {
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ if (Cfg.intr_combined_mode == 0)
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_DISTANCE_AND_RATE;
+ else {
+ if ((Cfg.threshold_distance_high == 0) &&
+ (Cfg.threshold_distance_low == 0))
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_RATE_ONLY;
+ else if ((Cfg.threshold_rate_high == 0) &&
+ (Cfg.threshold_rate_low == 0))
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_DISTANCE_ONLY;
+ else
+ pConfig->DetectionMode =
+ VL53L1_DETECTION_DISTANCE_OR_RATE;
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_PerformOffsetPerVcselCalibration(VL53L1_DEV Dev,
+ int32_t CalDistanceMilliMeter)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+ int32_t sum_ranging_range_A, sum_ranging_range_B;
+ uint8_t offset_meas_range_A, offset_meas_range_B;
+ int16_t Max, UnderMax, OverMax, Repeat;
+ int32_t inloopcount;
+ int32_t IncRounding;
+ int16_t meanDistance_mm;
+ VL53L1_RangingMeasurementData_t RangingMeasurementData;
+ VL53L1_LLDriverData_t *pdev;
+ uint8_t goodmeas;
+ VL53L1_PresetModes currentMode;
+ VL53L1_DistanceModes currentDist;
+ VL53L1_DistanceModes DistMode[3] = {VL53L1_DISTANCEMODE_SHORT,
+ VL53L1_DISTANCEMODE_MEDIUM, VL53L1_DISTANCEMODE_LONG};
+ int16_t offsetA[3];
+ int16_t offsetB[3];
+
+ VL53L1_Error SmudgeStatus = VL53L1_ERROR_NONE;
+ uint8_t smudge_corr_en;
+
+ LOG_FUNCTION_START("");
+
+ pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+
+ smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled;
+ SmudgeStatus = VL53L1_dynamic_xtalk_correction_disable(Dev);
+
+
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+ pdev->customer.mm_config__inner_offset_mm = 0;
+ pdev->customer.mm_config__outer_offset_mm = 0;
+ pdev->customer.mm_config__outer_offset_mm = 0;
+ memset(&pdev->per_vcsel_cal_data, 0, sizeof(pdev->per_vcsel_cal_data));
+
+ Repeat = 0;
+ Max = 2 * BDTable[
+ VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER];
+ UnderMax = 1 + (Max / 2);
+ OverMax = Max + (Max / 2);
+
+ Status = VL53L1_GetPresetMode(Dev, ¤tMode);
+ Status = VL53L1_GetDistanceMode(Dev, ¤tDist);
+
+ while ((Repeat < 3) && (Status == VL53L1_ERROR_NONE)) {
+ Status = VL53L1_SetDistanceMode(Dev, DistMode[Repeat]);
+ Status = VL53L1_StartMeasurement(Dev);
+
+
+ if (Status == VL53L1_ERROR_NONE) {
+ VL53L1_WaitMeasurementDataReady(Dev);
+ VL53L1_GetRangingMeasurementData(Dev, &RangingMeasurementData);
+ VL53L1_ClearInterruptAndStartMeasurement(Dev);
+ }
+
+
+ inloopcount = 0;
+ offset_meas_range_A = 0;
+ sum_ranging_range_A = 0;
+ offset_meas_range_B = 0;
+ sum_ranging_range_B = 0;
+ while ((Status == VL53L1_ERROR_NONE) && (inloopcount < Max) &&
+ (inloopcount < OverMax)) {
+ Status = VL53L1_WaitMeasurementDataReady(Dev);
+ if (Status == VL53L1_ERROR_NONE)
+ Status = VL53L1_GetRangingMeasurementData(Dev,
+ &RangingMeasurementData);
+ goodmeas = (RangingMeasurementData.RangeStatus ==
+ VL53L1_RANGESTATUS_RANGE_VALID);
+ if ((Status == VL53L1_ERROR_NONE) && goodmeas) {
+ if ((pdev->ll_state.cfg_internal_stream_count) & 0x01) {
+ sum_ranging_range_A = sum_ranging_range_A +
+ RangingMeasurementData.RangeMilliMeter;
+ offset_meas_range_A++;
+ } else {
+ sum_ranging_range_B = sum_ranging_range_B +
+ RangingMeasurementData.RangeMilliMeter;
+ offset_meas_range_B++;
+ }
+ inloopcount = offset_meas_range_A + offset_meas_range_B;
+ }
+ Status = VL53L1_ClearInterruptAndStartMeasurement(Dev);
+ }
+
+
+
+ if (inloopcount < UnderMax)
+ Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL;
+
+ VL53L1_StopMeasurement(Dev);
+
+ if (Status == VL53L1_ERROR_NONE) {
+
+ }
+
+
+ if ((sum_ranging_range_A < 0) ||
+ (sum_ranging_range_B < 0) ||
+ (sum_ranging_range_A > ((int32_t) offset_meas_range_A * 0xffff)) ||
+ (sum_ranging_range_B > ((int32_t) offset_meas_range_B * 0xffff))) {
+ Status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH;
+ }
+
+ if ((Status == VL53L1_ERROR_NONE) && (offset_meas_range_A > 0)) {
+ IncRounding = offset_meas_range_A / 2;
+ meanDistance_mm = (int16_t)((sum_ranging_range_A + IncRounding)
+ / offset_meas_range_A);
+ offsetA[Repeat] =
+ (int16_t)CalDistanceMilliMeter - meanDistance_mm;
+ }
+
+ if ((Status == VL53L1_ERROR_NONE) && (offset_meas_range_B > 0)) {
+ IncRounding = offset_meas_range_B / 2;
+ meanDistance_mm = (int16_t)((sum_ranging_range_B + IncRounding)
+ / offset_meas_range_B);
+ offsetB[Repeat] =
+ (int16_t)CalDistanceMilliMeter - meanDistance_mm;
+ }
+ Repeat++;
+ }
+
+
+ if ((SmudgeStatus == VL53L1_ERROR_NONE) && (smudge_corr_en == 1))
+ SmudgeStatus = VL53L1_dynamic_xtalk_correction_enable(Dev);
+
+ if (Status == VL53L1_ERROR_NONE) {
+ pdev->per_vcsel_cal_data.short_a_offset_mm = offsetA[0];
+ pdev->per_vcsel_cal_data.short_b_offset_mm = offsetB[0];
+ pdev->per_vcsel_cal_data.medium_a_offset_mm = offsetA[1];
+ pdev->per_vcsel_cal_data.medium_b_offset_mm = offsetB[1];
+ pdev->per_vcsel_cal_data.long_a_offset_mm = offsetA[2];
+ pdev->per_vcsel_cal_data.long_b_offset_mm = offsetB[2];
+ }
+
+ VL53L1_SetPresetMode(Dev, currentMode);
+ VL53L1_SetDistanceMode(Dev, currentDist);
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_api_calibration.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_calibration.c
new file mode 100644
index 000000000000..8d3710017b4d
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_calibration.c
@@ -0,0 +1,2725 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_ipp.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_register_funcs.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_hist_map.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_core.h"
+#include "vl53l1_wait.h"
+#include "vl53l1_api_preset_modes.h"
+#include "vl53l1_silicon_core.h"
+#include "vl53l1_api_core.h"
+#include "vl53l1_api_calibration.h"
+
+#ifdef VL53L1_LOG_ENABLE
+ #include "vl53l1_api_debug.h"
+#endif
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_run_ref_spad_char(
+ VL53L1_DEV Dev,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t comms_buffer[6];
+
+ VL53L1_refspadchar_config_t *prefspadchar = &(pdev->refspadchar);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_enable_powerforce(Dev);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_ref_spad_char_config(
+ Dev,
+ prefspadchar->VL53L1_p_009,
+ prefspadchar->timeout_us,
+ prefspadchar->target_count_rate_mcps,
+ prefspadchar->max_count_rate_limit_mcps,
+ prefspadchar->min_count_rate_limit_mcps,
+ pdev->stat_nvm.osc_measured__fast_osc__frequency);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_run_device_test(
+ Dev,
+ prefspadchar->device_test_mode);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_REF_SPAD_CHAR_RESULT__NUM_ACTUAL_REF_SPADS,
+ comms_buffer,
+ 2);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->dbg_results.ref_spad_char_result__num_actual_ref_spads =
+ comms_buffer[0];
+ pdev->dbg_results.ref_spad_char_result__ref_location =
+ comms_buffer[1];
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_REF_SPAD_MAN__NUM_REQUESTED_REF_SPADS,
+ comms_buffer,
+ 2);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->customer.ref_spad_man__num_requested_ref_spads =
+ comms_buffer[0];
+ pdev->customer.ref_spad_man__ref_location =
+ comms_buffer[1];
+ }
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__SPARE_0_SD1,
+ comms_buffer,
+ 6);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0,
+ comms_buffer,
+ 6);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->customer.global_config__spad_enables_ref_0 =
+ comms_buffer[0];
+ pdev->customer.global_config__spad_enables_ref_1 =
+ comms_buffer[1];
+ pdev->customer.global_config__spad_enables_ref_2 =
+ comms_buffer[2];
+ pdev->customer.global_config__spad_enables_ref_3 =
+ comms_buffer[3];
+ pdev->customer.global_config__spad_enables_ref_4 =
+ comms_buffer[4];
+ pdev->customer.global_config__spad_enables_ref_5 =
+ comms_buffer[5];
+ }
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "run_ref_spad_char():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_REF_SPAD_CHAR);
+#endif
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ switch (pdev->sys_results.result__range_status) {
+
+ case VL53L1_DEVICEERROR_REFSPADCHARNOTENOUGHDPADS:
+ status = VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS;
+ break;
+
+ case VL53L1_DEVICEERROR_REFSPADCHARMORETHANTARGET:
+ status = VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH;
+ break;
+
+ case VL53L1_DEVICEERROR_REFSPADCHARLESSTHANTARGET:
+ status = VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW;
+ break;
+ }
+ }
+
+
+
+
+
+
+ *pcal_status = status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_REF_SPAD_CHAR_NOT_ENOUGH_SPADS,
+ VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_REF_SPAD_CHAR_RATE_TOO_HIGH,
+ VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_REF_SPAD_CHAR_RATE_TOO_LOW,
+ VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW,
+ status);
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_xtalk_extraction(
+ VL53L1_DEV Dev,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+
+
+
+
+
+ VL53L1_xtalkextract_config_t *pX = &(pdev->xtalk_extract_cfg);
+ VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg);
+ VL53L1_xtalk_calibration_results_t *pXC = &(pdev->xtalk_cal);
+
+ uint8_t results_invalid = 0;
+
+ uint8_t i = 0;
+ uint16_t tmp16 = 0;
+
+ uint8_t measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.central_histogram_avg));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->xtalk_results.central_histogram_sum));
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR,
+
+
+ pX->dss_config__target_total_rate_mcps,
+ pX->phasecal_config_timeout_us,
+ pX->mm_config_timeout_us,
+ pX->range_config_timeout_us,
+
+
+ 100);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_xtalk_compensation(Dev);
+
+
+
+
+
+
+ pdev->xtalk_results.max_results = VL53L1_MAX_XTALK_RANGE_RESULTS;
+ pdev->xtalk_results.active_results = pdev->zone_cfg.active_zones+1;
+
+
+
+
+ pdev->xtalk_results.central_histogram__window_start = 0xFF;
+ pdev->xtalk_results.central_histogram__window_end = 0x00;
+
+ pdev->xtalk_results.num_of_samples_status = 0x00;
+ pdev->xtalk_results.zero_samples_status = 0x00;
+ pdev->xtalk_results.max_sigma_status = 0x00;
+
+ for (i = 0; i < pdev->xtalk_results.max_results; i++) {
+ pdev->xtalk_results.VL53L1_p_002[i].no_of_samples = 0;
+ pdev->xtalk_results.VL53L1_p_002[i].signal_total_events_avg = 0;
+ pdev->xtalk_results.VL53L1_p_002[i].signal_total_events_sum = 0;
+ pdev->xtalk_results.VL53L1_p_002[i].rate_per_spad_kcps_sum = 0;
+ pdev->xtalk_results.VL53L1_p_002[i].rate_per_spad_kcps_avg = 0;
+ pdev->xtalk_results.VL53L1_p_002[i].sigma_mm_sum = 0;
+ pdev->xtalk_results.VL53L1_p_002[i].sigma_mm_avg = 0;
+
+
+ pdev->xtalk_results.VL53L1_p_002[i].median_phase_sum = 0;
+ pdev->xtalk_results.VL53L1_p_002[i].median_phase_avg = 0;
+
+
+ }
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status =
+ VL53L1_get_and_avg_xtalk_samples(
+ Dev,
+
+
+ pX->num_of_samples,
+
+
+ measurement_mode,
+
+
+ pX->algo__crosstalk_extract_max_valid_range_mm,
+ pX->algo__crosstalk_extract_min_valid_range_mm,
+ pX->algo__crosstalk_extract_max_valid_rate_kcps,
+
+
+ 0x0,
+
+ 0x4,
+
+ &(pdev->xtalk_results),
+ &(pdev->xtalk_results.central_histogram_sum),
+ &(pdev->xtalk_results.central_histogram_avg));
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ if ((pdev->xtalk_results.VL53L1_p_002[4].no_of_samples == 0) ||
+ (pdev->xtalk_results.VL53L1_p_002[4].sigma_mm_avg >
+ ((uint32_t)pX->algo__crosstalk_extract_max_sigma_mm
+ << 5)))
+ results_invalid = 0x01;
+
+
+
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_xtalk_range_results(
+ &(pdev->xtalk_results),
+ "pdev->xtalk_results",
+ VL53L1_TRACE_MODULE_CORE);
+#endif
+
+ if ((status == VL53L1_ERROR_NONE) && (results_invalid == 0)) {
+
+ status =
+ VL53L1_ipp_xtalk_calibration_process_data(
+ Dev,
+ &(pdev->xtalk_results),
+ &(pdev->xtalk_shapes),
+ &(pdev->xtalk_cal));
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (i = 0; i < VL53L1_BIN_REC_SIZE; i++)
+ pXC->algo__xtalk_cpo_HistoMerge_kcps[i] =
+ pXC->algo__crosstalk_compensation_plane_offset_kcps;
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pXC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pXC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_plane_offset_kcps =
+ pXC->algo__crosstalk_compensation_plane_offset_kcps;
+
+
+ }
+
+
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_xtalk_compensation(Dev);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (i = 0; i < pdev->xtalk_results.max_results; i++) {
+
+
+ if (pdev->xtalk_results.VL53L1_p_002[i].no_of_samples !=
+
+
+ pX->num_of_samples) {
+
+
+ pdev->xtalk_results.num_of_samples_status =
+ pdev->xtalk_results.num_of_samples_status |
+ (1 << i);
+ }
+
+
+ if (pdev->xtalk_results.VL53L1_p_002[i].no_of_samples ==
+ 0x00) {
+ pdev->xtalk_results.zero_samples_status =
+ pdev->xtalk_results.zero_samples_status |
+ (1 << i);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+ tmp16 = pX->algo__crosstalk_extract_max_sigma_mm;
+ if (pdev->xtalk_results.VL53L1_p_002[i].sigma_mm_avg >
+ ((uint32_t)tmp16 << 5)) {
+ pdev->xtalk_results.max_sigma_status =
+ pdev->xtalk_results.max_sigma_status |
+ (1 << i);
+ }
+
+
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (results_invalid > 0) {
+
+
+ if (pdev->xtalk_results.VL53L1_p_002[4].no_of_samples == 0) {
+ status = VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL;
+ } else {
+
+
+
+ if (pdev->xtalk_results.VL53L1_p_002[4].sigma_mm_avg >
+ (((uint32_t)pX->algo__crosstalk_extract_max_sigma_mm)
+ << 5)) {
+ status =
+ VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL;
+ }
+
+
+ }
+ } else {
+
+
+ if (pdev->xtalk_results.zero_samples_status != 0x00) {
+ status = VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT;
+ } else {
+ if (pdev->xtalk_results.max_sigma_status != 0x00) {
+ status =
+ VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT;
+ } else {
+ if (pdev->xtalk_results.num_of_samples_status !=
+ 0x00)
+ status =
+ VL53L1_WARNING_XTALK_MISSING_SAMPLES;
+ }
+ }
+ }
+
+
+
+
+
+
+ pdev->xtalk_results.cal_status = status;
+ *pcal_status = pdev->xtalk_results.cal_status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL,
+ VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL,
+ VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FOR_GRADIENT_WARN,
+ VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FOR_GRADIENT_WARN,
+ VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_XTALK_EXTRACTION_MISSING_SAMPLES_WARN,
+ VL53L1_WARNING_XTALK_MISSING_SAMPLES,
+ status);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "run_xtalk_extraction():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_config(
+ &(pdev->xtalk_cfg),
+ "run_xtalk_extraction():pdev->lldata.xtalk_cfg.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_extract_config(
+ &(pdev->xtalk_extract_cfg),
+ "run_xtalk_extraction():pdev->lldata.xtalk_extract_cfg.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_histogram_bin_data(
+ &(pdev->hist_data),
+ "run_xtalk_extraction():pdev->lldata.hist_data.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_histogram_data(
+ &(pdev->xtalk_shapes),
+ "pdev->lldata.xtalk_shapes.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_range_results(
+ &(pdev->xtalk_results),
+ "run_xtalk_extraction():pdev->lldata.xtalk_results.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_get_and_avg_xtalk_samples(
+ VL53L1_DEV Dev,
+ uint8_t num_of_samples,
+ uint8_t measurement_mode,
+ int16_t xtalk_filter_thresh_max_mm,
+ int16_t xtalk_filter_thresh_min_mm,
+ uint16_t xtalk_max_valid_rate_kcps,
+ uint8_t xtalk_result_id,
+ uint8_t xtalk_histo_id,
+ VL53L1_xtalk_range_results_t *pXR,
+ VL53L1_histogram_bin_data_t *psum_histo,
+ VL53L1_histogram_bin_data_t *pavg_histo)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+#endif
+
+ VL53L1_range_results_t *prs =
+ (VL53L1_range_results_t *) pdev->wArea1;
+
+ VL53L1_range_data_t *prange_data;
+ VL53L1_xtalk_range_data_t *pxtalk_range_data;
+
+ uint8_t i = 0;
+ uint8_t j = 0;
+ uint8_t zone_id = 0;
+ uint8_t final_zone = pdev->zone_cfg.active_zones+1;
+ uint8_t valid_result;
+
+ uint8_t smudge_corr_en = 0;
+
+
+
+
+
+
+ smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled;
+
+ status = VL53L1_dynamic_xtalk_correction_disable(Dev);
+
+
+
+ VL53L1_load_patch(Dev);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+
+ for (i = 0; i <= (final_zone*num_of_samples); i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prs);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE &&
+ pdev->ll_state.rd_device_state !=
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) {
+
+ zone_id = pdev->ll_state.rd_zone_id + xtalk_result_id;
+ prange_data = &(prs->VL53L1_p_002[0]);
+
+
+
+ if (prs->active_results > 1) {
+ for (j = 1;
+ j < prs->active_results; j++) {
+ if (prs->VL53L1_p_002[j].median_range_mm
+ <
+ prange_data->median_range_mm)
+ prange_data =
+ &(prs->VL53L1_p_002[j]);
+
+ }
+ }
+
+ pxtalk_range_data = &(pXR->VL53L1_p_002[zone_id]);
+
+
+
+
+ if ((prs->active_results > 0) &&
+ (prange_data->median_range_mm <
+ xtalk_filter_thresh_max_mm) &&
+ (prange_data->median_range_mm >
+ xtalk_filter_thresh_min_mm) &&
+ (prange_data->VL53L1_p_012 <
+ (uint32_t)(xtalk_max_valid_rate_kcps * 16)))
+ valid_result = 1;
+ else
+ valid_result = 0;
+
+ if (valid_result == 1) {
+
+ pxtalk_range_data->no_of_samples++;
+
+ pxtalk_range_data->rate_per_spad_kcps_sum +=
+ prange_data->VL53L1_p_012;
+
+ pxtalk_range_data->signal_total_events_sum +=
+ prange_data->VL53L1_p_013;
+
+ pxtalk_range_data->sigma_mm_sum +=
+ (uint32_t)prange_data->VL53L1_p_005;
+
+
+
+
+ pxtalk_range_data->median_phase_sum +=
+ (uint32_t)prange_data->VL53L1_p_014;
+
+
+
+
+
+
+
+
+
+
+ }
+
+ if ((valid_result == 1) && (zone_id >= 4)) {
+ status = VL53L1_sum_histogram_data(
+ &(pdev->hist_data),
+ psum_histo);
+
+
+
+
+
+ if (prange_data->VL53L1_p_015 <
+ pXR->central_histogram__window_start)
+ pXR->central_histogram__window_start =
+ prange_data->VL53L1_p_015;
+
+
+
+ if (prange_data->VL53L1_p_016 >
+ pXR->central_histogram__window_end)
+ pXR->central_histogram__window_end =
+ prange_data->VL53L1_p_016;
+
+ }
+
+ }
+
+
+
+
+
+
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE) {
+ VL53L1_print_range_results(
+ &(pres->range_results),
+ "pres->range_results.",
+ VL53L1_TRACE_MODULE_CORE);
+ }
+#endif
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+
+
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+ VL53L1_unload_patch(Dev);
+
+
+
+
+ for (i = 0; i < (pdev->zone_cfg.active_zones+1); i++) {
+
+ pxtalk_range_data = &(pXR->VL53L1_p_002[i+xtalk_result_id]);
+
+ if (pxtalk_range_data->no_of_samples > 0) {
+ pxtalk_range_data->rate_per_spad_kcps_avg =
+ pxtalk_range_data->rate_per_spad_kcps_sum /
+ (uint32_t)pxtalk_range_data->no_of_samples;
+
+ pxtalk_range_data->signal_total_events_avg =
+ pxtalk_range_data->signal_total_events_sum /
+ (int32_t)pxtalk_range_data->no_of_samples;
+
+ pxtalk_range_data->sigma_mm_avg =
+ pxtalk_range_data->sigma_mm_sum /
+ (uint32_t)pxtalk_range_data->no_of_samples;
+
+
+
+
+ pxtalk_range_data->median_phase_avg =
+ pxtalk_range_data->median_phase_sum /
+ (uint32_t)pxtalk_range_data->no_of_samples;
+
+
+
+
+ } else {
+ pxtalk_range_data->rate_per_spad_kcps_avg =
+ pxtalk_range_data->rate_per_spad_kcps_sum;
+ pxtalk_range_data->signal_total_events_avg =
+ pxtalk_range_data->signal_total_events_sum;
+ pxtalk_range_data->sigma_mm_avg =
+ pxtalk_range_data->sigma_mm_sum;
+
+
+
+
+ pxtalk_range_data->median_phase_avg =
+ pxtalk_range_data->median_phase_sum;
+
+
+
+ }
+ }
+
+
+
+
+ memcpy(pavg_histo, &(pdev->hist_data),
+ sizeof(VL53L1_histogram_bin_data_t));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pxtalk_range_data = &(pXR->VL53L1_p_002[xtalk_histo_id]);
+
+ status = VL53L1_avg_histogram_data(
+ pxtalk_range_data->no_of_samples,
+ psum_histo,
+ pavg_histo);
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ if (smudge_corr_en == 1)
+ status = VL53L1_dynamic_xtalk_correction_enable(Dev);
+ }
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_run_offset_calibration(
+ VL53L1_DEV Dev,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_DevicePresetModes device_preset_modes[
+ VL53L1_MAX_OFFSET_RANGE_RESULTS];
+
+ VL53L1_range_results_t *prange_results =
+ (VL53L1_range_results_t *) pdev->wArea1;
+
+ VL53L1_range_data_t *pRData = NULL;
+ VL53L1_offset_range_data_t *pfs = NULL;
+ VL53L1_general_config_t *pG = &(pdev->gen_cfg);
+ VL53L1_additional_offset_cal_data_t *pAO = &(pdev->add_off_cal_data);
+
+ uint8_t i = 0;
+ uint8_t m = 0;
+ uint8_t measurement_mode =
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ uint16_t manual_effective_spads =
+ pG->dss_config__manual_effective_spads_select;
+
+ uint8_t num_of_samples[VL53L1_MAX_OFFSET_RANGE_RESULTS];
+
+ uint8_t smudge_corr_en = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ switch (pdev->offset_calibration_mode) {
+
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM:
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY:
+ device_preset_modes[0] =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING;
+ device_preset_modes[1] =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL;
+ device_preset_modes[2] =
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL;
+ break;
+
+ default:
+ device_preset_modes[0] =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING;
+ device_preset_modes[1] =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL;
+ device_preset_modes[2] =
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL;
+ break;
+ }
+
+
+
+
+
+ num_of_samples[0] = pdev->offsetcal_cfg.pre_num_of_samples;
+ num_of_samples[1] = pdev->offsetcal_cfg.mm1_num_of_samples;
+ num_of_samples[2] = pdev->offsetcal_cfg.mm2_num_of_samples;
+
+
+
+
+
+
+ switch (pdev->offset_calibration_mode) {
+
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY:
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY:
+
+
+ pdev->offset_results.active_results = 1;
+
+ break;
+
+ default:
+
+ pdev->customer.mm_config__inner_offset_mm = 0;
+ pdev->customer.mm_config__outer_offset_mm = 0;
+ pdev->offset_results.active_results =
+ VL53L1_MAX_OFFSET_RANGE_RESULTS;
+
+ break;
+ }
+
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+
+
+
+
+ pdev->offset_results.max_results = VL53L1_MAX_OFFSET_RANGE_RESULTS;
+ pdev->offset_results.cal_distance_mm = cal_distance_mm;
+ pdev->offset_results.cal_reflectance_pc = cal_reflectance_pc;
+
+ for (m = 0; m < VL53L1_MAX_OFFSET_RANGE_RESULTS; m++) {
+
+ pfs = &(pdev->offset_results.VL53L1_p_002[m]);
+ pfs->preset_mode = 0;
+ pfs->no_of_samples = 0;
+ pfs->effective_spads = 0;
+ pfs->peak_rate_mcps = 0;
+ pfs->VL53L1_p_005 = 0;
+ pfs->median_range_mm = 0;
+ }
+
+
+
+
+
+
+ smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled;
+
+ status = VL53L1_dynamic_xtalk_correction_disable(Dev);
+
+
+
+
+ for (m = 0; m < pdev->offset_results.active_results; m++) {
+
+ pfs = &(pdev->offset_results.VL53L1_p_002[m]);
+
+ pfs->preset_mode = device_preset_modes[m];
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ device_preset_modes[m],
+
+
+ pdev->offsetcal_cfg.dss_config__target_total_rate_mcps,
+ pdev->offsetcal_cfg.phasecal_config_timeout_us,
+ pdev->offsetcal_cfg.mm_config_timeout_us,
+ pdev->offsetcal_cfg.range_config_timeout_us,
+
+
+ 100);
+
+ pG->dss_config__manual_effective_spads_select =
+ manual_effective_spads;
+
+
+
+ VL53L1_load_patch(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+ for (i = 0; i <= (num_of_samples[m]+2); i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prange_results);
+
+
+
+
+
+
+
+
+
+ pRData = &(prange_results->VL53L1_p_002[0]);
+
+ if ((prange_results->active_results > 0 &&
+ prange_results->stream_count > 1) &&
+ (pRData->range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE)) {
+
+ pfs->no_of_samples++;
+ pfs->effective_spads +=
+ (uint32_t)pRData->VL53L1_p_006;
+ pfs->peak_rate_mcps +=
+ (uint32_t)pRData->peak_signal_count_rate_mcps;
+ pfs->VL53L1_p_005 +=
+ (uint32_t)pRData->VL53L1_p_005;
+ pfs->median_range_mm +=
+ (int32_t)pRData->median_range_mm;
+
+ pfs->dss_config__roi_mode_control =
+ pG->dss_config__roi_mode_control;
+ pfs->dss_config__manual_effective_spads_select =
+ pG->dss_config__manual_effective_spads_select;
+
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(Dev, 1000);
+ VL53L1_unload_patch(Dev);
+
+
+
+ if (pfs->no_of_samples > 0) {
+
+ pfs->effective_spads += (pfs->no_of_samples/2);
+ pfs->effective_spads /= pfs->no_of_samples;
+
+ pfs->peak_rate_mcps += (pfs->no_of_samples/2);
+ pfs->peak_rate_mcps /= pfs->no_of_samples;
+
+ pfs->VL53L1_p_005 += (pfs->no_of_samples/2);
+ pfs->VL53L1_p_005 /= pfs->no_of_samples;
+
+ pfs->median_range_mm += (pfs->no_of_samples/2);
+ pfs->median_range_mm /= pfs->no_of_samples;
+
+ pfs->range_mm_offset = (int32_t)cal_distance_mm;
+ pfs->range_mm_offset -= pfs->median_range_mm;
+
+
+
+ if (pfs->preset_mode ==
+ VL53L1_DEVICEPRESETMODE_STANDARD_RANGING)
+ manual_effective_spads =
+ (uint16_t)pfs->effective_spads;
+ }
+ }
+
+
+
+
+ switch (pdev->offset_calibration_mode) {
+
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY:
+ case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY:
+
+
+
+ pdev->customer.mm_config__inner_offset_mm +=
+ (int16_t)pdev->offset_results.VL53L1_p_002[0].range_mm_offset;
+ pdev->customer.mm_config__outer_offset_mm +=
+ (int16_t)pdev->offset_results.VL53L1_p_002[0].range_mm_offset;
+ break;
+
+ default:
+
+
+ pdev->customer.mm_config__inner_offset_mm =
+ (int16_t)pdev->offset_results.VL53L1_p_002[1].range_mm_offset;
+ pdev->customer.mm_config__outer_offset_mm =
+ (int16_t)pdev->offset_results.VL53L1_p_002[2].range_mm_offset;
+ pdev->customer.algo__part_to_part_range_offset_mm = 0;
+
+
+
+
+
+ pAO->result__mm_inner_actual_effective_spads =
+ (uint16_t)pdev->offset_results.VL53L1_p_002[1].effective_spads;
+ pAO->result__mm_outer_actual_effective_spads =
+ (uint16_t)pdev->offset_results.VL53L1_p_002[2].effective_spads;
+
+ pAO->result__mm_inner_peak_signal_count_rtn_mcps =
+ (uint16_t)pdev->offset_results.VL53L1_p_002[1].peak_rate_mcps;
+ pAO->result__mm_outer_peak_signal_count_rtn_mcps =
+ (uint16_t)pdev->offset_results.VL53L1_p_002[2].peak_rate_mcps;
+
+ break;
+ }
+
+
+
+
+
+
+
+ pdev->cust_dmax_cal.ref__actual_effective_spads =
+ (uint16_t)pdev->offset_results.VL53L1_p_002[0].effective_spads;
+ pdev->cust_dmax_cal.ref__peak_signal_count_rate_mcps =
+ (uint16_t)pdev->offset_results.VL53L1_p_002[0].peak_rate_mcps;
+
+
+
+ pdev->cust_dmax_cal.ref__distance_mm = cal_distance_mm * 16;
+
+ pdev->cust_dmax_cal.ref_reflectance_pc = cal_reflectance_pc;
+ pdev->cust_dmax_cal.coverglass_transmission = 0x0100;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ if (smudge_corr_en == 1)
+ status = VL53L1_dynamic_xtalk_correction_enable(Dev);
+ }
+
+
+
+
+
+
+
+
+ for (m = 0; m < pdev->offset_results.active_results; m++) {
+
+ pfs = &(pdev->offset_results.VL53L1_p_002[m]);
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->offset_results.cal_report = m;
+
+ if (pfs->no_of_samples < num_of_samples[m])
+ status =
+ VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES;
+
+
+
+
+
+
+ if (m == 0 && pfs->VL53L1_p_005 >
+ ((uint32_t)VL53L1_OFFSET_CAL_MAX_SIGMA_MM << 5))
+ status =
+ VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH;
+
+ if (pfs->peak_rate_mcps >
+ VL53L1_OFFSET_CAL_MAX_PRE_PEAK_RATE_MCPS)
+ status =
+ VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH;
+
+ if (pfs->dss_config__manual_effective_spads_select <
+ VL53L1_OFFSET_CAL_MIN_EFFECTIVE_SPADS)
+ status =
+ VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW;
+
+ if (pfs->dss_config__manual_effective_spads_select == 0)
+ status =
+ VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL;
+
+ if (pfs->no_of_samples == 0)
+ status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL;
+ }
+ }
+
+
+
+
+
+
+ pdev->offset_results.cal_status = status;
+ *pcal_status = pdev->offset_results.cal_status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_MISSING_SAMPLES,
+ VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_SIGMA_TOO_HIGH,
+ VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_RATE_TOO_HIGH,
+ VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_OFFSET_CAL_SPAD_COUNT_TOO_LOW,
+ VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW,
+ status);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "run_offset_calibration():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->fmt_dmax_cal),
+ "run_offset_calibration():pdev->lldata.fmt_dmax_cal.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->cust_dmax_cal),
+ "run_offset_calibration():pdev->lldata.cust_dmax_cal.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_additional_offset_cal_data(
+ &(pdev->add_off_cal_data),
+ "run_offset_calibration():pdev->lldata.add_off_cal_data.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+ VL53L1_print_offset_range_results(
+ &(pdev->offset_results),
+ "run_offset_calibration():pdev->lldata.offset_results.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_phasecal_average(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode,
+ uint8_t phasecal_result__vcsel_start,
+ uint16_t phasecal_num_of_samples,
+ VL53L1_range_results_t *prange_results,
+ uint16_t *pphasecal_result__reference_phase,
+ uint16_t *pzero_distance_phase)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint16_t i = 0;
+ uint16_t m = 0;
+ uint32_t samples = 0;
+
+ uint32_t period = 0;
+ uint32_t VL53L1_p_017 = 0;
+ uint32_t phasecal_result__reference_phase = 0;
+ uint32_t zero_distance_phase = 0;
+
+
+
+ VL53L1_load_patch(Dev);
+
+ for (m = 0; m < phasecal_num_of_samples; m++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+ for (i = 0; i <= 1; i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prange_results);
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(Dev, 1000);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ samples++;
+
+
+
+
+
+
+
+ period = 2048 *
+ (uint32_t)VL53L1_decode_vcsel_period(
+ pdev->hist_data.VL53L1_p_009);
+
+ VL53L1_p_017 = period;
+ VL53L1_p_017 += (uint32_t)(
+ pdev->hist_data.phasecal_result__reference_phase);
+ VL53L1_p_017 +=
+ (2048 *
+ (uint32_t)phasecal_result__vcsel_start);
+ VL53L1_p_017 -= (2048 *
+ (uint32_t)pdev->hist_data.cal_config__vcsel_start);
+
+ VL53L1_p_017 = VL53L1_p_017 % period;
+
+ phasecal_result__reference_phase += (uint32_t)(
+ pdev->hist_data.phasecal_result__reference_phase);
+
+ zero_distance_phase += (uint32_t)VL53L1_p_017;
+ }
+ }
+ VL53L1_unload_patch(Dev);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE && samples > 0) {
+
+ phasecal_result__reference_phase += (samples >> 1);
+ phasecal_result__reference_phase /= samples;
+
+ zero_distance_phase += (samples >> 1);
+ zero_distance_phase /= samples;
+
+ *pphasecal_result__reference_phase =
+ (uint16_t)phasecal_result__reference_phase;
+ *pzero_distance_phase =
+ (uint16_t)zero_distance_phase;
+ }
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_zone_calibration(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ VL53L1_DeviceZonePreset zone_preset,
+ VL53L1_zone_config_t *pzone_cfg,
+ int16_t cal_distance_mm,
+ uint16_t cal_reflectance_pc,
+ VL53L1_Error *pcal_status)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_range_results_t *pRR =
+ (VL53L1_range_results_t *) pdev->wArea1;
+ VL53L1_range_data_t *prange_data = NULL;
+ VL53L1_zone_calibration_data_t *pzone_data = NULL;
+
+ uint16_t i = 0;
+ uint16_t m = 0;
+
+ uint8_t z = 0;
+ uint8_t measurement_mode =
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+ VL53L1_OffsetCorrectionMode offset_cor_mode =
+ VL53L1_OFFSETCORRECTIONMODE__NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ device_preset_mode,
+
+
+ pdev->zonecal_cfg.dss_config__target_total_rate_mcps,
+ pdev->zonecal_cfg.phasecal_config_timeout_us,
+ pdev->zonecal_cfg.mm_config_timeout_us,
+ pdev->zonecal_cfg.range_config_timeout_us,
+
+
+ 100);
+
+
+
+
+ if (zone_preset == VL53L1_DEVICEZONEPRESET_CUSTOM) {
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_zone_config(
+ Dev,
+ pzone_cfg);
+
+ } else if (zone_preset != VL53L1_DEVICEZONEPRESET_NONE) {
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_zone_preset(
+ Dev,
+ zone_preset);
+ }
+
+
+
+
+
+
+ pres->zone_cal.preset_mode = device_preset_mode;
+ pres->zone_cal.zone_preset = zone_preset;
+
+
+ pres->zone_cal.cal_distance_mm = cal_distance_mm * 16;
+ pres->zone_cal.cal_reflectance_pc = cal_reflectance_pc;
+ pres->zone_cal.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_cal.active_zones = pdev->zone_cfg.active_zones + 1;
+
+ for (i = 0; i < VL53L1_MAX_USER_ZONES; i++) {
+ pres->zone_cal.VL53L1_p_002[i].no_of_samples = 0;
+ pres->zone_cal.VL53L1_p_002[i].effective_spads = 0;
+ pres->zone_cal.VL53L1_p_002[i].peak_rate_mcps = 0;
+ pres->zone_cal.VL53L1_p_002[i].VL53L1_p_014 = 0;
+ pres->zone_cal.VL53L1_p_002[i].VL53L1_p_005 = 0;
+ pres->zone_cal.VL53L1_p_002[i].median_range_mm = 0;
+ pres->zone_cal.VL53L1_p_002[i].range_mm_offset = 0;
+ }
+
+ pres->zone_cal.phasecal_result__reference_phase = 0;
+ pres->zone_cal.zero_distance_phase = 0;
+
+
+
+
+
+
+
+ status =
+ VL53L1_get_offset_correction_mode(
+ Dev,
+ &offset_cor_mode);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_offset_correction_mode(
+ Dev,
+ VL53L1_OFFSETCORRECTIONMODE__NONE);
+
+
+
+ VL53L1_load_patch(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+
+
+
+
+
+
+ m = (pdev->zonecal_cfg.zone_num_of_samples + 2) *
+ (uint16_t)pres->zone_cal.active_zones;
+
+
+
+ for (i = 0; i <= m; i++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_range_completion(Dev);
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_device_results(
+ Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ pRR);
+
+
+
+
+
+
+
+
+
+ prange_data = &(pRR->VL53L1_p_002[0]);
+
+ if (pRR->active_results > 0 &&
+ i > (uint16_t)pres->zone_cal.active_zones) {
+
+ if (prange_data->range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE) {
+
+ pres->zone_cal.phasecal_result__reference_phase
+ =
+ pdev->hist_data.phasecal_result__reference_phase
+ ;
+ pres->zone_cal.zero_distance_phase =
+ pdev->hist_data.zero_distance_phase;
+
+ pzone_data =
+ &(pres->zone_cal.VL53L1_p_002[pRR->zone_id]);
+ pzone_data->no_of_samples++;
+ pzone_data->effective_spads +=
+ (uint32_t)prange_data->VL53L1_p_006;
+ pzone_data->peak_rate_mcps += (uint32_t)(
+ prange_data->peak_signal_count_rate_mcps);
+ pzone_data->VL53L1_p_014 +=
+ (uint32_t)prange_data->VL53L1_p_014;
+ pzone_data->VL53L1_p_005 +=
+ (uint32_t)prange_data->VL53L1_p_005;
+ pzone_data->median_range_mm +=
+ (int32_t)prange_data->median_range_mm;
+
+ }
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_wait_for_firmware_ready(Dev);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev,
+ measurement_mode);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_stop_range(Dev);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(Dev, 1000);
+ VL53L1_unload_patch(Dev);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_run_phasecal_average(
+ Dev,
+ measurement_mode,
+ pdev->hist_data.phasecal_result__vcsel_start,
+
+
+ pdev->zonecal_cfg.phasecal_num_of_samples,
+
+
+ pRR,
+ &(pres->zone_cal.phasecal_result__reference_phase),
+ &(pres->zone_cal.zero_distance_phase));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_offset_correction_mode(
+ Dev,
+ offset_cor_mode);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (z = 0; z < pres->zone_cal.active_zones; z++) {
+
+ pzone_data = &(pres->zone_cal.VL53L1_p_002[z]);
+
+
+
+ if (pzone_data->no_of_samples > 0) {
+
+ pzone_data->effective_spads +=
+ (pzone_data->no_of_samples/2);
+ pzone_data->effective_spads /=
+ pzone_data->no_of_samples;
+
+ pzone_data->peak_rate_mcps +=
+ (pzone_data->no_of_samples/2);
+ pzone_data->peak_rate_mcps /=
+ pzone_data->no_of_samples;
+
+ pzone_data->VL53L1_p_014 +=
+ (pzone_data->no_of_samples/2);
+ pzone_data->VL53L1_p_014 /=
+ pzone_data->no_of_samples;
+
+ pzone_data->VL53L1_p_005 +=
+ (pzone_data->no_of_samples/2);
+ pzone_data->VL53L1_p_005 /=
+ pzone_data->no_of_samples;
+
+
+
+
+
+
+
+ pzone_data->median_range_mm =
+ VL53L1_range_maths(
+ pdev->stat_nvm.osc_measured__fast_osc__frequency
+ , (uint16_t)pzone_data->VL53L1_p_014,
+ pres->zone_cal.zero_distance_phase,
+ 2,
+
+ 0x0800,
+
+ 0);
+
+
+ pzone_data->range_mm_offset =
+ ((int32_t)cal_distance_mm) * 4;
+ pzone_data->range_mm_offset -=
+ pzone_data->median_range_mm;
+
+
+
+ if (pzone_data->no_of_samples <
+ pdev->zonecal_cfg.zone_num_of_samples)
+ status =
+ VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES;
+
+
+
+ if (pzone_data->VL53L1_p_005 >
+ ((uint32_t)VL53L1_ZONE_CAL_MAX_SIGMA_MM
+ << 5))
+ status =
+ VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH;
+
+ if (pzone_data->peak_rate_mcps >
+ VL53L1_ZONE_CAL_MAX_PRE_PEAK_RATE_MCPS)
+ status =
+ VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH;
+
+ } else {
+ status = VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL;
+ }
+ }
+ }
+
+
+
+
+
+
+ pres->zone_cal.cal_status = status;
+ *pcal_status = pres->zone_cal.cal_status;
+
+
+
+
+ IGNORE_STATUS(
+ IGNORE_ZONE_CAL_MISSING_SAMPLES,
+ VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_ZONE_CAL_SIGMA_TOO_HIGH,
+ VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH,
+ status);
+
+ IGNORE_STATUS(
+ IGNORE_ZONE_CAL_RATE_TOO_HIGH,
+ VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH,
+ status);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_zone_calibration_results(
+ &(pres->zone_cal),
+ "run_zone_calibration():pdev->llresults.zone_cal.",
+ VL53L1_TRACE_MODULE_OFFSET_DATA);
+
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_spad_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode,
+ VL53L1_DeviceSscArray array_select,
+ uint32_t ssc_config_timeout_us,
+ VL53L1_spad_rate_data_t *pspad_rate_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_powerforce(Dev);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->ssc_cfg.array_select = array_select;
+ pdev->ssc_cfg.timeout_us = ssc_config_timeout_us;
+ status =
+ VL53L1_set_ssc_config(
+ Dev,
+ &(pdev->ssc_cfg),
+ pdev->stat_nvm.osc_measured__fast_osc__frequency);
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_run_device_test(
+ Dev,
+ device_test_mode);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_spad_rate_data(
+ Dev,
+ pspad_rate_data);
+
+ if (device_test_mode == VL53L1_DEVICETESTMODE_LCR_VCSEL_ON)
+ pspad_rate_data->fractional_bits = 7;
+ else
+ pspad_rate_data->fractional_bits = 15;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_powerforce(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ VL53L1_print_spad_rate_data(
+ pspad_rate_data,
+ "run_spad_rate_map():",
+ VL53L1_TRACE_MODULE_SPAD_RATE_MAP);
+ VL53L1_print_spad_rate_map(
+ pspad_rate_data,
+ "run_spad_rate_map():",
+ VL53L1_TRACE_MODULE_SPAD_RATE_MAP);
+ }
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_device_test(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceTestMode device_test_mode)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t comms_buffer[2];
+ uint8_t gpio_hv_mux__ctrl = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_RdByte(
+ Dev,
+ VL53L1_GPIO_HV_MUX__CTRL,
+ &gpio_hv_mux__ctrl);
+
+ if (status == VL53L1_ERROR_NONE)
+ pdev->stat_cfg.gpio_hv_mux__ctrl = gpio_hv_mux__ctrl;
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_start_test(
+ Dev,
+ device_test_mode);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_test_completion(Dev);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__RANGE_STATUS,
+ comms_buffer,
+ 2);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->sys_results.result__range_status = comms_buffer[0];
+ pdev->sys_results.result__report_status = comms_buffer[1];
+ }
+
+
+
+
+ pdev->sys_results.result__range_status &=
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK;
+
+ if (status == VL53L1_ERROR_NONE) {
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ " Device Test Complete:\n\t%-32s = %3u\n\t%-32s = %3u\n",
+ "result__range_status",
+ pdev->sys_results.result__range_status,
+ "result__report_status",
+ pdev->sys_results.result__report_status);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_clear_interrupt(Dev);
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_start_test(
+ Dev,
+ 0x00);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_hist_xtalk_extract_data_init(
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data)
+{
+
+
+
+
+
+ int32_t lb = 0;
+
+ pxtalk_data->sample_count = 0U;
+ pxtalk_data->pll_period_mm = 0U;
+ pxtalk_data->peak_duration_us_sum = 0U;
+ pxtalk_data->effective_spad_count_sum = 0U;
+ pxtalk_data->zero_distance_phase_sum = 0U;
+ pxtalk_data->zero_distance_phase_avg = 0U;
+ pxtalk_data->event_scaler_sum = 0U;
+ pxtalk_data->event_scaler_avg = 4096U;
+ pxtalk_data->signal_events_sum = 0;
+ pxtalk_data->xtalk_rate_kcps_per_spad = 0U;
+ pxtalk_data->VL53L1_p_015 = 0U;
+ pxtalk_data->VL53L1_p_016 = 0U;
+ pxtalk_data->target_start = 0U;
+
+ for (lb = 0; lb < VL53L1_XTALK_HISTO_BINS; lb++)
+ pxtalk_data->bin_data_sums[lb] = 0;
+
+}
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_update(
+ int16_t target_distance_mm,
+ uint16_t target_width_oversize,
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status =
+ VL53L1_hist_xtalk_extract_calc_window(
+ target_distance_mm,
+ target_width_oversize,
+ phist_bins,
+ pxtalk_data);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_hist_xtalk_extract_calc_event_sums(
+ phist_bins,
+ pxtalk_data);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_fini(
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data,
+ VL53L1_xtalk_calibration_results_t *pxtalk_cal,
+ VL53L1_xtalk_histogram_shape_t *pxtalk_shape)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_xtalk_calibration_results_t *pX = pxtalk_cal;
+
+ LOG_FUNCTION_START("");
+
+ if (pxtalk_data->sample_count > 0) {
+
+
+
+ pxtalk_data->event_scaler_avg = pxtalk_data->event_scaler_sum;
+ pxtalk_data->event_scaler_avg +=
+ (pxtalk_data->sample_count >> 1);
+ pxtalk_data->event_scaler_avg /= pxtalk_data->sample_count;
+
+
+
+
+
+
+ status =
+ VL53L1_hist_xtalk_extract_calc_rate_per_spad(
+ pxtalk_data);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ pxtalk_data->zero_distance_phase_avg =
+ pxtalk_data->zero_distance_phase_sum;
+ pxtalk_data->zero_distance_phase_avg +=
+ (pxtalk_data->sample_count >> 1);
+ pxtalk_data->zero_distance_phase_avg /=
+ pxtalk_data->sample_count;
+
+
+
+ status =
+ VL53L1_hist_xtalk_extract_calc_shape(
+ pxtalk_data,
+ pxtalk_shape);
+
+
+
+
+
+
+
+
+
+
+
+ pxtalk_shape->phasecal_result__vcsel_start =
+ phist_bins->phasecal_result__vcsel_start;
+ pxtalk_shape->cal_config__vcsel_start =
+ phist_bins->cal_config__vcsel_start;
+ pxtalk_shape->vcsel_width =
+ phist_bins->vcsel_width;
+ pxtalk_shape->VL53L1_p_019 =
+ phist_bins->VL53L1_p_019;
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ pX->algo__crosstalk_compensation_plane_offset_kcps =
+ pxtalk_data->xtalk_rate_kcps_per_spad;
+ pX->algo__crosstalk_compensation_x_plane_gradient_kcps
+ = 0U;
+ pX->algo__crosstalk_compensation_y_plane_gradient_kcps
+ = 0U;
+
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_run_hist_xtalk_extraction(
+ VL53L1_DEV Dev,
+ int16_t cal_distance_mm,
+ VL53L1_Error *pcal_status)
+{
+ #define OVERSIZE 4
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_xtalkextract_config_t *pX = &(pdev->xtalk_extract_cfg);
+ VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg);
+ VL53L1_xtalk_calibration_results_t *pXC = &(pdev->xtalk_cal);
+ uint8_t smudge_corr_en = 0;
+ uint8_t i = 0;
+ int8_t k = 0;
+ uint8_t nbloops;
+ int32_t initMergeSize = 0;
+ int32_t MergeEnabled = 0;
+ uint32_t deltaXtalk;
+ uint32_t stepXtalk;
+ uint32_t XtalkMin;
+ uint32_t XtalkMax;
+ uint8_t measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ int8_t MaxId;
+ uint8_t histo_merge_nb;
+ uint8_t wait_for_accumulation;
+ VL53L1_range_results_t *prange_results =
+ (VL53L1_range_results_t *) pdev->wArea1;
+ uint8_t Very1stRange = 0;
+
+ LOG_FUNCTION_START("");
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_set_preset_mode(
+ Dev,
+ VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE,
+ pX->dss_config__target_total_rate_mcps,
+ pX->phasecal_config_timeout_us,
+ pX->mm_config_timeout_us,
+ pX->range_config_timeout_us,
+ 100);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ //if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_xtalk_compensation(Dev);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled;
+
+ //if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_dynamic_xtalk_correction_disable(Dev);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ VL53L1_load_patch(Dev);
+
+ VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE,
+ &initMergeSize);
+ VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE,
+ &MergeEnabled);
+ memset(&pdev->xtalk_cal, 0, sizeof(pdev->xtalk_cal));
+
+ //if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_and_start_range(
+ Dev, measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ MaxId = VL53L1_BIN_REC_SIZE - 1;
+ nbloops = (MergeEnabled == 0 ? 1 : 2);
+ for (k = 0; k < nbloops; k++) {
+ VL53L1_hist_xtalk_extract_data_init(
+ &(pdev->xtalk_extract));
+ VL53L1_set_tuning_parm(Dev,
+ VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE,
+ k * MaxId + 1);
+ for (i = 0; i <= pX->num_of_samples; i++) {
+ //if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_range_completion(Dev);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ //if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_get_device_results(Dev,
+ VL53L1_DEVICERESULTSLEVEL_FULL,
+ prange_results);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ Very1stRange =
+ (pdev->ll_state.rd_device_state ==
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC);
+ VL53L1_compute_histo_merge_nb(Dev, &histo_merge_nb);
+ wait_for_accumulation = ((k != 0) &&
+ (status == VL53L1_ERROR_NONE) &&
+ (histo_merge_nb < VL53L1_BIN_REC_SIZE));
+
+ if (wait_for_accumulation)
+ i = 0;
+ else {
+ if ((status == VL53L1_ERROR_NONE) &&
+ (!Very1stRange)) {
+ status =
+ VL53L1_hist_xtalk_extract_update(
+ cal_distance_mm,
+ OVERSIZE,
+ &(pdev->hist_data),
+ &(pdev->xtalk_extract));
+ }
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+ }
+
+ //if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_firmware_ready(Dev);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ //if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_clear_interrupt_and_enable_next_range(
+ Dev, measurement_mode);
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+
+ //if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_hist_xtalk_extract_fini(
+ &(pdev->hist_data),
+ &(pdev->xtalk_extract),
+ &(pdev->xtalk_cal),
+ &(pdev->xtalk_shapes.xtalk_shape));
+ if (status != VL53L1_ERROR_NONE)
+ goto LOOPOUT;
+ pXC->algo__xtalk_cpo_HistoMerge_kcps[k * MaxId] =
+ pXC->algo__crosstalk_compensation_plane_offset_kcps;
+ }
+ }
+
+LOOPOUT:
+
+ status = VL53L1_stop_range(Dev);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE,
+ initMergeSize);
+ }
+ status = VL53L1_unload_patch(Dev);
+
+ if (status != VL53L1_ERROR_NONE)
+ status = VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL;
+ else if ((MergeEnabled == 1) && (MaxId > 0)) {
+ XtalkMin = pXC->algo__xtalk_cpo_HistoMerge_kcps[0];
+ XtalkMax = pXC->algo__xtalk_cpo_HistoMerge_kcps[MaxId];
+ pXC->algo__crosstalk_compensation_plane_offset_kcps =
+ XtalkMin;
+ if (XtalkMax >= XtalkMin) {
+ deltaXtalk = XtalkMax - XtalkMin;
+ stepXtalk = deltaXtalk / MaxId;
+ for (k = 1; k < MaxId; k++)
+ pXC->algo__xtalk_cpo_HistoMerge_kcps[k] =
+ XtalkMin + stepXtalk * k;
+ } else
+ status =
+ VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL;
+ }
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pXC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pXC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_plane_offset_kcps =
+ pXC->algo__crosstalk_compensation_plane_offset_kcps;
+ }
+ pdev->xtalk_results.cal_status = status;
+ *pcal_status = pdev->xtalk_results.cal_status;
+
+ status = VL53L1_enable_xtalk_compensation(Dev);
+ if (smudge_corr_en == 1)
+ status = VL53L1_dynamic_xtalk_correction_enable(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "run_xtalk_extraction():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_config(
+ &(pdev->xtalk_cfg),
+ "run_xtalk_extraction():pdev->lldata.xtalk_cfg.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+
+ VL53L1_print_xtalk_histogram_data(
+ &(pdev->xtalk_shapes),
+ "pdev->lldata.xtalk_shapes.",
+ VL53L1_TRACE_MODULE_XTALK_DATA);
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_api_core.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_core.c
new file mode 100644
index 000000000000..9cf12aca1705
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_core.c
@@ -0,0 +1,7798 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_ipp.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_register_funcs.h"
+#include "vl53l1_hist_map.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_nvm_map.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm.h"
+#include "vl53l1_core.h"
+#include "vl53l1_wait.h"
+#include "vl53l1_zone_presets.h"
+#include "vl53l1_api_preset_modes.h"
+#include "vl53l1_silicon_core.h"
+#include "vl53l1_api_core.h"
+#include "vl53l1_tuning_parm_defaults.h"
+
+#ifdef VL53L1_LOG_ENABLE
+#include "vl53l1_api_debug.h"
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+#define VL53L1_MAX_I2C_XFER_SIZE 256
+
+static VL53L1_Error select_offset_per_vcsel(VL53L1_LLDriverData_t *pdev,
+ int16_t *poffset) {
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ int16_t tA, tB;
+
+ switch (pdev->preset_mode) {
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE:
+ tA = pdev->per_vcsel_cal_data.short_a_offset_mm;
+ tB = pdev->per_vcsel_cal_data.short_b_offset_mm;
+ break;
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE:
+ tA = pdev->per_vcsel_cal_data.medium_a_offset_mm;
+ tB = pdev->per_vcsel_cal_data.medium_b_offset_mm;
+ break;
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE:
+ tA = pdev->per_vcsel_cal_data.long_a_offset_mm;
+ tB = pdev->per_vcsel_cal_data.long_b_offset_mm;
+ break;
+ default:
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ *poffset = 0;
+ break;
+ }
+
+ if (status == VL53L1_ERROR_NONE)
+ *poffset =
+ ((pdev->ll_state.cfg_internal_stream_count) & 0x01) ? tA : tB;
+
+ return status;
+}
+
+VL53L1_Error VL53L1_load_patch(
+ VL53L1_DEV Dev) {
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ int32_t patch_tuning = 0;
+ uint8_t comms_buffer[256];
+ uint32_t patch_power;
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(Dev,
+ VL53L1_FIRMWARE__ENABLE, 0x00);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_enable_powerforce(Dev);
+
+ VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_PHASECAL_PATCH_POWER,
+ &patch_tuning);
+
+ switch (patch_tuning) {
+ case 0:
+ patch_power = 0x00;
+ break;
+ case 1:
+ patch_power = 0x10;
+ break;
+ case 2:
+ patch_power = 0x20;
+ break;
+ case 3:
+ patch_power = 0x40;
+ break;
+ default:
+ patch_power = 0x00;
+ }
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+ comms_buffer[0] = 0x29;
+ comms_buffer[1] = 0xC9;
+ comms_buffer[2] = 0x0E;
+ comms_buffer[3] = 0x40;
+ comms_buffer[4] = 0x28;
+ comms_buffer[5] = patch_power;
+
+
+ status = VL53L1_WriteMulti(Dev,
+ VL53L1_PATCH__OFFSET_0, comms_buffer, 6);
+ }
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ comms_buffer[0] = 0x03;
+ comms_buffer[1] = 0x6D;
+ comms_buffer[2] = 0x03;
+ comms_buffer[3] = 0x6F;
+ comms_buffer[4] = 0x07;
+ comms_buffer[5] = 0x29;
+ status = VL53L1_WriteMulti(Dev,
+ VL53L1_PATCH__ADDRESS_0, comms_buffer, 6);
+ }
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ comms_buffer[0] = 0x00;
+ comms_buffer[1] = 0x07;
+ status = VL53L1_WriteMulti(Dev,
+ VL53L1_PATCH__JMP_ENABLES, comms_buffer, 2);
+ }
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ comms_buffer[0] = 0x00;
+ comms_buffer[1] = 0x07;
+ status = VL53L1_WriteMulti(Dev,
+ VL53L1_PATCH__DATA_ENABLES, comms_buffer, 2);
+ }
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(Dev,
+ VL53L1_PATCH__CTRL, 0x01);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(Dev,
+ VL53L1_FIRMWARE__ENABLE, 0x01);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_unload_patch(
+ VL53L1_DEV Dev) {
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(Dev,
+ VL53L1_FIRMWARE__ENABLE, 0x00);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_disable_powerforce(Dev);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(Dev,
+ VL53L1_PATCH__CTRL, 0x00);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(Dev,
+ VL53L1_FIRMWARE__ENABLE, 0x01);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_get_version(
+ VL53L1_DEV Dev,
+ VL53L1_ll_version_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_init_version(Dev);
+
+ memcpy(pdata, &(pdev->version), sizeof(VL53L1_ll_version_t));
+
+ return VL53L1_ERROR_NONE;
+}
+
+
+VL53L1_Error VL53L1_get_device_firmware_version(
+ VL53L1_DEV Dev,
+ uint16_t *pfw_version)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_RdWord(
+ Dev,
+ VL53L1_MCU_GENERAL_PURPOSE__GP_0,
+ pfw_version);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_data_init(
+ VL53L1_DEV Dev,
+ uint8_t read_p2p_data)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+
+
+
+ VL53L1_zone_objects_t *pobjects;
+
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_UNKNOWN);
+
+ pres->range_results.max_results = VL53L1_MAX_RANGE_RESULTS;
+ pres->range_results.active_results = 0;
+ pres->zone_results.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_results.active_zones = 0;
+
+ for (i = 0; i < VL53L1_MAX_USER_ZONES; i++) {
+ pobjects = &(pres->zone_results.VL53L1_p_002[i]);
+ pobjects->xmonitor.VL53L1_p_020 = 0;
+ pobjects->xmonitor.VL53L1_p_021 = 0;
+ pobjects->xmonitor.VL53L1_p_014 = 0;
+ pobjects->xmonitor.range_status =
+ VL53L1_DEVICEERROR_NOUPDATE;
+ }
+
+
+
+
+ pres->zone_hists.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_hists.active_zones = 0;
+
+
+
+
+ pres->zone_cal.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_cal.active_zones = 0;
+ for (i = 0; i < VL53L1_MAX_USER_ZONES; i++) {
+ pres->zone_cal.VL53L1_p_002[i].no_of_samples = 0;
+ pres->zone_cal.VL53L1_p_002[i].effective_spads = 0;
+ pres->zone_cal.VL53L1_p_002[i].peak_rate_mcps = 0;
+ pres->zone_cal.VL53L1_p_002[i].median_range_mm = 0;
+ pres->zone_cal.VL53L1_p_002[i].range_mm_offset = 0;
+ }
+
+ pdev->wait_method = VL53L1_WAIT_METHOD_BLOCKING;
+ pdev->preset_mode = VL53L1_DEVICEPRESETMODE_STANDARD_RANGING;
+ pdev->zone_preset = VL53L1_DEVICEZONEPRESET_NONE;
+ pdev->measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_STOP;
+
+ pdev->offset_calibration_mode =
+ VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD;
+ pdev->offset_correction_mode =
+ VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS;
+ pdev->dmax_mode =
+ VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA;
+
+ pdev->phasecal_config_timeout_us = 1000;
+ pdev->mm_config_timeout_us = 2000;
+ pdev->range_config_timeout_us = 13000;
+ pdev->inter_measurement_period_ms = 100;
+ pdev->dss_config__target_total_rate_mcps = 0x0A00;
+ pdev->debug_mode = 0x00;
+
+ pdev->offset_results.max_results = VL53L1_MAX_OFFSET_RANGE_RESULTS;
+ pdev->offset_results.active_results = 0;
+
+
+
+
+
+ pdev->gain_cal.standard_ranging_gain_factor =
+ VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR_DEFAULT;
+ pdev->gain_cal.histogram_ranging_gain_factor =
+ VL53L1_TUNINGPARM_HIST_GAIN_FACTOR_DEFAULT;
+
+
+
+
+
+ VL53L1_init_version(Dev);
+
+
+
+ memset(pdev->multi_bins_rec, 0, sizeof(pdev->multi_bins_rec));
+ pdev->bin_rec_pos = 0;
+ pdev->pos_before_next_recom = 0;
+
+
+
+
+
+
+
+
+
+
+ if (read_p2p_data > 0 && status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_read_p2p_data(Dev);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_refspadchar_config_struct(
+ &(pdev->refspadchar));
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_ssc_config_struct(
+ &(pdev->ssc_cfg));
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_xtalk_config_struct(
+ &(pdev->customer),
+ &(pdev->xtalk_cfg));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_xtalk_extract_config_struct(
+ &(pdev->xtalk_extract_cfg));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_offset_cal_config_struct(
+ &(pdev->offsetcal_cfg));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_zone_cal_config_struct(
+ &(pdev->zonecal_cfg));
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_hist_post_process_config_struct(
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable,
+ &(pdev->histpostprocess));
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_hist_gen3_dmax_config_struct(
+ &(pdev->dmax_cfg));
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_init_tuning_parm_storage_struct(
+ &(pdev->tuning_parms));
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_set_preset_mode(
+ Dev,
+ pdev->preset_mode,
+ pdev->dss_config__target_total_rate_mcps,
+
+ pdev->phasecal_config_timeout_us,
+ pdev->mm_config_timeout_us,
+ pdev->range_config_timeout_us,
+ pdev->inter_measurement_period_ms);
+
+
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->hist_data));
+
+ VL53L1_init_histogram_bin_data_struct(
+ 0,
+ VL53L1_HISTOGRAM_BUFFER_SIZE,
+ &(pdev->hist_xtalk));
+
+
+
+ VL53L1_init_xtalk_bin_data_struct(
+ 0,
+ VL53L1_XTALK_HISTO_BINS,
+ &(pdev->xtalk_shapes.xtalk_shape));
+
+
+
+
+
+ VL53L1_xtalk_cal_data_init(
+ Dev
+ );
+
+
+
+
+
+ VL53L1_dynamic_xtalk_correction_data_init(
+ Dev
+ );
+
+
+
+
+
+ VL53L1_low_power_auto_data_init(
+ Dev
+ );
+
+#ifdef VL53L1_LOG_ENABLE
+
+
+
+
+ VL53L1_print_static_nvm_managed(
+ &(pdev->stat_nvm),
+ "data_init():pdev->lldata.stat_nvm.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_customer_nvm_managed(
+ &(pdev->customer),
+ "data_init():pdev->lldata.customer.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_nvm_copy_data(
+ &(pdev->nvm_copy_data),
+ "data_init():pdev->lldata.nvm_copy_data.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->fmt_dmax_cal),
+ "data_init():pdev->lldata.fmt_dmax_cal.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_dmax_calibration_data(
+ &(pdev->cust_dmax_cal),
+ "data_init():pdev->lldata.cust_dmax_cal.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_additional_offset_cal_data(
+ &(pdev->add_off_cal_data),
+ "data_init():pdev->lldata.add_off_cal_data.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_user_zone(
+ &(pdev->mm_roi),
+ "data_init():pdev->lldata.mm_roi.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_optical_centre(
+ &(pdev->optical_centre),
+ "data_init():pdev->lldata.optical_centre.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+ VL53L1_print_cal_peak_rate_map(
+ &(pdev->cal_peak_rate_map),
+ "data_init():pdev->lldata.cal_peak_rate_map.",
+ VL53L1_TRACE_MODULE_DATA_INIT);
+
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_read_p2p_data(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_customer_nvm_managed_t *pN = &(pdev->customer);
+ VL53L1_additional_offset_cal_data_t *pCD = &(pdev->add_off_cal_data);
+
+ VL53L1_decoded_nvm_fmt_range_data_t fmt_rrd;
+
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_get_static_nvm_managed(
+ Dev,
+ &(pdev->stat_nvm));
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_get_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_get_nvm_copy_data(
+ Dev,
+ &(pdev->nvm_copy_data));
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_copy_rtn_good_spads_to_buffer(
+ &(pdev->nvm_copy_data),
+ &(pdev->rtn_good_spads[0]));
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pHP->algo__crosstalk_compensation_plane_offset_kcps =
+ pN->algo__crosstalk_compensation_plane_offset_kcps;
+ pHP->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pN->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pHP->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pN->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_read_nvm_optical_centre(
+ Dev,
+ &(pdev->optical_centre));
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_read_nvm_cal_peak_rate_map(
+ Dev,
+ &(pdev->cal_peak_rate_map));
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status =
+ VL53L1_read_nvm_additional_offset_cal_data(
+ Dev,
+ &(pdev->add_off_cal_data));
+
+
+
+
+
+
+ if (pCD->result__mm_inner_peak_signal_count_rtn_mcps == 0 &&
+ pCD->result__mm_outer_peak_signal_count_rtn_mcps == 0) {
+
+ pCD->result__mm_inner_peak_signal_count_rtn_mcps
+ = 0x0080;
+
+ pCD->result__mm_outer_peak_signal_count_rtn_mcps
+ = 0x0180;
+
+
+
+
+
+ VL53L1_calc_mm_effective_spads(
+ pdev->nvm_copy_data.roi_config__mode_roi_centre_spad,
+ pdev->nvm_copy_data.roi_config__mode_roi_xy_size,
+ 0xC7,
+
+ 0xFF,
+ &(pdev->rtn_good_spads[0]),
+ VL53L1_RTN_SPAD_APERTURE_TRANSMISSION,
+ &(pCD->result__mm_inner_actual_effective_spads),
+ &(pCD->result__mm_outer_actual_effective_spads));
+ }
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status =
+ VL53L1_read_nvm_fmt_range_results_data(
+ Dev,
+ VL53L1_NVM__FMT__RANGE_RESULTS__140MM_DARK,
+ &fmt_rrd);
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->fmt_dmax_cal.ref__actual_effective_spads =
+ fmt_rrd.result__actual_effective_rtn_spads;
+ pdev->fmt_dmax_cal.ref__peak_signal_count_rate_mcps =
+ fmt_rrd.result__peak_signal_count_rate_rtn_mcps;
+ pdev->fmt_dmax_cal.ref__distance_mm =
+ fmt_rrd.measured_distance_mm;
+
+
+
+
+
+
+ if (pdev->cal_peak_rate_map.cal_reflectance_pc != 0) {
+ pdev->fmt_dmax_cal.ref_reflectance_pc =
+ pdev->cal_peak_rate_map.cal_reflectance_pc;
+ } else {
+ pdev->fmt_dmax_cal.ref_reflectance_pc = 0x0014;
+ }
+
+
+
+ pdev->fmt_dmax_cal.coverglass_transmission = 0x0100;
+ }
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_RdWord(
+ Dev,
+ VL53L1_RESULT__OSC_CALIBRATE_VAL,
+ &(pdev->dbg_results.result__osc_calibrate_val));
+
+
+
+
+
+
+ if (pdev->stat_nvm.osc_measured__fast_osc__frequency < 0x1000) {
+ trace_print(
+ VL53L1_TRACE_LEVEL_WARNING,
+ "\nInvalid %s value (0x%04X) - forcing to 0x%04X\n\n",
+ "pdev->stat_nvm.osc_measured__fast_osc__frequency",
+ pdev->stat_nvm.osc_measured__fast_osc__frequency,
+ 0xBCCC);
+ pdev->stat_nvm.osc_measured__fast_osc__frequency = 0xBCCC;
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_get_mode_mitigation_roi(
+ Dev,
+ &(pdev->mm_roi));
+
+
+
+
+
+
+ if (pdev->optical_centre.x_centre == 0 &&
+ pdev->optical_centre.y_centre == 0) {
+ pdev->optical_centre.x_centre =
+ pdev->mm_roi.x_centre << 4;
+ pdev->optical_centre.y_centre =
+ pdev->mm_roi.y_centre << 4;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_software_reset(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SOFT_RESET,
+ 0x00);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WaitUs(
+ Dev,
+ VL53L1_SOFTWARE_RESET_DURATION_US);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SOFT_RESET,
+ 0x01);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_wait_for_boot_completion(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_customer_nvm_managed_t *pN = &(pdev->customer);
+
+ uint32_t tempu32;
+
+ LOG_FUNCTION_START("");
+
+ if (pcal_data->struct_version !=
+ VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION) {
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ memcpy(
+ &(pdev->customer),
+ &(pcal_data->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+
+
+ memcpy(
+ &(pdev->add_off_cal_data),
+ &(pcal_data->add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+
+
+ memcpy(
+ &(pdev->fmt_dmax_cal),
+ &(pcal_data->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pdev->cust_dmax_cal),
+ &(pcal_data->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pdev->xtalk_shapes),
+ &(pcal_data->xtalkhisto),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+
+
+ memcpy(
+ &(pdev->gain_cal),
+ &(pcal_data->gain_cal),
+ sizeof(VL53L1_gain_calibration_data_t));
+
+
+
+ memcpy(
+ &(pdev->cal_peak_rate_map),
+ &(pcal_data->cal_peak_rate_map),
+ sizeof(VL53L1_cal_peak_rate_map_t));
+
+
+
+ memcpy(
+ &(pdev->per_vcsel_cal_data),
+ &(pcal_data->per_vcsel_cal_data),
+ sizeof(VL53L1_per_vcsel_period_offset_cal_data_t));
+
+
+
+
+
+
+ pC->algo__crosstalk_compensation_plane_offset_kcps =
+ pN->algo__crosstalk_compensation_plane_offset_kcps;
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pN->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pN->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+ pHP->algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pC->algo__crosstalk_compensation_plane_offset_kcps,
+ pC->histogram_mode_crosstalk_margin_kcps);
+
+ pHP->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pHP->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+ if (pC->global_crosstalk_compensation_enable == 0x00) {
+ pN->algo__crosstalk_compensation_plane_offset_kcps =
+ 0x00;
+ pN->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ 0x00;
+ pN->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ 0x00;
+ } else {
+ tempu32 =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pC->algo__crosstalk_compensation_plane_offset_kcps,
+ pC->lite_mode_crosstalk_margin_kcps);
+
+
+
+ if (tempu32 > 0xFFFF)
+ tempu32 = 0xFFFF;
+
+ pN->algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)tempu32;
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_part_to_part_data(
+ VL53L1_DEV Dev,
+ VL53L1_calibration_data_t *pcal_data)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg);
+ VL53L1_customer_nvm_managed_t *pCN = &(pcal_data->customer);
+
+ LOG_FUNCTION_START("");
+
+ pcal_data->struct_version =
+ VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION;
+
+
+
+ memcpy(
+ &(pcal_data->customer),
+ &(pdev->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+
+
+
+
+
+ if (pC->algo__crosstalk_compensation_plane_offset_kcps > 0xFFFF) {
+ pCN->algo__crosstalk_compensation_plane_offset_kcps =
+ 0xFFFF;
+ } else {
+ pCN->algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)pC->algo__crosstalk_compensation_plane_offset_kcps;
+ }
+ pCN->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pCN->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+ memcpy(
+ &(pcal_data->fmt_dmax_cal),
+ &(pdev->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->cust_dmax_cal),
+ &(pdev->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->add_off_cal_data),
+ &(pdev->add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->optical_centre),
+ &(pdev->optical_centre),
+ sizeof(VL53L1_optical_centre_t));
+
+
+
+ memcpy(
+ &(pcal_data->xtalkhisto),
+ &(pdev->xtalk_shapes),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->gain_cal),
+ &(pdev->gain_cal),
+ sizeof(VL53L1_gain_calibration_data_t));
+
+
+
+ memcpy(
+ &(pcal_data->cal_peak_rate_map),
+ &(pdev->cal_peak_rate_map),
+ sizeof(VL53L1_cal_peak_rate_map_t));
+
+
+
+ memcpy(
+ &(pcal_data->per_vcsel_cal_data),
+ &(pdev->per_vcsel_cal_data),
+ sizeof(VL53L1_per_vcsel_period_offset_cal_data_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t inter_measurement_period_ms)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->dbg_results.result__osc_calibrate_val == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->inter_measurement_period_ms = inter_measurement_period_ms;
+ pdev->tim_cfg.system__intermeasurement_period =
+ inter_measurement_period_ms *
+ (uint32_t)pdev->dbg_results.result__osc_calibrate_val;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_inter_measurement_period_ms(
+ VL53L1_DEV Dev,
+ uint32_t *pinter_measurement_period_ms)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->dbg_results.result__osc_calibrate_val == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE)
+ *pinter_measurement_period_ms =
+ pdev->tim_cfg.system__intermeasurement_period /
+ (uint32_t)pdev->dbg_results.result__osc_calibrate_val;
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->stat_nvm.osc_measured__fast_osc__frequency == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pdev->phasecal_config_timeout_us = phasecal_config_timeout_us;
+ pdev->mm_config_timeout_us = mm_config_timeout_us;
+ pdev->range_config_timeout_us = range_config_timeout_us;
+
+ status =
+ VL53L1_calc_timeout_register_values(
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us,
+ pdev->stat_nvm.osc_measured__fast_osc__frequency,
+ &(pdev->gen_cfg),
+ &(pdev->tim_cfg));
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_timeouts_us(
+ VL53L1_DEV Dev,
+ uint32_t *pphasecal_config_timeout_us,
+ uint32_t *pmm_config_timeout_us,
+ uint32_t *prange_config_timeout_us)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint32_t macro_period_us = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->stat_nvm.osc_measured__fast_osc__frequency == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ pdev->stat_nvm.osc_measured__fast_osc__frequency,
+ pdev->tim_cfg.range_config__vcsel_period_a);
+
+
+
+
+ *pphasecal_config_timeout_us =
+ VL53L1_calc_timeout_us(
+ (uint32_t)pdev->gen_cfg.phasecal_config__timeout_macrop,
+ macro_period_us);
+
+
+
+
+ timeout_encoded =
+ (uint16_t)pdev->tim_cfg.mm_config__timeout_macrop_a_hi;
+ timeout_encoded = (timeout_encoded << 8) +
+ (uint16_t)pdev->tim_cfg.mm_config__timeout_macrop_a_lo;
+
+ *pmm_config_timeout_us =
+ VL53L1_calc_decoded_timeout_us(
+ timeout_encoded,
+ macro_period_us);
+
+
+
+
+ timeout_encoded =
+ (uint16_t)pdev->tim_cfg.range_config__timeout_macrop_a_hi;
+ timeout_encoded = (timeout_encoded << 8) +
+ (uint16_t)pdev->tim_cfg.range_config__timeout_macrop_a_lo;
+
+ *prange_config_timeout_us =
+ VL53L1_calc_decoded_timeout_us(
+ timeout_encoded,
+ macro_period_us);
+
+ pdev->phasecal_config_timeout_us = *pphasecal_config_timeout_us;
+ pdev->mm_config_timeout_us = *pmm_config_timeout_us;
+ pdev->range_config_timeout_us = *prange_config_timeout_us;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t cal_config__repeat_period)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->gen_cfg.cal_config__repeat_rate = cal_config__repeat_period;
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_calibration_repeat_period(
+ VL53L1_DEV Dev,
+ uint16_t *pcal_config__repeat_period)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ *pcal_config__repeat_period = pdev->gen_cfg.cal_config__repeat_rate;
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_set_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t value)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t bit_mask = 0x01;
+ uint8_t clr_mask = 0xFF - bit_mask;
+ uint8_t bit_value = value & bit_mask;
+
+ if (bit_id <= VL53L1_DEVICESEQUENCECONFIG_RANGE) {
+
+ if (bit_id > 0) {
+ bit_mask = 0x01 << bit_id;
+ bit_value = bit_value << bit_id;
+ clr_mask = 0xFF - bit_mask;
+ }
+
+ pdev->dyn_cfg.system__sequence_config =
+ (pdev->dyn_cfg.system__sequence_config & clr_mask) |
+ bit_value;
+
+ } else {
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_sequence_config_bit(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceSequenceConfig bit_id,
+ uint8_t *pvalue)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t bit_mask = 0x01;
+
+ if (bit_id <= VL53L1_DEVICESEQUENCECONFIG_RANGE) {
+
+ if (bit_id > 0)
+ bit_mask = 0x01 << bit_id;
+
+ *pvalue =
+ pdev->dyn_cfg.system__sequence_config & bit_mask;
+
+ if (bit_id > 0)
+ *pvalue = *pvalue >> bit_id;
+
+ } else {
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity interrupt_polarity)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->stat_cfg.gpio_hv_mux__ctrl =
+ (pdev->stat_cfg.gpio_hv_mux__ctrl &
+ VL53L1_DEVICEINTERRUPTPOLARITY_CLEAR_MASK) |
+ (interrupt_polarity &
+ VL53L1_DEVICEINTERRUPTPOLARITY_BIT_MASK);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_set_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->refspadchar.device_test_mode = pdata->device_test_mode;
+ pdev->refspadchar.VL53L1_p_009 = pdata->VL53L1_p_009;
+ pdev->refspadchar.timeout_us = pdata->timeout_us;
+ pdev->refspadchar.target_count_rate_mcps =
+ pdata->target_count_rate_mcps;
+ pdev->refspadchar.min_count_rate_limit_mcps =
+ pdata->min_count_rate_limit_mcps;
+ pdev->refspadchar.max_count_rate_limit_mcps =
+ pdata->max_count_rate_limit_mcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_get_refspadchar_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_refspadchar_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdata->device_test_mode = pdev->refspadchar.device_test_mode;
+ pdata->VL53L1_p_009 = pdev->refspadchar.VL53L1_p_009;
+ pdata->timeout_us = pdev->refspadchar.timeout_us;
+ pdata->target_count_rate_mcps =
+ pdev->refspadchar.target_count_rate_mcps;
+ pdata->min_count_rate_limit_mcps =
+ pdev->refspadchar.min_count_rate_limit_mcps;
+ pdata->max_count_rate_limit_mcps =
+ pdev->refspadchar.max_count_rate_limit_mcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_set_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t range_ignore_thresh_mult,
+ uint16_t range_ignore_threshold_mcps)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps =
+ range_ignore_threshold_mcps;
+
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult =
+ range_ignore_thresh_mult;
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_range_ignore_threshold(
+ VL53L1_DEV Dev,
+ uint8_t *prange_ignore_thresh_mult,
+ uint16_t *prange_ignore_threshold_mcps_internal,
+ uint16_t *prange_ignore_threshold_mcps_current)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ *prange_ignore_thresh_mult =
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult;
+
+ *prange_ignore_threshold_mcps_current =
+ pdev->stat_cfg.algo__range_ignore_threshold_mcps;
+
+ *prange_ignore_threshold_mcps_internal =
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps;
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_get_interrupt_polarity(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceInterruptPolarity *pinterrupt_polarity)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ *pinterrupt_polarity =
+ pdev->stat_cfg.gpio_hv_mux__ctrl &
+ VL53L1_DEVICEINTERRUPTPOLARITY_BIT_MASK;
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_set_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ VL53L1_encode_row_col(
+ puser_zone->y_centre,
+ puser_zone->x_centre,
+ &(pdev->dyn_cfg.roi_config__user_roi_centre_spad));
+
+
+
+ VL53L1_encode_zone_size(
+ puser_zone->width,
+ puser_zone->height,
+ &(pdev->dyn_cfg.roi_config__user_roi_requested_global_xy_size));
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_user_zone(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *puser_zone)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ VL53L1_decode_row_col(
+ pdev->dyn_cfg.roi_config__user_roi_centre_spad,
+ &(puser_zone->y_centre),
+ &(puser_zone->x_centre));
+
+
+
+ VL53L1_decode_zone_size(
+ pdev->dyn_cfg.roi_config__user_roi_requested_global_xy_size,
+ &(puser_zone->width),
+ &(puser_zone->height));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_get_mode_mitigation_roi(
+ VL53L1_DEV Dev,
+ VL53L1_user_zone_t *pmm_roi)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t x = 0;
+ uint8_t y = 0;
+ uint8_t xy_size = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+ VL53L1_decode_row_col(
+ pdev->nvm_copy_data.roi_config__mode_roi_centre_spad,
+ &y,
+ &x);
+
+ pmm_roi->x_centre = x;
+ pmm_roi->y_centre = y;
+
+
+
+
+
+
+
+
+
+
+ xy_size = pdev->nvm_copy_data.roi_config__mode_roi_xy_size;
+
+ pmm_roi->height = xy_size >> 4;
+ pmm_roi->width = xy_size & 0x0F;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(&(pdev->zone_cfg.user_zones), &(pzone_cfg->user_zones),
+ sizeof(pdev->zone_cfg.user_zones));
+
+
+
+ pdev->zone_cfg.max_zones = pzone_cfg->max_zones;
+ pdev->zone_cfg.active_zones = pzone_cfg->active_zones;
+
+ status = VL53L1_init_zone_config_histogram_bins(&pdev->zone_cfg);
+
+
+
+
+
+
+
+
+
+
+ if (pzone_cfg->active_zones == 0)
+ pdev->gen_cfg.global_config__stream_divider = 0;
+ else if (pzone_cfg->active_zones < VL53L1_MAX_USER_ZONES)
+ pdev->gen_cfg.global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+ else
+ pdev->gen_cfg.global_config__stream_divider =
+ VL53L1_MAX_USER_ZONES + 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_zone_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(pzone_cfg, &(pdev->zone_cfg), sizeof(VL53L1_zone_config_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_get_preset_mode_timing_cfg(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ uint16_t *pdss_config__target_total_rate_mcps,
+ uint32_t *pphasecal_config_timeout_us,
+ uint32_t *pmm_config_timeout_us,
+ uint32_t *prange_config_timeout_us)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+ switch (device_preset_mode) {
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING:
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE:
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE:
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL:
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL:
+ case VL53L1_DEVICEPRESETMODE_OLT:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_lite_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_lite_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_lite_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_lite_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING:
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE:
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE:
+ case VL53L1_DEVICEPRESETMODE_SINGLESHOT_RANGING:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_timed_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_timed_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_timed_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_timed_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_SHORT_RANGE:
+ case VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_MEDIUM_RANGE:
+ case VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_LONG_RANGE:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_timed_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_timed_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_lpa_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_lpa_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM1:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM2:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_REF_ARRAY:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM1:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM2:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_CHARACTERISATION:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_long_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_histo_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_histo_us;
+
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mz_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_mz_med_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_mz_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_mz_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mz_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_mz_short_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_mz_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_mz_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mz_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_mz_long_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_mz_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_mz_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_SHORT_TIMING:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_short_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_histo_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_histo_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM1:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM2:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_med_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_histo_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_histo_us;
+ break;
+
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM1:
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM2:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_short_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_histo_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_histo_us;
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_SPECIAL_HISTOGRAM_SHORT_RANGE:
+ *pdss_config__target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_very_short_mcps;
+ *pphasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_short_us;
+ *pmm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_histo_us;
+ *prange_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_histo_us;
+ break;
+
+ default:
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_preset_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DevicePresetModes device_preset_mode,
+ uint16_t dss_config__target_total_rate_mcps,
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint32_t inter_measurement_period_ms)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_hist_post_process_config_t *phistpostprocess =
+ &(pdev->histpostprocess);
+
+ VL53L1_static_config_t *pstatic = &(pdev->stat_cfg);
+ VL53L1_histogram_config_t *phistogram = &(pdev->hist_cfg);
+ VL53L1_general_config_t *pgeneral = &(pdev->gen_cfg);
+ VL53L1_timing_config_t *ptiming = &(pdev->tim_cfg);
+ VL53L1_dynamic_config_t *pdynamic = &(pdev->dyn_cfg);
+ VL53L1_system_control_t *psystem = &(pdev->sys_ctrl);
+ VL53L1_zone_config_t *pzone_cfg = &(pdev->zone_cfg);
+ VL53L1_tuning_parm_storage_t *ptuning_parms = &(pdev->tuning_parms);
+ VL53L1_low_power_auto_data_t *plpadata =
+ &(pdev->low_power_auto_data);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->preset_mode = device_preset_mode;
+ pdev->mm_config_timeout_us = mm_config_timeout_us;
+ pdev->range_config_timeout_us = range_config_timeout_us;
+ pdev->inter_measurement_period_ms = inter_measurement_period_ms;
+
+
+
+
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_SW_STANDBY);
+
+
+
+
+ switch (device_preset_mode) {
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING:
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE:
+ status = VL53L1_preset_mode_standard_ranging_short_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE:
+ status = VL53L1_preset_mode_standard_ranging_long_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL:
+ status = VL53L1_preset_mode_standard_ranging_mm1_cal(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL:
+ status = VL53L1_preset_mode_standard_ranging_mm2_cal(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING:
+ status = VL53L1_preset_mode_timed_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE:
+ status = VL53L1_preset_mode_timed_ranging_short_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE:
+ status = VL53L1_preset_mode_timed_ranging_long_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING:
+ status = VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM1:
+ status = VL53L1_preset_mode_histogram_ranging_with_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_WITH_MM2:
+ status = VL53L1_preset_mode_histogram_ranging_with_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL:
+ status = VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL:
+ status = VL53L1_preset_mode_histogram_ranging_mm2_cal(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE:
+ status = VL53L1_preset_mode_histogram_multizone(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE:
+ status = VL53L1_preset_mode_histogram_multizone_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE:
+ status = VL53L1_preset_mode_histogram_multizone_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_REF_ARRAY:
+ status = VL53L1_preset_mode_histogram_ranging_ref(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_SHORT_TIMING:
+ status = VL53L1_preset_mode_histogram_ranging_short_timing(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE:
+ status = VL53L1_preset_mode_histogram_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM1:
+ status = VL53L1_preset_mode_histogram_long_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE_MM2:
+ status = VL53L1_preset_mode_histogram_long_range_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE:
+ status = VL53L1_preset_mode_histogram_medium_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM1:
+ status = VL53L1_preset_mode_histogram_medium_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE_MM2:
+ status = VL53L1_preset_mode_histogram_medium_range_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE:
+ status = VL53L1_preset_mode_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM1:
+ status = VL53L1_preset_mode_histogram_short_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE_MM2:
+ status = VL53L1_preset_mode_histogram_short_range_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_CHARACTERISATION:
+ status = VL53L1_preset_mode_histogram_characterisation(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR:
+ status = VL53L1_preset_mode_histogram_xtalk_planar(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM1:
+ status = VL53L1_preset_mode_histogram_xtalk_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_MM2:
+ status = VL53L1_preset_mode_histogram_xtalk_mm2(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_OLT:
+ status = VL53L1_preset_mode_olt(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_SINGLESHOT_RANGING:
+ status = VL53L1_preset_mode_singleshot_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_SHORT_RANGE:
+ status = VL53L1_preset_mode_low_power_auto_short_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg,
+ plpadata);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_MEDIUM_RANGE:
+ status = VL53L1_preset_mode_low_power_auto_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg,
+ plpadata);
+ break;
+
+ case VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_LONG_RANGE:
+ status = VL53L1_preset_mode_low_power_auto_long_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg,
+ plpadata);
+ break;
+
+
+ case VL53L1_DEVICEPRESETMODE_SPECIAL_HISTOGRAM_SHORT_RANGE:
+ status = VL53L1_preset_mode_special_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+ break;
+
+ default:
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pstatic->dss_config__target_total_rate_mcps =
+ dss_config__target_total_rate_mcps;
+ pdev->dss_config__target_total_rate_mcps =
+ dss_config__target_total_rate_mcps;
+
+ }
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_timeouts_us(
+ Dev,
+ phasecal_config_timeout_us,
+ mm_config_timeout_us,
+ range_config_timeout_us);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_set_inter_measurement_period_ms(
+ Dev,
+ inter_measurement_period_ms);
+
+
+
+
+ V53L1_init_zone_results_structure(
+ pdev->zone_cfg.active_zones+1,
+ &(pres->zone_results));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_zone_preset(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceZonePreset zone_preset)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_general_config_t *pgeneral = &(pdev->gen_cfg);
+ VL53L1_zone_config_t *pzone_cfg = &(pdev->zone_cfg);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->zone_preset = zone_preset;
+
+
+
+
+ switch (zone_preset) {
+
+ case VL53L1_DEVICEZONEPRESET_XTALK_PLANAR:
+ status =
+ VL53L1_zone_preset_xtalk_planar(
+ pgeneral,
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_1X1_SIZE_16X16:
+ status =
+ VL53L1_init_zone_config_structure(
+ 8, 1, 1,
+
+ 8, 1, 1,
+
+ 15, 15,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_1X2_SIZE_16X8:
+ status =
+ VL53L1_init_zone_config_structure(
+ 8, 1, 1,
+
+ 4, 8, 2,
+
+ 15, 7,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_2X1_SIZE_8X16:
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 8, 1, 1,
+
+ 7, 15,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_2X2_SIZE_8X8:
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_3X3_SIZE_5X5:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 5, 3,
+
+ 2, 5, 3,
+
+ 4, 4,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_4X4_SIZE_4X4:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 4, 4,
+
+ 2, 4, 4,
+
+ 3, 3,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_5X5_SIZE_4X4:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 3, 5,
+
+ 2, 3, 5,
+
+ 3, 3,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_11X11_SIZE_5X5:
+ status =
+ VL53L1_init_zone_config_structure(
+ 3, 1, 11,
+
+ 3, 1, 11,
+
+ 4, 4,
+
+ pzone_cfg);
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_13X13_SIZE_4X4:
+ status =
+ VL53L1_init_zone_config_structure(
+ 2, 1, 13,
+
+ 2, 1, 13,
+
+ 3, 3,
+
+ pzone_cfg);
+
+ break;
+
+ case VL53L1_DEVICEZONEPRESET_1X1_SIZE_4X4_POS_8X8:
+ status =
+ VL53L1_init_zone_config_structure(
+ 8, 1, 1,
+
+ 8, 1, 1,
+
+ 3, 3,
+
+ pzone_cfg);
+ break;
+
+ }
+
+
+
+
+
+
+
+
+
+
+ if (pzone_cfg->active_zones == 0)
+ pdev->gen_cfg.global_config__stream_divider = 0;
+ else if (pzone_cfg->active_zones < VL53L1_MAX_USER_ZONES)
+ pdev->gen_cfg.global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+ else
+ pdev->gen_cfg.global_config__stream_divider =
+ VL53L1_MAX_USER_ZONES + 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_enable_xtalk_compensation(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint32_t tempu32;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_customer_nvm_managed_t *pN = &(pdev->customer);
+
+ LOG_FUNCTION_START("");
+
+
+
+ tempu32 = VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pC->algo__crosstalk_compensation_plane_offset_kcps,
+ pC->lite_mode_crosstalk_margin_kcps);
+ if (tempu32 > 0xFFFF)
+ tempu32 = 0xFFFF;
+
+ pN->algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)tempu32;
+
+ pN->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+ pN->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+ pHP->algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pC->algo__crosstalk_compensation_plane_offset_kcps,
+ pC->histogram_mode_crosstalk_margin_kcps);
+
+ pHP->algo__crosstalk_compensation_x_plane_gradient_kcps
+ = pC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pHP->algo__crosstalk_compensation_y_plane_gradient_kcps
+ = pC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+ pC->global_crosstalk_compensation_enable = 0x01;
+
+ pHP->algo__crosstalk_compensation_enable =
+ pC->global_crosstalk_compensation_enable;
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pC->crosstalk_range_ignore_threshold_rate_mcps =
+ VL53L1_calc_range_ignore_threshold(
+ pC->algo__crosstalk_compensation_plane_offset_kcps,
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ pC->crosstalk_range_ignore_threshold_mult);
+}
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_set_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+void VL53L1_get_xtalk_compensation_enable(
+ VL53L1_DEV Dev,
+ uint8_t *pcrosstalk_compensation_enable)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ *pcrosstalk_compensation_enable =
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable;
+
+}
+
+
+VL53L1_Error VL53L1_get_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pxtalk_margin = pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_lite_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps = xtalk_margin;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t *pxtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pxtalk_margin = pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_xtalk_margin_kcps(
+ VL53L1_DEV Dev,
+ int16_t xtalk_margin)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps = xtalk_margin;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_restore_xtalk_nvm_default(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg);
+
+ LOG_FUNCTION_START("");
+
+ pC->algo__crosstalk_compensation_plane_offset_kcps =
+ pC->nvm_default__crosstalk_compensation_plane_offset_kcps;
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pC->nvm_default__crosstalk_compensation_x_plane_gradient_kcps;
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pC->nvm_default__crosstalk_compensation_y_plane_gradient_kcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_disable_xtalk_compensation(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_customer_nvm_managed_t *pN = &(pdev->customer);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pN->algo__crosstalk_compensation_plane_offset_kcps =
+ 0x00;
+
+ pN->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ 0x00;
+
+ pN->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ 0x00;
+
+
+
+
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable = 0x00;
+
+ pHP->algo__crosstalk_compensation_enable =
+ pdev->xtalk_cfg.global_crosstalk_compensation_enable;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps =
+ 0x0000;
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status =
+ VL53L1_set_customer_nvm_managed(
+ Dev,
+ &(pdev->customer));
+ }
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pphase_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+
+ LOG_FUNCTION_START("");
+
+ *pphase_consistency =
+ pHP->algo__consistency_check__phase_tolerance;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_phase_consistency(
+ VL53L1_DEV Dev,
+ uint8_t phase_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.algo__consistency_check__phase_tolerance =
+ phase_consistency;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t *pevent_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pevent_consistency =
+ pdev->histpostprocess.algo__consistency_check__event_sigma;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_event_consistency(
+ VL53L1_DEV Dev,
+ uint8_t event_consistency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.algo__consistency_check__event_sigma =
+ event_consistency;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t *pamb_thresh_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pamb_thresh_sigma =
+ pdev->histpostprocess.ambient_thresh_sigma1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_histogram_ambient_threshold_sigma(
+ VL53L1_DEV Dev,
+ uint8_t amb_thresh_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.ambient_thresh_sigma1 =
+ amb_thresh_sigma;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t *plite_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *plite_sigma =
+ pdev->tim_cfg.range_config__sigma_thresh;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_lite_sigma_threshold(
+ VL53L1_DEV Dev,
+ uint16_t lite_sigma)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->tim_cfg.range_config__sigma_thresh = lite_sigma;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t *plite_mincountrate)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *plite_mincountrate =
+ pdev->tim_cfg.range_config__min_count_rate_rtn_limit_mcps;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_lite_min_count_rate(
+ VL53L1_DEV Dev,
+ uint16_t lite_mincountrate)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->tim_cfg.range_config__min_count_rate_rtn_limit_mcps =
+ lite_mincountrate;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t *pmax_valid_range_mm,
+ int16_t *pmin_valid_range_mm,
+ uint16_t *pmax_valid_rate_kcps,
+ uint16_t *pmax_sigma_mm)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pmax_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm;
+ *pmin_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm;
+ *pmax_valid_rate_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps;
+ *pmax_sigma_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_xtalk_detect_config(
+ VL53L1_DEV Dev,
+ int16_t max_valid_range_mm,
+ int16_t min_valid_range_mm,
+ uint16_t max_valid_rate_kcps,
+ uint16_t max_sigma_mm)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm =
+ max_valid_range_mm;
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm =
+ min_valid_range_mm;
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps =
+ max_valid_rate_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm =
+ max_sigma_mm;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder *phist_target_order)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *phist_target_order =
+ pdev->histpostprocess.hist_target_order;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_target_order_mode(
+ VL53L1_DEV Dev,
+ VL53L1_HistTargetOrder hist_target_order)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->histpostprocess.hist_target_order = hist_target_order;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_get_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ for (i = 0; i < VL53L1_MAX_AMBIENT_DMAX_VALUES; i++) {
+ pdmax_reflectances->target_reflectance_for_dmax[i] =
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[i];
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_set_dmax_reflectance_values(
+ VL53L1_DEV Dev,
+ VL53L1_dmax_reflectance_array_t *pdmax_reflectances)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ for (i = 0; i < VL53L1_MAX_AMBIENT_DMAX_VALUES; i++) {
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[i] =
+ pdmax_reflectances->target_reflectance_for_dmax[i];
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+VL53L1_Error VL53L1_get_vhv_loopbound(
+ VL53L1_DEV Dev,
+ uint8_t *pvhv_loopbound)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pvhv_loopbound =
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound / 4;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_set_vhv_loopbound(
+ VL53L1_DEV Dev,
+ uint8_t vhv_loopbound)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound =
+ (pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound & 0x03) +
+ (vhv_loopbound * 4);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_get_vhv_config(
+ VL53L1_DEV Dev,
+ uint8_t *pvhv_init_en,
+ uint8_t *pvhv_init_value)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pvhv_init_en = (pdev->stat_nvm.vhv_config__init & 0x80) >> 7;
+ *pvhv_init_value =
+ (pdev->stat_nvm.vhv_config__init & 0x7F);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_set_vhv_config(
+ VL53L1_DEV Dev,
+ uint8_t vhv_init_en,
+ uint8_t vhv_init_value)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->stat_nvm.vhv_config__init =
+ ((vhv_init_en & 0x01) << 7) +
+ (vhv_init_value & 0x7F);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+VL53L1_Error VL53L1_init_and_start_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode,
+ VL53L1_DeviceConfigLevel device_config_level)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ uint8_t buffer[VL53L1_MAX_I2C_XFER_SIZE];
+
+ VL53L1_static_nvm_managed_t *pstatic_nvm = &(pdev->stat_nvm);
+ VL53L1_customer_nvm_managed_t *pcustomer_nvm = &(pdev->customer);
+ VL53L1_static_config_t *pstatic = &(pdev->stat_cfg);
+ VL53L1_general_config_t *pgeneral = &(pdev->gen_cfg);
+ VL53L1_timing_config_t *ptiming = &(pdev->tim_cfg);
+ VL53L1_dynamic_config_t *pdynamic = &(pdev->dyn_cfg);
+ VL53L1_system_control_t *psystem = &(pdev->sys_ctrl);
+
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+ VL53L1_customer_nvm_managed_t *pN = &(pdev->customer);
+
+ uint8_t *pbuffer = &buffer[0];
+ uint16_t i = 0;
+ uint16_t i2c_index = 0;
+ uint16_t i2c_buffer_offset_bytes = 0;
+ uint16_t i2c_buffer_size_bytes = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->measurement_mode = measurement_mode;
+
+
+
+
+ psystem->system__mode_start =
+ (psystem->system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK) |
+ measurement_mode;
+
+
+
+
+
+
+ status =
+ VL53L1_set_user_zone(
+ Dev,
+ &(pdev->zone_cfg.user_zones[pdev->ll_state.cfg_zone_id]));
+
+
+
+
+
+ if (pdev->zone_cfg.active_zones > 0) {
+ status =
+ VL53L1_set_zone_dss_config(
+ Dev,
+ &(pres->zone_dyn_cfgs.VL53L1_p_002[pdev->ll_state.cfg_zone_id])
+ );
+ }
+
+
+
+
+
+
+ if (((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM) == 0x00) &&
+ (pdev->xtalk_cfg.global_crosstalk_compensation_enable
+ == 0x01)) {
+ pdev->stat_cfg.algo__range_ignore_threshold_mcps =
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_rate_mcps;
+ }
+
+
+
+
+
+
+
+
+ if (pdev->low_power_auto_data.low_power_auto_range_count == 0xFF)
+ pdev->low_power_auto_data.low_power_auto_range_count = 0x0;
+
+
+
+ if ((pdev->low_power_auto_data.is_low_power_auto_mode == 1) &&
+ (pdev->low_power_auto_data.low_power_auto_range_count == 0)) {
+
+
+ pdev->low_power_auto_data.saved_interrupt_config =
+ pdev->gen_cfg.system__interrupt_config_gpio;
+
+
+ pdev->gen_cfg.system__interrupt_config_gpio = 1 << 5;
+
+
+ if ((pdev->dyn_cfg.system__sequence_config & (
+ VL53L1_SEQUENCE_MM1_EN | VL53L1_SEQUENCE_MM2_EN)) ==
+ 0x0) {
+ pN->algo__part_to_part_range_offset_mm =
+ (pN->mm_config__outer_offset_mm << 2);
+ } else {
+ pN->algo__part_to_part_range_offset_mm = 0x0;
+ }
+
+
+
+ if (device_config_level <
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS) {
+ device_config_level =
+ VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS;
+ }
+ }
+
+ if ((pdev->low_power_auto_data.is_low_power_auto_mode == 1) &&
+ (pdev->low_power_auto_data.low_power_auto_range_count == 1)) {
+
+
+ pdev->gen_cfg.system__interrupt_config_gpio =
+ pdev->low_power_auto_data.saved_interrupt_config;
+
+
+
+ device_config_level = VL53L1_DEVICECONFIGLEVEL_FULL;
+ }
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_save_cfg_data(Dev);
+
+
+
+
+
+
+ switch (device_config_level) {
+ case VL53L1_DEVICECONFIGLEVEL_FULL:
+ i2c_index = VL53L1_STATIC_NVM_MANAGED_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS:
+ i2c_index = VL53L1_CUSTOMER_NVM_MANAGED_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_STATIC_ONWARDS:
+ i2c_index = VL53L1_STATIC_CONFIG_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS:
+ i2c_index = VL53L1_GENERAL_CONFIG_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_TIMING_ONWARDS:
+ i2c_index = VL53L1_TIMING_CONFIG_I2C_INDEX;
+ break;
+ case VL53L1_DEVICECONFIGLEVEL_DYNAMIC_ONWARDS:
+ i2c_index = VL53L1_DYNAMIC_CONFIG_I2C_INDEX;
+ break;
+ default:
+ i2c_index = VL53L1_SYSTEM_CONTROL_I2C_INDEX;
+ break;
+ }
+
+
+
+
+ i2c_buffer_size_bytes =
+ (VL53L1_SYSTEM_CONTROL_I2C_INDEX +
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES) -
+ i2c_index;
+
+
+
+
+ pbuffer = &buffer[0];
+ for (i = 0; i < i2c_buffer_size_bytes; i++)
+ *pbuffer++ = 0;
+
+
+
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_FULL &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_STATIC_NVM_MANAGED_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_static_nvm_managed(
+ pstatic_nvm,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_customer_nvm_managed(
+ pcustomer_nvm,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_STATIC_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_STATIC_CONFIG_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_static_config(
+ pstatic,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_GENERAL_CONFIG_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_general_config(
+ pgeneral,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_TIMING_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_TIMING_CONFIG_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_timing_config(
+ ptiming,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (device_config_level >= VL53L1_DEVICECONFIGLEVEL_DYNAMIC_ONWARDS &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_DYNAMIC_CONFIG_I2C_INDEX - i2c_index;
+
+
+
+ if ((psystem->system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK) ==
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK) {
+ pdynamic->system__grouped_parameter_hold_0 =
+ pstate->cfg_gph_id | 0x01;
+ pdynamic->system__grouped_parameter_hold_1 =
+ pstate->cfg_gph_id | 0x01;
+ pdynamic->system__grouped_parameter_hold =
+ pstate->cfg_gph_id;
+ }
+ status =
+ VL53L1_i2c_encode_dynamic_config(
+ pdynamic,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_SYSTEM_CONTROL_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_encode_system_control(
+ psystem,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes]);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ i2c_index,
+ buffer,
+ (uint32_t)i2c_buffer_size_bytes);
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_update_ll_driver_rd_state(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_update_ll_driver_cfg_state(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_stop_range(
+ VL53L1_DEV Dev)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ pdev->sys_ctrl.system__mode_start =
+ (pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK) |
+ VL53L1_DEVICEMEASUREMENTMODE_ABORT;
+
+ status = VL53L1_set_system_control(
+ Dev,
+ &pdev->sys_ctrl);
+
+ pdev->sys_ctrl.system__mode_start =
+ (pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK);
+
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_SW_STANDBY);
+
+ V53L1_init_zone_results_structure(
+ pdev->zone_cfg.active_zones+1,
+ &(pres->zone_results));
+
+ V53L1_init_zone_dss_configs(Dev);
+ if (pdev->low_power_auto_data.is_low_power_auto_mode == 1)
+ VL53L1_low_power_auto_data_stop_range(Dev);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_measurement_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_results_level)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t buffer[VL53L1_MAX_I2C_XFER_SIZE];
+
+ VL53L1_system_results_t *psystem_results = &(pdev->sys_results);
+ VL53L1_core_results_t *pcore_results = &(pdev->core_results);
+ VL53L1_debug_results_t *pdebug_results = &(pdev->dbg_results);
+
+ uint16_t i2c_index = VL53L1_SYSTEM_RESULTS_I2C_INDEX;
+ uint16_t i2c_buffer_offset_bytes = 0;
+ uint16_t i2c_buffer_size_bytes = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ switch (device_results_level) {
+ case VL53L1_DEVICERESULTSLEVEL_FULL:
+ i2c_buffer_size_bytes =
+ (VL53L1_DEBUG_RESULTS_I2C_INDEX +
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES) -
+ i2c_index;
+ break;
+ case VL53L1_DEVICERESULTSLEVEL_UPTO_CORE:
+ i2c_buffer_size_bytes =
+ (VL53L1_CORE_RESULTS_I2C_INDEX +
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES) -
+ i2c_index;
+ break;
+ default:
+ i2c_buffer_size_bytes =
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES;
+ break;
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ i2c_index,
+ buffer,
+ (uint32_t)i2c_buffer_size_bytes);
+
+
+
+
+ if (device_results_level >= VL53L1_DEVICERESULTSLEVEL_FULL &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_DEBUG_RESULTS_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_decode_debug_results(
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes],
+ pdebug_results);
+ }
+
+ if (device_results_level >= VL53L1_DEVICERESULTSLEVEL_UPTO_CORE &&
+ status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes =
+ VL53L1_CORE_RESULTS_I2C_INDEX - i2c_index;
+
+ status =
+ VL53L1_i2c_decode_core_results(
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes],
+ pcore_results);
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ i2c_buffer_offset_bytes = 0;
+ status =
+ VL53L1_i2c_decode_system_results(
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ &buffer[i2c_buffer_offset_bytes],
+ psystem_results);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_device_results(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceResultsLevel device_results_level,
+ VL53L1_range_results_t *prange_results)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_range_results_t *presults =
+ &(pres->range_results);
+ VL53L1_zone_objects_t *pobjects =
+ &(pres->zone_results.VL53L1_p_002[0]);
+ VL53L1_ll_driver_state_t *pstate =
+ &(pdev->ll_state);
+ VL53L1_zone_config_t *pzone_cfg =
+ &(pdev->zone_cfg);
+ VL53L1_zone_hist_info_t *phist_info =
+ &(pres->zone_hists.VL53L1_p_002[0]);
+
+ VL53L1_dmax_calibration_data_t dmax_cal;
+ VL53L1_dmax_calibration_data_t *pdmax_cal = &dmax_cal;
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg);
+ VL53L1_low_power_auto_data_t *pL = &(pdev->low_power_auto_data);
+ VL53L1_histogram_bin_data_t *pHD = &(pdev->hist_data);
+ VL53L1_customer_nvm_managed_t *pN = &(pdev->customer);
+ VL53L1_zone_histograms_t *pZH = &(pres->zone_hists);
+ VL53L1_xtalk_calibration_results_t *pXCR = &(pdev->xtalk_cal);
+ uint8_t tmp8;
+ uint8_t zid;
+ uint8_t i;
+ uint8_t histo_merge_nb;
+ VL53L1_range_data_t *pdata;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if ((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM)
+ == VL53L1_DEVICESCHEDULERMODE_HISTOGRAM) {
+
+
+
+
+
+
+ status = VL53L1_get_histogram_bin_data(
+ Dev,
+ &(pdev->hist_data));
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE &&
+ pHD->number_of_ambient_bins == 0) {
+ zid = pdev->ll_state.rd_zone_id;
+ status = VL53L1_hist_copy_and_scale_ambient_info(
+ &(pZH->VL53L1_p_002[zid]),
+ &(pdev->hist_data));
+ }
+
+
+
+
+
+
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+
+ VL53L1_compute_histo_merge_nb(Dev, &histo_merge_nb);
+ if (histo_merge_nb == 0)
+ histo_merge_nb = 1;
+ pC->algo__crosstalk_compensation_plane_offset_kcps =
+ pXCR->algo__xtalk_cpo_HistoMerge_kcps[histo_merge_nb-1];
+
+ pHP->gain_factor =
+ pdev->gain_cal.histogram_ranging_gain_factor;
+
+ pHP->algo__crosstalk_compensation_plane_offset_kcps =
+ VL53L1_calc_crosstalk_plane_offset_with_margin(
+ pC->algo__crosstalk_compensation_plane_offset_kcps,
+ pC->histogram_mode_crosstalk_margin_kcps);
+
+ pHP->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pHP->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+ pdev->dmax_cfg.ambient_thresh_sigma =
+ pHP->ambient_thresh_sigma1;
+ pdev->dmax_cfg.min_ambient_thresh_events =
+ pHP->min_ambient_thresh_events;
+ pdev->dmax_cfg.signal_total_events_limit =
+ pHP->signal_total_events_limit;
+ pdev->dmax_cfg.dss_config__target_total_rate_mcps =
+ pdev->stat_cfg.dss_config__target_total_rate_mcps;
+ pdev->dmax_cfg.dss_config__aperture_attenuation =
+ pdev->gen_cfg.dss_config__aperture_attenuation;
+
+ pHP->algo__crosstalk_detect_max_valid_range_mm =
+ pC->algo__crosstalk_detect_max_valid_range_mm;
+ pHP->algo__crosstalk_detect_min_valid_range_mm =
+ pC->algo__crosstalk_detect_min_valid_range_mm;
+ pHP->algo__crosstalk_detect_max_valid_rate_kcps =
+ pC->algo__crosstalk_detect_max_valid_rate_kcps;
+ pHP->algo__crosstalk_detect_max_sigma_mm =
+ pC->algo__crosstalk_detect_max_sigma_mm;
+
+
+
+
+ VL53L1_copy_rtn_good_spads_to_buffer(
+ &(pdev->nvm_copy_data),
+ &(pdev->rtn_good_spads[0]));
+
+
+
+
+ switch (pdev->offset_correction_mode) {
+
+ case VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS:
+ tmp8 = pdev->gen_cfg.dss_config__aperture_attenuation;
+
+ VL53L1_hist_combine_mm1_mm2_offsets(
+ pN->mm_config__inner_offset_mm,
+ pN->mm_config__outer_offset_mm,
+ pdev->nvm_copy_data.roi_config__mode_roi_centre_spad,
+ pdev->nvm_copy_data.roi_config__mode_roi_xy_size,
+ pHD->roi_config__user_roi_centre_spad,
+ pHD->roi_config__user_roi_requested_global_xy_size,
+ &(pdev->add_off_cal_data),
+ &(pdev->rtn_good_spads[0]),
+ (uint16_t)tmp8,
+ &(pHP->range_offset_mm));
+ break;
+ case VL53L1_OFFSETCORRECTIONMODE__PER_ZONE_OFFSETS:
+ zid = pdev->ll_state.rd_zone_id;
+ pHP->range_offset_mm = (int16_t)(
+ pres->zone_cal.VL53L1_p_002[zid].range_mm_offset);
+ break;
+ case VL53L1_OFFSETCORRECTIONMODE__PER_VCSEL_OFFSETS:
+ select_offset_per_vcsel(
+ pdev,
+ &(pHP->range_offset_mm));
+ pHP->range_offset_mm *= 4;
+
+ break;
+ default:
+ pHP->range_offset_mm = 0;
+ break;
+
+ }
+ #if 0
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+ #endif
+
+ VL53L1_calc_max_effective_spads(
+ pHD->roi_config__user_roi_centre_spad,
+ pHD->roi_config__user_roi_requested_global_xy_size,
+ &(pdev->rtn_good_spads[0]),
+ (uint16_t)pdev->gen_cfg.dss_config__aperture_attenuation,
+ &(pdev->dmax_cfg.max_effective_spads));
+
+ status =
+ VL53L1_get_dmax_calibration_data(
+ Dev,
+ pdev->dmax_mode,
+ pdev->ll_state.rd_zone_id,
+ pdmax_cal);
+
+
+
+
+
+
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+
+ status = VL53L1_ipp_hist_process_data(
+ Dev,
+ pdmax_cal,
+ &(pdev->dmax_cfg),
+ &(pdev->histpostprocess),
+ &(pdev->hist_data),
+ &(pdev->xtalk_shapes),
+ pdev->wArea1,
+ pdev->wArea2,
+ &histo_merge_nb,
+ presults);
+
+
+ if ((pdev->tuning_parms.tp_hist_merge == 1) &&
+ (histo_merge_nb > 1))
+ for (i = 0; i < VL53L1_MAX_RANGE_RESULTS; i++) {
+ pdata = &(presults->VL53L1_p_002[i]);
+ pdata->VL53L1_p_020 /= histo_merge_nb;
+ pdata->VL53L1_p_021 /= histo_merge_nb;
+ pdata->VL53L1_p_013 /= histo_merge_nb;
+ pdata->peak_signal_count_rate_mcps /= histo_merge_nb;
+ pdata->avg_signal_count_rate_mcps /= histo_merge_nb;
+ pdata->ambient_count_rate_mcps /= histo_merge_nb;
+ pdata->VL53L1_p_012 /= histo_merge_nb;
+ }
+
+
+
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+
+ status = VL53L1_hist_wrap_dmax(
+ &(pdev->histpostprocess),
+ &(pdev->hist_data),
+ &(presults->wrap_dmax_mm));
+
+
+
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+
+ zid = pdev->ll_state.rd_zone_id;
+ status = VL53L1_hist_phase_consistency_check(
+ Dev,
+ &(pZH->VL53L1_p_002[zid]),
+ &(pres->zone_results.VL53L1_p_002[zid]),
+ presults);
+
+
+
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+
+ zid = pdev->ll_state.rd_zone_id;
+ status = VL53L1_hist_xmonitor_consistency_check(
+ Dev,
+ &(pZH->VL53L1_p_002[zid]),
+ &(pres->zone_results.VL53L1_p_002[zid]),
+ &(presults->xmonitor));
+
+
+
+
+
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+
+
+ zid = pdev->ll_state.rd_zone_id;
+ pZH->max_zones = VL53L1_MAX_USER_ZONES;
+ pZH->active_zones =
+ pdev->zone_cfg.active_zones+1;
+ pHD->zone_id = zid;
+
+ if (zid <
+ pres->zone_results.max_zones) {
+
+ phist_info =
+ &(pZH->VL53L1_p_002[zid]);
+
+ phist_info->rd_device_state =
+ pHD->rd_device_state;
+
+ phist_info->number_of_ambient_bins =
+ pHD->number_of_ambient_bins;
+
+ phist_info->result__dss_actual_effective_spads =
+ pHD->result__dss_actual_effective_spads;
+
+ phist_info->VL53L1_p_009 =
+ pHD->VL53L1_p_009;
+
+ phist_info->total_periods_elapsed =
+ pHD->total_periods_elapsed;
+
+ phist_info->ambient_events_sum =
+ pHD->ambient_events_sum;
+ }
+
+
+
+
+
+ /*
+ if (status != VL53L1_ERROR_NONE)
+ goto UPDATE_DYNAMIC_CONFIG;
+ */
+ VL53L1_hist_copy_results_to_sys_and_core(
+ &(pdev->hist_data),
+ presults,
+ &(pdev->sys_results),
+ &(pdev->core_results));
+
+
+
+
+
+
+UPDATE_DYNAMIC_CONFIG:
+ if (pzone_cfg->active_zones > 0) {
+ if (pstate->rd_device_state !=
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) {
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_dynamic_zone_update(
+ Dev, presults);
+ }
+ }
+
+
+
+
+
+ for (i = 0; i < VL53L1_MAX_USER_ZONES; i++) {
+ pzone_cfg->bin_config[i] =
+ ((pdev->ll_state.cfg_internal_stream_count)
+ & 0x01) ?
+ VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB :
+ VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
+ }
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_multizone_hist_bins_update(Dev);
+
+ }
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_dynamic_xtalk_correction_corrector(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_histogram_bin_data(
+ &(pdev->hist_data),
+ "get_device_results():pdev->lldata.hist_data.",
+ VL53L1_TRACE_MODULE_HISTOGRAM_DATA);
+#endif
+
+ } else {
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_get_measurement_results(
+ Dev,
+ device_results_level);
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_copy_sys_and_core_results_to_range_results(
+ (int32_t)pdev->gain_cal.standard_ranging_gain_factor,
+ &(pdev->sys_results),
+ &(pdev->core_results),
+ presults);
+
+
+
+
+
+ if (pL->is_low_power_auto_mode == 1) {
+
+
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (pL->low_power_auto_range_count == 0)) {
+
+ status =
+ VL53L1_low_power_auto_setup_manual_calibration(
+ Dev);
+ pL->low_power_auto_range_count = 1;
+ } else if ((status == VL53L1_ERROR_NONE) &&
+ (pL->low_power_auto_range_count == 1)) {
+ pL->low_power_auto_range_count = 2;
+ }
+
+
+
+ if ((pL->low_power_auto_range_count != 0xFF) &&
+ (status == VL53L1_ERROR_NONE)) {
+ status = VL53L1_low_power_auto_update_DSS(
+ Dev);
+ }
+ }
+
+
+ }
+
+
+
+ presults->cfg_device_state = pdev->ll_state.cfg_device_state;
+ presults->rd_device_state = pdev->ll_state.rd_device_state;
+ presults->zone_id = pdev->ll_state.rd_zone_id;
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+ pres->zone_results.max_zones = VL53L1_MAX_USER_ZONES;
+ pres->zone_results.active_zones = pdev->zone_cfg.active_zones+1;
+ zid = pdev->ll_state.rd_zone_id;
+
+ if (zid < pres->zone_results.max_zones) {
+
+ pobjects =
+ &(pres->zone_results.VL53L1_p_002[zid]);
+
+ pobjects->cfg_device_state =
+ presults->cfg_device_state;
+ pobjects->rd_device_state = presults->rd_device_state;
+ pobjects->zone_id = presults->zone_id;
+ pobjects->stream_count = presults->stream_count;
+
+
+
+
+ pobjects->xmonitor.VL53L1_p_020 =
+ presults->xmonitor.VL53L1_p_020;
+ pobjects->xmonitor.VL53L1_p_021 =
+ presults->xmonitor.VL53L1_p_021;
+ pobjects->xmonitor.VL53L1_p_014 =
+ presults->xmonitor.VL53L1_p_014;
+ pobjects->xmonitor.range_status =
+ presults->xmonitor.range_status;
+
+ pobjects->max_objects = presults->max_results;
+ pobjects->active_objects = presults->active_results;
+
+ for (i = 0; i < presults->active_results; i++) {
+ pobjects->VL53L1_p_002[i].VL53L1_p_020 =
+ presults->VL53L1_p_002[i].VL53L1_p_020;
+ pobjects->VL53L1_p_002[i].VL53L1_p_021 =
+ presults->VL53L1_p_002[i].VL53L1_p_021;
+ pobjects->VL53L1_p_002[i].VL53L1_p_014 =
+ presults->VL53L1_p_002[i].VL53L1_p_014;
+ pobjects->VL53L1_p_002[i].range_status =
+ presults->VL53L1_p_002[i].range_status;
+ }
+
+
+
+ }
+ }
+
+
+
+
+ memcpy(
+ prange_results,
+ presults,
+ sizeof(VL53L1_range_results_t));
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_check_ll_driver_rd_state(Dev);
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_range_results(
+ presults,
+ "get_device_results():pdev->llresults.range_results.",
+ VL53L1_TRACE_MODULE_RANGE_RESULTS_DATA);
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_clear_interrupt_and_enable_next_range(
+ VL53L1_DEV Dev,
+ uint8_t measurement_mode)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_init_and_start_range(
+ Dev,
+ measurement_mode,
+ VL53L1_DEVICECONFIGLEVEL_GENERAL_ONWARDS);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_histogram_bin_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg;
+
+ VL53L1_static_nvm_managed_t *pstat_nvm = &(pdev->stat_nvm);
+ VL53L1_static_config_t *pstat_cfg = &(pdev->stat_cfg);
+ VL53L1_general_config_t *pgen_cfg = &(pdev->gen_cfg);
+ VL53L1_timing_config_t *ptim_cfg = &(pdev->tim_cfg);
+ VL53L1_range_results_t *presults = &(pres->range_results);
+
+ uint8_t buffer[VL53L1_MAX_I2C_XFER_SIZE];
+ uint8_t *pbuffer = &buffer[0];
+ uint8_t bin_23_0 = 0x00;
+ uint16_t bin = 0;
+ uint16_t i2c_buffer_offset_bytes = 0;
+ uint16_t encoded_timeout = 0;
+
+ uint32_t pll_period_us = 0;
+ uint32_t periods_elapsed_tmp = 0;
+
+ uint8_t i = 0;
+ int32_t hist_merge = 0;
+ int32_t TuningBinRecSize = 0;
+ uint8_t recom_been_reset = 0;
+ uint8_t timing = 0;
+ int32_t rmt = 0;
+
+ int32_t diff_histo_stddev = 0;
+ int32_t total_rate_pre = 0;
+ int32_t total_rate_cur = 0;
+ uint8_t HighIndex, prev_pos;
+ int32_t PrevBin, CurrBin;
+ size_t copylength;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX,
+ pbuffer,
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_SIZE_BYTES);
+
+
+
+
+
+
+ pdata->result__interrupt_status = *(pbuffer + 0);
+ pdata->result__range_status = *(pbuffer + 1);
+ pdata->result__report_status = *(pbuffer + 2);
+ pdata->result__stream_count = *(pbuffer + 3);
+ pdata->result__dss_actual_effective_spads =
+ VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
+
+
+
+
+
+
+ i2c_buffer_offset_bytes =
+ VL53L1_PHASECAL_RESULT__REFERENCE_PHASE -
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ pbuffer = &buffer[i2c_buffer_offset_bytes];
+
+ pdata->phasecal_result__reference_phase =
+ VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ i2c_buffer_offset_bytes =
+ VL53L1_PHASECAL_RESULT__VCSEL_START -
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ pdata->phasecal_result__vcsel_start = buffer[i2c_buffer_offset_bytes];
+
+
+
+
+ pdev->dbg_results.phasecal_result__reference_phase =
+ pdata->phasecal_result__reference_phase;
+ pdev->dbg_results.phasecal_result__vcsel_start =
+ pdata->phasecal_result__vcsel_start;
+
+
+
+
+
+
+
+ i2c_buffer_offset_bytes =
+ VL53L1_RESULT__HISTOGRAM_BIN_23_0_MSB -
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ bin_23_0 = buffer[i2c_buffer_offset_bytes] << 2;
+
+ i2c_buffer_offset_bytes =
+ VL53L1_RESULT__HISTOGRAM_BIN_23_0_LSB -
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ bin_23_0 += buffer[i2c_buffer_offset_bytes];
+
+ i2c_buffer_offset_bytes =
+ VL53L1_RESULT__HISTOGRAM_BIN_23_0 -
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ buffer[i2c_buffer_offset_bytes] = bin_23_0;
+
+
+
+
+
+
+
+ i2c_buffer_offset_bytes =
+ VL53L1_RESULT__HISTOGRAM_BIN_0_2 -
+ VL53L1_HISTOGRAM_BIN_DATA_I2C_INDEX;
+
+ pbuffer = &buffer[i2c_buffer_offset_bytes];
+ for (bin = 0; bin < VL53L1_HISTOGRAM_BUFFER_SIZE; bin++) {
+ pdata->bin_data[bin] =
+ (int32_t)VL53L1_i2c_decode_uint32_t(3, pbuffer);
+ pbuffer += 3;
+ }
+
+
+
+
+
+
+
+
+
+
+ VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE,
+ &hist_merge);
+
+ VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE,
+ &TuningBinRecSize);
+
+ VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_RESET_MERGE_THRESHOLD, &rmt);
+
+ if (pdata->result__stream_count == 0) {
+
+
+ memset(pdev->multi_bins_rec, 0, sizeof(pdev->multi_bins_rec));
+ pdev->bin_rec_pos = 0;
+ pdev->pos_before_next_recom = 0;
+ }
+
+ if (hist_merge == 1) {
+
+
+
+
+
+
+
+
+ if (pdev->pos_before_next_recom == 0) {
+
+
+ timing = 1 - pdata->result__stream_count % 2;
+
+
+
+
+
+ diff_histo_stddev = 0;
+ total_rate_pre = 0;
+ total_rate_cur = 0;
+ HighIndex = VL53L1_HISTOGRAM_BUFFER_SIZE - timing * 4;
+ if (pdev->bin_rec_pos > 0)
+ prev_pos = pdev->bin_rec_pos - 1;
+ else
+ prev_pos = (TuningBinRecSize - 1);
+
+ if (pdev->multi_bins_rec[prev_pos][timing][4] > 0) {
+
+
+ for (bin = timing * 4; bin < HighIndex; bin++) {
+ total_rate_pre +=
+ pdev->multi_bins_rec[prev_pos][timing][bin];
+ total_rate_cur += pdata->bin_data[bin];
+ }
+
+ if ((total_rate_pre != 0) && (total_rate_cur != 0))
+ for (bin = timing * 4; bin < HighIndex; bin++) {
+ PrevBin = pdev->multi_bins_rec[prev_pos][timing][bin];
+ PrevBin = (PrevBin * 1000) / total_rate_pre;
+ CurrBin = pdata->bin_data[bin] * 1000 / total_rate_cur;
+ diff_histo_stddev += (PrevBin - CurrBin) *
+ (PrevBin - CurrBin);
+ }
+ }
+
+ if (diff_histo_stddev >= rmt) {
+ memset(pdev->multi_bins_rec, 0, sizeof(pdev->multi_bins_rec));
+ pdev->bin_rec_pos = 0;
+
+
+ recom_been_reset = 1;
+
+
+
+
+
+
+
+ if (timing == 0)
+ pdev->pos_before_next_recom = VL53L1_FRAME_WAIT_EVENT;
+ else
+ pdev->pos_before_next_recom = VL53L1_FRAME_WAIT_EVENT + 1;
+ } else {
+
+
+
+
+
+ copylength =
+ sizeof(pdev->multi_bins_rec[pdev->bin_rec_pos][timing]);
+ memcpy(&(pdev->multi_bins_rec[pdev->bin_rec_pos][timing]),
+ pdata->bin_data, copylength);
+ }
+
+
+
+
+
+
+
+ if (pdev->bin_rec_pos == (TuningBinRecSize - 1) && timing == 1)
+ pdev->bin_rec_pos = 0;
+ else if (timing == 1)
+ pdev->bin_rec_pos++;
+
+
+
+
+
+
+
+
+ if (!((recom_been_reset == 1) && (timing == 0)) &&
+ (pdev->pos_before_next_recom == 0)) {
+
+
+
+
+ for (bin = 0; bin < VL53L1_HISTOGRAM_BUFFER_SIZE; bin++)
+ pdata->bin_data[bin] = 0;
+
+
+
+
+ for (bin = 0; bin < VL53L1_HISTOGRAM_BUFFER_SIZE; bin++)
+ for (i = 0; i < TuningBinRecSize; i++)
+ pdata->bin_data[bin] +=
+ (pdev->multi_bins_rec[i][timing][bin]);
+ }
+ } else {
+
+
+
+
+
+ pdev->pos_before_next_recom--;
+ if (pdev->pos_before_next_recom == 255)
+ pdev->pos_before_next_recom = 0;
+ }
+ }
+
+
+
+ pdata->zone_id = pdev->ll_state.rd_zone_id;
+ pdata->VL53L1_p_022 = 0;
+ pdata->VL53L1_p_023 = VL53L1_HISTOGRAM_BUFFER_SIZE;
+ pdata->VL53L1_p_024 = VL53L1_HISTOGRAM_BUFFER_SIZE;
+
+ pdata->cal_config__vcsel_start = pgen_cfg->cal_config__vcsel_start;
+
+
+
+
+ pdata->vcsel_width =
+ ((uint16_t)pgen_cfg->global_config__vcsel_width) << 4;
+ pdata->vcsel_width +=
+ (uint16_t)pstat_cfg->ana_config__vcsel_pulse_width_offset;
+
+
+
+ pdata->VL53L1_p_019 =
+ pstat_nvm->osc_measured__fast_osc__frequency;
+
+
+
+
+ VL53L1_hist_get_bin_sequence_config(Dev, pdata);
+
+
+
+
+
+
+ if (pdev->ll_state.rd_timing_status == 0) {
+
+ encoded_timeout =
+ (ptim_cfg->range_config__timeout_macrop_a_hi << 8)
+ + ptim_cfg->range_config__timeout_macrop_a_lo;
+ pdata->VL53L1_p_009 = ptim_cfg->range_config__vcsel_period_a;
+ } else {
+
+ encoded_timeout =
+ (ptim_cfg->range_config__timeout_macrop_b_hi << 8)
+ + ptim_cfg->range_config__timeout_macrop_b_lo;
+ pdata->VL53L1_p_009 = ptim_cfg->range_config__vcsel_period_b;
+ }
+
+
+
+
+ pdata->number_of_ambient_bins = 0;
+
+ for (i = 0; i < 6; i++) {
+ if ((pdata->bin_seq[i] & 0x07) == 0x07)
+ pdata->number_of_ambient_bins =
+ pdata->number_of_ambient_bins + 0x04;
+ }
+
+ pdata->total_periods_elapsed =
+ VL53L1_decode_timeout(encoded_timeout);
+
+
+
+
+
+
+
+ pll_period_us =
+ VL53L1_calc_pll_period_us(pdata->VL53L1_p_019);
+
+
+
+
+ periods_elapsed_tmp = pdata->total_periods_elapsed + 1;
+
+
+
+
+
+
+ pdata->peak_duration_us =
+ VL53L1_duration_maths(
+ pll_period_us,
+ (uint32_t)pdata->vcsel_width,
+ VL53L1_RANGING_WINDOW_VCSEL_PERIODS,
+ periods_elapsed_tmp);
+
+ pdata->woi_duration_us = 0;
+
+
+
+
+ VL53L1_hist_calc_zero_distance_phase(pdata);
+
+
+
+
+
+
+ VL53L1_hist_estimate_ambient_from_ambient_bins(pdata);
+
+
+
+
+ pdata->cfg_device_state = pdev->ll_state.cfg_device_state;
+ pdata->rd_device_state = pdev->ll_state.rd_device_state;
+
+
+
+
+ pzone_dyn_cfg = &(pres->zone_dyn_cfgs.VL53L1_p_002[pdata->zone_id]);
+
+ pdata->roi_config__user_roi_centre_spad =
+ pzone_dyn_cfg->roi_config__user_roi_centre_spad;
+ pdata->roi_config__user_roi_requested_global_xy_size =
+ pzone_dyn_cfg->roi_config__user_roi_requested_global_xy_size;
+
+
+
+
+
+
+ presults->device_status = VL53L1_DEVICEERROR_NOUPDATE;
+
+
+
+
+ switch (pdata->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK) {
+
+ case VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE:
+ case VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE:
+ case VL53L1_DEVICEERROR_NOVHVVALUEFOUND:
+ case VL53L1_DEVICEERROR_USERROICLIP:
+ case VL53L1_DEVICEERROR_MULTCLIPFAIL:
+
+ presults->device_status = (pdata->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK);
+
+ status = VL53L1_ERROR_RANGE_ERROR;
+
+ break;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_copy_sys_and_core_results_to_range_results(
+ int32_t gain_factor,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore,
+ VL53L1_range_results_t *presults)
+{
+ uint8_t i = 0;
+
+ VL53L1_range_data_t *pdata;
+ int32_t range_mm = 0;
+ uint32_t tmpu32 = 0;
+ uint16_t rpscr_crosstalk_corrected_mcps_sd0;
+ uint16_t rmmo_effective_spads_sd0;
+ uint16_t rmmi_effective_spads_sd0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ presults->zone_id = 0;
+ presults->stream_count = psys->result__stream_count;
+ presults->wrap_dmax_mm = 0;
+ presults->max_results = VL53L1_MAX_RANGE_RESULTS;
+ presults->active_results = 1;
+ rpscr_crosstalk_corrected_mcps_sd0 =
+ psys->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0;
+ rmmo_effective_spads_sd0 =
+ psys->result__mm_outer_actual_effective_spads_sd0;
+ rmmi_effective_spads_sd0 =
+ psys->result__mm_inner_actual_effective_spads_sd0;
+
+
+ for (i = 0; i < VL53L1_MAX_AMBIENT_DMAX_VALUES; i++)
+ presults->VL53L1_p_007[i] = 0;
+
+ pdata = &(presults->VL53L1_p_002[0]);
+
+ for (i = 0; i < 2; i++) {
+
+ pdata->range_id = i;
+ pdata->time_stamp = 0;
+
+ if ((psys->result__stream_count == 0) &&
+ ((psys->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK) ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE)) {
+ pdata->range_status =
+ VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK;
+ } else {
+ pdata->range_status =
+ psys->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK;
+ }
+
+ pdata->VL53L1_p_015 = 0;
+ pdata->VL53L1_p_022 = 0;
+ pdata->VL53L1_p_025 = 0;
+ pdata->VL53L1_p_026 = 0;
+ pdata->VL53L1_p_016 = 0;
+ pdata->VL53L1_p_027 = 0;
+
+ switch (i) {
+
+ case 0:
+ if (psys->result__report_status ==
+ VL53L1_DEVICEREPORTSTATUS_MM1)
+ pdata->VL53L1_p_006 =
+ rmmi_effective_spads_sd0;
+ else if (psys->result__report_status ==
+ VL53L1_DEVICEREPORTSTATUS_MM2)
+ pdata->VL53L1_p_006 =
+ rmmo_effective_spads_sd0;
+ else
+ pdata->VL53L1_p_006 =
+ psys->result__dss_actual_effective_spads_sd0;
+
+ pdata->peak_signal_count_rate_mcps =
+ rpscr_crosstalk_corrected_mcps_sd0;
+ pdata->avg_signal_count_rate_mcps =
+ psys->result__avg_signal_count_rate_mcps_sd0;
+ pdata->ambient_count_rate_mcps =
+ psys->result__ambient_count_rate_mcps_sd0;
+
+
+
+
+
+
+ tmpu32 = ((uint32_t)psys->result__sigma_sd0 << 5);
+ if (tmpu32 > 0xFFFF)
+ tmpu32 = 0xFFFF;
+
+ pdata->VL53L1_p_005 = (uint16_t)tmpu32;
+
+
+
+
+ pdata->VL53L1_p_014 =
+ psys->result__phase_sd0;
+
+ range_mm = (int32_t)(
+ psys->result__final_crosstalk_corrected_range_mm_sd0);
+
+
+
+ range_mm *= gain_factor;
+ range_mm += 0x0400;
+ range_mm /= 0x0800;
+
+ pdata->median_range_mm = (int16_t)range_mm;
+
+ pdata->VL53L1_p_021 =
+ pcore->result_core__ranging_total_events_sd0;
+ pdata->VL53L1_p_013 =
+ pcore->result_core__signal_total_events_sd0;
+ pdata->total_periods_elapsed =
+ pcore->result_core__total_periods_elapsed_sd0;
+ pdata->VL53L1_p_020 =
+ pcore->result_core__ambient_window_events_sd0;
+
+ break;
+ case 1:
+
+ pdata->VL53L1_p_006 =
+ psys->result__dss_actual_effective_spads_sd1;
+ pdata->peak_signal_count_rate_mcps =
+ psys->result__peak_signal_count_rate_mcps_sd1;
+ pdata->avg_signal_count_rate_mcps =
+ 0xFFFF;
+ pdata->ambient_count_rate_mcps =
+ psys->result__ambient_count_rate_mcps_sd1;
+
+
+
+
+
+
+ tmpu32 = ((uint32_t)psys->result__sigma_sd1 << 5);
+ if (tmpu32 > 0xFFFF)
+ tmpu32 = 0xFFFF;
+
+ pdata->VL53L1_p_005 = (uint16_t)tmpu32;
+
+
+
+
+ pdata->VL53L1_p_014 =
+ psys->result__phase_sd1;
+
+ range_mm = (int32_t)(
+ psys->result__final_crosstalk_corrected_range_mm_sd1);
+
+
+
+ range_mm *= gain_factor;
+ range_mm += 0x0400;
+ range_mm /= 0x0800;
+
+ pdata->median_range_mm = (int16_t)range_mm;
+
+ pdata->VL53L1_p_021 =
+ pcore->result_core__ranging_total_events_sd1;
+ pdata->VL53L1_p_013 =
+ pcore->result_core__signal_total_events_sd1;
+ pdata->total_periods_elapsed =
+ pcore->result_core__total_periods_elapsed_sd1;
+ pdata->VL53L1_p_020 =
+ pcore->result_core__ambient_window_events_sd1;
+
+ break;
+ }
+
+
+
+
+
+ pdata->VL53L1_p_028 = pdata->VL53L1_p_014;
+ pdata->VL53L1_p_029 = pdata->VL53L1_p_014;
+ pdata->min_range_mm = pdata->median_range_mm;
+ pdata->max_range_mm = pdata->median_range_mm;
+
+ pdata++;
+ }
+
+
+
+
+
+
+ presults->device_status = VL53L1_DEVICEERROR_NOUPDATE;
+
+
+
+
+
+
+
+
+ switch (psys->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK) {
+
+ case VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE:
+ case VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE:
+ case VL53L1_DEVICEERROR_NOVHVVALUEFOUND:
+ case VL53L1_DEVICEERROR_USERROICLIP:
+ case VL53L1_DEVICEERROR_MULTCLIPFAIL:
+
+ presults->device_status = (psys->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK);
+
+ presults->VL53L1_p_002[0].range_status =
+ VL53L1_DEVICEERROR_NOUPDATE;
+ break;
+
+ }
+
+ LOG_FUNCTION_END(0);
+}
+
+
+VL53L1_Error VL53L1_set_zone_dss_config(
+ VL53L1_DEV Dev,
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+
+ LOG_FUNCTION_START("");
+
+ if (pstate->cfg_device_state ==
+ VL53L1_DEVICESTATE_RANGING_DSS_MANUAL) {
+ pdev->gen_cfg.dss_config__roi_mode_control =
+ VL53L1_DSS_CONTROL__MODE_EFFSPADS;
+ pdev->gen_cfg.dss_config__manual_effective_spads_select =
+ pzone_dyn_cfg->dss_requested_effective_spad_count;
+ } else {
+ pdev->gen_cfg.dss_config__roi_mode_control =
+ VL53L1_DSS_CONTROL__MODE_TARGET_RATE;
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_calc_ambient_dmax(
+ VL53L1_DEV Dev,
+ uint16_t target_reflectance,
+ int16_t *pambient_dmax_mm)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_dmax_calibration_data_t dmax_cal;
+ VL53L1_dmax_calibration_data_t *pdmax_cal = &dmax_cal;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status =
+ VL53L1_get_dmax_calibration_data(
+ Dev,
+ pdev->debug_mode,
+ pdev->ll_state.rd_zone_id,
+ pdmax_cal);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ipp_hist_ambient_dmax(
+ Dev,
+ target_reflectance,
+ &(pdev->fmt_dmax_cal),
+ &(pdev->dmax_cfg),
+ &(pdev->hist_data),
+ pambient_dmax_mm);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_distance,
+ VL53L1_GPIO_Interrupt_Mode intr_mode_rate,
+ uint8_t intr_new_measure_ready,
+ uint8_t intr_no_target,
+ uint8_t intr_combined_mode,
+ uint16_t thresh_distance_high,
+ uint16_t thresh_distance_low,
+ uint16_t thresh_rate_high,
+ uint16_t thresh_rate_low
+ )
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_GPIO_interrupt_config_t *pintconf =
+ &(pdev->gpio_interrupt_config);
+
+ LOG_FUNCTION_START("");
+
+
+
+ pintconf->intr_mode_distance = intr_mode_distance;
+ pintconf->intr_mode_rate = intr_mode_rate;
+ pintconf->intr_new_measure_ready = intr_new_measure_ready;
+ pintconf->intr_no_target = intr_no_target;
+ pintconf->intr_combined_mode = intr_combined_mode;
+ pintconf->threshold_distance_high = thresh_distance_high;
+ pintconf->threshold_distance_low = thresh_distance_low;
+ pintconf->threshold_rate_high = thresh_rate_high;
+ pintconf->threshold_rate_low = thresh_rate_low;
+
+
+
+ pdev->gen_cfg.system__interrupt_config_gpio =
+ VL53L1_encode_GPIO_interrupt_config(pintconf);
+
+
+
+
+ status = VL53L1_set_GPIO_thresholds_from_struct(
+ Dev,
+ pintconf);
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_interrupt_config_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t intconf)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_GPIO_interrupt_config_t *pintconf =
+ &(pdev->gpio_interrupt_config);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(pintconf, &(intconf), sizeof(VL53L1_GPIO_interrupt_config_t));
+
+
+
+ pdev->gen_cfg.system__interrupt_config_gpio =
+ VL53L1_encode_GPIO_interrupt_config(pintconf);
+
+
+
+ status = VL53L1_set_GPIO_thresholds_from_struct(
+ Dev,
+ pintconf);
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_GPIO_interrupt_config(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pdev->gpio_interrupt_config = VL53L1_decode_GPIO_interrupt_config(
+ pdev->gen_cfg.system__interrupt_config_gpio);
+
+
+
+
+
+ pdev->gpio_interrupt_config.threshold_distance_high =
+ pdev->dyn_cfg.system__thresh_high;
+ pdev->gpio_interrupt_config.threshold_distance_low =
+ pdev->dyn_cfg.system__thresh_low;
+
+ pdev->gpio_interrupt_config.threshold_rate_high =
+ pdev->gen_cfg.system__thresh_rate_high;
+ pdev->gpio_interrupt_config.threshold_rate_low =
+ pdev->gen_cfg.system__thresh_rate_low;
+
+ if (pintconf == &(pdev->gpio_interrupt_config)) {
+
+
+ } else {
+
+
+
+ memcpy(pintconf, &(pdev->gpio_interrupt_config),
+ sizeof(VL53L1_GPIO_interrupt_config_t));
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->dmax_mode = dmax_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_dmax_mode(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode *pdmax_mode)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *pdmax_mode = pdev->dmax_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_dmax_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceDmaxMode dmax_mode,
+ uint8_t zone_id,
+ VL53L1_dmax_calibration_data_t *pdmax_cal)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ switch (dmax_mode) {
+
+ case VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA:
+ pdmax_cal->ref__actual_effective_spads =
+ (uint16_t)pres->zone_cal.VL53L1_p_002[zone_id].effective_spads;
+ pdmax_cal->ref__peak_signal_count_rate_mcps =
+ (uint16_t)pres->zone_cal.VL53L1_p_002[zone_id].peak_rate_mcps;
+ pdmax_cal->ref__distance_mm =
+ pres->zone_cal.cal_distance_mm;
+ pdmax_cal->ref_reflectance_pc =
+ pres->zone_cal.cal_reflectance_pc;
+ pdmax_cal->coverglass_transmission = 0x0100;
+ break;
+
+ case VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA:
+ memcpy(
+ pdmax_cal,
+ &(pdev->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+ break;
+
+ case VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA:
+ memcpy(
+ pdmax_cal,
+ &(pdev->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+ break;
+
+ default:
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ &(pdev->dmax_cfg),
+ pdmax_cfg,
+ sizeof(VL53L1_hist_gen3_dmax_config_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_hist_dmax_config(
+ VL53L1_DEV Dev,
+ VL53L1_hist_gen3_dmax_config_t *pdmax_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ pdmax_cfg,
+ &(pdev->dmax_cfg),
+ sizeof(VL53L1_hist_gen3_dmax_config_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode offset_cal_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->offset_calibration_mode = offset_cal_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_offset_calibration_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCalibrationMode *poffset_cal_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *poffset_cal_mode = pdev->offset_calibration_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionMode offset_cor_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->offset_correction_mode = offset_cor_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_offset_correction_mode(
+ VL53L1_DEV Dev,
+ VL53L1_OffsetCorrectionMode *poffset_cor_mode)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ *poffset_cor_mode = pdev->offset_correction_mode;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_set_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverResults_t *pres = VL53L1DevStructGetLLResultsHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ if (pzone_cal->struct_version !=
+ VL53L1_LL_ZONE_CALIBRATION_DATA_STRUCT_VERSION)
+ status = VL53L1_ERROR_INVALID_PARAMS;
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+
+ memcpy(
+ &(pres->zone_cal),
+ pzone_cal,
+ sizeof(VL53L1_zone_calibration_results_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_zone_calibration_data(
+ VL53L1_DEV Dev,
+ VL53L1_zone_calibration_results_t *pzone_cal)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverResults_t *pres = VL53L1DevStructGetLLResultsHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ pzone_cal,
+ &(pres->zone_cal),
+ sizeof(VL53L1_zone_calibration_results_t));
+
+ pzone_cal->struct_version =
+ VL53L1_LL_ZONE_CALIBRATION_DATA_STRUCT_VERSION;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_tuning_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_tuning_parameters_t *ptun_data)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_xtalkextract_config_t *pXC = &(pdev->xtalk_extract_cfg);
+
+ LOG_FUNCTION_START("");
+
+ ptun_data->vl53l1_tuningparm_version =
+ pdev->tuning_parms.tp_tuning_parm_version;
+
+ ptun_data->vl53l1_tuningparm_key_table_version =
+ pdev->tuning_parms.tp_tuning_parm_key_table_version;
+
+
+ ptun_data->vl53l1_tuningparm_lld_version =
+ pdev->tuning_parms.tp_tuning_parm_lld_version;
+
+ ptun_data->vl53l1_tuningparm_hist_algo_select =
+ pHP->hist_algo_select;
+
+ ptun_data->vl53l1_tuningparm_hist_target_order =
+ pHP->hist_target_order;
+
+ ptun_data->vl53l1_tuningparm_hist_filter_woi_0 =
+ pHP->filter_woi0;
+
+ ptun_data->vl53l1_tuningparm_hist_filter_woi_1 =
+ pHP->filter_woi1;
+
+ ptun_data->vl53l1_tuningparm_hist_amb_est_method =
+ pHP->hist_amb_est_method;
+
+ ptun_data->vl53l1_tuningparm_hist_amb_thresh_sigma_0 =
+ pHP->ambient_thresh_sigma0;
+
+ ptun_data->vl53l1_tuningparm_hist_amb_thresh_sigma_1 =
+ pHP->ambient_thresh_sigma1;
+
+ ptun_data->vl53l1_tuningparm_hist_min_amb_thresh_events =
+ pHP->min_ambient_thresh_events;
+
+ ptun_data->vl53l1_tuningparm_hist_amb_events_scaler =
+ pHP->ambient_thresh_events_scaler;
+
+ ptun_data->vl53l1_tuningparm_hist_noise_threshold =
+ pHP->noise_threshold;
+
+ ptun_data->vl53l1_tuningparm_hist_signal_total_events_limit =
+ pHP->signal_total_events_limit;
+
+ ptun_data->vl53l1_tuningparm_hist_sigma_est_ref_mm =
+ pHP->sigma_estimator__sigma_ref_mm;
+
+ ptun_data->vl53l1_tuningparm_hist_sigma_thresh_mm =
+ pHP->sigma_thresh;
+
+ ptun_data->vl53l1_tuningparm_hist_gain_factor =
+ pdev->gain_cal.histogram_ranging_gain_factor;
+
+ ptun_data->vl53l1_tuningparm_consistency_hist_phase_tolerance =
+ pHP->algo__consistency_check__phase_tolerance;
+
+ ptun_data->vl53l1_tuningparm_consistency_hist_min_max_tolerance_mm =
+ pHP->algo__consistency_check__min_max_tolerance;
+
+ ptun_data->vl53l1_tuningparm_consistency_hist_event_sigma =
+ pHP->algo__consistency_check__event_sigma;
+
+ ptun_data->vl53l1_tuningparm_consistency_hist_event_sigma_min_spad_limit
+ = pHP->algo__consistency_check__event_min_spad_count;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_rtn_histo_long_range =
+ pdev->tuning_parms.tp_init_phase_rtn_hist_long;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_rtn_histo_med_range =
+ pdev->tuning_parms.tp_init_phase_rtn_hist_med;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_rtn_histo_short_range =
+ pdev->tuning_parms.tp_init_phase_rtn_hist_short;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_ref_histo_long_range =
+ pdev->tuning_parms.tp_init_phase_ref_hist_long;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_ref_histo_med_range =
+ pdev->tuning_parms.tp_init_phase_ref_hist_med;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_ref_histo_short_range =
+ pdev->tuning_parms.tp_init_phase_ref_hist_short;
+
+ ptun_data->vl53l1_tuningparm_xtalk_detect_min_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm;
+
+ ptun_data->vl53l1_tuningparm_xtalk_detect_max_valid_range_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm;
+
+ ptun_data->vl53l1_tuningparm_xtalk_detect_max_sigma_mm =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm;
+
+ ptun_data->vl53l1_tuningparm_xtalk_detect_min_max_tolerance =
+ pHP->algo__crosstalk_detect_min_max_tolerance;
+
+ ptun_data->vl53l1_tuningparm_xtalk_detect_max_valid_rate_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps;
+
+ ptun_data->vl53l1_tuningparm_xtalk_detect_event_sigma =
+ pHP->algo__crosstalk_detect_event_sigma;
+
+ ptun_data->vl53l1_tuningparm_hist_xtalk_margin_kcps =
+ pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps;
+
+ ptun_data->vl53l1_tuningparm_consistency_lite_phase_tolerance =
+ pdev->tuning_parms.tp_consistency_lite_phase_tolerance;
+
+ ptun_data->vl53l1_tuningparm_phasecal_target =
+ pdev->tuning_parms.tp_phasecal_target;
+
+ ptun_data->vl53l1_tuningparm_lite_cal_repeat_rate =
+ pdev->tuning_parms.tp_cal_repeat_rate;
+
+ ptun_data->vl53l1_tuningparm_lite_ranging_gain_factor =
+ pdev->gain_cal.standard_ranging_gain_factor;
+
+ ptun_data->vl53l1_tuningparm_lite_min_clip_mm =
+ pdev->tuning_parms.tp_lite_min_clip;
+
+ ptun_data->vl53l1_tuningparm_lite_long_sigma_thresh_mm =
+ pdev->tuning_parms.tp_lite_long_sigma_thresh_mm;
+
+ ptun_data->vl53l1_tuningparm_lite_med_sigma_thresh_mm =
+ pdev->tuning_parms.tp_lite_med_sigma_thresh_mm;
+
+ ptun_data->vl53l1_tuningparm_lite_short_sigma_thresh_mm =
+ pdev->tuning_parms.tp_lite_short_sigma_thresh_mm;
+
+ ptun_data->vl53l1_tuningparm_lite_long_min_count_rate_rtn_mcps =
+ pdev->tuning_parms.tp_lite_long_min_count_rate_rtn_mcps;
+
+ ptun_data->vl53l1_tuningparm_lite_med_min_count_rate_rtn_mcps =
+ pdev->tuning_parms.tp_lite_med_min_count_rate_rtn_mcps;
+
+ ptun_data->vl53l1_tuningparm_lite_short_min_count_rate_rtn_mcps =
+ pdev->tuning_parms.tp_lite_short_min_count_rate_rtn_mcps;
+
+ ptun_data->vl53l1_tuningparm_lite_sigma_est_pulse_width =
+ pdev->tuning_parms.tp_lite_sigma_est_pulse_width_ns;
+
+ ptun_data->vl53l1_tuningparm_lite_sigma_est_amb_width_ns =
+ pdev->tuning_parms.tp_lite_sigma_est_amb_width_ns;
+
+ ptun_data->vl53l1_tuningparm_lite_sigma_ref_mm =
+ pdev->tuning_parms.tp_lite_sigma_ref_mm;
+
+ ptun_data->vl53l1_tuningparm_lite_rit_mult =
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult;
+
+ ptun_data->vl53l1_tuningparm_lite_seed_config =
+ pdev->tuning_parms.tp_lite_seed_cfg;
+
+ ptun_data->vl53l1_tuningparm_lite_quantifier =
+ pdev->tuning_parms.tp_lite_quantifier;
+
+ ptun_data->vl53l1_tuningparm_lite_first_order_select =
+ pdev->tuning_parms.tp_lite_first_order_select;
+
+ ptun_data->vl53l1_tuningparm_lite_xtalk_margin_kcps =
+ pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_rtn_lite_long_range =
+ pdev->tuning_parms.tp_init_phase_rtn_lite_long;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_rtn_lite_med_range =
+ pdev->tuning_parms.tp_init_phase_rtn_lite_med;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_rtn_lite_short_range =
+ pdev->tuning_parms.tp_init_phase_rtn_lite_short;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_ref_lite_long_range =
+ pdev->tuning_parms.tp_init_phase_ref_lite_long;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_ref_lite_med_range =
+ pdev->tuning_parms.tp_init_phase_ref_lite_med;
+
+ ptun_data->vl53l1_tuningparm_initial_phase_ref_lite_short_range =
+ pdev->tuning_parms.tp_init_phase_ref_lite_short;
+
+ ptun_data->vl53l1_tuningparm_timed_seed_config =
+ pdev->tuning_parms.tp_timed_seed_cfg;
+
+ ptun_data->vl53l1_tuningparm_dmax_cfg_signal_thresh_sigma =
+ pdev->dmax_cfg.signal_thresh_sigma;
+
+ ptun_data->vl53l1_tuningparm_dmax_cfg_reflectance_array_0 =
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[0];
+
+ ptun_data->vl53l1_tuningparm_dmax_cfg_reflectance_array_1 =
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[1];
+
+ ptun_data->vl53l1_tuningparm_dmax_cfg_reflectance_array_2 =
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[2];
+
+ ptun_data->vl53l1_tuningparm_dmax_cfg_reflectance_array_3 =
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[3];
+
+ ptun_data->vl53l1_tuningparm_dmax_cfg_reflectance_array_4 =
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[4];
+
+ ptun_data->vl53l1_tuningparm_vhv_loopbound =
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound;
+
+ ptun_data->vl53l1_tuningparm_refspadchar_device_test_mode =
+ pdev->refspadchar.device_test_mode;
+
+ ptun_data->vl53l1_tuningparm_refspadchar_vcsel_period =
+ pdev->refspadchar.VL53L1_p_009;
+
+ ptun_data->vl53l1_tuningparm_refspadchar_phasecal_timeout_us =
+ pdev->refspadchar.timeout_us;
+
+ ptun_data->vl53l1_tuningparm_refspadchar_target_count_rate_mcps =
+ pdev->refspadchar.target_count_rate_mcps;
+
+ ptun_data->vl53l1_tuningparm_refspadchar_min_countrate_limit_mcps =
+ pdev->refspadchar.min_count_rate_limit_mcps;
+
+ ptun_data->vl53l1_tuningparm_refspadchar_max_countrate_limit_mcps =
+ pdev->refspadchar.max_count_rate_limit_mcps;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_num_of_samples =
+ pXC->num_of_samples;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_min_filter_thresh_mm =
+ pXC->algo__crosstalk_extract_min_valid_range_mm;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_max_filter_thresh_mm =
+ pXC->algo__crosstalk_extract_max_valid_range_mm;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_dss_rate_mcps =
+ pXC->dss_config__target_total_rate_mcps;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_phasecal_timeout_us =
+ pXC->phasecal_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_max_valid_rate_kcps =
+ pXC->algo__crosstalk_extract_max_valid_rate_kcps;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_sigma_threshold_mm =
+ pXC->algo__crosstalk_extract_max_sigma_mm;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_dss_timeout_us =
+ pXC->mm_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_xtalk_extract_bin_timeout_us =
+ pXC->range_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_offset_cal_dss_rate_mcps =
+ pdev->offsetcal_cfg.dss_config__target_total_rate_mcps;
+
+ ptun_data->vl53l1_tuningparm_offset_cal_phasecal_timeout_us =
+ pdev->offsetcal_cfg.phasecal_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_offset_cal_mm_timeout_us =
+ pdev->offsetcal_cfg.mm_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_offset_cal_range_timeout_us =
+ pdev->offsetcal_cfg.range_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_offset_cal_pre_samples =
+ pdev->offsetcal_cfg.pre_num_of_samples;
+
+ ptun_data->vl53l1_tuningparm_offset_cal_mm1_samples =
+ pdev->offsetcal_cfg.mm1_num_of_samples;
+
+ ptun_data->vl53l1_tuningparm_offset_cal_mm2_samples =
+ pdev->offsetcal_cfg.mm2_num_of_samples;
+
+ ptun_data->vl53l1_tuningparm_zone_cal_dss_rate_mcps =
+ pdev->zonecal_cfg.dss_config__target_total_rate_mcps;
+
+ ptun_data->vl53l1_tuningparm_zone_cal_phasecal_timeout_us =
+ pdev->zonecal_cfg.phasecal_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_zone_cal_dss_timeout_us =
+ pdev->zonecal_cfg.mm_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_zone_cal_phasecal_num_samples =
+ pdev->zonecal_cfg.phasecal_num_of_samples;
+
+ ptun_data->vl53l1_tuningparm_zone_cal_range_timeout_us =
+ pdev->zonecal_cfg.range_config_timeout_us;
+
+ ptun_data->vl53l1_tuningparm_zone_cal_zone_num_samples =
+ pdev->zonecal_cfg.zone_num_of_samples;
+
+ ptun_data->vl53l1_tuningparm_spadmap_vcsel_period =
+ pdev->ssc_cfg.VL53L1_p_009;
+
+ ptun_data->vl53l1_tuningparm_spadmap_vcsel_start =
+ pdev->ssc_cfg.vcsel_start;
+
+ ptun_data->vl53l1_tuningparm_spadmap_rate_limit_mcps =
+ pdev->ssc_cfg.rate_limit_mcps;
+
+ ptun_data->vl53l1_tuningparm_lite_dss_config_target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_lite_mcps;
+
+ ptun_data->vl53l1_tuningparm_ranging_dss_config_target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mcps;
+
+ ptun_data->vl53l1_tuningparm_mz_dss_config_target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_histo_mz_mcps;
+
+ ptun_data->vl53l1_tuningparm_timed_dss_config_target_total_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_timed_mcps;
+
+ ptun_data->vl53l1_tuningparm_lite_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_lite_us;
+
+ ptun_data->vl53l1_tuningparm_ranging_long_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_long_us;
+
+ ptun_data->vl53l1_tuningparm_ranging_med_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_med_us;
+
+ ptun_data->vl53l1_tuningparm_ranging_short_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_hist_short_us;
+
+ ptun_data->vl53l1_tuningparm_mz_long_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_mz_long_us;
+
+ ptun_data->vl53l1_tuningparm_mz_med_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_mz_med_us;
+
+ ptun_data->vl53l1_tuningparm_mz_short_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_mz_short_us;
+
+ ptun_data->vl53l1_tuningparm_timed_phasecal_config_timeout_us =
+ pdev->tuning_parms.tp_phasecal_timeout_timed_us;
+
+ ptun_data->vl53l1_tuningparm_lite_mm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_lite_us;
+
+ ptun_data->vl53l1_tuningparm_ranging_mm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_histo_us;
+
+ ptun_data->vl53l1_tuningparm_mz_mm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_mz_us;
+
+ ptun_data->vl53l1_tuningparm_timed_mm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_timed_us;
+
+ ptun_data->vl53l1_tuningparm_lite_range_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_lite_us;
+
+ ptun_data->vl53l1_tuningparm_ranging_range_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_histo_us;
+
+ ptun_data->vl53l1_tuningparm_mz_range_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_mz_us;
+
+ ptun_data->vl53l1_tuningparm_timed_range_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_timed_us;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_smudge_margin =
+ pdev->smudge_correct_config.smudge_margin;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_noise_margin =
+ pdev->smudge_correct_config.noise_margin;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_xtalk_offset_limit =
+ pdev->smudge_correct_config.user_xtalk_offset_limit;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_xtalk_offset_limit_hi =
+ pdev->smudge_correct_config.user_xtalk_offset_limit_hi;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_sample_limit =
+ pdev->smudge_correct_config.sample_limit;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_single_xtalk_delta =
+ pdev->smudge_correct_config.single_xtalk_delta;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_averaged_xtalk_delta =
+ pdev->smudge_correct_config.averaged_xtalk_delta;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_clip_limit =
+ pdev->smudge_correct_config.smudge_corr_clip_limit;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_scaler_calc_method =
+ pdev->smudge_correct_config.scaler_calc_method;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_xgradient_scaler =
+ pdev->smudge_correct_config.x_gradient_scaler;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_ygradient_scaler =
+ pdev->smudge_correct_config.y_gradient_scaler;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_user_scaler_set =
+ pdev->smudge_correct_config.user_scaler_set;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_smudge_cor_single_apply =
+ pdev->smudge_correct_config.smudge_corr_single_apply;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_xtalk_amb_threshold =
+ pdev->smudge_correct_config.smudge_corr_ambient_threshold;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_nodetect_amb_threshold_kcps =
+ pdev->smudge_correct_config.nodetect_ambient_threshold;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_nodetect_sample_limit =
+ pdev->smudge_correct_config.nodetect_sample_limit;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_nodetect_xtalk_offset_kcps =
+ pdev->smudge_correct_config.nodetect_xtalk_offset;
+
+ ptun_data->vl53l1_tuningparm_dynxtalk_nodetect_min_range_mm =
+ pdev->smudge_correct_config.nodetect_min_range_mm;
+
+ ptun_data->vl53l1_tuningparm_lowpowerauto_vhv_loop_bound =
+ pdev->low_power_auto_data.vhv_loop_bound;
+
+ ptun_data->vl53l1_tuningparm_lowpowerauto_mm_config_timeout_us =
+ pdev->tuning_parms.tp_mm_timeout_lpa_us;
+
+ ptun_data->vl53l1_tuningparm_lowpowerauto_range_config_timeout_us =
+ pdev->tuning_parms.tp_range_timeout_lpa_us;
+
+ ptun_data->vl53l1_tuningparm_very_short_dss_rate_mcps =
+ pdev->tuning_parms.tp_dss_target_very_short_mcps;
+
+ ptun_data->vl53l1_tuningparm_phasecal_patch_power =
+ pdev->tuning_parms.tp_phasecal_patch_power;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_tuning_parm(
+ VL53L1_DEV Dev,
+ VL53L1_TuningParms tuning_parm_key,
+ int32_t *ptuning_parm_value)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_xtalkextract_config_t *pXC = &(pdev->xtalk_extract_cfg);
+
+ LOG_FUNCTION_START("");
+
+ switch (tuning_parm_key) {
+
+ case VL53L1_TUNINGPARM_VERSION:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_tuning_parm_version;
+ break;
+ case VL53L1_TUNINGPARM_KEY_TABLE_VERSION:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_tuning_parm_key_table_version;
+ break;
+ case VL53L1_TUNINGPARM_LLD_VERSION:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_tuning_parm_lld_version;
+ break;
+ case VL53L1_TUNINGPARM_HIST_ALGO_SELECT:
+ *ptuning_parm_value =
+ (int32_t)pHP->hist_algo_select;
+ break;
+ case VL53L1_TUNINGPARM_HIST_TARGET_ORDER:
+ *ptuning_parm_value =
+ (int32_t)pHP->hist_target_order;
+ break;
+ case VL53L1_TUNINGPARM_HIST_FILTER_WOI_0:
+ *ptuning_parm_value =
+ (int32_t)pHP->filter_woi0;
+ break;
+ case VL53L1_TUNINGPARM_HIST_FILTER_WOI_1:
+ *ptuning_parm_value =
+ (int32_t)pHP->filter_woi1;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_EST_METHOD:
+ *ptuning_parm_value =
+ (int32_t)pHP->hist_amb_est_method;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_0:
+ *ptuning_parm_value =
+ (int32_t)pHP->ambient_thresh_sigma0;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_1:
+ *ptuning_parm_value =
+ (int32_t)pHP->ambient_thresh_sigma1;
+ break;
+ case VL53L1_TUNINGPARM_HIST_MIN_AMB_THRESH_EVENTS:
+ *ptuning_parm_value =
+ (int32_t)pHP->min_ambient_thresh_events;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_EVENTS_SCALER:
+ *ptuning_parm_value =
+ (int32_t)pHP->ambient_thresh_events_scaler;
+ break;
+ case VL53L1_TUNINGPARM_HIST_NOISE_THRESHOLD:
+ *ptuning_parm_value =
+ (int32_t)pHP->noise_threshold;
+ break;
+ case VL53L1_TUNINGPARM_HIST_SIGNAL_TOTAL_EVENTS_LIMIT:
+ *ptuning_parm_value =
+ (int32_t)pHP->signal_total_events_limit;
+ break;
+ case VL53L1_TUNINGPARM_HIST_SIGMA_EST_REF_MM:
+ *ptuning_parm_value =
+ (int32_t)pHP->sigma_estimator__sigma_ref_mm;
+ break;
+ case VL53L1_TUNINGPARM_HIST_SIGMA_THRESH_MM:
+ *ptuning_parm_value =
+ (int32_t)pHP->sigma_thresh;
+ break;
+ case VL53L1_TUNINGPARM_HIST_GAIN_FACTOR:
+ *ptuning_parm_value =
+ (int32_t)pdev->gain_cal.histogram_ranging_gain_factor;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_PHASE_TOLERANCE:
+ *ptuning_parm_value =
+ (int32_t)pHP->algo__consistency_check__phase_tolerance;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_MIN_MAX_TOLERANCE_MM:
+ *ptuning_parm_value =
+ (int32_t)pHP->algo__consistency_check__min_max_tolerance;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA:
+ *ptuning_parm_value =
+ (int32_t)pHP->algo__consistency_check__event_sigma;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_MIN_SPAD_LIMIT:
+ *ptuning_parm_value =
+ (int32_t)pHP->algo__consistency_check__event_min_spad_count;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_LONG_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_rtn_hist_long;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_MED_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_rtn_hist_med;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_SHORT_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_rtn_hist_short;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_LONG_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_ref_hist_long;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_MED_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_ref_hist_med;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_SHORT_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_ref_hist_short;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MIN_VALID_RANGE_MM:
+ *ptuning_parm_value = (int32_t)(
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm);
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RANGE_MM:
+ *ptuning_parm_value = (int32_t)(
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm);
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MAX_SIGMA_MM:
+ *ptuning_parm_value =
+ (int32_t)pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MIN_MAX_TOLERANCE:
+ *ptuning_parm_value =
+ (int32_t)pHP->algo__crosstalk_detect_min_max_tolerance;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RATE_KCPS:
+ *ptuning_parm_value = (int32_t)(
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps);
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_EVENT_SIGMA:
+ *ptuning_parm_value =
+ (int32_t)pHP->algo__crosstalk_detect_event_sigma;
+ break;
+ case VL53L1_TUNINGPARM_HIST_XTALK_MARGIN_KCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_LITE_PHASE_TOLERANCE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_consistency_lite_phase_tolerance;
+ break;
+ case VL53L1_TUNINGPARM_PHASECAL_TARGET:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_target;
+ break;
+ case VL53L1_TUNINGPARM_LITE_CAL_REPEAT_RATE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_cal_repeat_rate;
+ break;
+ case VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR:
+ *ptuning_parm_value =
+ (int32_t)pdev->gain_cal.standard_ranging_gain_factor;
+ break;
+ case VL53L1_TUNINGPARM_LITE_MIN_CLIP_MM:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_min_clip;
+ break;
+ case VL53L1_TUNINGPARM_LITE_LONG_SIGMA_THRESH_MM:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_long_sigma_thresh_mm;
+ break;
+ case VL53L1_TUNINGPARM_LITE_MED_SIGMA_THRESH_MM:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_med_sigma_thresh_mm;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SHORT_SIGMA_THRESH_MM:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_short_sigma_thresh_mm;
+ break;
+ case VL53L1_TUNINGPARM_LITE_LONG_MIN_COUNT_RATE_RTN_MCPS:
+ *ptuning_parm_value = (int32_t)(
+ pdev->tuning_parms.tp_lite_long_min_count_rate_rtn_mcps);
+ break;
+ case VL53L1_TUNINGPARM_LITE_MED_MIN_COUNT_RATE_RTN_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_med_min_count_rate_rtn_mcps;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SHORT_MIN_COUNT_RATE_RTN_MCPS:
+ *ptuning_parm_value = (int32_t)(
+ pdev->tuning_parms.tp_lite_short_min_count_rate_rtn_mcps);
+ break;
+ case VL53L1_TUNINGPARM_LITE_SIGMA_EST_PULSE_WIDTH:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_sigma_est_pulse_width_ns;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SIGMA_EST_AMB_WIDTH_NS:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_sigma_est_amb_width_ns;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SIGMA_REF_MM:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_sigma_ref_mm;
+ break;
+ case VL53L1_TUNINGPARM_LITE_RIT_MULT:
+ *ptuning_parm_value =
+ (int32_t)pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SEED_CONFIG:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_seed_cfg;
+ break;
+ case VL53L1_TUNINGPARM_LITE_QUANTIFIER:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_quantifier;
+ break;
+ case VL53L1_TUNINGPARM_LITE_FIRST_ORDER_SELECT:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_lite_first_order_select;
+ break;
+ case VL53L1_TUNINGPARM_LITE_XTALK_MARGIN_KCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_LONG_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_rtn_lite_long;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_MED_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_rtn_lite_med;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_SHORT_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_rtn_lite_short;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_LONG_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_ref_lite_long;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_MED_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_ref_lite_med;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_SHORT_RANGE:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_init_phase_ref_lite_short;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_SEED_CONFIG:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_timed_seed_cfg;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_SIGNAL_THRESH_SIGMA:
+ *ptuning_parm_value =
+ (int32_t)pdev->dmax_cfg.signal_thresh_sigma;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_0:
+ *ptuning_parm_value =
+ (int32_t)pdev->dmax_cfg.target_reflectance_for_dmax_calc[0];
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_1:
+ *ptuning_parm_value =
+ (int32_t)pdev->dmax_cfg.target_reflectance_for_dmax_calc[1];
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_2:
+ *ptuning_parm_value =
+ (int32_t)pdev->dmax_cfg.target_reflectance_for_dmax_calc[2];
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_3:
+ *ptuning_parm_value =
+ (int32_t)pdev->dmax_cfg.target_reflectance_for_dmax_calc[3];
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_4:
+ *ptuning_parm_value =
+ (int32_t)pdev->dmax_cfg.target_reflectance_for_dmax_calc[4];
+ break;
+ case VL53L1_TUNINGPARM_VHV_LOOPBOUND:
+ *ptuning_parm_value =
+ (int32_t)pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_DEVICE_TEST_MODE:
+ *ptuning_parm_value =
+ (int32_t)pdev->refspadchar.device_test_mode;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_VCSEL_PERIOD:
+ *ptuning_parm_value =
+ (int32_t)pdev->refspadchar.VL53L1_p_009;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_PHASECAL_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->refspadchar.timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_TARGET_COUNT_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->refspadchar.target_count_rate_mcps;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_MIN_COUNTRATE_LIMIT_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->refspadchar.min_count_rate_limit_mcps;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_MAX_COUNTRATE_LIMIT_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->refspadchar.max_count_rate_limit_mcps;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_NUM_OF_SAMPLES:
+ *ptuning_parm_value =
+ (int32_t)pXC->num_of_samples;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_MIN_FILTER_THRESH_MM:
+ *ptuning_parm_value =
+ (int32_t)pXC->algo__crosstalk_extract_min_valid_range_mm;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_FILTER_THRESH_MM:
+ *ptuning_parm_value =
+ (int32_t)pXC->algo__crosstalk_extract_max_valid_range_mm;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pXC->dss_config__target_total_rate_mcps;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_PHASECAL_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pXC->phasecal_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_VALID_RATE_KCPS:
+ *ptuning_parm_value =
+ (int32_t)pXC->algo__crosstalk_extract_max_valid_rate_kcps;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_SIGMA_THRESHOLD_MM:
+ *ptuning_parm_value =
+ (int32_t)pXC->algo__crosstalk_extract_max_sigma_mm;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pXC->mm_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_BIN_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pXC->range_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_DSS_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->offsetcal_cfg.dss_config__target_total_rate_mcps;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_PHASECAL_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->offsetcal_cfg.phasecal_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_MM_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->offsetcal_cfg.mm_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_RANGE_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->offsetcal_cfg.range_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_PRE_SAMPLES:
+ *ptuning_parm_value =
+ (int32_t)pdev->offsetcal_cfg.pre_num_of_samples;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_MM1_SAMPLES:
+ *ptuning_parm_value =
+ (int32_t)pdev->offsetcal_cfg.mm1_num_of_samples;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_MM2_SAMPLES:
+ *ptuning_parm_value =
+ (int32_t)pdev->offsetcal_cfg.mm2_num_of_samples;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_DSS_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->zonecal_cfg.dss_config__target_total_rate_mcps;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->zonecal_cfg.phasecal_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_DSS_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->zonecal_cfg.mm_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_NUM_SAMPLES:
+ *ptuning_parm_value =
+ (int32_t)pdev->zonecal_cfg.phasecal_num_of_samples;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_RANGE_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->zonecal_cfg.range_config_timeout_us;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_ZONE_NUM_SAMPLES:
+ *ptuning_parm_value =
+ (int32_t)pdev->zonecal_cfg.zone_num_of_samples;
+ break;
+ case VL53L1_TUNINGPARM_SPADMAP_VCSEL_PERIOD:
+ *ptuning_parm_value =
+ (int32_t)pdev->ssc_cfg.VL53L1_p_009;
+ break;
+ case VL53L1_TUNINGPARM_SPADMAP_VCSEL_START:
+ *ptuning_parm_value =
+ (int32_t)pdev->ssc_cfg.vcsel_start;
+ break;
+ case VL53L1_TUNINGPARM_SPADMAP_RATE_LIMIT_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->ssc_cfg.rate_limit_mcps;
+ break;
+ case VL53L1_TUNINGPARM_LITE_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_dss_target_lite_mcps;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_dss_target_histo_mcps;
+ break;
+ case VL53L1_TUNINGPARM_MZ_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_dss_target_histo_mz_mcps;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_dss_target_timed_mcps;
+ break;
+ case VL53L1_TUNINGPARM_LITE_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_lite_us;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_LONG_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_hist_long_us;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_MED_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_hist_med_us;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_SHORT_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_hist_short_us;
+ break;
+ case VL53L1_TUNINGPARM_MZ_LONG_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_mz_long_us;
+ break;
+ case VL53L1_TUNINGPARM_MZ_MED_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_mz_med_us;
+ break;
+ case VL53L1_TUNINGPARM_MZ_SHORT_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_mz_short_us;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_PHASECAL_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_phasecal_timeout_timed_us;
+ break;
+ case VL53L1_TUNINGPARM_LITE_MM_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_mm_timeout_lite_us;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_MM_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_mm_timeout_histo_us;
+ break;
+ case VL53L1_TUNINGPARM_MZ_MM_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_mm_timeout_mz_us;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_MM_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_mm_timeout_timed_us;
+ break;
+ case VL53L1_TUNINGPARM_LITE_RANGE_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_range_timeout_lite_us;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_RANGE_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_range_timeout_histo_us;
+ break;
+ case VL53L1_TUNINGPARM_MZ_RANGE_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_range_timeout_mz_us;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_RANGE_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_range_timeout_timed_us;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_MARGIN:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.smudge_margin;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NOISE_MARGIN:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.noise_margin;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.user_xtalk_offset_limit;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_HI:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.user_xtalk_offset_limit_hi;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SAMPLE_LIMIT:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.sample_limit;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SINGLE_XTALK_DELTA:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.single_xtalk_delta;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_AVERAGED_XTALK_DELTA:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.averaged_xtalk_delta;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_CLIP_LIMIT:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.smudge_corr_clip_limit;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SCALER_CALC_METHOD:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.scaler_calc_method;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XGRADIENT_SCALER:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.x_gradient_scaler;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_YGRADIENT_SCALER:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.y_gradient_scaler;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_USER_SCALER_SET:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.user_scaler_set;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_COR_SINGLE_APPLY:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.smudge_corr_single_apply;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XTALK_AMB_THRESHOLD:
+ *ptuning_parm_value = (int32_t)(
+ pdev->smudge_correct_config.smudge_corr_ambient_threshold);
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_AMB_THRESHOLD_KCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.nodetect_ambient_threshold;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_SAMPLE_LIMIT:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.nodetect_sample_limit;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.nodetect_xtalk_offset;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_MIN_RANGE_MM:
+ *ptuning_parm_value =
+ (int32_t)pdev->smudge_correct_config.nodetect_min_range_mm;
+ break;
+ case VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND:
+ *ptuning_parm_value =
+ (int32_t)pdev->low_power_auto_data.vhv_loop_bound;
+ break;
+ case VL53L1_TUNINGPARM_LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_mm_timeout_lpa_us;
+ break;
+ case VL53L1_TUNINGPARM_LOWPOWERAUTO_RANGE_CONFIG_TIMEOUT_US:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_range_timeout_lpa_us;
+ break;
+ case VL53L1_TUNINGPARM_VERY_SHORT_DSS_RATE_MCPS:
+ *ptuning_parm_value =
+ (int32_t)pdev->tuning_parms.tp_dss_target_very_short_mcps;
+ break;
+ case VL53L1_TUNINGPARM_PHASECAL_PATCH_POWER:
+ *ptuning_parm_value =
+ (int32_t) pdev->tuning_parms.tp_phasecal_patch_power;
+ break;
+ case VL53L1_TUNINGPARM_HIST_MERGE:
+ *ptuning_parm_value =
+ (int32_t) pdev->tuning_parms.tp_hist_merge;
+ break;
+ case VL53L1_TUNINGPARM_RESET_MERGE_THRESHOLD:
+ *ptuning_parm_value =
+ (int32_t) pdev->tuning_parms.tp_reset_merge_threshold;
+ break;
+ case VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE:
+ *ptuning_parm_value =
+ (int32_t) pdev->tuning_parms.tp_hist_merge_max_size;
+ break;
+
+
+ default:
+ *ptuning_parm_value = 0x7FFFFFFF;
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_set_tuning_parm(
+ VL53L1_DEV Dev,
+ VL53L1_TuningParms tuning_parm_key,
+ int32_t tuning_parm_value)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_hist_post_process_config_t *pHP = &(pdev->histpostprocess);
+ VL53L1_xtalkextract_config_t *pXC = &(pdev->xtalk_extract_cfg);
+
+ LOG_FUNCTION_START("");
+
+ switch (tuning_parm_key) {
+
+ case VL53L1_TUNINGPARM_VERSION:
+ pdev->tuning_parms.tp_tuning_parm_version =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_KEY_TABLE_VERSION:
+ pdev->tuning_parms.tp_tuning_parm_key_table_version =
+ (uint16_t)tuning_parm_value;
+ if ((uint16_t)tuning_parm_value
+ != VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT)
+ status = VL53L1_ERROR_TUNING_PARM_KEY_MISMATCH;
+
+ break;
+ case VL53L1_TUNINGPARM_LLD_VERSION:
+ pdev->tuning_parms.tp_tuning_parm_lld_version =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_ALGO_SELECT:
+ pHP->hist_algo_select =
+ (VL53L1_HistAlgoSelect)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_TARGET_ORDER:
+ pHP->hist_target_order =
+ (VL53L1_HistTargetOrder)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_FILTER_WOI_0:
+ pHP->filter_woi0 =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_FILTER_WOI_1:
+ pHP->filter_woi1 =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_EST_METHOD:
+ pHP->hist_amb_est_method =
+ (VL53L1_HistAmbEstMethod)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_0:
+ pHP->ambient_thresh_sigma0 =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_1:
+ pHP->ambient_thresh_sigma1 =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_MIN_AMB_THRESH_EVENTS:
+ pHP->min_ambient_thresh_events =
+ (int32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_AMB_EVENTS_SCALER:
+ pHP->ambient_thresh_events_scaler =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_NOISE_THRESHOLD:
+ pHP->noise_threshold =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_SIGNAL_TOTAL_EVENTS_LIMIT:
+ pHP->signal_total_events_limit =
+ (int32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_SIGMA_EST_REF_MM:
+ pHP->sigma_estimator__sigma_ref_mm =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_SIGMA_THRESH_MM:
+ pHP->sigma_thresh =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_GAIN_FACTOR:
+ pdev->gain_cal.histogram_ranging_gain_factor =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_PHASE_TOLERANCE:
+ pHP->algo__consistency_check__phase_tolerance =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_MIN_MAX_TOLERANCE_MM:
+ pHP->algo__consistency_check__min_max_tolerance =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA:
+ pHP->algo__consistency_check__event_sigma =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_MIN_SPAD_LIMIT:
+ pHP->algo__consistency_check__event_min_spad_count =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_LONG_RANGE:
+ pdev->tuning_parms.tp_init_phase_rtn_hist_long =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_MED_RANGE:
+ pdev->tuning_parms.tp_init_phase_rtn_hist_med =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_SHORT_RANGE:
+ pdev->tuning_parms.tp_init_phase_rtn_hist_short =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_LONG_RANGE:
+ pdev->tuning_parms.tp_init_phase_ref_hist_long =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_MED_RANGE:
+ pdev->tuning_parms.tp_init_phase_ref_hist_med =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_SHORT_RANGE:
+ pdev->tuning_parms.tp_init_phase_ref_hist_short =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MIN_VALID_RANGE_MM:
+ pdev->xtalk_cfg.algo__crosstalk_detect_min_valid_range_mm =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RANGE_MM:
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_range_mm =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MAX_SIGMA_MM:
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_sigma_mm =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MIN_MAX_TOLERANCE:
+ pHP->algo__crosstalk_detect_min_max_tolerance =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RATE_KCPS:
+ pdev->xtalk_cfg.algo__crosstalk_detect_max_valid_rate_kcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_DETECT_EVENT_SIGMA:
+ pHP->algo__crosstalk_detect_event_sigma =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_XTALK_MARGIN_KCPS:
+ pdev->xtalk_cfg.histogram_mode_crosstalk_margin_kcps =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_CONSISTENCY_LITE_PHASE_TOLERANCE:
+ pdev->tuning_parms.tp_consistency_lite_phase_tolerance =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_PHASECAL_TARGET:
+ pdev->tuning_parms.tp_phasecal_target =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_CAL_REPEAT_RATE:
+ pdev->tuning_parms.tp_cal_repeat_rate =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR:
+ pdev->gain_cal.standard_ranging_gain_factor =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_MIN_CLIP_MM:
+ pdev->tuning_parms.tp_lite_min_clip =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_LONG_SIGMA_THRESH_MM:
+ pdev->tuning_parms.tp_lite_long_sigma_thresh_mm =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_MED_SIGMA_THRESH_MM:
+ pdev->tuning_parms.tp_lite_med_sigma_thresh_mm =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SHORT_SIGMA_THRESH_MM:
+ pdev->tuning_parms.tp_lite_short_sigma_thresh_mm =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_LONG_MIN_COUNT_RATE_RTN_MCPS:
+ pdev->tuning_parms.tp_lite_long_min_count_rate_rtn_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_MED_MIN_COUNT_RATE_RTN_MCPS:
+ pdev->tuning_parms.tp_lite_med_min_count_rate_rtn_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SHORT_MIN_COUNT_RATE_RTN_MCPS:
+ pdev->tuning_parms.tp_lite_short_min_count_rate_rtn_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SIGMA_EST_PULSE_WIDTH:
+ pdev->tuning_parms.tp_lite_sigma_est_pulse_width_ns =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SIGMA_EST_AMB_WIDTH_NS:
+ pdev->tuning_parms.tp_lite_sigma_est_amb_width_ns =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SIGMA_REF_MM:
+ pdev->tuning_parms.tp_lite_sigma_ref_mm =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_RIT_MULT:
+ pdev->xtalk_cfg.crosstalk_range_ignore_threshold_mult =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_SEED_CONFIG:
+ pdev->tuning_parms.tp_lite_seed_cfg =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_QUANTIFIER:
+ pdev->tuning_parms.tp_lite_quantifier =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_FIRST_ORDER_SELECT:
+ pdev->tuning_parms.tp_lite_first_order_select =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_XTALK_MARGIN_KCPS:
+ pdev->xtalk_cfg.lite_mode_crosstalk_margin_kcps =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_LONG_RANGE:
+ pdev->tuning_parms.tp_init_phase_rtn_lite_long =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_MED_RANGE:
+ pdev->tuning_parms.tp_init_phase_rtn_lite_med =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_SHORT_RANGE:
+ pdev->tuning_parms.tp_init_phase_rtn_lite_short =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_LONG_RANGE:
+ pdev->tuning_parms.tp_init_phase_ref_lite_long =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_MED_RANGE:
+ pdev->tuning_parms.tp_init_phase_ref_lite_med =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_SHORT_RANGE:
+ pdev->tuning_parms.tp_init_phase_ref_lite_short =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_SEED_CONFIG:
+ pdev->tuning_parms.tp_timed_seed_cfg =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_SIGNAL_THRESH_SIGMA:
+ pdev->dmax_cfg.signal_thresh_sigma =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_0:
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[0] =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_1:
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[1] =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_2:
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[2] =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_3:
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[3] =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_4:
+ pdev->dmax_cfg.target_reflectance_for_dmax_calc[4] =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_VHV_LOOPBOUND:
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_DEVICE_TEST_MODE:
+ pdev->refspadchar.device_test_mode =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_VCSEL_PERIOD:
+ pdev->refspadchar.VL53L1_p_009 =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_PHASECAL_TIMEOUT_US:
+ pdev->refspadchar.timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_TARGET_COUNT_RATE_MCPS:
+ pdev->refspadchar.target_count_rate_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_MIN_COUNTRATE_LIMIT_MCPS:
+ pdev->refspadchar.min_count_rate_limit_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_REFSPADCHAR_MAX_COUNTRATE_LIMIT_MCPS:
+ pdev->refspadchar.max_count_rate_limit_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_NUM_OF_SAMPLES:
+ pXC->num_of_samples =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_MIN_FILTER_THRESH_MM:
+ pXC->algo__crosstalk_extract_min_valid_range_mm =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_FILTER_THRESH_MM:
+ pXC->algo__crosstalk_extract_max_valid_range_mm =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_RATE_MCPS:
+ pXC->dss_config__target_total_rate_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_PHASECAL_TIMEOUT_US:
+ pXC->phasecal_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_VALID_RATE_KCPS:
+ pXC->algo__crosstalk_extract_max_valid_rate_kcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_SIGMA_THRESHOLD_MM:
+ pXC->algo__crosstalk_extract_max_sigma_mm =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_TIMEOUT_US:
+ pXC->mm_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_XTALK_EXTRACT_BIN_TIMEOUT_US:
+ pXC->range_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_DSS_RATE_MCPS:
+ pdev->offsetcal_cfg.dss_config__target_total_rate_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_PHASECAL_TIMEOUT_US:
+ pdev->offsetcal_cfg.phasecal_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_MM_TIMEOUT_US:
+ pdev->offsetcal_cfg.mm_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_RANGE_TIMEOUT_US:
+ pdev->offsetcal_cfg.range_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_PRE_SAMPLES:
+ pdev->offsetcal_cfg.pre_num_of_samples =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_MM1_SAMPLES:
+ pdev->offsetcal_cfg.mm1_num_of_samples =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_OFFSET_CAL_MM2_SAMPLES:
+ pdev->offsetcal_cfg.mm2_num_of_samples =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_DSS_RATE_MCPS:
+ pdev->zonecal_cfg.dss_config__target_total_rate_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_TIMEOUT_US:
+ pdev->zonecal_cfg.phasecal_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_DSS_TIMEOUT_US:
+ pdev->zonecal_cfg.mm_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_NUM_SAMPLES:
+ pdev->zonecal_cfg.phasecal_num_of_samples =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_RANGE_TIMEOUT_US:
+ pdev->zonecal_cfg.range_config_timeout_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_ZONE_CAL_ZONE_NUM_SAMPLES:
+ pdev->zonecal_cfg.zone_num_of_samples =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_SPADMAP_VCSEL_PERIOD:
+ pdev->ssc_cfg.VL53L1_p_009 =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_SPADMAP_VCSEL_START:
+ pdev->ssc_cfg.vcsel_start =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_SPADMAP_RATE_LIMIT_MCPS:
+ pdev->ssc_cfg.rate_limit_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ pdev->tuning_parms.tp_dss_target_lite_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ pdev->tuning_parms.tp_dss_target_histo_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_MZ_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ pdev->tuning_parms.tp_dss_target_histo_mz_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS:
+ pdev->tuning_parms.tp_dss_target_timed_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_lite_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_LONG_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_hist_long_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_MED_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_hist_med_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_SHORT_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_hist_short_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_MZ_LONG_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_mz_long_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_MZ_MED_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_mz_med_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_MZ_SHORT_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_mz_short_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_PHASECAL_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_phasecal_timeout_timed_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_MM_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_mm_timeout_lite_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_MM_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_mm_timeout_histo_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_MZ_MM_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_mm_timeout_mz_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_MM_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_mm_timeout_timed_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LITE_RANGE_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_range_timeout_lite_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_RANGING_RANGE_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_range_timeout_histo_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_MZ_RANGE_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_range_timeout_mz_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_TIMED_RANGE_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_range_timeout_timed_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_MARGIN:
+ pdev->smudge_correct_config.smudge_margin =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NOISE_MARGIN:
+ pdev->smudge_correct_config.noise_margin =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT:
+ pdev->smudge_correct_config.user_xtalk_offset_limit =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_HI:
+ pdev->smudge_correct_config.user_xtalk_offset_limit_hi =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SAMPLE_LIMIT:
+ pdev->smudge_correct_config.sample_limit =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SINGLE_XTALK_DELTA:
+ pdev->smudge_correct_config.single_xtalk_delta =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_AVERAGED_XTALK_DELTA:
+ pdev->smudge_correct_config.averaged_xtalk_delta =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_CLIP_LIMIT:
+ pdev->smudge_correct_config.smudge_corr_clip_limit =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_SCALER_CALC_METHOD:
+ pdev->smudge_correct_config.scaler_calc_method =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XGRADIENT_SCALER:
+ pdev->smudge_correct_config.x_gradient_scaler =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_YGRADIENT_SCALER:
+ pdev->smudge_correct_config.y_gradient_scaler =
+ (int16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_USER_SCALER_SET:
+ pdev->smudge_correct_config.user_scaler_set =
+ (uint8_t)tuning_parm_value;
+ break;
+
+ case VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_COR_SINGLE_APPLY:
+ pdev->smudge_correct_config.smudge_corr_single_apply =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_XTALK_AMB_THRESHOLD:
+ pdev->smudge_correct_config.smudge_corr_ambient_threshold =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_AMB_THRESHOLD_KCPS:
+ pdev->smudge_correct_config.nodetect_ambient_threshold =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_SAMPLE_LIMIT:
+ pdev->smudge_correct_config.nodetect_sample_limit =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS:
+ pdev->smudge_correct_config.nodetect_xtalk_offset =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_DYNXTALK_NODETECT_MIN_RANGE_MM:
+ pdev->smudge_correct_config.nodetect_min_range_mm =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND:
+ pdev->low_power_auto_data.vhv_loop_bound =
+ (uint8_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_mm_timeout_lpa_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_LOWPOWERAUTO_RANGE_CONFIG_TIMEOUT_US:
+ pdev->tuning_parms.tp_range_timeout_lpa_us =
+ (uint32_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_VERY_SHORT_DSS_RATE_MCPS:
+ pdev->tuning_parms.tp_dss_target_very_short_mcps =
+ (uint16_t)tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_PHASECAL_PATCH_POWER:
+ pdev->tuning_parms.tp_phasecal_patch_power =
+ (uint16_t) tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_MERGE:
+ pdev->tuning_parms.tp_hist_merge =
+ (uint16_t) tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_RESET_MERGE_THRESHOLD:
+ pdev->tuning_parms.tp_reset_merge_threshold =
+ (uint16_t) tuning_parm_value;
+ break;
+ case VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE:
+ pdev->tuning_parms.tp_hist_merge_max_size =
+ (uint16_t) tuning_parm_value;
+ break;
+
+
+ default:
+ status = VL53L1_ERROR_INVALID_PARAMS;
+ break;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_enable(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->smudge_correct_config.smudge_corr_enabled = 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_disable(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->smudge_correct_config.smudge_corr_enabled = 0;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_apply_enable(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->smudge_correct_config.smudge_corr_apply_enabled = 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_apply_disable(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->smudge_correct_config.smudge_corr_apply_enabled = 0;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_single_apply_enable(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->smudge_correct_config.smudge_corr_single_apply = 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_single_apply_disable(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->smudge_correct_config.smudge_corr_single_apply = 0;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_set_scalers(
+ VL53L1_DEV Dev,
+ int16_t x_scaler_in,
+ int16_t y_scaler_in,
+ uint8_t user_scaler_set_in
+ )
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->smudge_correct_config.x_gradient_scaler = x_scaler_in;
+ pdev->smudge_correct_config.y_gradient_scaler = y_scaler_in;
+ pdev->smudge_correct_config.user_scaler_set = user_scaler_set_in;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_get_current_xtalk_settings(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_calibration_results_t *pxtalk
+ )
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t i;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pxtalk->algo__crosstalk_compensation_plane_offset_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps;
+ pxtalk->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pxtalk->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps;
+ for (i = 0; i < VL53L1_BIN_REC_SIZE; i++)
+ pxtalk->algo__xtalk_cpo_HistoMerge_kcps[i] =
+ pdev->xtalk_cal.algo__xtalk_cpo_HistoMerge_kcps[i];
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_current_xtalk_settings(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_calibration_results_t *pxtalk
+ )
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t i;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->xtalk_cfg.algo__crosstalk_compensation_plane_offset_kcps =
+ pxtalk->algo__crosstalk_compensation_plane_offset_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pxtalk->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdev->xtalk_cfg.algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pxtalk->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ for (i = 0; i < VL53L1_BIN_REC_SIZE; i++)
+ pdev->xtalk_cal.algo__xtalk_cpo_HistoMerge_kcps[i] =
+ pxtalk->algo__xtalk_cpo_HistoMerge_kcps[i];
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_api_debug.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_debug.c
new file mode 100644
index 000000000000..0383bac3b14b
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_debug.c
@@ -0,0 +1,3629 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm.h"
+#include "vl53l1_core.h"
+#include "vl53l1_api_debug.h"
+
+#ifdef VL53L1_LOG_ENABLE
+#include "vl53l1_nvm_debug.h"
+#endif
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(trace_flags, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_decode_calibration_data_buffer(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_calibration_data_t *pdata)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (sizeof(VL53L1_calibration_data_t) > buf_size)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ memcpy(pdata, pbuffer, sizeof(VL53L1_calibration_data_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_nvm_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_decoded_nvm_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_read_nvm(Dev, 0, pdata);
+
+#ifdef VL53L1_LOG_ENABLE
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_print_decoded_nvm_data(
+ pdata,
+ "get_nvm_debug_data():pnvm_info.",
+ VL53L1_TRACE_MODULE_NVM_DATA);
+#endif
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_histogram_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ pdata,
+ &(pdev->hist_data),
+ sizeof(VL53L1_histogram_bin_data_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_get_additional_data(
+ VL53L1_DEV Dev,
+ VL53L1_additional_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pdata->preset_mode = pdev->preset_mode;
+ pdata->zone_preset = pdev->zone_preset;
+ pdata->measurement_mode = pdev->measurement_mode;
+ pdata->offset_calibration_mode = pdev->offset_calibration_mode;
+ pdata->offset_correction_mode = pdev->offset_correction_mode;
+ pdata->dmax_mode = pdev->dmax_mode;
+
+ pdata->phasecal_config_timeout_us = pdev->phasecal_config_timeout_us;
+ pdata->mm_config_timeout_us = pdev->mm_config_timeout_us;
+ pdata->range_config_timeout_us = pdev->range_config_timeout_us;
+ pdata->inter_measurement_period_ms = pdev->inter_measurement_period_ms;
+ pdata->dss_config__target_total_rate_mcps =
+ pdev->dss_config__target_total_rate_mcps;
+
+
+
+
+ status =
+ VL53L1_get_histogram_debug_data(
+ Dev,
+ &(pdata->VL53L1_p_010));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_get_xtalk_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_xtalk_debug_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ &(pdata->customer),
+ &(pdev->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+ memcpy(
+ &(pdata->xtalk_cfg),
+ &(pdev->xtalk_cfg),
+ sizeof(VL53L1_xtalk_config_t));
+
+ memcpy(
+ &(pdata->hist_data),
+ &(pdev->hist_data),
+ sizeof(VL53L1_histogram_bin_data_t));
+
+ memcpy(
+ &(pdata->xtalk_shapes),
+ &(pdev->xtalk_shapes),
+ sizeof(VL53L1_xtalk_histogram_data_t));
+
+ memcpy(
+ &(pdata->xtalk_results),
+ &(pdev->xtalk_results),
+ sizeof(VL53L1_xtalk_range_results_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_offset_debug_data(
+ VL53L1_DEV Dev,
+ VL53L1_offset_debug_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+ memcpy(
+ &(pdata->customer),
+ &(pdev->customer),
+ sizeof(VL53L1_customer_nvm_managed_t));
+
+ memcpy(
+ &(pdata->fmt_dmax_cal),
+ &(pdev->fmt_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+ memcpy(
+ &(pdata->cust_dmax_cal),
+ &(pdev->cust_dmax_cal),
+ sizeof(VL53L1_dmax_calibration_data_t));
+
+ memcpy(
+ &(pdata->add_off_cal_data),
+ &(pdev->add_off_cal_data),
+ sizeof(VL53L1_additional_offset_cal_data_t));
+
+ memcpy(
+ &(pdata->offset_results),
+ &(pdev->offset_results),
+ sizeof(VL53L1_offset_range_results_t));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+#ifdef VL53L1_LOG_ENABLE
+
+void VL53L1_signed_fixed_point_sprintf(
+ int32_t signed_fp_value,
+ uint8_t frac_bits,
+ uint16_t buf_size,
+ char *pbuffer)
+{
+
+
+
+
+
+ uint32_t fp_value = 0;
+ uint32_t unity_fp_value = 0;
+ uint32_t sign_bit = 0;
+ uint32_t int_part = 0;
+ uint32_t frac_part = 0;
+ uint32_t dec_points = 0;
+ uint32_t dec_scaler = 0;
+ uint32_t dec_part = 0;
+
+ uint64_t tmp_long_int = 0;
+
+ char fmt[VL53L1_MAX_STRING_LENGTH];
+
+ SUPPRESS_UNUSED_WARNING(buf_size);
+
+
+
+
+ sign_bit = signed_fp_value >> 31;
+
+ if (sign_bit > 0) {
+ fp_value = 0x80000000 -
+ (0x7FFFFFFF & (uint32_t)signed_fp_value);
+ } else
+ fp_value = (uint32_t)signed_fp_value;
+
+ int_part = fp_value >> frac_bits;
+ unity_fp_value = 0x01 << frac_bits;
+ frac_part = fp_value & (unity_fp_value-1);
+
+
+
+
+
+ dec_points = 2;
+ dec_scaler = 100;
+
+ while (dec_scaler < unity_fp_value) {
+ dec_points++;
+ dec_scaler *= 10;
+ }
+
+
+
+ if (sign_bit > 0)
+ sprintf(fmt, "-%%u.%%0%uu", dec_points);
+ else
+ sprintf(fmt, "%%u.%%0%uu", dec_points);
+
+
+
+
+
+ tmp_long_int = (uint64_t)frac_part * (uint64_t)dec_scaler;
+ tmp_long_int += (uint64_t)unity_fp_value/2;
+
+ tmp_long_int = do_division_u(tmp_long_int, (uint64_t)unity_fp_value);
+
+ dec_part = (uint32_t)tmp_long_int;
+
+
+
+ sprintf(
+ pbuffer,
+ fmt,
+ int_part,
+ dec_part);
+}
+
+
+void VL53L1_print_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "i2c_slave__device_address",
+ pdata->i2c_slave__device_address);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vhv_ref_sel_vddpix",
+ pdata->ana_config__vhv_ref_sel_vddpix);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vhv_ref_sel_vquench",
+ pdata->ana_config__vhv_ref_sel_vquench);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__reg_avdd1v2_sel",
+ pdata->ana_config__reg_avdd1v2_sel);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__fast_osc__trim",
+ pdata->ana_config__fast_osc__trim);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->osc_measured__fast_osc__frequency,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "osc_measured__fast_osc__frequency",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__timeout_macrop_loop_bound",
+ pdata->vhv_config__timeout_macrop_loop_bound);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__count_thresh",
+ pdata->vhv_config__count_thresh);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__offset",
+ pdata->vhv_config__offset);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "vhv_config__init",
+ pdata->vhv_config__init);
+}
+
+
+void VL53L1_print_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ int16_t tmpi16;
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_0",
+ pdata->global_config__spad_enables_ref_0);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_1",
+ pdata->global_config__spad_enables_ref_1);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_2",
+ pdata->global_config__spad_enables_ref_2);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_3",
+ pdata->global_config__spad_enables_ref_3);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_4",
+ pdata->global_config__spad_enables_ref_4);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_ref_5",
+ pdata->global_config__spad_enables_ref_5);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__ref_en_start_select",
+ pdata->global_config__ref_en_start_select);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_man__num_requested_ref_spads",
+ pdata->ref_spad_man__num_requested_ref_spads);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_man__ref_location",
+ pdata->ref_spad_man__ref_location);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ tmpi16 = pdata->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)tmpi16,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ tmpi16 = pdata->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)tmpi16,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref_spad_char__total_rate_target_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref_spad_char__total_rate_target_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__part_to_part_range_offset_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__part_to_part_range_offset_mm",
+ fp_text);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "mm_config__inner_offset_mm",
+ pdata->mm_config__inner_offset_mm);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "mm_config__outer_offset_mm",
+ pdata->mm_config__outer_offset_mm);
+}
+
+
+void VL53L1_print_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__model_id",
+ pdata->identification__model_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__module_type",
+ pdata->identification__module_type);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__revision_id",
+ pdata->identification__revision_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "identification__module_id",
+ pdata->identification__module_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__fast_osc__trim_max",
+ pdata->ana_config__fast_osc__trim_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__fast_osc__freq_set",
+ pdata->ana_config__fast_osc__freq_set);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vcsel_trim",
+ pdata->ana_config__vcsel_trim);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vcsel_selion",
+ pdata->ana_config__vcsel_selion);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ana_config__vcsel_selion_max",
+ pdata->ana_config__vcsel_selion_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "protected_laser_safety__lock_bit",
+ pdata->protected_laser_safety__lock_bit);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__key",
+ pdata->laser_safety__key);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__key_ro",
+ pdata->laser_safety__key_ro);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__clip",
+ pdata->laser_safety__clip);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "laser_safety__mult",
+ pdata->laser_safety__mult);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_0",
+ pdata->global_config__spad_enables_rtn_0);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_1",
+ pdata->global_config__spad_enables_rtn_1);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_2",
+ pdata->global_config__spad_enables_rtn_2);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_3",
+ pdata->global_config__spad_enables_rtn_3);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_4",
+ pdata->global_config__spad_enables_rtn_4);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_5",
+ pdata->global_config__spad_enables_rtn_5);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_6",
+ pdata->global_config__spad_enables_rtn_6);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_7",
+ pdata->global_config__spad_enables_rtn_7);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_8",
+ pdata->global_config__spad_enables_rtn_8);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_9",
+ pdata->global_config__spad_enables_rtn_9);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_10",
+ pdata->global_config__spad_enables_rtn_10);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_11",
+ pdata->global_config__spad_enables_rtn_11);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_12",
+ pdata->global_config__spad_enables_rtn_12);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_13",
+ pdata->global_config__spad_enables_rtn_13);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_14",
+ pdata->global_config__spad_enables_rtn_14);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_15",
+ pdata->global_config__spad_enables_rtn_15);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_16",
+ pdata->global_config__spad_enables_rtn_16);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_17",
+ pdata->global_config__spad_enables_rtn_17);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_18",
+ pdata->global_config__spad_enables_rtn_18);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_19",
+ pdata->global_config__spad_enables_rtn_19);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_20",
+ pdata->global_config__spad_enables_rtn_20);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_21",
+ pdata->global_config__spad_enables_rtn_21);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_22",
+ pdata->global_config__spad_enables_rtn_22);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_23",
+ pdata->global_config__spad_enables_rtn_23);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_24",
+ pdata->global_config__spad_enables_rtn_24);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_25",
+ pdata->global_config__spad_enables_rtn_25);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_26",
+ pdata->global_config__spad_enables_rtn_26);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_27",
+ pdata->global_config__spad_enables_rtn_27);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_28",
+ pdata->global_config__spad_enables_rtn_28);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_29",
+ pdata->global_config__spad_enables_rtn_29);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_30",
+ pdata->global_config__spad_enables_rtn_30);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_config__spad_enables_rtn_31",
+ pdata->global_config__spad_enables_rtn_31);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "roi_config__mode_roi_centre_spad",
+ pdata->roi_config__mode_roi_centre_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "roi_config__mode_roi_xy_size",
+ pdata->roi_config__mode_roi_xy_size);
+}
+
+
+void VL53L1_print_histogram_bin_data(
+ VL53L1_histogram_bin_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cfg_device_state",
+ pdata->cfg_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "rd_device_state",
+ pdata->rd_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_022",
+ pdata->VL53L1_p_022);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_023",
+ pdata->VL53L1_p_023);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_024",
+ pdata->VL53L1_p_024);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "number_of_ambient_bins",
+ pdata->number_of_ambient_bins);
+
+ for (i = 0; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH; i++) {
+ sprintf(ppre_text, "%sbin_seq[%u]", pprefix, i);
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->bin_seq[i]);
+ }
+
+ for (i = 0; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH; i++) {
+ sprintf(ppre_text, "%sbin_rep[%u]", pprefix, i);
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->bin_rep[i]);
+ }
+
+ for (i = 0; i < pdata->VL53L1_p_024; i++) {
+ sprintf(ppre_text, "%sbin_data[%u]", pprefix, i);
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %d\n",
+ ppre_text,
+ pdata->bin_data[i]);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__interrupt_status",
+ pdata->result__interrupt_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__range_status",
+ pdata->result__range_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__report_status",
+ pdata->result__report_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__stream_count",
+ pdata->result__stream_count);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__dss_actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__dss_actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->phasecal_result__reference_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "phasecal_result__reference_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_result__vcsel_start",
+ pdata->phasecal_result__vcsel_start);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_config__vcsel_start",
+ pdata->cal_config__vcsel_start);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (uint32_t)pdata->vcsel_width,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "vcsel_width",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_009",
+ pdata->VL53L1_p_009);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_019,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_019",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "total_periods_elapsed",
+ pdata->total_periods_elapsed);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "peak_duration_us",
+ pdata->peak_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "woi_duration_us",
+ pdata->woi_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "min_bin_value",
+ pdata->min_bin_value);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_bin_value",
+ pdata->max_bin_value);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "number_of_ambient_samples",
+ pdata->number_of_ambient_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "ambient_events_sum",
+ pdata->ambient_events_sum);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_p_004",
+ pdata->VL53L1_p_004);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "roi_config__user_roi_centre_spad",
+ pdata->roi_config__user_roi_centre_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%02X\n",
+ pprefix,
+ "roi_config__user_roi_requested_global_xy_size",
+ pdata->roi_config__user_roi_requested_global_xy_size);
+}
+
+
+void VL53L1_print_xtalk_histogram_shape_data(
+ VL53L1_xtalk_histogram_shape_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_022",
+ pdata->VL53L1_p_022);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_023",
+ pdata->VL53L1_p_023);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_024",
+ pdata->VL53L1_p_024);
+
+ for (i = 0; i < pdata->VL53L1_p_024; i++) {
+
+ sprintf(ppre_text, "%sbin_data[%u]", pprefix, i);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->bin_data[i],
+ 10,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %s\n",
+ ppre_text,
+ fp_text);
+ }
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->phasecal_result__reference_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "phasecal_result__reference_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_result__vcsel_start",
+ pdata->phasecal_result__vcsel_start);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_config__vcsel_start",
+ pdata->cal_config__vcsel_start);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->vcsel_width,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "vcsel_width",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_019,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_019",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+}
+
+
+void VL53L1_print_xtalk_histogram_data(
+ VL53L1_xtalk_histogram_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+
+
+ sprintf(ppre_text, "%sxtalk_shape.", pprefix);
+ VL53L1_print_xtalk_histogram_shape_data(
+ &(pdata->xtalk_shape),
+ ppre_text, trace_flags);
+
+
+
+ sprintf(ppre_text, "%sxtalk_hist_removed.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &(pdata->xtalk_hist_removed),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_range_data(
+ VL53L1_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_id",
+ pdata->range_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "time_stamp",
+ pdata->time_stamp);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_015",
+ pdata->VL53L1_p_015);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_022",
+ pdata->VL53L1_p_022);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_025",
+ pdata->VL53L1_p_025);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_026",
+ pdata->VL53L1_p_026);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_016",
+ pdata->VL53L1_p_016);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_027",
+ pdata->VL53L1_p_027);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->width,
+ 4, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "width",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_030",
+ pdata->VL53L1_p_030);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->fast_osc_frequency,
+ 12, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "fast_osc_frequency",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_006,
+ 8, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "actual_effective_spad",
+ fp_text);
+
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "total_periods_elapsed",
+ pdata->total_periods_elapsed);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "peak_duration_us",
+ pdata->peak_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "woi_duration_us",
+ pdata->woi_duration_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_p_020",
+ pdata->VL53L1_p_020);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_p_021",
+ pdata->VL53L1_p_021);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "VL53L1_p_013",
+ pdata->VL53L1_p_013);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_signal_count_rate_mcps,
+ 7, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "peak_signal_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->avg_signal_count_rate_mcps,
+ 7, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "avg_signal_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ambient_count_rate_mcps,
+ 7, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ambient_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->total_rate_per_spad_mcps,
+ 13, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "total_rate_per_spad_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_012,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_012",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_005,
+ 2, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_005",
+ fp_text);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_028,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_028",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_014,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_014",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_029,
+ 11, VL53L1_MAX_STRING_LENGTH, fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_029",
+ fp_text);
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "min_range_mm",
+ pdata->min_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "median_range_mm",
+ pdata->median_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "max_range_mm",
+ pdata->max_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_status",
+ pdata->range_status);
+}
+
+
+void VL53L1_print_range_results(
+ VL53L1_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cfg_device_state",
+ pdata->cfg_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "rd_device_state",
+ pdata->rd_device_state);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zone_id",
+ pdata->zone_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "stream_count",
+ pdata->stream_count);
+
+ for (i = 0; i < VL53L1_MAX_AMBIENT_DMAX_VALUES; i++) {
+ sprintf(
+ ppre_text,
+ "%sambient_dmax_mm[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->VL53L1_p_007[i]);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "device_status",
+ pdata->device_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "wrap_dmax_mm",
+ pdata->wrap_dmax_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_results",
+ pdata->max_results);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_results",
+ pdata->active_results);
+
+ for (i = 0; i < pdata->active_results; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_range_data(
+ &pdata->VL53L1_p_002[i],
+ ppre_text, trace_flags);
+ }
+
+ sprintf(ppre_text, "%sxmonitor.", pprefix);
+ VL53L1_print_range_data(
+ &pdata->xmonitor,
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_offset_range_results(
+ VL53L1_offset_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_distance_mm",
+ pdata->cal_distance_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_reflectance_pc",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_status",
+ pdata->cal_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_report",
+ pdata->cal_report);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_results",
+ pdata->max_results);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_results",
+ pdata->active_results);
+
+ for (i = 0; i < pdata->active_results; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_offset_range_data(
+ &(pdata->VL53L1_p_002[i]),
+ ppre_text, trace_flags);
+ }
+}
+
+
+void VL53L1_print_offset_range_data(
+ VL53L1_offset_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "preset_mode",
+ pdata->preset_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "dss_config__roi_mode_control",
+ pdata->dss_config__roi_mode_control);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->dss_config__manual_effective_spads_select,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "dss_config__manual_effective_spads_select",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "no_of_samples",
+ pdata->no_of_samples);
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "peak_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_005,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_005",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "median_range_mm",
+ pdata->median_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "range_mm_offset",
+ pdata->range_mm_offset);
+}
+
+
+void VL53L1_print_cal_peak_rate_map(
+ VL53L1_cal_peak_rate_map_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+ uint8_t x = 0;
+ uint8_t y = 0;
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_distance_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_distance_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_reflectance_pc",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_samples",
+ pdata->max_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "width",
+ pdata->width);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "height",
+ pdata->height);
+
+ i = 0;
+ for (y = 0; y < pdata->height; y++) {
+ for (x = 0; x < pdata->width; x++) {
+
+ sprintf(ppre_text, "%speak_rate_mcps[%u]", pprefix, i);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_rate_mcps[i],
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %s\n",
+ ppre_text,
+ fp_text);
+
+ i++;
+ }
+ }
+}
+
+void VL53L1_print_additional_data(
+ VL53L1_additional_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "preset_mode",
+ pdata->preset_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zone_preset",
+ pdata->zone_preset);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "measurement_mode",
+ pdata->measurement_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "offset_calibration_mode",
+ pdata->offset_calibration_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "offset_correction_mode",
+ pdata->offset_correction_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "dmax_mode",
+ pdata->dmax_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_config_timeout_us",
+ pdata->phasecal_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "mm_config_timeout_us",
+ pdata->mm_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_config_timeout_us",
+ pdata->range_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "inter_measurement_period_ms",
+ pdata->inter_measurement_period_ms);
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->dss_config__target_total_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "dss_config__target_total_rate_mcps",
+ fp_text);
+
+ sprintf(ppre_text, "%s VL53L1_p_010.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &pdata->VL53L1_p_010,
+ ppre_text, trace_flags);
+
+
+}
+
+
+void VL53L1_print_additional_offset_cal_data(
+ VL53L1_additional_offset_cal_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_inner_actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_inner_actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_outer_actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_outer_actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_inner_peak_signal_count_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_inner_peak_signal_count_rtn_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__mm_outer_peak_signal_count_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__mm_outer_peak_signal_count_rtn_mcps",
+ fp_text);
+}
+
+
+void VL53L1_print_gain_calibration_data(
+ VL53L1_gain_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->standard_ranging_gain_factor,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "standard_ranging_gain_factor",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->histogram_ranging_gain_factor,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "histogram_ranging_gain_factor",
+ fp_text);
+}
+
+
+void VL53L1_print_zone_calibration_data(
+ VL53L1_zone_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "no_of_samples",
+ pdata->no_of_samples);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->peak_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "peak_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_014,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_014",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->VL53L1_p_005,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "VL53L1_p_005",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->median_range_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "median_range_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->range_mm_offset,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "range_mm_offset",
+ fp_text);
+}
+
+
+void VL53L1_print_zone_calibration_results(
+ VL53L1_zone_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "preset_mode",
+ pdata->preset_mode);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zone_preset",
+ pdata->zone_preset);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_distance_mm",
+ pdata->cal_distance_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->cal_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "cal_reflectance_pc",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->phasecal_result__reference_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "phasecal_result__reference_phase",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->zero_distance_phase,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "zero_distance_phase",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_status",
+ pdata->cal_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_zones",
+ pdata->max_zones);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_zones",
+ pdata->active_zones);
+
+ for (i = 0; i < pdata->active_zones; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_zone_calibration_data(
+ &(pdata->VL53L1_p_002[i]),
+ ppre_text, trace_flags);
+ }
+}
+
+void VL53L1_print_xtalk_range_results(
+ VL53L1_xtalk_range_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+ uint8_t i = 0;
+
+ VL53L1_histogram_bin_data_t *pbin_data;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "cal_status",
+ pdata->cal_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "num_of_samples_status",
+ pdata->num_of_samples_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zero_samples_status",
+ pdata->zero_samples_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_sigma_status",
+ pdata->max_sigma_status);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_results",
+ pdata->max_results);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_results",
+ pdata->active_results);
+
+ for (i = 0; i < pdata->active_results; i++) {
+ sprintf(ppre_text, "%sdata[%u].", pprefix, i);
+ VL53L1_print_xtalk_range_data(
+ &(pdata->VL53L1_p_002[i]),
+ ppre_text, trace_flags);
+ }
+
+ sprintf(ppre_text, "%scentral_histogram_sum.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &pdata->central_histogram_sum,
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scentral_histogram_avg.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &pdata->central_histogram_avg,
+ ppre_text, trace_flags);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_015",
+ pdata->central_histogram__window_start);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "VL53L1_p_016",
+ pdata->central_histogram__window_end);
+
+ pbin_data = &(pdata->histogram_avg_1[0]);
+
+ for (i = 0; i < 5; i++) {
+ sprintf(ppre_text, "%shistogram_avg_1[%u].", pprefix, i);
+ VL53L1_print_histogram_bin_data(
+ pbin_data,
+ ppre_text, trace_flags);
+ pbin_data++;
+ }
+
+ pbin_data = &(pdata->histogram_avg_2[0]);
+
+ for (i = 0; i < 5; i++) {
+ sprintf(ppre_text, "%shistogram_avg_2[%u].", pprefix, i);
+ VL53L1_print_histogram_bin_data(
+ pbin_data,
+ ppre_text, trace_flags);
+ pbin_data++;
+ }
+
+ pbin_data = &(pdata->xtalk_avg[0]);
+
+ for (i = 0; i < 5; i++) {
+ sprintf(ppre_text, "%sxtalk_avg[%u].", pprefix, i);
+ VL53L1_print_histogram_bin_data(
+ pbin_data,
+ ppre_text, trace_flags);
+ pbin_data++;
+ }
+}
+
+
+void VL53L1_print_xtalk_range_data(
+ VL53L1_xtalk_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "no_of_samples",
+ pdata->no_of_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "signal_total_events_sum",
+ pdata->signal_total_events_sum);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "signal_total_events_avg",
+ pdata->signal_total_events_avg);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->rate_per_spad_kcps_sum,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "rate_per_spad_kcps_sum",
+ fp_text);
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->rate_per_spad_kcps_avg,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "rate_per_spad_kcps_avg",
+ fp_text);
+}
+
+
+void VL53L1_print_xtalk_calibration_results(
+ VL53L1_xtalk_calibration_results_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ int16_t tmpi16;
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ tmpi16 = pdata->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)tmpi16,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ tmpi16 = pdata->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)tmpi16,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+}
+
+
+void VL53L1_print_xtalk_config(
+ VL53L1_xtalk_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ int16_t tmpi16;
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ tmpi16 = pdata->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)tmpi16,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ tmpi16 = pdata->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)tmpi16,
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "global_crosstalk_compensation_enable",
+ pdata->global_crosstalk_compensation_enable);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->histogram_mode_crosstalk_margin_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "histogram_mode_crosstalk_margin_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->lite_mode_crosstalk_margin_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "lite_mode_crosstalk_margin_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->crosstalk_range_ignore_threshold_mult,
+ 5,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "crosstalk_range_ignore_threshold_mult",
+ fp_text);
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->crosstalk_range_ignore_threshold_rate_mcps,
+ 13,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "crosstalk_range_ignore_threshold_rate_mcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "algo__crosstalk_detect_max_valid_range_mm",
+ pdata->algo__crosstalk_detect_max_valid_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "algo__crosstalk_detect_min_valid_range_mm",
+ pdata->algo__crosstalk_detect_min_valid_range_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_detect_max_valid_rate_kcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_detect_max_valid_rate_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_detect_max_sigma_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_detect_max_sigma_mm",
+ fp_text);
+
+}
+
+
+void VL53L1_print_xtalk_extract_config(
+ VL53L1_xtalkextract_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->dss_config__target_total_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "dss_config__target_total_rate_mcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "mm_config_timeout_us",
+ pdata->mm_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_config_timeout_us",
+ pdata->range_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "num_of_samples",
+ pdata->num_of_samples);
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "algo__crosstalk_extract_max_valid_range_mm",
+ pdata->algo__crosstalk_extract_max_valid_range_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "algo__crosstalk_extract_min_valid_range_mm",
+ pdata->algo__crosstalk_extract_min_valid_range_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_extract_max_valid_rate_kcps,
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_extract_max_valid_rate_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->algo__crosstalk_extract_max_sigma_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "algo__crosstalk_extract_max_sigma_mm",
+ fp_text);
+
+}
+
+
+void VL53L1_print_zone_cal_config(
+ VL53L1_zonecal_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->dss_config__target_total_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "dss_config__target_total_rate_mcps",
+ fp_text);
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "mm_config_timeout_us",
+ pdata->mm_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_config_timeout_us",
+ pdata->range_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_config_timeout_us",
+ pdata->phasecal_config_timeout_us);
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_num_of_samples",
+ pdata->phasecal_num_of_samples);
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "zone_num_of_samples",
+ pdata->zone_num_of_samples);
+
+}
+
+void VL53L1_print_offset_cal_config(
+ VL53L1_offsetcal_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->dss_config__target_total_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "dss_config__target_total_rate_mcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "phasecal_config_timeout_us",
+ pdata->phasecal_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "range_config_timeout_us",
+ pdata->range_config_timeout_us);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "pre_num_of_samples",
+ pdata->pre_num_of_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "mm1_num_of_samples",
+ pdata->mm1_num_of_samples);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "mm2_num_of_samples",
+ pdata->mm2_num_of_samples);
+
+
+}
+
+
+void VL53L1_print_dmax_calibration_data(
+ VL53L1_dmax_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref__actual_effective_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref__actual_effective_spads",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref__peak_signal_count_rate_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref__peak_signal_count_rate_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref__distance_mm,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref__distance_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->ref_reflectance_pc,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "ref_reflectance_pc",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->coverglass_transmission,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "coverglass_transmission",
+ fp_text);
+}
+
+
+void VL53L1_print_calibration_data(
+ VL53L1_calibration_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = 0x%08X\n",
+ pprefix,
+ "struct_version",
+ pdata->struct_version);
+
+ sprintf(ppre_text, "%scustomer.", pprefix);
+ VL53L1_print_customer_nvm_managed(
+ &(pdata->customer),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sfmt_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->fmt_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scust_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->cust_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sadd_off_cal_data.", pprefix);
+ VL53L1_print_additional_offset_cal_data(
+ &(pdata->add_off_cal_data),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%soptical_centre.", pprefix);
+ VL53L1_print_optical_centre(
+ &(pdata->optical_centre),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sxtalkhisto.", pprefix);
+ VL53L1_print_xtalk_histogram_data(
+ &(pdata->xtalkhisto),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sgain_cal.", pprefix);
+ VL53L1_print_gain_calibration_data(
+ &(pdata->gain_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scal_peak_rate_map.", pprefix);
+ VL53L1_print_cal_peak_rate_map(
+ &(pdata->cal_peak_rate_map),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_xtalk_debug_data(
+ VL53L1_xtalk_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ sprintf(ppre_text, "%scustomer.", pprefix);
+ VL53L1_print_customer_nvm_managed(
+ &(pdata->customer),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sxtalk_cfg.", pprefix);
+ VL53L1_print_xtalk_config(
+ &(pdata->xtalk_cfg),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sxtalk_extract_cfg.", pprefix);
+ VL53L1_print_xtalk_extract_config(
+ &(pdata->xtalk_extract_cfg),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%shist_data.", pprefix);
+ VL53L1_print_histogram_bin_data(
+ &(pdata->hist_data),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sxtalk_shapes.", pprefix);
+ VL53L1_print_xtalk_histogram_data(
+ &(pdata->xtalk_shapes),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sgain_cal.", pprefix);
+ VL53L1_print_xtalk_range_results(
+ &(pdata->xtalk_results),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_offset_debug_data(
+ VL53L1_offset_debug_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ sprintf(ppre_text, "%scustomer.", pprefix);
+ VL53L1_print_customer_nvm_managed(
+ &(pdata->customer),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sfmt_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->fmt_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%scust_dmax_cal.", pprefix);
+ VL53L1_print_dmax_calibration_data(
+ &(pdata->cust_dmax_cal),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%sadd_off_cal_data.", pprefix);
+ VL53L1_print_additional_offset_cal_data(
+ &(pdata->add_off_cal_data),
+ ppre_text, trace_flags);
+
+ sprintf(ppre_text, "%soffset_results.", pprefix);
+ VL53L1_print_offset_range_results(
+ &(pdata->offset_results),
+ ppre_text, trace_flags);
+}
+
+
+void VL53L1_print_zone_config(
+ VL53L1_zone_config_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "max_zones",
+ pdata->max_zones);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "active_zones",
+ pdata->active_zones);
+
+ for (i = 0; i < pdata->active_zones; i++) {
+ sprintf(ppre_text, "%suser_zones[%u].", pprefix, i);
+ VL53L1_print_user_zone(
+ &pdata->user_zones[i],
+ ppre_text,
+ trace_flags);
+ }
+}
+
+
+void VL53L1_print_optical_centre(
+ VL53L1_optical_centre_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->x_centre,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "x_centre",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->y_centre,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "y_centre",
+ fp_text);
+}
+
+
+void VL53L1_print_user_zone(
+ VL53L1_user_zone_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "x_centre",
+ pdata->x_centre);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "y_centre",
+ pdata->y_centre);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "width",
+ pdata->width);
+
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "height",
+ pdata->height);
+}
+
+
+void VL53L1_print_spad_rate_data(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+
+ uint16_t spad_no = 0;
+ uint8_t row = 0;
+ uint8_t col = 0;
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%8s,%4s,%4s, %s\n",
+ pprefix,
+ "spad_no",
+ "row",
+ "col",
+ "peak_rate_mcps");
+
+ for (spad_no = 0; spad_no < pspad_rates->no_of_values; spad_no++) {
+
+
+
+ VL53L1_decode_row_col(
+ (uint8_t)spad_no,
+ &row,
+ &col);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pspad_rates->rate_data[spad_no],
+ pspad_rates->fractional_bits,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%8u,%4u,%4u, %s\n",
+ pprefix,
+ spad_no,
+ row,
+ col,
+ fp_text);
+ }
+}
+
+
+void VL53L1_print_spad_rate_map(
+ VL53L1_spad_rate_data_t *pspad_rates,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+
+ uint8_t spad_no = 0;
+ uint8_t row = 0;
+ uint8_t col = 0;
+
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%4s",
+ pprefix,
+ " ");
+
+ for (col = 0; col < VL53L1_SPAD_ARRAY_WIDTH; col++)
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ ",%8u",
+ col);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n");
+
+
+
+
+ for (row = 0; row < VL53L1_SPAD_ARRAY_HEIGHT; row++) {
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%4u",
+ pprefix,
+ row);
+
+ for (col = 0; col < VL53L1_SPAD_ARRAY_HEIGHT; col++) {
+
+
+
+
+ VL53L1_encode_row_col(
+ row,
+ col,
+ &spad_no);
+
+
+
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pspad_rates->rate_data[spad_no],
+ pspad_rates->fractional_bits,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+
+
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ ",%8s",
+ fp_text);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n");
+ }
+}
+
+
+#endif
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_api_preset_modes.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_preset_modes.c
new file mode 100644
index 000000000000..224c82924f80
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_preset_modes.c
@@ -0,0 +1,4939 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_zone_presets.h"
+#include "vl53l1_core.h"
+#include "vl53l1_api_preset_modes.h"
+#include "vl53l1_tuning_parm_defaults.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API,\
+ status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_init_refspadchar_config_struct(
+ VL53L1_refspadchar_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+ pdata->device_test_mode =
+ VL53L1_TUNINGPARM_REFSPADCHAR_DEVICE_TEST_MODE_DEFAULT;
+ pdata->VL53L1_p_009 =
+ VL53L1_TUNINGPARM_REFSPADCHAR_VCSEL_PERIOD_DEFAULT;
+ pdata->timeout_us =
+ VL53L1_TUNINGPARM_REFSPADCHAR_PHASECAL_TIMEOUT_US_DEFAULT;
+ pdata->target_count_rate_mcps =
+ VL53L1_TUNINGPARM_REFSPADCHAR_TARGET_COUNT_RATE_MCPS_DEFAULT;
+ pdata->min_count_rate_limit_mcps =
+ VL53L1_TUNINGPARM_REFSPADCHAR_MIN_COUNTRATE_LIMIT_MCPS_DEFAULT;
+ pdata->max_count_rate_limit_mcps =
+ VL53L1_TUNINGPARM_REFSPADCHAR_MAX_COUNTRATE_LIMIT_MCPS_DEFAULT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_ssc_config_struct(
+ VL53L1_ssc_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ pdata->array_select = VL53L1_DEVICESSCARRAY_RTN;
+
+
+
+ pdata->VL53L1_p_009 =
+ VL53L1_TUNINGPARM_SPADMAP_VCSEL_PERIOD_DEFAULT;
+
+
+
+ pdata->vcsel_start =
+ VL53L1_TUNINGPARM_SPADMAP_VCSEL_START_DEFAULT;
+
+
+
+ pdata->vcsel_width = 0x02;
+
+
+
+ pdata->timeout_us = 36000;
+
+
+
+
+
+
+ pdata->rate_limit_mcps =
+ VL53L1_TUNINGPARM_SPADMAP_RATE_LIMIT_MCPS_DEFAULT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_xtalk_config_struct(
+ VL53L1_customer_nvm_managed_t *pnvm,
+ VL53L1_xtalk_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdata->algo__crosstalk_compensation_plane_offset_kcps =
+ pnvm->algo__crosstalk_compensation_plane_offset_kcps;
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+
+
+ pdata->nvm_default__crosstalk_compensation_plane_offset_kcps =
+ (uint32_t)pnvm->algo__crosstalk_compensation_plane_offset_kcps;
+ pdata->nvm_default__crosstalk_compensation_x_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pdata->nvm_default__crosstalk_compensation_y_plane_gradient_kcps =
+ pnvm->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+ pdata->histogram_mode_crosstalk_margin_kcps =
+ VL53L1_TUNINGPARM_HIST_XTALK_MARGIN_KCPS_DEFAULT;
+ pdata->lite_mode_crosstalk_margin_kcps =
+ VL53L1_TUNINGPARM_LITE_XTALK_MARGIN_KCPS_DEFAULT;
+
+
+
+
+ pdata->crosstalk_range_ignore_threshold_mult =
+ VL53L1_TUNINGPARM_LITE_RIT_MULT_DEFAULT;
+
+ if ((pdata->algo__crosstalk_compensation_plane_offset_kcps == 0x00)
+ && (pdata->algo__crosstalk_compensation_x_plane_gradient_kcps
+ == 0x00)
+ && (pdata->algo__crosstalk_compensation_y_plane_gradient_kcps
+ == 0x00))
+ pdata->global_crosstalk_compensation_enable = 0x00;
+ else
+ pdata->global_crosstalk_compensation_enable = 0x01;
+
+
+ if ((status == VL53L1_ERROR_NONE) &&
+ (pdata->global_crosstalk_compensation_enable == 0x01)) {
+ pdata->crosstalk_range_ignore_threshold_rate_mcps =
+ VL53L1_calc_range_ignore_threshold(
+ pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ pdata->crosstalk_range_ignore_threshold_mult);
+ } else {
+ pdata->crosstalk_range_ignore_threshold_rate_mcps = 0;
+ }
+
+
+
+
+
+
+
+ pdata->algo__crosstalk_detect_min_valid_range_mm =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MIN_VALID_RANGE_MM_DEFAULT;
+ pdata->algo__crosstalk_detect_max_valid_range_mm =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RANGE_MM_DEFAULT;
+ pdata->algo__crosstalk_detect_max_valid_rate_kcps =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RATE_KCPS_DEFAULT;
+ pdata->algo__crosstalk_detect_max_sigma_mm =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MAX_SIGMA_MM_DEFAULT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_init_xtalk_extract_config_struct(
+ VL53L1_xtalkextract_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pdata->dss_config__target_total_rate_mcps =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_RATE_MCPS_DEFAULT;
+
+
+ pdata->mm_config_timeout_us =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_DSS_TIMEOUT_US_DEFAULT;
+
+
+ pdata->num_of_samples =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_NUM_OF_SAMPLES_DEFAULT;
+
+ pdata->phasecal_config_timeout_us =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_PHASECAL_TIMEOUT_US_DEFAULT;
+
+
+ pdata->range_config_timeout_us =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_BIN_TIMEOUT_US_DEFAULT;
+
+
+
+
+
+
+ pdata->algo__crosstalk_extract_min_valid_range_mm =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_MIN_FILTER_THRESH_MM_DEFAULT;
+ pdata->algo__crosstalk_extract_max_valid_range_mm =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_FILTER_THRESH_MM_DEFAULT;
+ pdata->algo__crosstalk_extract_max_valid_rate_kcps =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_MAX_VALID_RATE_KCPS_DEFAULT;
+ pdata->algo__crosstalk_extract_max_sigma_mm =
+ VL53L1_TUNINGPARM_XTALK_EXTRACT_SIGMA_THRESHOLD_MM_DEFAULT;
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_offset_cal_config_struct(
+ VL53L1_offsetcal_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pdata->dss_config__target_total_rate_mcps =
+ VL53L1_TUNINGPARM_OFFSET_CAL_DSS_RATE_MCPS_DEFAULT;
+
+
+ pdata->phasecal_config_timeout_us =
+ VL53L1_TUNINGPARM_OFFSET_CAL_PHASECAL_TIMEOUT_US_DEFAULT;
+
+
+ pdata->range_config_timeout_us =
+ VL53L1_TUNINGPARM_OFFSET_CAL_RANGE_TIMEOUT_US_DEFAULT;
+
+
+ pdata->mm_config_timeout_us =
+ VL53L1_TUNINGPARM_OFFSET_CAL_MM_TIMEOUT_US_DEFAULT;
+
+
+
+
+
+
+ pdata->pre_num_of_samples =
+ VL53L1_TUNINGPARM_OFFSET_CAL_PRE_SAMPLES_DEFAULT;
+ pdata->mm1_num_of_samples =
+ VL53L1_TUNINGPARM_OFFSET_CAL_MM1_SAMPLES_DEFAULT;
+ pdata->mm2_num_of_samples =
+ VL53L1_TUNINGPARM_OFFSET_CAL_MM2_SAMPLES_DEFAULT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_init_zone_cal_config_struct(
+ VL53L1_zonecal_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pdata->dss_config__target_total_rate_mcps =
+ VL53L1_TUNINGPARM_ZONE_CAL_DSS_RATE_MCPS_DEFAULT;
+
+
+ pdata->phasecal_config_timeout_us =
+ VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_TIMEOUT_US_DEFAULT;
+
+
+ pdata->range_config_timeout_us =
+ VL53L1_TUNINGPARM_ZONE_CAL_RANGE_TIMEOUT_US_DEFAULT;
+
+
+ pdata->mm_config_timeout_us =
+ VL53L1_TUNINGPARM_ZONE_CAL_DSS_TIMEOUT_US_DEFAULT;
+
+
+
+
+
+
+ pdata->phasecal_num_of_samples =
+ VL53L1_TUNINGPARM_ZONE_CAL_PHASECAL_NUM_SAMPLES_DEFAULT;
+ pdata->zone_num_of_samples =
+ VL53L1_TUNINGPARM_ZONE_CAL_ZONE_NUM_SAMPLES_DEFAULT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_hist_post_process_config_struct(
+ uint8_t xtalk_compensation_enable,
+ VL53L1_hist_post_process_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pdata->hist_algo_select =
+ VL53L1_TUNINGPARM_HIST_ALGO_SELECT_DEFAULT;
+
+
+
+
+ pdata->hist_target_order =
+ VL53L1_TUNINGPARM_HIST_TARGET_ORDER_DEFAULT;
+
+
+
+
+ pdata->filter_woi0 =
+ VL53L1_TUNINGPARM_HIST_FILTER_WOI_0_DEFAULT;
+
+ pdata->filter_woi1 =
+ VL53L1_TUNINGPARM_HIST_FILTER_WOI_1_DEFAULT;
+
+
+
+
+ pdata->hist_amb_est_method =
+ VL53L1_TUNINGPARM_HIST_AMB_EST_METHOD_DEFAULT;
+
+ pdata->ambient_thresh_sigma0 =
+ VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_0_DEFAULT;
+
+ pdata->ambient_thresh_sigma1 =
+ VL53L1_TUNINGPARM_HIST_AMB_THRESH_SIGMA_1_DEFAULT;
+
+
+
+
+ pdata->ambient_thresh_events_scaler =
+ VL53L1_TUNINGPARM_HIST_AMB_EVENTS_SCALER_DEFAULT;
+
+
+
+ pdata->min_ambient_thresh_events =
+ VL53L1_TUNINGPARM_HIST_MIN_AMB_THRESH_EVENTS_DEFAULT;
+
+
+ pdata->noise_threshold =
+ VL53L1_TUNINGPARM_HIST_NOISE_THRESHOLD_DEFAULT;
+
+
+ pdata->signal_total_events_limit =
+ VL53L1_TUNINGPARM_HIST_SIGNAL_TOTAL_EVENTS_LIMIT_DEFAULT;
+
+ pdata->sigma_estimator__sigma_ref_mm =
+ VL53L1_TUNINGPARM_HIST_SIGMA_EST_REF_MM_DEFAULT;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdata->sigma_thresh =
+ VL53L1_TUNINGPARM_HIST_SIGMA_THRESH_MM_DEFAULT;
+
+ pdata->range_offset_mm = 0;
+
+
+ pdata->gain_factor =
+ VL53L1_TUNINGPARM_HIST_GAIN_FACTOR_DEFAULT;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdata->valid_phase_low = 0x08;
+ pdata->valid_phase_high = 0x88;
+
+
+
+
+
+
+
+
+
+ pdata->algo__consistency_check__phase_tolerance =
+ VL53L1_TUNINGPARM_CONSISTENCY_HIST_PHASE_TOLERANCE_DEFAULT;
+
+
+
+
+
+
+
+
+
+ pdata->algo__consistency_check__event_sigma =
+ VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_DEFAULT;
+
+
+
+ pdata->algo__consistency_check__event_min_spad_count =
+ VL53L1_TUNINGPARM_CONSISTENCY_HIST_EVENT_SIGMA_MIN_SPAD_LIMIT_DEFAULT;
+
+
+
+
+
+ pdata->algo__consistency_check__min_max_tolerance =
+ VL53L1_TUNINGPARM_CONSISTENCY_HIST_MIN_MAX_TOLERANCE_MM_DEFAULT;
+
+
+
+ pdata->algo__crosstalk_compensation_enable = xtalk_compensation_enable;
+
+
+
+
+
+
+
+
+
+
+
+ pdata->algo__crosstalk_detect_min_valid_range_mm =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MIN_VALID_RANGE_MM_DEFAULT;
+ pdata->algo__crosstalk_detect_max_valid_range_mm =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RANGE_MM_DEFAULT;
+ pdata->algo__crosstalk_detect_max_valid_rate_kcps =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MAX_VALID_RATE_KCPS_DEFAULT;
+ pdata->algo__crosstalk_detect_max_sigma_mm =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MAX_SIGMA_MM_DEFAULT;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdata->algo__crosstalk_detect_event_sigma =
+ VL53L1_TUNINGPARM_XTALK_DETECT_EVENT_SIGMA_DEFAULT;
+
+
+
+
+
+ pdata->algo__crosstalk_detect_min_max_tolerance =
+ VL53L1_TUNINGPARM_XTALK_DETECT_MIN_MAX_TOLERANCE_DEFAULT;
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_dmax_calibration_data_struct(
+ VL53L1_dmax_calibration_data_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pdata->ref__actual_effective_spads = 0x5F2D;
+
+
+ pdata->ref__peak_signal_count_rate_mcps = 0x0844;
+
+
+ pdata->ref__distance_mm = 0x08A5;
+
+
+
+
+ pdata->ref_reflectance_pc = 0x0014;
+
+
+
+ pdata->coverglass_transmission = 0x0100;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_tuning_parm_storage_struct(
+ VL53L1_tuning_parm_storage_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ pdata->tp_tuning_parm_version =
+ VL53L1_TUNINGPARM_VERSION_DEFAULT;
+ pdata->tp_tuning_parm_key_table_version =
+ VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT;
+ pdata->tp_tuning_parm_lld_version =
+ VL53L1_TUNINGPARM_LLD_VERSION_DEFAULT;
+ pdata->tp_init_phase_rtn_lite_long =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_LONG_RANGE_DEFAULT;
+ pdata->tp_init_phase_rtn_lite_med =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_MED_RANGE_DEFAULT;
+ pdata->tp_init_phase_rtn_lite_short =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_SHORT_RANGE_DEFAULT;
+ pdata->tp_init_phase_ref_lite_long =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_LONG_RANGE_DEFAULT;
+ pdata->tp_init_phase_ref_lite_med =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_MED_RANGE_DEFAULT;
+ pdata->tp_init_phase_ref_lite_short =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_SHORT_RANGE_DEFAULT;
+ pdata->tp_init_phase_rtn_hist_long =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_LONG_RANGE_DEFAULT;
+ pdata->tp_init_phase_rtn_hist_med =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_MED_RANGE_DEFAULT;
+ pdata->tp_init_phase_rtn_hist_short =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_HISTO_SHORT_RANGE_DEFAULT;
+ pdata->tp_init_phase_ref_hist_long =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_LONG_RANGE_DEFAULT;
+ pdata->tp_init_phase_ref_hist_med =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_MED_RANGE_DEFAULT;
+ pdata->tp_init_phase_ref_hist_short =
+ VL53L1_TUNINGPARM_INITIAL_PHASE_REF_HISTO_SHORT_RANGE_DEFAULT;
+ pdata->tp_consistency_lite_phase_tolerance =
+ VL53L1_TUNINGPARM_CONSISTENCY_LITE_PHASE_TOLERANCE_DEFAULT;
+ pdata->tp_phasecal_target =
+ VL53L1_TUNINGPARM_PHASECAL_TARGET_DEFAULT;
+ pdata->tp_cal_repeat_rate =
+ VL53L1_TUNINGPARM_LITE_CAL_REPEAT_RATE_DEFAULT;
+ pdata->tp_lite_min_clip =
+ VL53L1_TUNINGPARM_LITE_MIN_CLIP_MM_DEFAULT;
+ pdata->tp_lite_long_sigma_thresh_mm =
+ VL53L1_TUNINGPARM_LITE_LONG_SIGMA_THRESH_MM_DEFAULT;
+ pdata->tp_lite_med_sigma_thresh_mm =
+ VL53L1_TUNINGPARM_LITE_MED_SIGMA_THRESH_MM_DEFAULT;
+ pdata->tp_lite_short_sigma_thresh_mm =
+ VL53L1_TUNINGPARM_LITE_SHORT_SIGMA_THRESH_MM_DEFAULT;
+ pdata->tp_lite_long_min_count_rate_rtn_mcps =
+ VL53L1_TUNINGPARM_LITE_LONG_MIN_COUNT_RATE_RTN_MCPS_DEFAULT;
+ pdata->tp_lite_med_min_count_rate_rtn_mcps =
+ VL53L1_TUNINGPARM_LITE_MED_MIN_COUNT_RATE_RTN_MCPS_DEFAULT;
+ pdata->tp_lite_short_min_count_rate_rtn_mcps =
+ VL53L1_TUNINGPARM_LITE_SHORT_MIN_COUNT_RATE_RTN_MCPS_DEFAULT;
+ pdata->tp_lite_sigma_est_pulse_width_ns =
+ VL53L1_TUNINGPARM_LITE_SIGMA_EST_PULSE_WIDTH_DEFAULT;
+ pdata->tp_lite_sigma_est_amb_width_ns =
+ VL53L1_TUNINGPARM_LITE_SIGMA_EST_AMB_WIDTH_NS_DEFAULT;
+ pdata->tp_lite_sigma_ref_mm =
+ VL53L1_TUNINGPARM_LITE_SIGMA_REF_MM_DEFAULT;
+ pdata->tp_lite_seed_cfg =
+ VL53L1_TUNINGPARM_LITE_SEED_CONFIG_DEFAULT;
+ pdata->tp_timed_seed_cfg =
+ VL53L1_TUNINGPARM_TIMED_SEED_CONFIG_DEFAULT;
+ pdata->tp_lite_quantifier =
+ VL53L1_TUNINGPARM_LITE_QUANTIFIER_DEFAULT;
+ pdata->tp_lite_first_order_select =
+ VL53L1_TUNINGPARM_LITE_FIRST_ORDER_SELECT_DEFAULT;
+
+
+
+
+
+
+ pdata->tp_dss_target_lite_mcps =
+ VL53L1_TUNINGPARM_LITE_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT;
+ pdata->tp_dss_target_histo_mcps =
+ VL53L1_TUNINGPARM_RANGING_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT;
+ pdata->tp_dss_target_histo_mz_mcps =
+ VL53L1_TUNINGPARM_MZ_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT;
+ pdata->tp_dss_target_timed_mcps =
+ VL53L1_TUNINGPARM_TIMED_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT;
+ pdata->tp_phasecal_timeout_lite_us =
+ VL53L1_TUNINGPARM_LITE_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_phasecal_timeout_hist_long_us =
+ VL53L1_TUNINGPARM_RANGING_LONG_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_phasecal_timeout_hist_med_us =
+ VL53L1_TUNINGPARM_RANGING_MED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_phasecal_timeout_hist_short_us =
+ VL53L1_TUNINGPARM_RANGING_SHORT_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_phasecal_timeout_mz_long_us =
+ VL53L1_TUNINGPARM_MZ_LONG_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_phasecal_timeout_mz_med_us =
+ VL53L1_TUNINGPARM_MZ_MED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_phasecal_timeout_mz_short_us =
+ VL53L1_TUNINGPARM_MZ_SHORT_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_phasecal_timeout_timed_us =
+ VL53L1_TUNINGPARM_TIMED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_mm_timeout_lite_us =
+ VL53L1_TUNINGPARM_LITE_MM_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_mm_timeout_histo_us =
+ VL53L1_TUNINGPARM_RANGING_MM_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_mm_timeout_mz_us =
+ VL53L1_TUNINGPARM_MZ_MM_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_mm_timeout_timed_us =
+ VL53L1_TUNINGPARM_TIMED_MM_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_range_timeout_lite_us =
+ VL53L1_TUNINGPARM_LITE_RANGE_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_range_timeout_histo_us =
+ VL53L1_TUNINGPARM_RANGING_RANGE_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_range_timeout_mz_us =
+ VL53L1_TUNINGPARM_MZ_RANGE_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_range_timeout_timed_us =
+ VL53L1_TUNINGPARM_TIMED_RANGE_CONFIG_TIMEOUT_US_DEFAULT;
+
+
+
+
+ pdata->tp_mm_timeout_lpa_us =
+ VL53L1_TUNINGPARM_LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US_DEFAULT;
+ pdata->tp_range_timeout_lpa_us =
+ VL53L1_TUNINGPARM_LOWPOWERAUTO_RANGE_CONFIG_TIMEOUT_US_DEFAULT;
+
+ pdata->tp_dss_target_very_short_mcps =
+ VL53L1_TUNINGPARM_VERY_SHORT_DSS_RATE_MCPS_DEFAULT;
+
+ pdata->tp_phasecal_patch_power =
+ VL53L1_TUNINGPARM_PHASECAL_PATCH_POWER_DEFAULT;
+
+ pdata->tp_hist_merge =
+ VL53L1_TUNINGPARM_HIST_MERGE_DEFAULT;
+
+ pdata->tp_reset_merge_threshold =
+ VL53L1_TUNINGPARM_RESET_MERGE_THRESHOLD_DEFAULT;
+
+ pdata->tp_hist_merge_max_size =
+ VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE_DEFAULT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_hist_gen3_dmax_config_struct(
+ VL53L1_hist_gen3_dmax_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdata->dss_config__target_total_rate_mcps = 0x1400;
+ pdata->dss_config__aperture_attenuation = 0x38;
+
+ pdata->signal_thresh_sigma =
+ VL53L1_TUNINGPARM_DMAX_CFG_SIGNAL_THRESH_SIGMA_DEFAULT;
+ pdata->ambient_thresh_sigma = 0x70;
+ pdata->min_ambient_thresh_events = 16;
+ pdata->signal_total_events_limit = 100;
+ pdata->max_effective_spads = 0xFFFF;
+
+
+
+
+
+
+
+
+
+
+
+ pdata->target_reflectance_for_dmax_calc[0] =
+ VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_0_DEFAULT;
+ pdata->target_reflectance_for_dmax_calc[1] =
+ VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_1_DEFAULT;
+ pdata->target_reflectance_for_dmax_calc[2] =
+ VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_2_DEFAULT;
+ pdata->target_reflectance_for_dmax_calc[3] =
+ VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_3_DEFAULT;
+ pdata->target_reflectance_for_dmax_calc[4] =
+ VL53L1_TUNINGPARM_DMAX_CFG_REFLECTANCE_ARRAY_4_DEFAULT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pstatic->dss_config__target_total_rate_mcps = 0x0A00;
+ pstatic->debug__ctrl = 0x00;
+ pstatic->test_mode__ctrl = 0x00;
+ pstatic->clk_gating__ctrl = 0x00;
+ pstatic->nvm_bist__ctrl = 0x00;
+ pstatic->nvm_bist__num_nvm_words = 0x00;
+ pstatic->nvm_bist__start_address = 0x00;
+ pstatic->host_if__status = 0x00;
+ pstatic->pad_i2c_hv__config = 0x00;
+ pstatic->pad_i2c_hv__extsup_config = 0x00;
+
+
+
+
+
+
+ pstatic->gpio_hv_pad__ctrl = 0x00;
+
+
+
+
+
+
+
+
+ pstatic->gpio_hv_mux__ctrl =
+ VL53L1_DEVICEINTERRUPTPOLARITY_ACTIVE_LOW |
+ VL53L1_DEVICEGPIOMODE_OUTPUT_RANGE_AND_ERROR_INTERRUPTS;
+
+ pstatic->gpio__tio_hv_status = 0x02;
+ pstatic->gpio__fio_hv_status = 0x00;
+ pstatic->ana_config__spad_sel_pswidth = 0x02;
+ pstatic->ana_config__vcsel_pulse_width_offset = 0x08;
+ pstatic->ana_config__fast_osc__config_ctrl = 0x00;
+
+ pstatic->sigma_estimator__effective_pulse_width_ns =
+ ptuning_parms->tp_lite_sigma_est_pulse_width_ns;
+ pstatic->sigma_estimator__effective_ambient_width_ns =
+ ptuning_parms->tp_lite_sigma_est_amb_width_ns;
+ pstatic->sigma_estimator__sigma_ref_mm =
+ ptuning_parms->tp_lite_sigma_ref_mm;
+
+
+ pstatic->algo__crosstalk_compensation_valid_height_mm = 0x01;
+ pstatic->spare_host_config__static_config_spare_0 = 0x00;
+ pstatic->spare_host_config__static_config_spare_1 = 0x00;
+
+ pstatic->algo__range_ignore_threshold_mcps = 0x0000;
+
+
+
+ pstatic->algo__range_ignore_valid_height_mm = 0xff;
+ pstatic->algo__range_min_clip =
+ ptuning_parms->tp_lite_min_clip;
+
+
+
+
+
+
+ pstatic->algo__consistency_check__tolerance =
+ ptuning_parms->tp_consistency_lite_phase_tolerance;
+ pstatic->spare_host_config__static_config_spare_2 = 0x00;
+ pstatic->sd_config__reset_stages_msb = 0x00;
+ pstatic->sd_config__reset_stages_lsb = 0x00;
+
+ pgeneral->gph_config__stream_count_update_value = 0x00;
+ pgeneral->global_config__stream_divider = 0x00;
+ pgeneral->system__interrupt_config_gpio =
+ VL53L1_INTERRUPT_CONFIG_NEW_SAMPLE_READY;
+ pgeneral->cal_config__vcsel_start = 0x0B;
+
+
+
+
+
+
+
+
+ pgeneral->cal_config__repeat_rate =
+ ptuning_parms->tp_cal_repeat_rate;
+ pgeneral->global_config__vcsel_width = 0x02;
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0x0D;
+
+
+ pgeneral->phasecal_config__target =
+ ptuning_parms->tp_phasecal_target;
+ pgeneral->phasecal_config__override = 0x00;
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__TARGET_RATE;
+
+
+ pgeneral->system__thresh_rate_high = 0x0000;
+ pgeneral->system__thresh_rate_low = 0x0000;
+
+
+ pgeneral->dss_config__manual_effective_spads_select = 0x8C00;
+ pgeneral->dss_config__manual_block_select = 0x00;
+
+
+
+
+
+
+
+
+ pgeneral->dss_config__aperture_attenuation = 0x38;
+ pgeneral->dss_config__max_spads_limit = 0xFF;
+ pgeneral->dss_config__min_spads_limit = 0x01;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x1a;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x20;
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x01;
+ ptiming->range_config__timeout_macrop_a_lo = 0xCC;
+
+
+ ptiming->range_config__vcsel_period_a = 0x0B;
+
+
+ ptiming->range_config__timeout_macrop_b_hi = 0x01;
+ ptiming->range_config__timeout_macrop_b_lo = 0xF5;
+
+
+ ptiming->range_config__vcsel_period_b = 0x09;
+
+
+
+
+
+
+
+ ptiming->range_config__sigma_thresh =
+ ptuning_parms->tp_lite_med_sigma_thresh_mm;
+
+
+
+
+
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps =
+ ptuning_parms->tp_lite_med_min_count_rate_rtn_mcps;
+
+
+
+
+
+
+ ptiming->range_config__valid_phase_low = 0x08;
+ ptiming->range_config__valid_phase_high = 0x78;
+ ptiming->system__intermeasurement_period = 0x00000000;
+ ptiming->system__fractional_enable = 0x00;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ phistogram->histogram_config__low_amb_even_bin_0_1 = 0x07;
+ phistogram->histogram_config__low_amb_even_bin_2_3 = 0x21;
+ phistogram->histogram_config__low_amb_even_bin_4_5 = 0x43;
+
+ phistogram->histogram_config__low_amb_odd_bin_0_1 = 0x10;
+ phistogram->histogram_config__low_amb_odd_bin_2_3 = 0x32;
+ phistogram->histogram_config__low_amb_odd_bin_4_5 = 0x54;
+
+ phistogram->histogram_config__mid_amb_even_bin_0_1 = 0x07;
+ phistogram->histogram_config__mid_amb_even_bin_2_3 = 0x21;
+ phistogram->histogram_config__mid_amb_even_bin_4_5 = 0x43;
+
+ phistogram->histogram_config__mid_amb_odd_bin_0_1 = 0x10;
+ phistogram->histogram_config__mid_amb_odd_bin_2 = 0x02;
+ phistogram->histogram_config__mid_amb_odd_bin_3_4 = 0x43;
+ phistogram->histogram_config__mid_amb_odd_bin_5 = 0x05;
+
+ phistogram->histogram_config__user_bin_offset = 0x00;
+
+ phistogram->histogram_config__high_amb_even_bin_0_1 = 0x07;
+ phistogram->histogram_config__high_amb_even_bin_2_3 = 0x21;
+ phistogram->histogram_config__high_amb_even_bin_4_5 = 0x43;
+
+ phistogram->histogram_config__high_amb_odd_bin_0_1 = 0x10;
+ phistogram->histogram_config__high_amb_odd_bin_2_3 = 0x32;
+ phistogram->histogram_config__high_amb_odd_bin_4_5 = 0x54;
+
+ phistogram->histogram_config__amb_thresh_low = 0xFFFF;
+ phistogram->histogram_config__amb_thresh_high = 0xFFFF;
+
+ phistogram->histogram_config__spad_array_selection = 0x00;
+
+
+
+
+
+
+
+
+ pzone_cfg->max_zones = VL53L1_MAX_USER_ZONES;
+ pzone_cfg->active_zones = 0x00;
+ pzone_cfg->user_zones[0].height = 0x0f;
+ pzone_cfg->user_zones[0].width = 0x0f;
+ pzone_cfg->user_zones[0].x_centre = 0x08;
+ pzone_cfg->user_zones[0].y_centre = 0x08;
+
+
+
+
+ pdynamic->system__grouped_parameter_hold_0 = 0x01;
+
+ pdynamic->system__thresh_high = 0x0000;
+ pdynamic->system__thresh_low = 0x0000;
+ pdynamic->system__enable_xtalk_per_quadrant = 0x00;
+ pdynamic->system__seed_config =
+ ptuning_parms->tp_lite_seed_cfg;
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x0B;
+
+
+ pdynamic->sd_config__woi_sd1 = 0x09;
+
+ pdynamic->sd_config__initial_phase_sd0 =
+ ptuning_parms->tp_init_phase_rtn_lite_med;
+ pdynamic->sd_config__initial_phase_sd1 =
+ ptuning_parms->tp_init_phase_ref_lite_med;
+
+ pdynamic->system__grouped_parameter_hold_1 = 0x01;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pdynamic->sd_config__first_order_select =
+ ptuning_parms->tp_lite_first_order_select;
+ pdynamic->sd_config__quantifier =
+ ptuning_parms->tp_lite_quantifier;
+
+
+
+
+
+
+ pdynamic->roi_config__user_roi_centre_spad = 0xC7;
+
+
+ pdynamic->roi_config__user_roi_requested_global_xy_size = 0xFF;
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ pdynamic->system__grouped_parameter_hold = 0x02;
+
+
+
+
+
+ psystem->system__stream_count_ctrl = 0x00;
+ psystem->firmware__enable = 0x01;
+ psystem->system__interrupt_clear =
+ VL53L1_CLEAR_RANGE_INT;
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_STREAMING |
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_short_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x07;
+ ptiming->range_config__vcsel_period_b = 0x05;
+ ptiming->range_config__sigma_thresh =
+ ptuning_parms->tp_lite_short_sigma_thresh_mm;
+ ptiming->range_config__min_count_rate_rtn_limit_mcps =
+ ptuning_parms->tp_lite_short_min_count_rate_rtn_mcps;
+ ptiming->range_config__valid_phase_low = 0x08;
+ ptiming->range_config__valid_phase_high = 0x38;
+
+
+
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x07;
+ pdynamic->sd_config__woi_sd1 = 0x05;
+ pdynamic->sd_config__initial_phase_sd0 =
+ ptuning_parms->tp_init_phase_rtn_lite_short;
+ pdynamic->sd_config__initial_phase_sd1 =
+ ptuning_parms->tp_init_phase_ref_lite_short;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_long_range(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x0F;
+ ptiming->range_config__vcsel_period_b = 0x0D;
+ ptiming->range_config__sigma_thresh =
+ ptuning_parms->tp_lite_long_sigma_thresh_mm;
+ ptiming->range_config__min_count_rate_rtn_limit_mcps =
+ ptuning_parms->tp_lite_long_min_count_rate_rtn_mcps;
+ ptiming->range_config__valid_phase_low = 0x08;
+ ptiming->range_config__valid_phase_high = 0xB8;
+
+
+
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x0F;
+ pdynamic->sd_config__woi_sd1 = 0x0D;
+ pdynamic->sd_config__initial_phase_sd0 =
+ ptuning_parms->tp_init_phase_rtn_lite_long;
+ pdynamic->sd_config__initial_phase_sd1 =
+ ptuning_parms->tp_init_phase_ref_lite_long;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm1_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_standard_ranging_mm2_cal(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0xB1;
+
+
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0xD4;
+
+
+
+
+ ptiming->system__intermeasurement_period = 0x00000600;
+ pdynamic->system__seed_config =
+ ptuning_parms->tp_timed_seed_cfg;
+
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO |
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_short_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging_short_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x01;
+ ptiming->range_config__timeout_macrop_a_lo = 0x84;
+
+
+ ptiming->range_config__timeout_macrop_b_hi = 0x01;
+ ptiming->range_config__timeout_macrop_b_lo = 0xB1;
+
+ ptiming->system__intermeasurement_period = 0x00000600;
+ pdynamic->system__seed_config =
+ ptuning_parms->tp_timed_seed_cfg;
+
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO |
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_timed_ranging_long_range(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging_long_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x97;
+
+
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0xB1;
+
+ ptiming->system__intermeasurement_period = 0x00000600;
+ pdynamic->system__seed_config =
+ ptuning_parms->tp_timed_seed_cfg;
+
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO |
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_TIMED;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_preset_mode_low_power_auto_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_low_power_auto_data_t *plpadata)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_timed_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_config_low_power_auto_mode(
+ pgeneral,
+ pdynamic,
+ plpadata
+ );
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_low_power_auto_short_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_low_power_auto_data_t *plpadata)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_timed_ranging_short_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_config_low_power_auto_mode(
+ pgeneral,
+ pdynamic,
+ plpadata
+ );
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_low_power_auto_long_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_low_power_auto_data_t *plpadata)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_timed_ranging_long_range(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_config_low_power_auto_mode(
+ pgeneral,
+ pdynamic,
+ plpadata
+ );
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_singleshot_ranging(
+
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pdynamic->system__grouped_parameter_hold = 0x00;
+
+
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0xB1;
+
+
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0xD4;
+
+ pdynamic->system__seed_config =
+ ptuning_parms->tp_timed_seed_cfg;
+
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO |
+ VL53L1_DEVICEREADOUTMODE_SINGLE_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pstatic->dss_config__target_total_rate_mcps = 0x1400;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 0, 1, 2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 0, 1, 2, 3, 4, 5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x0B;
+ pdynamic->sd_config__woi_sd0 = 0x09;
+ pdynamic->sd_config__woi_sd1 = 0x0B;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x20;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x1A;
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x28;
+
+
+
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x21;
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xF5;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x88;
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+
+
+
+
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_with_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging_with_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+0, 8+1, 8+2, 8+3, 8+4, 8+5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+0, 8+1, 8+2, 8+3, 8+4, 8+5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_mm2_cal(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging_mm1_cal(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_short_timing(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ pstatic->dss_config__target_total_rate_mcps = 0x1400;
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 7, 0, 1, 2, 3, 4,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 7, 0, 1, 2, 3, 4,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x04;
+ ptiming->range_config__vcsel_period_b = 0x03;
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x42;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x42;
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x52;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x66;
+
+ pgeneral->cal_config__vcsel_start = 0x04;
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xa4;
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+
+
+
+
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 0, 1, 2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+
+ 0, 1, 2, 3, 4, 5,
+
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x0b;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x21;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x1b;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x29;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x22;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x09;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xF5;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x09;
+ pdynamic->sd_config__woi_sd1 = 0x0B;
+ pdynamic->sd_config__initial_phase_sd0 =
+ ptuning_parms->tp_init_phase_rtn_hist_long;
+ pdynamic->sd_config__initial_phase_sd1 =
+ ptuning_parms->tp_init_phase_ref_hist_long;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x88;
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 8+0, 8+1, 8+2, 3, 4, 5,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_long_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_long_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 1, 2, 2,
+ 0, 1, 2, 1, 2, 3,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 1, 2, 2,
+ 0, 1, 2, 1, 2, 3,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x05;
+ ptiming->range_config__vcsel_period_b = 0x07;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x36;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x28;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x44;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x33;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x05;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xF5;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x05;
+ pdynamic->sd_config__woi_sd1 = 0x07;
+ pdynamic->sd_config__initial_phase_sd0 =
+ ptuning_parms->tp_init_phase_rtn_hist_med;
+ pdynamic->sd_config__initial_phase_sd1 =
+ ptuning_parms->tp_init_phase_ref_hist_med;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x48;
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_medium_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 1, 2, 2,
+ 8+0, 8+1, 8+2, 1, 2, 3,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 1, 2, 2,
+ 8+0, 8+1, 8+2, 1, 2, 3,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_medium_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_medium_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 7, 0, 1, 1, 1,
+ 0, 1, 1, 1, 2, 2,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 7, 0, 1, 1, 1,
+ 0, 1, 1, 1, 2, 2,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x03;
+ ptiming->range_config__vcsel_period_b = 0x05;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x52;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x37;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x66;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x44;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x03;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xF5;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x03;
+ pdynamic->sd_config__woi_sd1 = 0x05;
+ pdynamic->sd_config__initial_phase_sd0 =
+ ptuning_parms->tp_init_phase_rtn_hist_short;
+ pdynamic->sd_config__initial_phase_sd1 =
+ ptuning_parms->tp_init_phase_ref_hist_short;
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x08;
+ phistpostprocess->valid_phase_high = 0x28;
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN |
+
+
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_special_histogram_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 7, 0, 0, 1, 1,
+ 0, 0, 0, 1, 1, 1,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 7, 0, 0, 1, 1,
+ 0, 0, 0, 1, 1, 1,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x02;
+ ptiming->range_config__vcsel_period_b = 0x03;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x00;
+
+
+
+
+
+ pgeneral->phasecal_config__target = 0x31;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x02;
+ pdynamic->sd_config__woi_sd1 = 0x03;
+ pdynamic->sd_config__initial_phase_sd0 =
+ ptuning_parms->tp_init_phase_rtn_hist_short;
+ pdynamic->sd_config__initial_phase_sd1 =
+ ptuning_parms->tp_init_phase_ref_hist_short;
+
+
+
+
+
+
+
+
+ phistpostprocess->valid_phase_low = 0x10;
+ phistpostprocess->valid_phase_high = 0x18;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 7, 0, 1, 1, 1,
+ 8+0, 8+1, 1, 1, 2, 2,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 7, 0, 1, 1, 1,
+ 8+0, 8+1, 1, 1, 2, 2,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_short_range_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_short_range_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_characterisation(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ pstatic->debug__ctrl = 0x01;
+ psystem->power_management__go1_power_force = 0x01;
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_SPLIT_MANUAL |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_planar(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_multizone_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_zone_preset_xtalk_planar(
+ pgeneral,
+ pzone_cfg);
+
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x09;
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 7, 0, 1, 2, 3, 4,
+ 7, 0, 1, 2, 3, 4,
+ phistogram);
+
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 7, 0, 1, 2, 3, 4,
+
+ 7, 0, 1, 2, 3, 4,
+
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_set_histogram_multizone_initial_bin_config(
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg));
+ }
+
+
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm1(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+
+
+ VL53L1_init_histogram_config_structure(
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ phistogram);
+
+
+
+
+
+
+ VL53L1_init_histogram_multizone_config_structure(
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ 8+7, 8+0, 8+1, 8+2, 8+3, 8+4,
+ &(pzone_cfg->multizone_hist_cfg));
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+
+
+
+
+
+
+ ptiming->range_config__vcsel_period_a = 0x09;
+ ptiming->range_config__vcsel_period_b = 0x09;
+
+
+
+
+
+
+ ptiming->mm_config__timeout_macrop_a_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_a_lo = 0x21;
+ ptiming->mm_config__timeout_macrop_b_hi = 0x00;
+ ptiming->mm_config__timeout_macrop_b_lo = 0x21;
+
+
+
+
+ ptiming->range_config__timeout_macrop_a_hi = 0x00;
+ ptiming->range_config__timeout_macrop_a_lo = 0x29;
+ ptiming->range_config__timeout_macrop_b_hi = 0x00;
+ ptiming->range_config__timeout_macrop_b_lo = 0x29;
+
+
+
+
+ pgeneral->cal_config__vcsel_start = 0x09;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pgeneral->phasecal_config__timeout_macrop = 0xF5;
+
+
+
+
+ pdynamic->sd_config__woi_sd0 = 0x09;
+ pdynamic->sd_config__woi_sd1 = 0x09;
+ pdynamic->sd_config__initial_phase_sd0 = 0x09;
+ pdynamic->sd_config__initial_phase_sd1 = 0x06;
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM1_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+
+
+ psystem->system__mode_start =
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM |
+ VL53L1_DEVICEREADOUTMODE_DUAL_SD |
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_xtalk_mm2(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_xtalk_mm1(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+ VL53L1_SEQUENCE_DSS2_EN |
+ VL53L1_SEQUENCE_MM2_EN |
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_medium_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+
+ pgeneral->global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_set_histogram_multizone_initial_bin_config(
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg));
+ }
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_short_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_short_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+
+ pgeneral->global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_set_histogram_multizone_initial_bin_config(
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg)
+ );
+ }
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_multizone_long_range(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_long_range(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+ status =
+ VL53L1_init_zone_config_structure(
+ 4, 8, 2,
+
+ 4, 8, 2,
+
+ 7, 7,
+
+ pzone_cfg);
+
+ pgeneral->global_config__stream_divider =
+ pzone_cfg->active_zones + 1;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_set_histogram_multizone_initial_bin_config(
+ pzone_cfg,
+ phistogram,
+ &(pzone_cfg->multizone_hist_cfg));
+ }
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_preset_mode_olt(
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_preset_mode_standard_ranging(
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+
+ psystem->system__stream_count_ctrl = 0x01;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_copy_hist_cfg_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic)
+{
+
+
+
+
+
+
+ LOG_FUNCTION_START("");
+
+ SUPPRESS_UNUSED_WARNING(pgeneral);
+
+ pstatic->sigma_estimator__effective_pulse_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_0_1;
+ pstatic->sigma_estimator__effective_ambient_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_2_3;
+ pstatic->sigma_estimator__sigma_ref_mm =
+ phistogram->histogram_config__high_amb_even_bin_4_5;
+
+ pstatic->algo__crosstalk_compensation_valid_height_mm =
+ phistogram->histogram_config__high_amb_odd_bin_0_1;
+
+ pstatic->spare_host_config__static_config_spare_0 =
+ phistogram->histogram_config__high_amb_odd_bin_2_3;
+ pstatic->spare_host_config__static_config_spare_1 =
+ phistogram->histogram_config__high_amb_odd_bin_4_5;
+
+ pstatic->algo__range_ignore_threshold_mcps =
+ (((uint16_t)phistogram->histogram_config__mid_amb_even_bin_0_1)
+ << 8)
+ + (uint16_t)phistogram->histogram_config__mid_amb_even_bin_2_3;
+
+ pstatic->algo__range_ignore_valid_height_mm =
+ phistogram->histogram_config__mid_amb_even_bin_4_5;
+ pstatic->algo__range_min_clip =
+ phistogram->histogram_config__mid_amb_odd_bin_0_1;
+ pstatic->algo__consistency_check__tolerance =
+ phistogram->histogram_config__mid_amb_odd_bin_2;
+
+ pstatic->spare_host_config__static_config_spare_2 =
+ phistogram->histogram_config__mid_amb_odd_bin_3_4;
+ pstatic->sd_config__reset_stages_msb =
+ phistogram->histogram_config__mid_amb_odd_bin_5;
+
+ pstatic->sd_config__reset_stages_lsb =
+ phistogram->histogram_config__user_bin_offset;
+
+ ptiming->range_config__sigma_thresh =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_0_1)
+ << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_even_bin_2_3;
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_4_5)
+ << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_odd_bin_0_1;
+
+ ptiming->range_config__valid_phase_low =
+ phistogram->histogram_config__low_amb_odd_bin_2_3;
+ ptiming->range_config__valid_phase_high =
+ phistogram->histogram_config__low_amb_odd_bin_4_5;
+
+ pdynamic->system__thresh_high =
+ phistogram->histogram_config__amb_thresh_low;
+
+ pdynamic->system__thresh_low =
+ phistogram->histogram_config__amb_thresh_high;
+
+ pdynamic->system__enable_xtalk_per_quadrant =
+ phistogram->histogram_config__spad_array_selection;
+
+ LOG_FUNCTION_END(0);
+
+}
+
+void VL53L1_copy_hist_bins_to_static_cfg(
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_timing_config_t *ptiming)
+{
+
+
+
+
+
+
+ LOG_FUNCTION_START("");
+
+ pstatic->sigma_estimator__effective_pulse_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_0_1;
+ pstatic->sigma_estimator__effective_ambient_width_ns =
+ phistogram->histogram_config__high_amb_even_bin_2_3;
+ pstatic->sigma_estimator__sigma_ref_mm =
+ phistogram->histogram_config__high_amb_even_bin_4_5;
+
+ pstatic->algo__crosstalk_compensation_valid_height_mm =
+ phistogram->histogram_config__high_amb_odd_bin_0_1;
+
+ pstatic->spare_host_config__static_config_spare_0 =
+ phistogram->histogram_config__high_amb_odd_bin_2_3;
+ pstatic->spare_host_config__static_config_spare_1 =
+ phistogram->histogram_config__high_amb_odd_bin_4_5;
+
+ pstatic->algo__range_ignore_threshold_mcps =
+ (((uint16_t)phistogram->histogram_config__mid_amb_even_bin_0_1)
+ << 8)
+ + (uint16_t)phistogram->histogram_config__mid_amb_even_bin_2_3;
+
+ pstatic->algo__range_ignore_valid_height_mm =
+ phistogram->histogram_config__mid_amb_even_bin_4_5;
+ pstatic->algo__range_min_clip =
+ phistogram->histogram_config__mid_amb_odd_bin_0_1;
+ pstatic->algo__consistency_check__tolerance =
+ phistogram->histogram_config__mid_amb_odd_bin_2;
+
+ pstatic->spare_host_config__static_config_spare_2 =
+ phistogram->histogram_config__mid_amb_odd_bin_3_4;
+ pstatic->sd_config__reset_stages_msb =
+ phistogram->histogram_config__mid_amb_odd_bin_5;
+
+ ptiming->range_config__sigma_thresh =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_0_1)
+ << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_even_bin_2_3;
+
+ ptiming->range_config__min_count_rate_rtn_limit_mcps =
+ (((uint16_t)phistogram->histogram_config__low_amb_even_bin_4_5)
+ << 8)
+ + (uint16_t)phistogram->histogram_config__low_amb_odd_bin_0_1;
+
+ ptiming->range_config__valid_phase_low =
+ phistogram->histogram_config__low_amb_odd_bin_2_3;
+ ptiming->range_config__valid_phase_high =
+ phistogram->histogram_config__low_amb_odd_bin_4_5;
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+VL53L1_Error VL53L1_preset_mode_histogram_ranging_ref(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_static_config_t *pstatic,
+ VL53L1_histogram_config_t *phistogram,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_system_control_t *psystem,
+ VL53L1_tuning_parm_storage_t *ptuning_parms,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_preset_mode_histogram_ranging(
+ phistpostprocess,
+ pstatic,
+ phistogram,
+ pgeneral,
+ ptiming,
+ pdynamic,
+ psystem,
+ ptuning_parms,
+ pzone_cfg);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+ phistogram->histogram_config__spad_array_selection = 0x01;
+
+
+
+
+ VL53L1_copy_hist_cfg_to_static_cfg(
+ phistogram,
+ pstatic,
+ pgeneral,
+ ptiming,
+ pdynamic);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_api_strings.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_strings.c
new file mode 100644
index 000000000000..deec3c512107
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_api_strings.c
@@ -0,0 +1,334 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_api_core.h"
+#include "vl53l1_api_strings.h"
+#include "vl53l1_error_codes.h"
+#include "vl53l1_error_strings.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, \
+ ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_get_range_status_string(
+ uint8_t RangeStatus,
+ char *pRangeStatusString)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pRangeStatusString, "");
+#else
+ switch (RangeStatus) {
+ case 0:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_RANGEVALID);
+ break;
+ case 1:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_SIGMA);
+ break;
+ case 2:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_SIGNAL);
+ break;
+ case 3:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_MINRANGE);
+ break;
+ case 4:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_PHASE);
+ break;
+ case 5:
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_HW);
+ break;
+
+ default:
+
+ VL53L1_COPYSTRING(pRangeStatusString,
+ VL53L1_STRING_RANGESTATUS_NONE);
+ }
+#endif
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_pal_state_string(
+ VL53L1_State PalStateCode,
+ char *pPalStateString)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pPalStateString, "");
+#else
+ switch (PalStateCode) {
+ case VL53L1_STATE_POWERDOWN:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_POWERDOWN);
+ break;
+ case VL53L1_STATE_WAIT_STATICINIT:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_WAIT_STATICINIT);
+ break;
+ case VL53L1_STATE_STANDBY:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_STANDBY);
+ break;
+ case VL53L1_STATE_IDLE:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_IDLE);
+ break;
+ case VL53L1_STATE_RUNNING:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_RUNNING);
+ break;
+ case VL53L1_STATE_RESET:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_RESET);
+ break;
+ case VL53L1_STATE_UNKNOWN:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_UNKNOWN);
+ break;
+ case VL53L1_STATE_ERROR:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_ERROR);
+ break;
+
+ default:
+ VL53L1_COPYSTRING(pPalStateString,
+ VL53L1_STRING_STATE_UNKNOWN);
+ }
+#endif
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+VL53L1_Error VL53L1_get_sequence_steps_info(
+ VL53L1_SequenceStepId SequenceStepId,
+ char *pSequenceStepsString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pSequenceStepsString, "");
+#else
+ switch (SequenceStepId) {
+ case VL53L1_SEQUENCESTEP_VHV:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_VHV);
+ break;
+ case VL53L1_SEQUENCESTEP_PHASECAL:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_PHASECAL);
+ break;
+ case VL53L1_SEQUENCESTEP_REFPHASE:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_DSS1);
+ break;
+ case VL53L1_SEQUENCESTEP_DSS1:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_DSS1);
+ break;
+ case VL53L1_SEQUENCESTEP_DSS2:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_DSS2);
+ break;
+ case VL53L1_SEQUENCESTEP_MM1:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_MM1);
+ break;
+ case VL53L1_SEQUENCESTEP_MM2:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_MM2);
+ break;
+ case VL53L1_SEQUENCESTEP_RANGE:
+ VL53L1_COPYSTRING(pSequenceStepsString,
+ VL53L1_STRING_SEQUENCESTEP_RANGE);
+ break;
+ default:
+ Status = VL53L1_ERROR_INVALID_PARAMS;
+ }
+#endif
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
+VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
+ char *pLimitCheckString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pLimitCheckString, "");
+#else
+ switch (LimitCheckId) {
+ case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
+ VL53L1_COPYSTRING(pLimitCheckString,
+ VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
+ break;
+ case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
+ VL53L1_COPYSTRING(pLimitCheckString,
+ VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
+ break;
+ default:
+ VL53L1_COPYSTRING(pLimitCheckString,
+ VL53L1_STRING_UNKNOW_ERROR_CODE);
+ }
+#endif
+
+ LOG_FUNCTION_END(Status);
+ return Status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_core.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_core.c
new file mode 100644
index 000000000000..8a5a8c67a634
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_core.c
@@ -0,0 +1,5952 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_register_funcs.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_hist_structs.h"
+#include "vl53l1_api_preset_modes.h"
+#include "vl53l1_core.h"
+#include "vl53l1_tuning_parm_defaults.h"
+
+
+
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \
+ status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+void VL53L1_init_version(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->version.ll_major = VL53L1_LL_API_IMPLEMENTATION_VER_MAJOR;
+ pdev->version.ll_minor = VL53L1_LL_API_IMPLEMENTATION_VER_MINOR;
+ pdev->version.ll_build = VL53L1_LL_API_IMPLEMENTATION_VER_SUB;
+ pdev->version.ll_revision = VL53L1_LL_API_IMPLEMENTATION_VER_REVISION;
+}
+
+
+void VL53L1_init_ll_driver_state(
+ VL53L1_DEV Dev,
+ VL53L1_DeviceState device_state)
+{
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+
+ pstate->cfg_device_state = device_state;
+ pstate->cfg_stream_count = 0;
+ pstate->cfg_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->cfg_timing_status = 0;
+ pstate->cfg_zone_id = 0;
+
+ pstate->rd_device_state = device_state;
+ pstate->rd_stream_count = 0;
+ pstate->rd_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+
+}
+
+
+VL53L1_Error VL53L1_update_ll_driver_rd_state(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+
+
+
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if ((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK) == 0x00) {
+
+ pstate->rd_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+
+ } else {
+
+
+
+
+
+
+ if (pstate->rd_stream_count == 0xFF)
+ pstate->rd_stream_count = 0x80;
+ else
+ pstate->rd_stream_count++;
+
+
+
+
+
+ status = VL53L1_update_internal_stream_counters(Dev,
+ pstate->rd_stream_count,
+ &(pstate->rd_internal_stream_count),
+ &(pstate->rd_internal_stream_count_val));
+
+
+
+
+
+
+ pstate->rd_gph_id ^= VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+
+
+
+
+ switch (pstate->rd_device_state) {
+
+ case VL53L1_DEVICESTATE_SW_STANDBY:
+
+ if ((pdev->dyn_cfg.system__grouped_parameter_hold &
+ VL53L1_GROUPEDPARAMETERHOLD_ID_MASK) > 0) {
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC;
+ } else {
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones)
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ else
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+ }
+
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC:
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_zone_id = 0;
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones)
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ else
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_GATHER_DATA:
+ pstate->rd_zone_id++;
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones)
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ else
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA:
+ pstate->rd_zone_id = 0;
+ pstate->rd_timing_status ^= 0x01;
+
+ if (pstate->rd_zone_id >=
+ pdev->zone_cfg.active_zones)
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA;
+ else
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA;
+ break;
+
+ default:
+ pstate->rd_device_state =
+ VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->rd_stream_count = 0;
+ pstate->rd_internal_stream_count = 0;
+ pstate->rd_internal_stream_count_val = 0;
+ pstate->rd_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->rd_timing_status = 0;
+ pstate->rd_zone_id = 0;
+ break;
+ }
+ }
+
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_check_ll_driver_rd_state(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+ VL53L1_system_results_t *psys_results = &(pdev->sys_results);
+ VL53L1_histogram_bin_data_t *phist_data = &(pdev->hist_data);
+ VL53L1_zone_private_dyn_cfgs_t *pZ = &(pres->zone_dyn_cfgs);
+
+ uint8_t device_range_status = 0;
+ uint8_t device_stream_count = 0;
+ uint8_t device_gph_id = 0;
+ uint8_t histogram_mode = 0;
+ uint8_t expected_stream_count = 0;
+ uint8_t expected_gph_id = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ device_range_status =
+ psys_results->result__range_status &
+ VL53L1_RANGE_STATUS__RANGE_STATUS_MASK;
+
+ device_stream_count = psys_results->result__stream_count;
+
+
+
+
+ histogram_mode =
+ (pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM) ==
+ VL53L1_DEVICESCHEDULERMODE_HISTOGRAM;
+
+
+
+ device_gph_id = (psys_results->result__interrupt_status &
+ VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK) >> 4;
+
+ if (histogram_mode)
+ device_gph_id = (phist_data->result__interrupt_status &
+ VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK) >> 4;
+
+
+
+
+ if (!((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK) ==
+ VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK))
+ goto ENDFUNC;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (pstate->rd_device_state ==
+ VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) {
+
+ if (histogram_mode == 0) {
+ if (device_range_status !=
+ VL53L1_DEVICEERROR_GPHSTREAMCOUNT0READY)
+ status =
+ VL53L1_ERROR_GPH_SYNC_CHECK_FAIL;
+
+ }
+ } else {
+ if (pstate->rd_stream_count != device_stream_count)
+ status = VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL;
+
+
+
+
+
+ if (pstate->rd_gph_id != device_gph_id)
+ status = VL53L1_ERROR_GPH_ID_CHECK_FAIL;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ expected_stream_count =
+ pZ->VL53L1_p_002[pstate->rd_zone_id].expected_stream_count;
+ expected_gph_id =
+ pZ->VL53L1_p_002[pstate->rd_zone_id].expected_gph_id;
+
+
+
+
+
+
+ if (expected_stream_count != device_stream_count) {
+
+
+
+
+
+ if (!((pdev->zone_cfg.active_zones == 0) &&
+ (device_stream_count == 255)))
+ status =
+ VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+ if (expected_gph_id != device_gph_id)
+ status = VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL;
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ENDFUNC:
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_update_ll_driver_cfg_state(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+ VL53L1_zone_private_dyn_cfgs_t *pZ = &(pres->zone_dyn_cfgs);
+
+ uint8_t prev_cfg_zone_id;
+ uint8_t prev_cfg_gph_id;
+ uint8_t prev_cfg_stream_count;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ if ((pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK) == 0x00) {
+
+ pstate->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->cfg_stream_count = 0;
+ pstate->cfg_internal_stream_count = 0;
+ pstate->cfg_internal_stream_count_val = 0;
+ pstate->cfg_gph_id = VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->cfg_timing_status = 0;
+ pstate->cfg_zone_id = 0;
+ prev_cfg_zone_id = 0;
+ prev_cfg_gph_id = 0;
+ prev_cfg_stream_count = 0;
+
+ } else {
+
+
+
+
+ prev_cfg_gph_id = pstate->cfg_gph_id;
+ prev_cfg_zone_id = pstate->cfg_zone_id;
+ prev_cfg_stream_count = pstate->cfg_stream_count;
+
+
+
+
+
+
+ if (pstate->cfg_stream_count == 0xFF)
+ pstate->cfg_stream_count = 0x80;
+ else
+ pstate->cfg_stream_count++;
+
+
+
+
+
+ status = VL53L1_update_internal_stream_counters(
+ Dev,
+ pstate->cfg_stream_count,
+ &(pstate->cfg_internal_stream_count),
+ &(pstate->cfg_internal_stream_count_val));
+
+
+
+
+
+
+ pstate->cfg_gph_id ^= VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+
+
+
+
+
+
+ switch (pstate->cfg_device_state) {
+
+ case VL53L1_DEVICESTATE_SW_STANDBY:
+ pstate->cfg_zone_id = 1;
+ if (pstate->cfg_zone_id >
+ pdev->zone_cfg.active_zones) {
+ pstate->cfg_zone_id = 0;
+ pstate->cfg_timing_status ^= 0x01;
+ }
+ pstate->cfg_stream_count = 1;
+
+ if (pdev->gen_cfg.global_config__stream_divider == 0) {
+ pstate->cfg_internal_stream_count = 1;
+ pstate->cfg_internal_stream_count_val = 0;
+ } else {
+ pstate->cfg_internal_stream_count = 0;
+ pstate->cfg_internal_stream_count_val = 1;
+ }
+ pstate->cfg_device_state =
+ VL53L1_DEVICESTATE_RANGING_DSS_AUTO;
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_DSS_AUTO:
+ pstate->cfg_zone_id++;
+ if (pstate->cfg_zone_id >
+ pdev->zone_cfg.active_zones) {
+
+ pstate->cfg_zone_id = 0;
+ pstate->cfg_timing_status ^= 0x01;
+
+
+
+
+
+
+ if (pdev->zone_cfg.active_zones > 0) {
+ pstate->cfg_device_state =
+ VL53L1_DEVICESTATE_RANGING_DSS_MANUAL;
+ }
+ }
+ break;
+
+ case VL53L1_DEVICESTATE_RANGING_DSS_MANUAL:
+ pstate->cfg_zone_id++;
+ if (pstate->cfg_zone_id >
+ pdev->zone_cfg.active_zones) {
+ pstate->cfg_zone_id = 0;
+ pstate->cfg_timing_status ^= 0x01;
+ }
+ break;
+
+ default:
+ pstate->cfg_device_state =
+ VL53L1_DEVICESTATE_SW_STANDBY;
+ pstate->cfg_stream_count = 0;
+ pstate->cfg_internal_stream_count = 0;
+ pstate->cfg_internal_stream_count_val = 0;
+ pstate->cfg_gph_id =
+ VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ pstate->cfg_timing_status = 0;
+ pstate->cfg_zone_id = 0;
+ break;
+ }
+ }
+
+
+
+
+
+ if (pdev->zone_cfg.active_zones == 0) {
+
+
+
+
+
+ pZ->VL53L1_p_002[prev_cfg_zone_id].expected_stream_count
+ = prev_cfg_stream_count - 1;
+
+ pZ->VL53L1_p_002[pstate->rd_zone_id].expected_gph_id =
+ prev_cfg_gph_id ^ VL53L1_GROUPEDPARAMETERHOLD_ID_MASK;
+ } else {
+ pZ->VL53L1_p_002[prev_cfg_zone_id].expected_stream_count
+ = prev_cfg_stream_count;
+ pZ->VL53L1_p_002[prev_cfg_zone_id].expected_gph_id =
+ prev_cfg_gph_id;
+ }
+
+
+
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_copy_rtn_good_spads_to_buffer(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+ *(pbuffer + 0) = pdata->global_config__spad_enables_rtn_0;
+ *(pbuffer + 1) = pdata->global_config__spad_enables_rtn_1;
+ *(pbuffer + 2) = pdata->global_config__spad_enables_rtn_2;
+ *(pbuffer + 3) = pdata->global_config__spad_enables_rtn_3;
+ *(pbuffer + 4) = pdata->global_config__spad_enables_rtn_4;
+ *(pbuffer + 5) = pdata->global_config__spad_enables_rtn_5;
+ *(pbuffer + 6) = pdata->global_config__spad_enables_rtn_6;
+ *(pbuffer + 7) = pdata->global_config__spad_enables_rtn_7;
+ *(pbuffer + 8) = pdata->global_config__spad_enables_rtn_8;
+ *(pbuffer + 9) = pdata->global_config__spad_enables_rtn_9;
+ *(pbuffer + 10) = pdata->global_config__spad_enables_rtn_10;
+ *(pbuffer + 11) = pdata->global_config__spad_enables_rtn_11;
+ *(pbuffer + 12) = pdata->global_config__spad_enables_rtn_12;
+ *(pbuffer + 13) = pdata->global_config__spad_enables_rtn_13;
+ *(pbuffer + 14) = pdata->global_config__spad_enables_rtn_14;
+ *(pbuffer + 15) = pdata->global_config__spad_enables_rtn_15;
+ *(pbuffer + 16) = pdata->global_config__spad_enables_rtn_16;
+ *(pbuffer + 17) = pdata->global_config__spad_enables_rtn_17;
+ *(pbuffer + 18) = pdata->global_config__spad_enables_rtn_18;
+ *(pbuffer + 19) = pdata->global_config__spad_enables_rtn_19;
+ *(pbuffer + 20) = pdata->global_config__spad_enables_rtn_20;
+ *(pbuffer + 21) = pdata->global_config__spad_enables_rtn_21;
+ *(pbuffer + 22) = pdata->global_config__spad_enables_rtn_22;
+ *(pbuffer + 23) = pdata->global_config__spad_enables_rtn_23;
+ *(pbuffer + 24) = pdata->global_config__spad_enables_rtn_24;
+ *(pbuffer + 25) = pdata->global_config__spad_enables_rtn_25;
+ *(pbuffer + 26) = pdata->global_config__spad_enables_rtn_26;
+ *(pbuffer + 27) = pdata->global_config__spad_enables_rtn_27;
+ *(pbuffer + 28) = pdata->global_config__spad_enables_rtn_28;
+ *(pbuffer + 29) = pdata->global_config__spad_enables_rtn_29;
+ *(pbuffer + 30) = pdata->global_config__spad_enables_rtn_30;
+ *(pbuffer + 31) = pdata->global_config__spad_enables_rtn_31;
+}
+
+
+void VL53L1_init_system_results(
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ pdata->result__interrupt_status = 0xFF;
+ pdata->result__range_status = 0xFF;
+ pdata->result__report_status = 0xFF;
+ pdata->result__stream_count = 0xFF;
+
+ pdata->result__dss_actual_effective_spads_sd0 = 0xFFFF;
+ pdata->result__peak_signal_count_rate_mcps_sd0 = 0xFFFF;
+ pdata->result__ambient_count_rate_mcps_sd0 = 0xFFFF;
+ pdata->result__sigma_sd0 = 0xFFFF;
+ pdata->result__phase_sd0 = 0xFFFF;
+ pdata->result__final_crosstalk_corrected_range_mm_sd0 = 0xFFFF;
+ pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ 0xFFFF;
+ pdata->result__mm_inner_actual_effective_spads_sd0 = 0xFFFF;
+ pdata->result__mm_outer_actual_effective_spads_sd0 = 0xFFFF;
+ pdata->result__avg_signal_count_rate_mcps_sd0 = 0xFFFF;
+
+ pdata->result__dss_actual_effective_spads_sd1 = 0xFFFF;
+ pdata->result__peak_signal_count_rate_mcps_sd1 = 0xFFFF;
+ pdata->result__ambient_count_rate_mcps_sd1 = 0xFFFF;
+ pdata->result__sigma_sd1 = 0xFFFF;
+ pdata->result__phase_sd1 = 0xFFFF;
+ pdata->result__final_crosstalk_corrected_range_mm_sd1 = 0xFFFF;
+ pdata->result__spare_0_sd1 = 0xFFFF;
+ pdata->result__spare_1_sd1 = 0xFFFF;
+ pdata->result__spare_2_sd1 = 0xFFFF;
+ pdata->result__spare_3_sd1 = 0xFF;
+
+}
+
+
+void V53L1_init_zone_results_structure(
+ uint8_t active_zones,
+ VL53L1_zone_results_t *pdata)
+{
+
+
+
+
+ uint8_t z = 0;
+ VL53L1_zone_objects_t *pobjects;
+
+ pdata->max_zones = VL53L1_MAX_USER_ZONES;
+ pdata->active_zones = active_zones;
+
+ for (z = 0; z < pdata->max_zones; z++) {
+ pobjects = &(pdata->VL53L1_p_002[z]);
+ pobjects->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pobjects->rd_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pobjects->max_objects = VL53L1_MAX_RANGE_RESULTS;
+ pobjects->active_objects = 0;
+ }
+}
+
+void V53L1_init_zone_dss_configs(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+ uint8_t z = 0;
+ uint8_t max_zones = VL53L1_MAX_USER_ZONES;
+ VL53L1_zone_private_dyn_cfgs_t *pdata = &(pres->zone_dyn_cfgs);
+
+ for (z = 0; z < max_zones; z++) {
+ pdata->VL53L1_p_002[z].dss_mode =
+ VL53L1_DSS_CONTROL__MODE_TARGET_RATE;
+ pdata->VL53L1_p_002[z].dss_requested_effective_spad_count = 0;
+ }
+}
+
+
+void VL53L1_init_histogram_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata)
+{
+
+
+
+
+
+
+ pdata->histogram_config__low_amb_even_bin_0_1 =
+ (even_bin1 << 4) + even_bin0;
+ pdata->histogram_config__low_amb_even_bin_2_3 =
+ (even_bin3 << 4) + even_bin2;
+ pdata->histogram_config__low_amb_even_bin_4_5 =
+ (even_bin5 << 4) + even_bin4;
+
+ pdata->histogram_config__low_amb_odd_bin_0_1 =
+ (odd_bin1 << 4) + odd_bin0;
+ pdata->histogram_config__low_amb_odd_bin_2_3 =
+ (odd_bin3 << 4) + odd_bin2;
+ pdata->histogram_config__low_amb_odd_bin_4_5 =
+ (odd_bin5 << 4) + odd_bin4;
+
+ pdata->histogram_config__mid_amb_even_bin_0_1 =
+ pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__mid_amb_even_bin_2_3 =
+ pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__mid_amb_even_bin_4_5 =
+ pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__mid_amb_odd_bin_0_1 =
+ pdata->histogram_config__low_amb_odd_bin_0_1;
+ pdata->histogram_config__mid_amb_odd_bin_2 = odd_bin2;
+ pdata->histogram_config__mid_amb_odd_bin_3_4 =
+ (odd_bin4 << 4) + odd_bin3;
+ pdata->histogram_config__mid_amb_odd_bin_5 = odd_bin5;
+
+ pdata->histogram_config__user_bin_offset = 0x00;
+
+ pdata->histogram_config__high_amb_even_bin_0_1 =
+ pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__high_amb_even_bin_2_3 =
+ pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__high_amb_even_bin_4_5 =
+ pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__high_amb_odd_bin_0_1 =
+ pdata->histogram_config__low_amb_odd_bin_0_1;
+ pdata->histogram_config__high_amb_odd_bin_2_3 =
+ pdata->histogram_config__low_amb_odd_bin_2_3;
+ pdata->histogram_config__high_amb_odd_bin_4_5 =
+ pdata->histogram_config__low_amb_odd_bin_4_5;
+
+
+
+
+ pdata->histogram_config__amb_thresh_low = 0xFFFF;
+ pdata->histogram_config__amb_thresh_high = 0xFFFF;
+
+
+
+
+ pdata->histogram_config__spad_array_selection = 0x00;
+
+}
+
+void VL53L1_init_histogram_multizone_config_structure(
+ uint8_t even_bin0,
+ uint8_t even_bin1,
+ uint8_t even_bin2,
+ uint8_t even_bin3,
+ uint8_t even_bin4,
+ uint8_t even_bin5,
+ uint8_t odd_bin0,
+ uint8_t odd_bin1,
+ uint8_t odd_bin2,
+ uint8_t odd_bin3,
+ uint8_t odd_bin4,
+ uint8_t odd_bin5,
+ VL53L1_histogram_config_t *pdata)
+{
+
+
+
+
+
+
+
+ pdata->histogram_config__low_amb_even_bin_0_1 =
+ (even_bin1 << 4) + even_bin0;
+ pdata->histogram_config__low_amb_even_bin_2_3 =
+ (even_bin3 << 4) + even_bin2;
+ pdata->histogram_config__low_amb_even_bin_4_5 =
+ (even_bin5 << 4) + even_bin4;
+
+ pdata->histogram_config__low_amb_odd_bin_0_1 =
+ pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__low_amb_odd_bin_2_3
+ = pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__low_amb_odd_bin_4_5
+ = pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__mid_amb_even_bin_0_1 =
+ pdata->histogram_config__low_amb_even_bin_0_1;
+ pdata->histogram_config__mid_amb_even_bin_2_3
+ = pdata->histogram_config__low_amb_even_bin_2_3;
+ pdata->histogram_config__mid_amb_even_bin_4_5
+ = pdata->histogram_config__low_amb_even_bin_4_5;
+
+ pdata->histogram_config__mid_amb_odd_bin_0_1
+ = pdata->histogram_config__low_amb_odd_bin_0_1;
+ pdata->histogram_config__mid_amb_odd_bin_2 = odd_bin2;
+ pdata->histogram_config__mid_amb_odd_bin_3_4 =
+ (odd_bin4 << 4) + odd_bin3;
+ pdata->histogram_config__mid_amb_odd_bin_5 = odd_bin5;
+
+ pdata->histogram_config__user_bin_offset = 0x00;
+
+ pdata->histogram_config__high_amb_even_bin_0_1 =
+ (odd_bin1 << 4) + odd_bin0;
+ pdata->histogram_config__high_amb_even_bin_2_3 =
+ (odd_bin3 << 4) + odd_bin2;
+ pdata->histogram_config__high_amb_even_bin_4_5 =
+ (odd_bin5 << 4) + odd_bin4;
+
+ pdata->histogram_config__high_amb_odd_bin_0_1
+ = pdata->histogram_config__high_amb_even_bin_0_1;
+ pdata->histogram_config__high_amb_odd_bin_2_3
+ = pdata->histogram_config__high_amb_even_bin_2_3;
+ pdata->histogram_config__high_amb_odd_bin_4_5
+ = pdata->histogram_config__high_amb_even_bin_4_5;
+
+
+
+
+ pdata->histogram_config__amb_thresh_low = 0xFFFF;
+ pdata->histogram_config__amb_thresh_high = 0xFFFF;
+
+
+
+
+ pdata->histogram_config__spad_array_selection = 0x00;
+}
+
+
+void VL53L1_init_xtalk_bin_data_struct(
+ uint32_t bin_value,
+ uint16_t VL53L1_p_024,
+ VL53L1_xtalk_histogram_shape_t *pdata)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+
+ pdata->zone_id = 0;
+ pdata->time_stamp = 0;
+
+ pdata->VL53L1_p_022 = 0;
+ pdata->VL53L1_p_023 = VL53L1_XTALK_HISTO_BINS;
+ pdata->VL53L1_p_024 = (uint8_t)VL53L1_p_024;
+
+ pdata->phasecal_result__reference_phase = 0;
+ pdata->phasecal_result__vcsel_start = 0;
+ pdata->cal_config__vcsel_start = 0;
+
+ pdata->vcsel_width = 0;
+ pdata->VL53L1_p_019 = 0;
+
+ pdata->zero_distance_phase = 0;
+
+ for (i = 0; i < VL53L1_XTALK_HISTO_BINS; i++) {
+ if (i < VL53L1_p_024)
+ pdata->bin_data[i] = bin_value;
+ else
+ pdata->bin_data[i] = 0;
+ }
+}
+
+
+void VL53L1_i2c_encode_uint16_t(
+ uint16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ uint16_t VL53L1_p_002 = 0;
+
+ VL53L1_p_002 = ip_value;
+
+ for (i = 0; i < count; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_p_002 & 0x00FF);
+ VL53L1_p_002 = VL53L1_p_002 >> 8;
+ }
+}
+
+uint16_t VL53L1_i2c_decode_uint16_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t value = 0x00;
+
+ while (count-- > 0)
+ value = (value << 8) | (uint16_t)*pbuffer++;
+
+ return value;
+}
+
+
+void VL53L1_i2c_encode_int16_t(
+ int16_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ int16_t VL53L1_p_002 = 0;
+
+ VL53L1_p_002 = ip_value;
+
+ for (i = 0; i < count; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_p_002 & 0x00FF);
+ VL53L1_p_002 = VL53L1_p_002 >> 8;
+ }
+}
+
+int16_t VL53L1_i2c_decode_int16_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ int16_t value = 0x00;
+
+
+
+ if (*pbuffer >= 0x80)
+ value = 0xFFFF;
+
+ while (count-- > 0)
+ value = (value << 8) | (int16_t)*pbuffer++;
+
+ return value;
+}
+
+void VL53L1_i2c_encode_uint32_t(
+ uint32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ uint32_t VL53L1_p_002 = 0;
+
+ VL53L1_p_002 = ip_value;
+
+ for (i = 0; i < count; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_p_002 & 0x00FF);
+ VL53L1_p_002 = VL53L1_p_002 >> 8;
+ }
+}
+
+uint32_t VL53L1_i2c_decode_uint32_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint32_t value = 0x00;
+
+ while (count-- > 0)
+ value = (value << 8) | (uint32_t)*pbuffer++;
+
+ return value;
+}
+
+
+uint32_t VL53L1_i2c_decode_with_mask(
+ uint16_t count,
+ uint8_t *pbuffer,
+ uint32_t bit_mask,
+ uint32_t down_shift,
+ uint32_t offset)
+{
+
+
+
+
+
+
+ uint32_t value = 0x00;
+
+
+
+ while (count-- > 0)
+ value = (value << 8) | (uint32_t)*pbuffer++;
+
+
+
+ value = value & bit_mask;
+ if (down_shift > 0)
+ value = value >> down_shift;
+
+
+
+ value = value + offset;
+
+ return value;
+}
+
+
+void VL53L1_i2c_encode_int32_t(
+ int32_t ip_value,
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+ int32_t VL53L1_p_002 = 0;
+
+ VL53L1_p_002 = ip_value;
+
+ for (i = 0; i < count; i++) {
+ pbuffer[count-i-1] = (uint8_t)(VL53L1_p_002 & 0x00FF);
+ VL53L1_p_002 = VL53L1_p_002 >> 8;
+ }
+}
+
+int32_t VL53L1_i2c_decode_int32_t(
+ uint16_t count,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ int32_t value = 0x00;
+
+
+
+ if (*pbuffer >= 0x80)
+ value = 0xFFFFFFFF;
+
+ while (count-- > 0)
+ value = (value << 8) | (int32_t)*pbuffer++;
+
+ return value;
+}
+
+
+VL53L1_Error VL53L1_start_test(
+ VL53L1_DEV Dev,
+ uint8_t test_mode__ctrl)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_TEST_MODE__CTRL,
+ test_mode__ctrl);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_firmware_enable_register(
+ VL53L1_DEV Dev,
+ uint8_t value)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->sys_ctrl.firmware__enable = value;
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_FIRMWARE__ENABLE,
+ pdev->sys_ctrl.firmware__enable);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_enable_firmware(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_firmware_enable_register(Dev, 0x01);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_disable_firmware(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_firmware_enable_register(Dev, 0x00);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_powerforce_register(
+ VL53L1_DEV Dev,
+ uint8_t value)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ pdev->sys_ctrl.power_management__go1_power_force = value;
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE,
+ pdev->sys_ctrl.power_management__go1_power_force);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_enable_powerforce(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_powerforce_register(Dev, 0x01);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_disable_powerforce(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_powerforce_register(Dev, 0x00);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_clear_interrupt(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->sys_ctrl.system__interrupt_clear = VL53L1_CLEAR_RANGE_INT;
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SYSTEM__INTERRUPT_CLEAR,
+ pdev->sys_ctrl.system__interrupt_clear);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_force_shadow_stream_count_to_zero(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_SHADOW_RESULT__STREAM_COUNT,
+ 0x00);
+ }
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ return status;
+}
+
+
+uint32_t VL53L1_calc_macro_period_us(
+ uint16_t fast_osc_frequency,
+ uint8_t VL53L1_p_009)
+{
+
+
+
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+ uint8_t VL53L1_p_031 = 0;
+ uint32_t macro_period_us = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
+
+
+
+
+
+
+ VL53L1_p_031 = VL53L1_decode_vcsel_period(VL53L1_p_009);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ macro_period_us =
+ (uint32_t)VL53L1_MACRO_PERIOD_VCSEL_PERIODS *
+ pll_period_us;
+ macro_period_us = macro_period_us >> 6;
+
+ macro_period_us = macro_period_us * (uint32_t)VL53L1_p_031;
+ macro_period_us = macro_period_us >> 6;
+
+
+
+
+
+
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return macro_period_us;
+}
+
+
+uint16_t VL53L1_calc_range_ignore_threshold(
+ uint32_t central_rate,
+ int16_t x_gradient,
+ int16_t y_gradient,
+ uint8_t rate_mult)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ int32_t range_ignore_thresh_int = 0;
+ uint16_t range_ignore_thresh_kcps = 0;
+ int32_t central_rate_int = 0;
+ int16_t x_gradient_int = 0;
+ int16_t y_gradient_int = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ central_rate_int = ((int32_t)central_rate * (1 << 4)) / (1000);
+
+ if (x_gradient < 0)
+ x_gradient_int = x_gradient * -1;
+
+ if (y_gradient < 0)
+ y_gradient_int = y_gradient * -1;
+
+
+
+
+
+
+
+
+ range_ignore_thresh_int = (8 * x_gradient_int * 4) +
+ (8 * y_gradient_int * 4);
+
+
+
+
+ range_ignore_thresh_int = range_ignore_thresh_int / 1000;
+
+
+
+
+ range_ignore_thresh_int = range_ignore_thresh_int + central_rate_int;
+
+
+
+
+ range_ignore_thresh_int = (int32_t)rate_mult * range_ignore_thresh_int;
+
+ range_ignore_thresh_int = (range_ignore_thresh_int + (1<<4)) / (1<<5);
+
+
+
+
+ if (range_ignore_thresh_int > 0xFFFF)
+ range_ignore_thresh_kcps = 0xFFFF;
+ else
+ range_ignore_thresh_kcps = (uint16_t)range_ignore_thresh_int;
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return range_ignore_thresh_kcps;
+}
+
+
+uint32_t VL53L1_calc_timeout_mclks(
+ uint32_t timeout_us,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_mclks = 0;
+
+ LOG_FUNCTION_START("");
+
+ timeout_mclks =
+ ((timeout_us << 12) + (macro_period_us>>1)) /
+ macro_period_us;
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_mclks;
+}
+
+
+uint16_t VL53L1_calc_encoded_timeout(
+ uint32_t timeout_us,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_mclks = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+ timeout_mclks =
+ VL53L1_calc_timeout_mclks(timeout_us, macro_period_us);
+
+ timeout_encoded =
+ VL53L1_encode_timeout(timeout_mclks);
+
+
+
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_encoded;
+}
+
+
+uint32_t VL53L1_calc_timeout_us(
+ uint32_t timeout_mclks,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_us = 0;
+ uint64_t tmp = 0;
+
+ LOG_FUNCTION_START("");
+
+ tmp = (uint64_t)timeout_mclks * (uint64_t)macro_period_us;
+ tmp += 0x00800;
+ tmp = tmp >> 12;
+
+ timeout_us = (uint32_t)tmp;
+
+
+
+
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_us;
+}
+
+uint32_t VL53L1_calc_crosstalk_plane_offset_with_margin(
+ uint32_t plane_offset_kcps,
+ int16_t margin_offset_kcps)
+{
+ uint32_t plane_offset_with_margin = 0;
+ int32_t plane_offset_kcps_temp = 0;
+
+ LOG_FUNCTION_START("");
+
+ plane_offset_kcps_temp =
+ (int32_t)plane_offset_kcps +
+ (int32_t)margin_offset_kcps;
+
+ if (plane_offset_kcps_temp < 0)
+ plane_offset_kcps_temp = 0;
+ else
+ if (plane_offset_kcps_temp > 0x3FFFF)
+ plane_offset_kcps_temp = 0x3FFFF;
+
+ plane_offset_with_margin = (uint32_t) plane_offset_kcps_temp;
+
+ LOG_FUNCTION_END(0);
+
+ return plane_offset_with_margin;
+
+}
+
+uint32_t VL53L1_calc_decoded_timeout_us(
+ uint16_t timeout_encoded,
+ uint32_t macro_period_us)
+{
+
+
+
+
+
+
+
+
+
+
+ uint32_t timeout_mclks = 0;
+ uint32_t timeout_us = 0;
+
+ LOG_FUNCTION_START("");
+
+ timeout_mclks =
+ VL53L1_decode_timeout(timeout_encoded);
+
+ timeout_us =
+ VL53L1_calc_timeout_us(timeout_mclks, macro_period_us);
+
+ LOG_FUNCTION_END(0);
+
+ return timeout_us;
+}
+
+
+uint16_t VL53L1_encode_timeout(uint32_t timeout_mclks)
+{
+
+
+
+
+
+ uint16_t encoded_timeout = 0;
+ uint32_t ls_byte = 0;
+ uint16_t ms_byte = 0;
+
+ if (timeout_mclks > 0) {
+ ls_byte = timeout_mclks - 1;
+
+ while ((ls_byte & 0xFFFFFF00) > 0) {
+ ls_byte = ls_byte >> 1;
+ ms_byte++;
+ }
+
+ encoded_timeout = (ms_byte << 8)
+ + (uint16_t) (ls_byte & 0x000000FF);
+ }
+
+ return encoded_timeout;
+}
+
+
+uint32_t VL53L1_decode_timeout(uint16_t encoded_timeout)
+{
+
+
+
+
+
+
+ uint32_t timeout_macro_clks = 0;
+
+ timeout_macro_clks = ((uint32_t) (encoded_timeout & 0x00FF)
+ << (uint32_t) ((encoded_timeout & 0xFF00) >> 8)) + 1;
+
+ return timeout_macro_clks;
+}
+
+
+VL53L1_Error VL53L1_calc_timeout_register_values(
+ uint32_t phasecal_config_timeout_us,
+ uint32_t mm_config_timeout_us,
+ uint32_t range_config_timeout_us,
+ uint16_t fast_osc_frequency,
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_timing_config_t *ptiming)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint32_t macro_period_us = 0;
+ uint32_t timeout_mclks = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (fast_osc_frequency == 0) {
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+ } else {
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ ptiming->range_config__vcsel_period_a);
+
+
+
+ timeout_mclks =
+ VL53L1_calc_timeout_mclks(
+ phasecal_config_timeout_us,
+ macro_period_us);
+
+
+
+ if (timeout_mclks > 0xFF)
+ timeout_mclks = 0xFF;
+
+ pgeneral->phasecal_config__timeout_macrop =
+ (uint8_t)timeout_mclks;
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ mm_config_timeout_us,
+ macro_period_us);
+
+ ptiming->mm_config__timeout_macrop_a_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->mm_config__timeout_macrop_a_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ range_config_timeout_us,
+ macro_period_us);
+
+ ptiming->range_config__timeout_macrop_a_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->range_config__timeout_macrop_a_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ ptiming->range_config__vcsel_period_b);
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ mm_config_timeout_us,
+ macro_period_us);
+
+ ptiming->mm_config__timeout_macrop_b_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->mm_config__timeout_macrop_b_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+
+
+
+ timeout_encoded = VL53L1_calc_encoded_timeout(
+ range_config_timeout_us,
+ macro_period_us);
+
+ ptiming->range_config__timeout_macrop_b_hi =
+ (uint8_t)((timeout_encoded & 0xFF00) >> 8);
+ ptiming->range_config__timeout_macrop_b_lo =
+ (uint8_t) (timeout_encoded & 0x00FF);
+ }
+
+ LOG_FUNCTION_END(0);
+
+ return status;
+
+}
+
+
+uint8_t VL53L1_encode_vcsel_period(uint8_t VL53L1_p_031)
+{
+
+
+
+
+
+
+ uint8_t vcsel_period_reg = 0;
+
+ vcsel_period_reg = (VL53L1_p_031 >> 1) - 1;
+
+ return vcsel_period_reg;
+}
+
+
+uint32_t VL53L1_decode_unsigned_integer(
+ uint8_t *pbuffer,
+ uint8_t no_of_bytes)
+{
+
+
+
+
+
+ uint8_t i = 0;
+ uint32_t decoded_value = 0;
+
+ for (i = 0; i < no_of_bytes; i++)
+ decoded_value = (decoded_value << 8) + (uint32_t)pbuffer[i];
+
+ return decoded_value;
+}
+
+
+void VL53L1_encode_unsigned_integer(
+ uint32_t ip_value,
+ uint8_t no_of_bytes,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+ uint8_t i = 0;
+ uint32_t VL53L1_p_002 = 0;
+
+ VL53L1_p_002 = ip_value;
+ for (i = 0; i < no_of_bytes; i++) {
+ pbuffer[no_of_bytes-i-1] = VL53L1_p_002 & 0x00FF;
+ VL53L1_p_002 = VL53L1_p_002 >> 8;
+ }
+}
+
+
+VL53L1_Error VL53L1_hist_copy_and_scale_ambient_info(
+ VL53L1_zone_hist_info_t *pidata,
+ VL53L1_histogram_bin_data_t *podata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ int64_t VL53L1_p_008 = 0;
+ int64_t tmpi = 0;
+ int64_t tmpo = 0;
+
+ LOG_FUNCTION_START("");
+
+
+ if (pidata->result__dss_actual_effective_spads == 0) {
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+ } else {
+ if (pidata->number_of_ambient_bins > 0 &&
+ podata->number_of_ambient_bins == 0) {
+
+
+
+
+
+
+
+
+
+
+ tmpo = 1 + (int64_t)podata->total_periods_elapsed;
+ tmpo *=
+ (int64_t)podata->result__dss_actual_effective_spads;
+
+ tmpi = 1 + (int64_t)pidata->total_periods_elapsed;
+ tmpi *=
+ (int64_t)pidata->result__dss_actual_effective_spads;
+
+ VL53L1_p_008 = tmpo *
+ (int64_t)pidata->ambient_events_sum;
+ VL53L1_p_008 += (tmpi/2);
+
+
+
+
+ if (tmpi != 0)
+ VL53L1_p_008 = do_division_s(VL53L1_p_008, tmpi);
+
+ podata->ambient_events_sum = (int32_t)VL53L1_p_008;
+
+
+
+
+
+
+ podata->VL53L1_p_004 =
+ podata->ambient_events_sum;
+ podata->VL53L1_p_004 +=
+ ((int32_t)pidata->number_of_ambient_bins / 2);
+ podata->VL53L1_p_004 /=
+ (int32_t)pidata->number_of_ambient_bins;
+ }
+ }
+
+ LOG_FUNCTION_END(0);
+
+ return status;
+}
+
+
+void VL53L1_hist_get_bin_sequence_config(
+ VL53L1_DEV Dev,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ int32_t amb_thresh_low = 0;
+ int32_t amb_thresh_high = 0;
+
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ amb_thresh_low = 1024 *
+ (int32_t)pdev->hist_cfg.histogram_config__amb_thresh_low;
+ amb_thresh_high = 1024 *
+ (int32_t)pdev->hist_cfg.histogram_config__amb_thresh_high;
+
+
+
+
+
+
+
+
+
+
+ if ((pdev->ll_state.rd_stream_count & 0x01) == 0) {
+
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_4_5 >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_4_5 & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_2_3 >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_2_3 & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_0_1 >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__mid_amb_even_bin_0_1 & 0x0F;
+
+ if (pdata->ambient_events_sum > amb_thresh_high) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_4_5
+ >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_4_5
+ & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_2_3
+ >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_2_3
+ & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_0_1
+ >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__high_amb_even_bin_0_1
+ & 0x0F;
+ }
+
+ if (pdata->ambient_events_sum < amb_thresh_low) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_4_5
+ >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_4_5
+ & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_2_3
+ >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_2_3
+ & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_0_1
+ >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__low_amb_even_bin_0_1
+ & 0x0F;
+ }
+
+ } else {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_5
+ & 0x0F;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_3_4
+ & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_3_4
+ >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_2 &
+ 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_0_1
+ >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__mid_amb_odd_bin_0_1
+ & 0x0F;
+
+ if (pdata->ambient_events_sum > amb_thresh_high) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_4_5
+ >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_4_5
+ & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_2_3
+ >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_2_3
+ & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_0_1
+ >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__high_amb_odd_bin_0_1
+ & 0x0F;
+ }
+
+ if (pdata->ambient_events_sum < amb_thresh_low) {
+ pdata->bin_seq[5] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_4_5
+ >> 4;
+ pdata->bin_seq[4] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_4_5
+ & 0x0F;
+ pdata->bin_seq[3] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_2_3
+ >> 4;
+ pdata->bin_seq[2] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_2_3
+ & 0x0F;
+ pdata->bin_seq[1] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_0_1
+ >> 4;
+ pdata->bin_seq[0] =
+ pdev->hist_cfg.histogram_config__low_amb_odd_bin_0_1
+ & 0x0F;
+ }
+ }
+
+
+
+
+ for (i = 0; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH; i++)
+ pdata->bin_rep[i] = 1;
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+VL53L1_Error VL53L1_hist_phase_consistency_check(
+ VL53L1_DEV Dev,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_results_t *prange_curr)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t lc = 0;
+ uint8_t p = 0;
+
+ uint16_t phase_delta = 0;
+ uint16_t phase_tolerance = 0;
+
+ int32_t events_delta = 0;
+ int32_t events_tolerance = 0;
+
+
+
+ uint8_t event_sigma;
+ uint16_t event_min_spad_count;
+ uint16_t min_max_tolerance;
+ uint8_t pht;
+
+ VL53L1_DeviceError range_status = 0;
+
+ LOG_FUNCTION_START("");
+
+ event_sigma =
+ pdev->histpostprocess.algo__consistency_check__event_sigma;
+ event_min_spad_count =
+ pdev->histpostprocess.algo__consistency_check__event_min_spad_count;
+ min_max_tolerance =
+ pdev->histpostprocess.algo__consistency_check__min_max_tolerance;
+
+
+
+ pht = pdev->histpostprocess.algo__consistency_check__phase_tolerance;
+ phase_tolerance = (uint16_t)pht;
+ phase_tolerance = phase_tolerance << 8;
+
+
+
+
+ if (prange_prev->rd_device_state !=
+ VL53L1_DEVICESTATE_RANGING_GATHER_DATA &&
+ prange_prev->rd_device_state !=
+ VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA)
+ return status;
+
+
+
+
+ if (phase_tolerance == 0)
+ return status;
+
+ for (lc = 0; lc < prange_curr->active_results; lc++) {
+
+ if (!((prange_curr->VL53L1_p_002[lc].range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE) ||
+ (prange_curr->VL53L1_p_002[lc].range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK)))
+ continue;
+
+
+
+
+
+
+
+
+ if (prange_prev->active_objects == 0)
+ prange_curr->VL53L1_p_002[lc].range_status =
+ VL53L1_DEVICEERROR_PREV_RANGE_NO_TARGETS;
+ else
+ prange_curr->VL53L1_p_002[lc].range_status =
+ VL53L1_DEVICEERROR_PHASECONSISTENCY;
+
+
+
+
+
+
+
+
+
+
+ for (p = 0; p < prange_prev->active_objects; p++) {
+
+ if (prange_curr->VL53L1_p_002[lc].VL53L1_p_014 >
+ prange_prev->VL53L1_p_002[p].VL53L1_p_014) {
+ phase_delta =
+ prange_curr->VL53L1_p_002[lc].VL53L1_p_014 -
+ prange_prev->VL53L1_p_002[p].VL53L1_p_014;
+ } else {
+ phase_delta =
+ prange_prev->VL53L1_p_002[p].VL53L1_p_014 -
+ prange_curr->VL53L1_p_002[lc].VL53L1_p_014;
+ }
+
+ if (phase_delta < phase_tolerance) {
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_hist_events_consistency_check(
+ event_sigma,
+ event_min_spad_count,
+ phist_prev,
+ &(prange_prev->VL53L1_p_002[p]),
+ &(prange_curr->VL53L1_p_002[lc]),
+ &events_tolerance,
+ &events_delta,
+ &range_status);
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE &&
+ range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE)
+ status =
+ VL53L1_hist_merged_pulse_check(
+ min_max_tolerance,
+ &(prange_curr->VL53L1_p_002[lc]),
+ &range_status);
+
+ prange_curr->VL53L1_p_002[lc].range_status =
+ range_status;
+ }
+ }
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_hist_events_consistency_check(
+ uint8_t event_sigma,
+ uint16_t min_effective_spad_count,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_object_data_t *prange_prev,
+ VL53L1_range_data_t *prange_curr,
+ int32_t *pevents_tolerance,
+ int32_t *pevents_delta,
+ VL53L1_DeviceError *prange_status)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ int64_t tmpp = 0;
+ int64_t tmpc = 0;
+ int64_t events_scaler = 0;
+ int64_t events_scaler_sq = 0;
+ int64_t c_signal_events = 0;
+ int64_t c_sig_noise_sq = 0;
+ int64_t c_amb_noise_sq = 0;
+ int64_t p_amb_noise_sq = 0;
+
+ int32_t p_signal_events = 0;
+ uint32_t noise_sq_sum = 0;
+
+
+
+
+ if (event_sigma == 0) {
+ *prange_status = VL53L1_DEVICEERROR_RANGECOMPLETE;
+ return status;
+ }
+
+
+
+
+ tmpp = 1 + (int64_t)phist_prev->total_periods_elapsed;
+ tmpp *= (int64_t)phist_prev->result__dss_actual_effective_spads;
+
+
+
+
+ tmpc = 1 + (int64_t)prange_curr->total_periods_elapsed;
+ tmpc *= (int64_t)prange_curr->VL53L1_p_006;
+
+
+
+
+ events_scaler = tmpp * 4096;
+ events_scaler += (tmpc/2);
+ if (tmpc != 0)
+ events_scaler = do_division_s(events_scaler, tmpc);
+
+ events_scaler_sq = events_scaler * events_scaler;
+ events_scaler_sq += 2048;
+ events_scaler_sq /= 4096;
+
+
+
+
+ c_signal_events = (int64_t)prange_curr->VL53L1_p_021;
+ c_signal_events -= (int64_t)prange_curr->VL53L1_p_020;
+ c_signal_events *= (int64_t)events_scaler;
+ c_signal_events += 2048;
+ c_signal_events /= 4096;
+
+ c_sig_noise_sq = (int64_t)events_scaler_sq;
+ c_sig_noise_sq *= (int64_t)prange_curr->VL53L1_p_021;
+ c_sig_noise_sq += 2048;
+ c_sig_noise_sq /= 4096;
+
+ c_amb_noise_sq = (int64_t)events_scaler_sq;
+ c_amb_noise_sq *= (int64_t)prange_curr->VL53L1_p_020;
+ c_amb_noise_sq += 2048;
+ c_amb_noise_sq /= 4096;
+
+
+
+ c_amb_noise_sq += 2;
+ c_amb_noise_sq /= 4;
+
+
+
+
+
+
+
+ p_amb_noise_sq =
+ (int64_t)prange_prev->VL53L1_p_020;
+
+
+
+ p_amb_noise_sq += 2;
+ p_amb_noise_sq /= 4;
+
+ noise_sq_sum =
+ (uint32_t)prange_prev->VL53L1_p_021 +
+ (uint32_t)c_sig_noise_sq +
+ (uint32_t)p_amb_noise_sq +
+ (uint32_t)c_amb_noise_sq;
+
+ *pevents_tolerance =
+ (int32_t)VL53L1_isqrt(noise_sq_sum * 16);
+
+ *pevents_tolerance *= (int32_t)event_sigma;
+ *pevents_tolerance += 32;
+ *pevents_tolerance /= 64;
+
+ p_signal_events = (int32_t)prange_prev->VL53L1_p_021;
+ p_signal_events -= (int32_t)prange_prev->VL53L1_p_020;
+
+ if ((int32_t)c_signal_events > p_signal_events)
+ *pevents_delta =
+ (int32_t)c_signal_events - p_signal_events;
+ else
+ *pevents_delta =
+ p_signal_events - (int32_t)c_signal_events;
+
+ if (*pevents_delta > *pevents_tolerance &&
+ prange_curr->VL53L1_p_006 > min_effective_spad_count)
+ *prange_status = VL53L1_DEVICEERROR_EVENTCONSISTENCY;
+ else
+ *prange_status = VL53L1_DEVICEERROR_RANGECOMPLETE;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ return status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_hist_merged_pulse_check(
+ int16_t min_max_tolerance_mm,
+ VL53L1_range_data_t *pdata,
+ VL53L1_DeviceError *prange_status)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ int16_t delta_mm = 0;
+
+ if (pdata->max_range_mm > pdata->min_range_mm)
+ delta_mm =
+ pdata->max_range_mm - pdata->min_range_mm;
+ else
+ delta_mm =
+ pdata->min_range_mm - pdata->max_range_mm;
+
+ if (min_max_tolerance_mm > 0 &&
+ delta_mm > min_max_tolerance_mm)
+ *prange_status = VL53L1_DEVICEERROR_RANGECOMPLETE_MERGED_PULSE;
+ else
+ *prange_status = VL53L1_DEVICEERROR_RANGECOMPLETE;
+
+ return status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_hist_xmonitor_consistency_check(
+ VL53L1_DEV Dev,
+ VL53L1_zone_hist_info_t *phist_prev,
+ VL53L1_zone_objects_t *prange_prev,
+ VL53L1_range_data_t *prange_curr)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ int32_t events_delta = 0;
+ int32_t events_tolerance = 0;
+ uint8_t event_sigma;
+ uint16_t min_spad_count;
+
+ event_sigma = pdev->histpostprocess.algo__crosstalk_detect_event_sigma;
+ min_spad_count =
+ pdev->histpostprocess.algo__consistency_check__event_min_spad_count;
+
+ if (prange_curr->range_status == VL53L1_DEVICEERROR_RANGECOMPLETE ||
+ prange_curr->range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK ||
+ prange_curr->range_status ==
+ VL53L1_DEVICEERROR_EVENTCONSISTENCY) {
+
+ if (prange_prev->xmonitor.range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE ||
+ prange_prev->xmonitor.range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK ||
+ prange_prev->xmonitor.range_status ==
+ VL53L1_DEVICEERROR_EVENTCONSISTENCY) {
+
+ prange_curr->range_status =
+ VL53L1_DEVICEERROR_RANGECOMPLETE;
+
+ status =
+ VL53L1_hist_events_consistency_check(
+ event_sigma,
+ min_spad_count,
+ phist_prev,
+ &(prange_prev->xmonitor),
+ prange_curr,
+ &events_tolerance,
+ &events_delta,
+ &(prange_curr->range_status));
+
+ }
+ }
+
+ return status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_hist_wrap_dmax(
+ VL53L1_hist_post_process_config_t *phistpostprocess,
+ VL53L1_histogram_bin_data_t *pcurrent,
+ int16_t *pwrap_dmax_mm)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint32_t pll_period_mm = 0;
+ uint32_t wrap_dmax_phase = 0;
+ uint32_t range_mm = 0;
+
+ LOG_FUNCTION_START("");
+
+ *pwrap_dmax_mm = 0;
+
+
+ if (pcurrent->VL53L1_p_019 != 0) {
+
+
+
+
+ pll_period_mm =
+ VL53L1_calc_pll_period_mm(
+ pcurrent->VL53L1_p_019);
+
+
+
+
+ wrap_dmax_phase =
+ (uint32_t)phistpostprocess->valid_phase_high << 8;
+
+
+
+
+
+ range_mm = wrap_dmax_phase * pll_period_mm;
+ range_mm = (range_mm + (1<<14)) >> 15;
+
+ *pwrap_dmax_mm = (int16_t)range_mm;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+void VL53L1_hist_combine_mm1_mm2_offsets(
+ int16_t mm1_offset_mm,
+ int16_t mm2_offset_mm,
+ uint8_t encoded_mm_roi_centre,
+ uint8_t encoded_mm_roi_size,
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ VL53L1_additional_offset_cal_data_t *pcal_data,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ int16_t *prange_offset_mm)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint16_t max_mm_inner_effective_spads = 0;
+ uint16_t max_mm_outer_effective_spads = 0;
+ uint16_t mm_inner_effective_spads = 0;
+ uint16_t mm_outer_effective_spads = 0;
+
+ uint32_t scaled_mm1_peak_rate_mcps = 0;
+ uint32_t scaled_mm2_peak_rate_mcps = 0;
+
+ int32_t tmp0 = 0;
+ int32_t tmp1 = 0;
+
+
+
+
+ VL53L1_calc_mm_effective_spads(
+ encoded_mm_roi_centre,
+ encoded_mm_roi_size,
+ 0xC7,
+
+ 0xFF,
+ pgood_spads,
+ aperture_attenuation,
+ &max_mm_inner_effective_spads,
+ &max_mm_outer_effective_spads);
+
+ if ((max_mm_inner_effective_spads == 0) ||
+ (max_mm_outer_effective_spads == 0))
+ goto FAIL;
+
+
+
+
+ VL53L1_calc_mm_effective_spads(
+ encoded_mm_roi_centre,
+ encoded_mm_roi_size,
+ encoded_zone_centre,
+ encoded_zone_size,
+ pgood_spads,
+ aperture_attenuation,
+ &mm_inner_effective_spads,
+ &mm_outer_effective_spads);
+
+
+
+
+ scaled_mm1_peak_rate_mcps =
+ (uint32_t)pcal_data->result__mm_inner_peak_signal_count_rtn_mcps;
+ scaled_mm1_peak_rate_mcps *= (uint32_t)mm_inner_effective_spads;
+ scaled_mm1_peak_rate_mcps /= (uint32_t)max_mm_inner_effective_spads;
+
+ scaled_mm2_peak_rate_mcps =
+ (uint32_t)pcal_data->result__mm_outer_peak_signal_count_rtn_mcps;
+ scaled_mm2_peak_rate_mcps *= (uint32_t)mm_outer_effective_spads;
+ scaled_mm2_peak_rate_mcps /= (uint32_t)max_mm_outer_effective_spads;
+
+
+
+
+ tmp0 = ((int32_t)mm1_offset_mm * (int32_t)scaled_mm1_peak_rate_mcps);
+ tmp0 += ((int32_t)mm2_offset_mm * (int32_t)scaled_mm2_peak_rate_mcps);
+
+ tmp1 = (int32_t)scaled_mm1_peak_rate_mcps +
+ (int32_t)scaled_mm2_peak_rate_mcps;
+
+
+
+
+
+
+ if (tmp1 != 0)
+ tmp0 = (tmp0 * 4) / tmp1;
+FAIL:
+ *prange_offset_mm = (int16_t)tmp0;
+
+}
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_window(
+ int16_t target_distance_mm,
+ uint16_t target_width_oversize,
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ pxtalk_data->pll_period_mm =
+ VL53L1_calc_pll_period_mm(phist_bins->VL53L1_p_019);
+
+
+
+ pxtalk_data->xtalk_width_phase =
+ (int32_t)phist_bins->vcsel_width * 128;
+ pxtalk_data->target_width_phase =
+ pxtalk_data->xtalk_width_phase +
+ (int32_t)target_width_oversize * 128;
+
+
+
+
+
+
+
+ pxtalk_data->xtalk_start_phase =
+ (int32_t)phist_bins->zero_distance_phase -
+ (pxtalk_data->xtalk_width_phase / 2);
+ pxtalk_data->xtalk_end_phase =
+ (int32_t)pxtalk_data->xtalk_start_phase +
+ pxtalk_data->xtalk_width_phase;
+
+ if (pxtalk_data->xtalk_start_phase < 0)
+ pxtalk_data->xtalk_start_phase = 0;
+
+
+
+
+
+
+
+
+ pxtalk_data->VL53L1_p_015 =
+ (uint8_t)(pxtalk_data->xtalk_start_phase / 2048);
+
+
+
+ pxtalk_data->VL53L1_p_016 =
+ (uint8_t)((pxtalk_data->xtalk_end_phase + 2047) / 2048);
+
+
+
+
+
+
+
+ pxtalk_data->target_start_phase =
+ (int32_t)target_distance_mm * 2048 * 16;
+ pxtalk_data->target_start_phase +=
+ ((int32_t)pxtalk_data->pll_period_mm / 2);
+ pxtalk_data->target_start_phase /= (int32_t)pxtalk_data->pll_period_mm;
+ pxtalk_data->target_start_phase +=
+ (int32_t)phist_bins->zero_distance_phase;
+
+
+
+
+
+
+ pxtalk_data->target_start_phase -=
+ (pxtalk_data->target_width_phase / 2);
+ pxtalk_data->target_end_phase =
+ (int32_t)pxtalk_data->target_start_phase +
+ pxtalk_data->target_width_phase;
+
+ if (pxtalk_data->target_start_phase < 0)
+ pxtalk_data->target_start_phase = 0;
+
+
+
+ pxtalk_data->target_start =
+ (uint8_t)(pxtalk_data->target_start_phase / 2048);
+
+
+
+ if (pxtalk_data->VL53L1_p_016 > (pxtalk_data->target_start-1))
+ pxtalk_data->VL53L1_p_016 = pxtalk_data->target_start-1;
+
+
+
+ pxtalk_data->effective_width =
+ (2048 * ((int32_t)pxtalk_data->VL53L1_p_016+1));
+ pxtalk_data->effective_width -= pxtalk_data->xtalk_start_phase;
+
+
+
+
+
+ if (pxtalk_data->effective_width > pxtalk_data->xtalk_width_phase)
+ pxtalk_data->effective_width = pxtalk_data->xtalk_width_phase;
+
+ if (pxtalk_data->effective_width < 1)
+ pxtalk_data->effective_width = 1;
+
+
+
+ pxtalk_data->event_scaler = pxtalk_data->xtalk_width_phase * 1000;
+ pxtalk_data->event_scaler += (pxtalk_data->effective_width / 2);
+ pxtalk_data->event_scaler /= pxtalk_data->effective_width;
+
+
+
+
+
+ if (pxtalk_data->event_scaler < 1000)
+ pxtalk_data->event_scaler = 1000;
+
+ if (pxtalk_data->event_scaler > 4000)
+ pxtalk_data->event_scaler = 4000;
+
+
+
+ pxtalk_data->event_scaler_sum += pxtalk_data->event_scaler;
+
+
+
+ pxtalk_data->peak_duration_us_sum +=
+ (uint32_t)phist_bins->peak_duration_us;
+
+
+
+ pxtalk_data->effective_spad_count_sum +=
+ (uint32_t)phist_bins->result__dss_actual_effective_spads;
+
+
+
+ pxtalk_data->zero_distance_phase_sum +=
+ (uint32_t)phist_bins->zero_distance_phase;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_event_sums(
+ VL53L1_histogram_bin_data_t *phist_bins,
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t lb = 0;
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ for (lb = pxtalk_data->VL53L1_p_015;
+ lb <= pxtalk_data->VL53L1_p_016;
+ lb++) {
+
+
+
+ i = (lb + phist_bins->number_of_ambient_bins +
+ phist_bins->VL53L1_p_024) %
+ phist_bins->VL53L1_p_024;
+
+
+
+ pxtalk_data->signal_events_sum += phist_bins->bin_data[i];
+ pxtalk_data->signal_events_sum -=
+ phist_bins->VL53L1_p_004;
+ }
+
+
+
+
+ for (lb = 0; lb < VL53L1_XTALK_HISTO_BINS &&
+ lb < phist_bins->VL53L1_p_024; lb++) {
+
+
+
+ i = (lb + phist_bins->number_of_ambient_bins +
+ phist_bins->VL53L1_p_024) %
+ phist_bins->VL53L1_p_024;
+
+
+
+ pxtalk_data->bin_data_sums[lb] += phist_bins->bin_data[i];
+ pxtalk_data->bin_data_sums[lb] -=
+ phist_bins->VL53L1_p_004;
+ }
+
+ pxtalk_data->sample_count += 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_rate_per_spad(
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint64_t tmp64_0 = 0;
+ uint64_t tmp64_1 = 0;
+ uint64_t xtalk_per_spad = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ if (pxtalk_data->signal_events_sum > 0) {
+ tmp64_0 =
+ ((uint64_t)pxtalk_data->signal_events_sum *
+ (uint64_t)pxtalk_data->sample_count *
+ (uint64_t)pxtalk_data->event_scaler_avg * 256U) << 9U;
+ tmp64_1 =
+ (uint64_t)pxtalk_data->effective_spad_count_sum *
+ (uint64_t)pxtalk_data->peak_duration_us_sum;
+
+
+
+
+ if (tmp64_1 > 0U) {
+
+
+ tmp64_0 = tmp64_0 + (tmp64_1 >> 1U);
+ xtalk_per_spad = do_division_u(tmp64_0, tmp64_1);
+ } else {
+ xtalk_per_spad = (uint64_t)tmp64_0;
+ }
+
+ } else {
+ status = VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL;
+ }
+
+ pxtalk_data->xtalk_rate_kcps_per_spad = (uint32_t)xtalk_per_spad;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_hist_xtalk_extract_calc_shape(
+ VL53L1_hist_xtalk_extract_data_t *pxtalk_data,
+ VL53L1_xtalk_histogram_shape_t *pxtalk_shape)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ int32_t lb = 0;
+ uint64_t total_events = 0U;
+ uint64_t tmp64_0 = 0U;
+ int32_t remaining_area = 1024;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pxtalk_shape->VL53L1_p_022 = 0;
+ pxtalk_shape->VL53L1_p_023 = VL53L1_XTALK_HISTO_BINS;
+ pxtalk_shape->VL53L1_p_024 = VL53L1_XTALK_HISTO_BINS;
+
+ pxtalk_shape->zero_distance_phase =
+ (uint16_t)pxtalk_data->zero_distance_phase_avg;
+ pxtalk_shape->phasecal_result__reference_phase =
+ (uint16_t)pxtalk_data->zero_distance_phase_avg + (3*2048);
+
+
+
+
+ if (pxtalk_data->signal_events_sum > 0)
+ total_events =
+ (uint64_t)pxtalk_data->signal_events_sum *
+ (uint64_t)pxtalk_data->event_scaler_avg;
+ else
+ total_events = 1;
+ if (total_events == 0)
+ total_events = 1;
+
+
+
+ remaining_area = 1024;
+ pxtalk_data->max_shape_value = 0;
+
+ for (lb = 0; lb < VL53L1_XTALK_HISTO_BINS; lb++) {
+
+ if ((lb < (int32_t)pxtalk_data->VL53L1_p_015 ||
+ lb > (int32_t)pxtalk_data->VL53L1_p_016) ||
+ pxtalk_data->bin_data_sums[lb] < 0) {
+
+
+
+
+
+
+ if (remaining_area > 0 && remaining_area < 1024) {
+ if (remaining_area >
+ pxtalk_data->max_shape_value) {
+ pxtalk_shape->bin_data[lb] =
+ (uint32_t)pxtalk_data->max_shape_value;
+ remaining_area -=
+ pxtalk_data->max_shape_value;
+ } else {
+ pxtalk_shape->bin_data[lb] =
+ (uint32_t)remaining_area;
+ remaining_area = 0;
+ }
+ } else {
+ pxtalk_shape->bin_data[lb] = 0;
+ }
+
+ } else {
+
+
+
+
+ tmp64_0 =
+ (uint64_t)pxtalk_data->bin_data_sums[lb]
+ * 1024U * 1000U;
+ tmp64_0 += (total_events >> 1);
+ tmp64_0 = do_division_u(tmp64_0, total_events);
+ if (tmp64_0 > 0xFFFFU)
+ tmp64_0 = 0xFFFFU;
+
+ pxtalk_shape->bin_data[lb] = (uint32_t)tmp64_0;
+
+
+
+
+
+ if ((int32_t)pxtalk_shape->bin_data[lb] >
+ pxtalk_data->max_shape_value)
+ pxtalk_data->max_shape_value =
+ (int32_t)pxtalk_shape->bin_data[lb];
+
+ remaining_area -= (int32_t)pxtalk_shape->bin_data[lb];
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_hist_xtalk_shape_model(
+ uint16_t events_per_bin,
+ uint16_t pulse_centre,
+ uint16_t pulse_width,
+ VL53L1_xtalk_histogram_shape_t *pxtalk_shape)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint32_t phase_start = 0;
+ uint32_t phase_stop = 0;
+ uint32_t phase_bin = 0;
+
+ uint32_t bin_start = 0;
+ uint32_t bin_stop = 0;
+
+ uint32_t lb = 0;
+ uint16_t VL53L1_p_008 = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pxtalk_shape->VL53L1_p_022 = 0;
+ pxtalk_shape->VL53L1_p_023 = VL53L1_XTALK_HISTO_BINS;
+ pxtalk_shape->VL53L1_p_024 = VL53L1_XTALK_HISTO_BINS;
+
+ pxtalk_shape->zero_distance_phase = pulse_centre;
+ pxtalk_shape->phasecal_result__reference_phase =
+ pulse_centre + (3*2048);
+
+
+
+ if (pulse_centre > (pulse_width >> 1))
+ phase_start = (uint32_t)pulse_centre -
+ ((uint32_t)pulse_width >> 1);
+ else
+ phase_start = 0;
+
+ phase_stop = (uint32_t)pulse_centre +
+ ((uint32_t)pulse_width >> 1);
+
+
+
+ bin_start = (phase_start / 2048);
+ bin_stop = (phase_stop / 2048);
+
+ for (lb = 0; lb < VL53L1_XTALK_HISTO_BINS; lb++) {
+ VL53L1_p_008 = 0;
+
+
+
+ if (lb == bin_start && lb == bin_stop) {
+ VL53L1_p_008 =
+ VL53L1_hist_xtalk_shape_model_interp(
+ events_per_bin,
+ phase_stop - phase_start);
+
+ } else if (lb > bin_start && lb < bin_stop) {
+
+
+
+ VL53L1_p_008 = events_per_bin;
+
+ } else if (lb == bin_start) {
+
+
+
+ phase_bin = (lb + 1) * 2048;
+ VL53L1_p_008 =
+ VL53L1_hist_xtalk_shape_model_interp(
+ events_per_bin,
+ (phase_bin - phase_start));
+
+ } else if (lb == bin_stop) {
+
+
+
+ phase_bin = lb * 2048;
+ VL53L1_p_008 =
+ VL53L1_hist_xtalk_shape_model_interp(
+ events_per_bin,
+ (phase_stop - phase_bin));
+ }
+
+ pxtalk_shape->bin_data[lb] = VL53L1_p_008;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+uint16_t VL53L1_hist_xtalk_shape_model_interp(
+ uint16_t events_per_bin,
+ uint32_t phase_delta)
+{
+
+
+
+
+
+
+
+
+
+ uint32_t VL53L1_p_008 = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+ VL53L1_p_008 = (uint32_t)events_per_bin * phase_delta;
+ VL53L1_p_008 += 1024;
+ VL53L1_p_008 /= 2048;
+
+
+
+ if (VL53L1_p_008 > 0xFFFFU)
+ VL53L1_p_008 = 0xFFFFU;
+
+ LOG_FUNCTION_END(0);
+
+ return (uint16_t)VL53L1_p_008;
+}
+
+
+void VL53L1_spad_number_to_byte_bit_index(
+ uint8_t spad_number,
+ uint8_t *pbyte_index,
+ uint8_t *pbit_index,
+ uint8_t *pbit_mask)
+{
+
+
+
+
+
+
+
+
+
+
+ *pbyte_index = spad_number >> 3;
+ *pbit_index = spad_number & 0x07;
+ *pbit_mask = 0x01 << *pbit_index;
+
+}
+
+
+void VL53L1_encode_row_col(
+ uint8_t row,
+ uint8_t col,
+ uint8_t *pspad_number)
+{
+
+
+
+
+
+ if (row > 7)
+ *pspad_number = 128 + (col << 3) + (15-row);
+ else
+ *pspad_number = ((15-col) << 3) + row;
+
+}
+
+
+void VL53L1_decode_zone_size(
+ uint8_t encoded_xy_size,
+ uint8_t *pwidth,
+ uint8_t *pheight)
+{
+
+
+
+
+
+
+
+
+
+
+
+ *pheight = encoded_xy_size >> 4;
+ *pwidth = encoded_xy_size & 0x0F;
+
+}
+
+
+void VL53L1_encode_zone_size(
+ uint8_t width,
+ uint8_t height,
+ uint8_t *pencoded_xy_size)
+{
+
+
+
+
+
+
+
+
+
+
+ *pencoded_xy_size = (height << 4) + width;
+
+}
+
+
+void VL53L1_decode_zone_limits(
+ uint8_t encoded_xy_centre,
+ uint8_t encoded_xy_size,
+ int16_t *px_ll,
+ int16_t *py_ll,
+ int16_t *px_ur,
+ int16_t *py_ur)
+{
+
+
+
+
+
+
+
+
+
+ uint8_t x_centre = 0;
+ uint8_t y_centre = 0;
+ uint8_t width = 0;
+ uint8_t height = 0;
+
+
+
+
+ VL53L1_decode_row_col(
+ encoded_xy_centre,
+ &y_centre,
+ &x_centre);
+
+ VL53L1_decode_zone_size(
+ encoded_xy_size,
+ &width,
+ &height);
+
+
+
+
+ *px_ll = (int16_t)x_centre - ((int16_t)width + 1) / 2;
+ if (*px_ll < 0)
+ *px_ll = 0;
+
+ *px_ur = *px_ll + (int16_t)width;
+ if (*px_ur > (VL53L1_SPAD_ARRAY_WIDTH-1))
+ *px_ur = VL53L1_SPAD_ARRAY_WIDTH-1;
+
+ *py_ll = (int16_t)y_centre - ((int16_t)height + 1) / 2;
+ if (*py_ll < 0)
+ *py_ll = 0;
+
+ *py_ur = *py_ll + (int16_t)height;
+ if (*py_ur > (VL53L1_SPAD_ARRAY_HEIGHT-1))
+ *py_ur = VL53L1_SPAD_ARRAY_HEIGHT-1;
+}
+
+
+uint8_t VL53L1_is_aperture_location(
+ uint8_t row,
+ uint8_t col)
+{
+
+
+
+
+
+ uint8_t is_aperture = 0;
+ uint8_t mod_row = row % 4;
+ uint8_t mod_col = col % 4;
+
+ if (mod_row == 0 && mod_col == 2)
+ is_aperture = 1;
+
+ if (mod_row == 2 && mod_col == 0)
+ is_aperture = 1;
+
+ return is_aperture;
+}
+
+
+void VL53L1_calc_max_effective_spads(
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ uint16_t *pmax_effective_spads)
+{
+
+
+
+
+
+
+ int16_t x = 0;
+ int16_t y = 0;
+
+ int16_t zone_x_ll = 0;
+ int16_t zone_y_ll = 0;
+ int16_t zone_x_ur = 0;
+ int16_t zone_y_ur = 0;
+
+ uint8_t spad_number = 0;
+ uint8_t byte_index = 0;
+ uint8_t bit_index = 0;
+ uint8_t bit_mask = 0;
+
+ uint8_t is_aperture = 0;
+
+
+
+
+ VL53L1_decode_zone_limits(
+ encoded_zone_centre,
+ encoded_zone_size,
+ &zone_x_ll,
+ &zone_y_ll,
+ &zone_x_ur,
+ &zone_y_ur);
+
+
+
+
+
+
+
+ *pmax_effective_spads = 0;
+
+ for (y = zone_y_ll; y <= zone_y_ur; y++) {
+ for (x = zone_x_ll; x <= zone_x_ur; x++) {
+
+
+
+
+ VL53L1_encode_row_col(
+ (uint8_t)y,
+ (uint8_t)x,
+ &spad_number);
+
+
+
+
+
+
+
+
+ VL53L1_spad_number_to_byte_bit_index(
+ spad_number,
+ &byte_index,
+ &bit_index,
+ &bit_mask);
+
+
+
+
+ if ((pgood_spads[byte_index] & bit_mask) > 0) {
+
+
+
+ is_aperture = VL53L1_is_aperture_location(
+ (uint8_t)y,
+ (uint8_t)x);
+
+ if (is_aperture > 0)
+ *pmax_effective_spads +=
+ aperture_attenuation;
+ else
+ *pmax_effective_spads += 0x0100;
+
+ }
+ }
+ }
+}
+
+
+void VL53L1_calc_mm_effective_spads(
+ uint8_t encoded_mm_roi_centre,
+ uint8_t encoded_mm_roi_size,
+ uint8_t encoded_zone_centre,
+ uint8_t encoded_zone_size,
+ uint8_t *pgood_spads,
+ uint16_t aperture_attenuation,
+ uint16_t *pmm_inner_effective_spads,
+ uint16_t *pmm_outer_effective_spads)
+{
+
+
+
+
+
+
+
+ int16_t x = 0;
+ int16_t y = 0;
+
+ int16_t mm_x_ll = 0;
+ int16_t mm_y_ll = 0;
+ int16_t mm_x_ur = 0;
+ int16_t mm_y_ur = 0;
+
+ int16_t zone_x_ll = 0;
+ int16_t zone_y_ll = 0;
+ int16_t zone_x_ur = 0;
+ int16_t zone_y_ur = 0;
+
+ uint8_t spad_number = 0;
+ uint8_t byte_index = 0;
+ uint8_t bit_index = 0;
+ uint8_t bit_mask = 0;
+
+ uint8_t is_aperture = 0;
+ uint16_t spad_attenuation = 0;
+
+
+
+
+ VL53L1_decode_zone_limits(
+ encoded_mm_roi_centre,
+ encoded_mm_roi_size,
+ &mm_x_ll,
+ &mm_y_ll,
+ &mm_x_ur,
+ &mm_y_ur);
+
+ VL53L1_decode_zone_limits(
+ encoded_zone_centre,
+ encoded_zone_size,
+ &zone_x_ll,
+ &zone_y_ll,
+ &zone_x_ur,
+ &zone_y_ur);
+
+
+
+
+
+
+
+
+
+ *pmm_inner_effective_spads = 0;
+ *pmm_outer_effective_spads = 0;
+
+ for (y = zone_y_ll; y <= zone_y_ur; y++) {
+ for (x = zone_x_ll; x <= zone_x_ur; x++) {
+
+
+
+
+ VL53L1_encode_row_col(
+ (uint8_t)y,
+ (uint8_t)x,
+ &spad_number);
+
+
+
+
+
+
+
+
+ VL53L1_spad_number_to_byte_bit_index(
+ spad_number,
+ &byte_index,
+ &bit_index,
+ &bit_mask);
+
+
+
+
+ if ((pgood_spads[byte_index] & bit_mask) > 0) {
+
+
+
+ is_aperture = VL53L1_is_aperture_location(
+ (uint8_t)y,
+ (uint8_t)x);
+
+ if (is_aperture > 0)
+ spad_attenuation = aperture_attenuation;
+ else
+ spad_attenuation = 0x0100;
+
+
+
+
+
+
+
+ if (x >= mm_x_ll && x <= mm_x_ur &&
+ y >= mm_y_ll && y <= mm_y_ur)
+ *pmm_inner_effective_spads +=
+ spad_attenuation;
+ else
+ *pmm_outer_effective_spads +=
+ spad_attenuation;
+ }
+ }
+ }
+}
+
+
+void VL53L1_hist_copy_results_to_sys_and_core(
+ VL53L1_histogram_bin_data_t *pbins,
+ VL53L1_range_results_t *phist,
+ VL53L1_system_results_t *psys,
+ VL53L1_core_results_t *pcore)
+{
+
+
+
+
+
+ uint8_t i = 0;
+
+ VL53L1_range_data_t *pdata;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ VL53L1_init_system_results(psys);
+
+
+
+
+ psys->result__interrupt_status = pbins->result__interrupt_status;
+ psys->result__range_status = phist->active_results;
+ psys->result__report_status = pbins->result__report_status;
+ psys->result__stream_count = pbins->result__stream_count;
+
+ pdata = &(phist->VL53L1_p_002[0]);
+
+ for (i = 0; i < phist->active_results; i++) {
+
+ switch (i) {
+ case 0:
+ psys->result__dss_actual_effective_spads_sd0 =
+ pdata->VL53L1_p_006;
+ psys->result__peak_signal_count_rate_mcps_sd0 =
+ pdata->peak_signal_count_rate_mcps;
+ psys->result__avg_signal_count_rate_mcps_sd0 =
+ pdata->avg_signal_count_rate_mcps;
+ psys->result__ambient_count_rate_mcps_sd0 =
+ pdata->ambient_count_rate_mcps;
+
+ psys->result__sigma_sd0 = pdata->VL53L1_p_005;
+ psys->result__phase_sd0 = pdata->VL53L1_p_014;
+
+ psys->result__final_crosstalk_corrected_range_mm_sd0 =
+ (uint16_t)pdata->median_range_mm;
+
+ psys->result__phase_sd1 = pdata->zero_distance_phase;
+
+ pcore->result_core__ranging_total_events_sd0 =
+ pdata->VL53L1_p_021;
+ pcore->result_core__signal_total_events_sd0 =
+ pdata->VL53L1_p_013;
+ pcore->result_core__total_periods_elapsed_sd0 =
+ pdata->total_periods_elapsed;
+ pcore->result_core__ambient_window_events_sd0 =
+ pdata->VL53L1_p_020;
+
+ break;
+ case 1:
+ psys->result__dss_actual_effective_spads_sd1 =
+ pdata->VL53L1_p_006;
+ psys->result__peak_signal_count_rate_mcps_sd1 =
+ pdata->peak_signal_count_rate_mcps;
+ psys->result__ambient_count_rate_mcps_sd1 =
+ pdata->ambient_count_rate_mcps;
+
+ psys->result__sigma_sd1 = pdata->VL53L1_p_005;
+ psys->result__phase_sd1 = pdata->VL53L1_p_014;
+
+ psys->result__final_crosstalk_corrected_range_mm_sd1 =
+ (uint16_t)pdata->median_range_mm;
+
+ pcore->result_core__ranging_total_events_sd1 =
+ pdata->VL53L1_p_021;
+ pcore->result_core__signal_total_events_sd1 =
+ pdata->VL53L1_p_013;
+ pcore->result_core__total_periods_elapsed_sd1 =
+ pdata->total_periods_elapsed;
+ pcore->result_core__ambient_window_events_sd1 =
+ pdata->VL53L1_p_020;
+ break;
+ }
+
+ pdata++;
+ }
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+VL53L1_Error VL53L1_sum_histogram_data(
+ VL53L1_histogram_bin_data_t *phist_input,
+ VL53L1_histogram_bin_data_t *phist_output)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+ uint8_t smallest_bin_num = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ if (phist_output->VL53L1_p_024 >=
+ phist_input->VL53L1_p_024)
+ smallest_bin_num = phist_input->VL53L1_p_024;
+ else
+ smallest_bin_num = phist_output->VL53L1_p_024;
+ }
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ for (i = 0; i < smallest_bin_num; i++)
+
+
+ phist_output->bin_data[i] += phist_input->bin_data[i];
+
+ if (status == VL53L1_ERROR_NONE)
+
+ phist_output->VL53L1_p_004 +=
+ phist_input->VL53L1_p_004;
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_avg_histogram_data(
+ uint8_t no_of_samples,
+ VL53L1_histogram_bin_data_t *phist_sum,
+ VL53L1_histogram_bin_data_t *phist_avg)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ for (i = 0; i < phist_sum->VL53L1_p_024; i++) {
+
+
+
+
+ if (no_of_samples > 0)
+ phist_avg->bin_data[i] =
+ phist_sum->bin_data[i] /
+ (int32_t)no_of_samples;
+ else
+ phist_avg->bin_data[i] = phist_sum->bin_data[i];
+ }
+ }
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ if (no_of_samples > 0)
+ phist_avg->VL53L1_p_004 =
+ phist_sum->VL53L1_p_004 /
+ (int32_t)no_of_samples;
+ else
+ phist_avg->VL53L1_p_004 =
+ phist_sum->VL53L1_p_004;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_save_cfg_data(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+
+ VL53L1_zone_private_dyn_cfg_t *pzone_dyn_cfg;
+ VL53L1_dynamic_config_t *pdynamic = &(pdev->dyn_cfg);
+
+ LOG_FUNCTION_START("");
+
+ pzone_dyn_cfg =
+ &(pres->zone_dyn_cfgs.VL53L1_p_002[pdev->ll_state.cfg_zone_id]);
+
+ pzone_dyn_cfg->expected_stream_count =
+ pdev->ll_state.cfg_stream_count;
+
+ pzone_dyn_cfg->expected_gph_id =
+ pdev->ll_state.cfg_gph_id;
+
+ pzone_dyn_cfg->roi_config__user_roi_centre_spad =
+ pdynamic->roi_config__user_roi_centre_spad;
+
+ pzone_dyn_cfg->roi_config__user_roi_requested_global_xy_size =
+ pdynamic->roi_config__user_roi_requested_global_xy_size;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_dynamic_zone_update(
+ VL53L1_DEV Dev,
+ VL53L1_range_results_t *presults)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres =
+ VL53L1DevStructGetLLResultsHandle(Dev);
+ VL53L1_zone_private_dyn_cfgs_t *pZ = &(pres->zone_dyn_cfgs);
+
+ uint8_t zone_id = pdev->ll_state.rd_zone_id;
+ uint8_t i;
+ uint16_t max_total_rate_per_spads;
+ uint16_t target_rate =
+ pdev->stat_cfg.dss_config__target_total_rate_mcps;
+ uint32_t temp = 0xFFFF;
+#ifdef VL53L1_LOG_ENABLE
+ uint16_t eff_spad_cnt =
+ pZ->VL53L1_p_002[zone_id].dss_requested_effective_spad_count;
+#endif
+
+ LOG_FUNCTION_START("");
+
+ pZ->VL53L1_p_002[zone_id].dss_requested_effective_spad_count = 0;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: peak signal count rate mcps:");
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ "%u actual effective spads: %u\n",
+ presults->VL53L1_p_002[0].peak_signal_count_rate_mcps,
+ presults->VL53L1_p_002[0].VL53L1_p_006);
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: active results: %u\n",
+ presults->active_results);
+
+ max_total_rate_per_spads =
+ presults->VL53L1_p_002[0].total_rate_per_spad_mcps;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: max total rate per spad at start: %u\n",
+ max_total_rate_per_spads);
+
+ for (i = 1; i < presults->active_results; i++) {
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: zone total rate per spad: zone_id: %u,",
+ i);
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ "total rate per spad: %u\n",
+ presults->VL53L1_p_002[i].total_rate_per_spad_mcps);
+
+ if (presults->VL53L1_p_002[i].total_rate_per_spad_mcps >
+ max_total_rate_per_spads)
+ max_total_rate_per_spads =
+ presults->VL53L1_p_002[i].total_rate_per_spad_mcps;
+
+ }
+
+ if (max_total_rate_per_spads == 0) {
+
+
+
+
+
+ temp = 0xFFFF;
+ } else {
+
+
+
+
+
+ temp = target_rate << 14;
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: 1: temp: %u\n",
+ temp);
+
+
+
+
+
+ temp = temp / max_total_rate_per_spads;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: 2: temp: %u\n",
+ temp);
+
+
+
+
+
+ if (temp > 0xFFFF)
+ temp = 0xFFFF;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: 3: temp: %u\n",
+ temp);
+ }
+
+ pZ->VL53L1_p_002[zone_id].dss_requested_effective_spad_count =
+ (uint16_t)temp;
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " DYNZONEUPDATE: zone_id: %u, target_rate: %u,",
+ zone_id,
+ target_rate);
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ "max_total_rate_per_spads: %u, requested_spads: %u\n",
+ max_total_rate_per_spads,
+ eff_spad_cnt);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_multizone_hist_bins_update(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_ll_driver_state_t *pstate = &(pdev->ll_state);
+ VL53L1_zone_config_t *pzone_cfg = &(pdev->zone_cfg);
+ VL53L1_histogram_config_t *phist_cfg = &(pdev->hist_cfg);
+ VL53L1_histogram_config_t *pmulti_hist =
+ &(pzone_cfg->multizone_hist_cfg);
+
+ uint8_t next_range_is_odd_timing = (pstate->cfg_stream_count) % 2;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (pzone_cfg->bin_config[pdev->ll_state.cfg_zone_id] ==
+ VL53L1_ZONECONFIG_BINCONFIG__LOWAMB) {
+ if (!next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting LOWAMB EVEN timing\n");
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+ }
+
+ if (next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting LOWAMB ODD timing\n");
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+ }
+ } else if (pzone_cfg->bin_config[pdev->ll_state.cfg_zone_id] ==
+ VL53L1_ZONECONFIG_BINCONFIG__MIDAMB) {
+
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting MIDAMB timing\n");
+ if (!next_range_is_odd_timing) {
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting MIDAMB EVEN timing\n");
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+ }
+
+ if (next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting MIDAMB ODD timing\n");
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+ }
+ } else if (pzone_cfg->bin_config[pdev->ll_state.cfg_zone_id] ==
+ VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB) {
+ if (!next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting HIGHAMB EVEN timing\n"
+ );
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ }
+
+ if (next_range_is_odd_timing) {
+ trace_print (VL53L1_TRACE_LEVEL_DEBUG,
+ " HISTBINCONFIGUPDATE: Setting HIGHAMB ODD timing\n");
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ }
+ }
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+ VL53L1_copy_hist_bins_to_static_cfg(
+ phist_cfg,
+ &(pdev->stat_cfg),
+ &(pdev->tim_cfg));
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_update_internal_stream_counters(
+ VL53L1_DEV Dev,
+ uint8_t external_stream_count,
+ uint8_t *pinternal_stream_count,
+ uint8_t *pinternal_stream_count_val)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t stream_divider;
+
+ VL53L1_LLDriverData_t *pdev =
+ VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ stream_divider = pdev->gen_cfg.global_config__stream_divider;
+
+ if (stream_divider == 0) {
+
+
+
+
+
+
+ *pinternal_stream_count = external_stream_count;
+
+ } else if (*pinternal_stream_count_val == (stream_divider-1)) {
+
+
+
+
+
+ if (*pinternal_stream_count == 0xFF)
+ *pinternal_stream_count = 0x80;
+ else
+ *pinternal_stream_count = *pinternal_stream_count + 1;
+
+
+
+
+
+ *pinternal_stream_count_val = 0;
+
+ } else {
+
+
+
+
+
+ *pinternal_stream_count_val = *pinternal_stream_count_val + 1;
+ }
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ "UPDINTSTREAMCOUNT internal_steam_count: %d,",
+ *pinternal_stream_count);
+
+ trace_print(VL53L1_TRACE_LEVEL_DEBUG,
+ "internal_stream_count_val: %d, divider: %d\n",
+ *pinternal_stream_count_val,
+ stream_divider);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_histogram_multizone_initial_bin_config(
+ VL53L1_zone_config_t *pzone_cfg,
+ VL53L1_histogram_config_t *phist_cfg,
+ VL53L1_histogram_config_t *pmulti_hist)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (pzone_cfg->bin_config[0] ==
+ VL53L1_ZONECONFIG_BINCONFIG__LOWAMB) {
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__low_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__low_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__low_amb_even_bin_4_5;
+ } else if (pzone_cfg->bin_config[0] ==
+ VL53L1_ZONECONFIG_BINCONFIG__MIDAMB) {
+
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__mid_amb_even_bin_4_5;
+ } else if (pzone_cfg->bin_config[0] ==
+ VL53L1_ZONECONFIG_BINCONFIG__HIGHAMB) {
+ phist_cfg->histogram_config__low_amb_even_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_even_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_even_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ phist_cfg->histogram_config__low_amb_odd_bin_0_1 =
+ pmulti_hist->histogram_config__high_amb_even_bin_0_1;
+ phist_cfg->histogram_config__low_amb_odd_bin_2_3 =
+ pmulti_hist->histogram_config__high_amb_even_bin_2_3;
+ phist_cfg->histogram_config__low_amb_odd_bin_4_5 =
+ pmulti_hist->histogram_config__high_amb_even_bin_4_5;
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+uint8_t VL53L1_encode_GPIO_interrupt_config(
+ VL53L1_GPIO_interrupt_config_t *pintconf)
+{
+ uint8_t system__interrupt_config;
+
+ system__interrupt_config = pintconf->intr_mode_distance;
+ system__interrupt_config |= ((pintconf->intr_mode_rate) << 2);
+ system__interrupt_config |= ((pintconf->intr_new_measure_ready) << 5);
+ system__interrupt_config |= ((pintconf->intr_no_target) << 6);
+ system__interrupt_config |= ((pintconf->intr_combined_mode) << 7);
+
+ return system__interrupt_config;
+}
+
+
+
+
+
+
+VL53L1_GPIO_interrupt_config_t VL53L1_decode_GPIO_interrupt_config(
+ uint8_t system__interrupt_config)
+{
+ VL53L1_GPIO_interrupt_config_t intconf;
+
+ intconf.intr_mode_distance = system__interrupt_config & 0x03;
+ intconf.intr_mode_rate = (system__interrupt_config >> 2) & 0x03;
+ intconf.intr_new_measure_ready = (system__interrupt_config >> 5) & 0x01;
+ intconf.intr_no_target = (system__interrupt_config >> 6) & 0x01;
+ intconf.intr_combined_mode = (system__interrupt_config >> 7) & 0x01;
+
+
+
+ intconf.threshold_rate_low = 0;
+ intconf.threshold_rate_high = 0;
+ intconf.threshold_distance_low = 0;
+ intconf.threshold_distance_high = 0;
+
+ return intconf;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_distance_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->dyn_cfg.system__thresh_high = threshold_high;
+ pdev->dyn_cfg.system__thresh_low = threshold_low;
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_rate_threshold(
+ VL53L1_DEV Dev,
+ uint16_t threshold_high,
+ uint16_t threshold_low)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->gen_cfg.system__thresh_rate_high = threshold_high;
+ pdev->gen_cfg.system__thresh_rate_low = threshold_low;
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+
+
+
+
+VL53L1_Error VL53L1_set_GPIO_thresholds_from_struct(
+ VL53L1_DEV Dev,
+ VL53L1_GPIO_interrupt_config_t *pintconf)
+{
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_set_GPIO_distance_threshold(
+ Dev,
+ pintconf->threshold_distance_high,
+ pintconf->threshold_distance_low);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status =
+ VL53L1_set_GPIO_rate_threshold(
+ Dev,
+ pintconf->threshold_rate_high,
+ pintconf->threshold_rate_low);
+ }
+
+ LOG_FUNCTION_END(status);
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_ref_spad_char_config(
+ VL53L1_DEV Dev,
+ uint8_t vcsel_period_a,
+ uint32_t phasecal_timeout_us,
+ uint16_t total_rate_target_mcps,
+ uint16_t max_count_rate_rtn_limit_mcps,
+ uint16_t min_count_rate_rtn_limit_mcps,
+ uint16_t fast_osc_frequency)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t buffer[2];
+
+ uint32_t macro_period_us = 0;
+ uint32_t timeout_mclks = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ vcsel_period_a);
+
+
+
+
+
+
+ timeout_mclks = phasecal_timeout_us << 12;
+ timeout_mclks = timeout_mclks + (macro_period_us>>1);
+ timeout_mclks = timeout_mclks / macro_period_us;
+
+ if (timeout_mclks > 0xFF)
+ pdev->gen_cfg.phasecal_config__timeout_macrop = 0xFF;
+ else
+ pdev->gen_cfg.phasecal_config__timeout_macrop =
+ (uint8_t)timeout_mclks;
+
+ pdev->tim_cfg.range_config__vcsel_period_a = vcsel_period_a;
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_PHASECAL_CONFIG__TIMEOUT_MACROP,
+ pdev->gen_cfg.phasecal_config__timeout_macrop);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGE_CONFIG__VCSEL_PERIOD_A,
+ pdev->tim_cfg.range_config__vcsel_period_a);
+
+
+
+
+
+
+
+ buffer[0] = pdev->tim_cfg.range_config__vcsel_period_a;
+ buffer[1] = pdev->tim_cfg.range_config__vcsel_period_a;
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SD_CONFIG__WOI_SD0,
+ buffer,
+ 2);
+
+
+
+
+
+
+
+ pdev->customer.ref_spad_char__total_rate_target_mcps =
+ total_rate_target_mcps;
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrWord(
+ Dev,
+ VL53L1_REF_SPAD_CHAR__TOTAL_RATE_TARGET_MCPS,
+ total_rate_target_mcps);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrWord(
+ Dev,
+ VL53L1_RANGE_CONFIG__SIGMA_THRESH,
+ max_count_rate_rtn_limit_mcps);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrWord(
+ Dev,
+ VL53L1_RANGE_CONFIG__MIN_COUNT_RATE_RTN_LIMIT_MCPS,
+ min_count_rate_rtn_limit_mcps);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_ssc_config(
+ VL53L1_DEV Dev,
+ VL53L1_ssc_config_t *pssc_cfg,
+ uint16_t fast_osc_frequency)
+{
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t buffer[5];
+
+ uint32_t macro_period_us = 0;
+ uint16_t timeout_encoded = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ macro_period_us =
+ VL53L1_calc_macro_period_us(
+ fast_osc_frequency,
+ pssc_cfg->VL53L1_p_009);
+
+
+
+
+
+ timeout_encoded =
+ VL53L1_calc_encoded_timeout(
+ pssc_cfg->timeout_us,
+ macro_period_us);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_CAL_CONFIG__VCSEL_START,
+ pssc_cfg->vcsel_start);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__VCSEL_WIDTH,
+ pssc_cfg->vcsel_width);
+
+
+
+
+ buffer[0] = (uint8_t)((timeout_encoded & 0x0000FF00) >> 8);
+ buffer[1] = (uint8_t) (timeout_encoded & 0x000000FF);
+ buffer[2] = pssc_cfg->VL53L1_p_009;
+ buffer[3] = (uint8_t)((pssc_cfg->rate_limit_mcps & 0x0000FF00) >> 8);
+ buffer[4] = (uint8_t) (pssc_cfg->rate_limit_mcps & 0x000000FF);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RANGE_CONFIG__TIMEOUT_MACROP_B_HI,
+ buffer,
+ 5);
+
+
+
+
+
+
+
+ buffer[0] = pssc_cfg->VL53L1_p_009;
+ buffer[1] = pssc_cfg->VL53L1_p_009;
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SD_CONFIG__WOI_SD0,
+ buffer,
+ 2);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WrByte(
+ Dev,
+ VL53L1_NVM_BIST__CTRL,
+ pssc_cfg->array_select);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_spad_rate_data(
+ VL53L1_DEV Dev,
+ VL53L1_spad_rate_data_t *pspad_rates)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ int i = 0;
+
+ uint8_t VL53L1_p_002[512];
+ uint8_t *pdata = &VL53L1_p_002[0];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PRIVATE__PATCH_BASE_ADDR_RSLV,
+ pdata,
+ 512);
+
+
+
+ pdata = &VL53L1_p_002[0];
+ for (i = 0; i < VL53L1_NO_OF_SPAD_ENABLES; i++) {
+ pspad_rates->rate_data[i] =
+ (uint16_t)VL53L1_decode_unsigned_integer(pdata, 2);
+ pdata += 2;
+ }
+
+
+
+
+ pspad_rates->VL53L1_p_023 = VL53L1_NO_OF_SPAD_ENABLES;
+ pspad_rates->no_of_values = VL53L1_NO_OF_SPAD_ENABLES;
+ pspad_rates->fractional_bits = 15;
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_calc_required_samples(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres = VL53L1DevStructGetLLResultsHandle(Dev);
+ VL53L1_smudge_corrector_config_t *pconfig =
+ &(pdev->smudge_correct_config);
+ VL53L1_smudge_corrector_internals_t *pint =
+ &(pdev->smudge_corrector_internals);
+
+ VL53L1_range_results_t *presults = &(pres->range_results);
+ VL53L1_range_data_t *pxmonitor = &(presults->xmonitor);
+
+ uint32_t peak_duration_us = pxmonitor->peak_duration_us;
+
+ uint64_t temp64a;
+ uint64_t temp64z;
+
+ LOG_FUNCTION_START("");
+
+ if (peak_duration_us == 0)
+ peak_duration_us = 1000;
+
+ temp64a = pxmonitor->VL53L1_p_021 +
+ pxmonitor->VL53L1_p_020;
+ temp64a = do_division_u((temp64a * 1000), peak_duration_us);
+ temp64a = do_division_u((temp64a * 1000), peak_duration_us);
+
+ temp64z = (uint64_t)pconfig->noise_margin * (uint64_t)pxmonitor->VL53L1_p_006;
+ if (temp64z == 0)
+ temp64z = 1;
+ temp64a = temp64a * 1000 * 256;
+ temp64a = do_division_u(temp64a, temp64z);
+ temp64a = temp64a * 1000 * 256;
+ temp64a = do_division_u(temp64a, temp64z);
+
+ pint->required_samples = (uint32_t)temp64a;
+
+
+
+ if (pint->required_samples < 2)
+ pint->required_samples = 2;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_calc_new_xtalk(
+ VL53L1_DEV Dev,
+ uint32_t xtalk_offset_out,
+ VL53L1_smudge_corrector_config_t *pconfig,
+ VL53L1_smudge_corrector_data_t *pout,
+ uint8_t add_smudge,
+ uint8_t soft_update
+ )
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ int16_t x_gradient_scaler;
+ int16_t y_gradient_scaler;
+ uint32_t orig_xtalk_offset;
+ int16_t orig_x_gradient;
+ int16_t orig_y_gradient;
+ uint8_t histo_merge_nb;
+ uint8_t i;
+ int32_t itemp32;
+ uint32_t SmudgeFactor;
+ VL53L1_xtalk_config_t *pX = &(pdev->xtalk_cfg);
+ VL53L1_xtalk_calibration_results_t *pC = &(pdev->xtalk_cal);
+
+ LOG_FUNCTION_START("");
+
+
+
+ if (add_smudge == 1) {
+ pout->algo__crosstalk_compensation_plane_offset_kcps =
+ (uint32_t)xtalk_offset_out +
+ (uint32_t)pconfig->smudge_margin;
+ } else {
+ pout->algo__crosstalk_compensation_plane_offset_kcps =
+ (uint32_t)xtalk_offset_out;
+ }
+
+
+
+ orig_xtalk_offset =
+ pX->nvm_default__crosstalk_compensation_plane_offset_kcps;
+
+ orig_x_gradient =
+ pX->nvm_default__crosstalk_compensation_x_plane_gradient_kcps;
+
+ orig_y_gradient =
+ pX->nvm_default__crosstalk_compensation_y_plane_gradient_kcps;
+
+ if (((pconfig->user_scaler_set == 0) ||
+ (pconfig->scaler_calc_method == 1)) &&
+ (pC->algo__crosstalk_compensation_plane_offset_kcps != 0)) {
+
+
+ VL53L1_compute_histo_merge_nb(Dev, &histo_merge_nb);
+ if (histo_merge_nb == 0)
+ orig_xtalk_offset =
+ pC->algo__crosstalk_compensation_plane_offset_kcps;
+ else
+ orig_xtalk_offset =
+ pC->algo__xtalk_cpo_HistoMerge_kcps[histo_merge_nb-1];
+
+
+ orig_x_gradient =
+ pC->algo__crosstalk_compensation_x_plane_gradient_kcps;
+
+ orig_y_gradient =
+ pC->algo__crosstalk_compensation_y_plane_gradient_kcps;
+ }
+
+
+
+ if ((pconfig->user_scaler_set == 0) && (orig_x_gradient == 0))
+ pout->gradient_zero_flag |= 0x01;
+
+ if ((pconfig->user_scaler_set == 0) && (orig_y_gradient == 0))
+ pout->gradient_zero_flag |= 0x02;
+
+
+
+
+
+
+ if (orig_xtalk_offset == 0)
+ orig_xtalk_offset = 1;
+
+
+
+
+ if (pconfig->user_scaler_set == 1) {
+ x_gradient_scaler = pconfig->x_gradient_scaler;
+ y_gradient_scaler = pconfig->y_gradient_scaler;
+ } else {
+
+
+
+
+ x_gradient_scaler = (int16_t)do_division_s(
+ (((int32_t)orig_x_gradient) << 6),
+ orig_xtalk_offset);
+ pconfig->x_gradient_scaler = x_gradient_scaler;
+ y_gradient_scaler = (int16_t)do_division_s(
+ (((int32_t)orig_y_gradient) << 6),
+ orig_xtalk_offset);
+ pconfig->y_gradient_scaler = y_gradient_scaler;
+ }
+
+
+
+
+ if (pconfig->scaler_calc_method == 0) {
+
+
+
+
+
+
+ itemp32 = (int32_t)(
+ pout->algo__crosstalk_compensation_plane_offset_kcps *
+ x_gradient_scaler);
+ itemp32 = itemp32 >> 6;
+ if (itemp32 > 0xFFFF)
+ itemp32 = 0xFFFF;
+
+ pout->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (int16_t)itemp32;
+
+ itemp32 = (int32_t)(
+ pout->algo__crosstalk_compensation_plane_offset_kcps *
+ y_gradient_scaler);
+ itemp32 = itemp32 >> 6;
+ if (itemp32 > 0xFFFF)
+ itemp32 = 0xFFFF;
+
+ pout->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (int16_t)itemp32;
+ } else if (pconfig->scaler_calc_method == 1) {
+
+
+
+
+
+ itemp32 = (int32_t)(orig_xtalk_offset -
+ pout->algo__crosstalk_compensation_plane_offset_kcps);
+ itemp32 = (int32_t)(do_division_s(itemp32, 16));
+ itemp32 = itemp32 << 2;
+ itemp32 = itemp32 + (int32_t)(orig_x_gradient);
+ if (itemp32 > 0xFFFF)
+ itemp32 = 0xFFFF;
+
+ pout->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (int16_t)itemp32;
+
+ itemp32 = (int32_t)(orig_xtalk_offset -
+ pout->algo__crosstalk_compensation_plane_offset_kcps);
+ itemp32 = (int32_t)(do_division_s(itemp32, 80));
+ itemp32 = itemp32 << 2;
+ itemp32 = itemp32 + (int32_t)(orig_y_gradient);
+ if (itemp32 > 0xFFFF)
+ itemp32 = 0xFFFF;
+
+ pout->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (int16_t)itemp32;
+ }
+
+
+
+ if (pconfig->smudge_corr_apply_enabled == 1 &&
+ (soft_update != 1)
+ ) {
+
+
+ pout->new_xtalk_applied_flag = 1;
+
+
+
+ pX->algo__crosstalk_compensation_plane_offset_kcps =
+ pout->algo__crosstalk_compensation_plane_offset_kcps;
+ pX->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ pout->algo__crosstalk_compensation_x_plane_gradient_kcps;
+ pX->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ pout->algo__crosstalk_compensation_y_plane_gradient_kcps;
+
+
+ VL53L1_compute_histo_merge_nb(Dev, &histo_merge_nb);
+ if ((histo_merge_nb > 0) &&
+ (pout->algo__crosstalk_compensation_plane_offset_kcps != 0)) {
+
+
+ SmudgeFactor = pC->algo__xtalk_cpo_HistoMerge_kcps[histo_merge_nb-1] * 1000 /
+ pout->algo__crosstalk_compensation_plane_offset_kcps ;
+ if (SmudgeFactor > 0)
+ for (i = 0; i < VL53L1_BIN_REC_SIZE; i++) {
+ pC->algo__xtalk_cpo_HistoMerge_kcps[i] *= 1000;
+ pC->algo__xtalk_cpo_HistoMerge_kcps[i] /= SmudgeFactor;
+ }
+ }
+
+
+
+ if (pconfig->smudge_corr_single_apply == 1) {
+
+
+ pconfig->smudge_corr_apply_enabled = 0;
+ pconfig->smudge_corr_single_apply = 0;
+ }
+ }
+
+
+
+ if (soft_update != 1)
+ pout->smudge_corr_valid = 1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+#define CONT_CONTINUE 0
+#define CONT_NEXT_LOOP 1
+#define CONT_RESET 2
+VL53L1_Error VL53L1_dynamic_xtalk_correction_corrector(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres = VL53L1DevStructGetLLResultsHandle(Dev);
+ VL53L1_smudge_corrector_config_t *pconfig =
+ &(pdev->smudge_correct_config);
+ VL53L1_smudge_corrector_internals_t *pint =
+ &(pdev->smudge_corrector_internals);
+ VL53L1_smudge_corrector_data_t *pout =
+ &(pres->range_results.smudge_corrector_data);
+ VL53L1_range_results_t *pR = &(pres->range_results);
+ VL53L1_xtalk_config_t *pX = &(pdev->xtalk_cfg);
+
+ uint8_t run_smudge_detection = 0;
+ uint8_t run_nodetect = 0;
+ uint8_t ambient_check = 0;
+ int32_t itemp32 = 0;
+ uint64_t utemp64 = 0;
+ uint8_t continue_processing = CONT_CONTINUE;
+ uint32_t xtalk_offset_out = 0;
+ uint32_t xtalk_offset_in = 0;
+ uint32_t current_xtalk = 0;
+ uint32_t smudge_margin_adjusted = 0;
+ uint8_t i = 0;
+ uint8_t nodetect_index = 0;
+ uint16_t amr;
+
+ uint32_t cco;
+
+ uint8_t histo_merge_nb;
+
+
+ LOG_FUNCTION_START("");
+
+ VL53L1_compute_histo_merge_nb(Dev, &histo_merge_nb);
+ if (histo_merge_nb == 0)
+ histo_merge_nb = 1;
+
+
+ VL53L1_dynamic_xtalk_correction_output_init(pres);
+
+
+
+ ambient_check = (pconfig->smudge_corr_ambient_threshold == 0) ||
+ ((pconfig->smudge_corr_ambient_threshold * histo_merge_nb) >
+ ((uint32_t)pR->xmonitor.ambient_count_rate_mcps));
+
+
+
+
+ run_smudge_detection = (pconfig->smudge_corr_enabled == 1) &&
+ ambient_check &&
+ (pR->xmonitor.range_status
+ == VL53L1_DEVICEERROR_RANGECOMPLETE) &&
+ (histo_merge_nb == VL53L1_BIN_REC_SIZE);
+
+
+
+
+ if ((pR->xmonitor.range_status
+ != VL53L1_DEVICEERROR_RANGECOMPLETE) &&
+ (pconfig->smudge_corr_enabled == 1)) {
+
+
+ run_nodetect = 2;
+ for (i = 0; i < pR->active_results; i++) {
+ if (pR->VL53L1_p_002[i].range_status ==
+ VL53L1_DEVICEERROR_RANGECOMPLETE) {
+ if (pR->VL53L1_p_002[i].median_range_mm
+ <=
+ pconfig->nodetect_min_range_mm) {
+ run_nodetect = 0;
+ } else {
+ if (run_nodetect == 2) {
+ run_nodetect = 1;
+ nodetect_index = i;
+ }
+ }
+ }
+ }
+
+ if (run_nodetect == 2)
+
+
+ run_nodetect = 0;
+
+ amr =
+ pR->VL53L1_p_002[nodetect_index].ambient_count_rate_mcps;
+
+ if (run_nodetect == 1) {
+
+
+
+
+
+
+
+ utemp64 = 1000 * ((uint64_t)amr);
+
+
+
+ utemp64 = utemp64 << 9;
+
+
+
+ if (utemp64 < pconfig->nodetect_ambient_threshold)
+ run_nodetect = 1;
+ else
+ run_nodetect = 0;
+
+ }
+ }
+
+
+ if (run_smudge_detection == 1) {
+
+
+ pint->nodetect_counter = 0;
+
+
+
+ VL53L1_dynamic_xtalk_correction_calc_required_samples(Dev);
+
+
+
+ xtalk_offset_in =
+ pR->xmonitor.VL53L1_p_012;
+
+
+
+ cco = pX->algo__crosstalk_compensation_plane_offset_kcps;
+ current_xtalk = ((uint32_t)cco) << 2;
+
+
+
+ smudge_margin_adjusted =
+ ((uint32_t)(pconfig->smudge_margin)) << 2;
+
+
+
+ itemp32 = xtalk_offset_in - current_xtalk +
+ smudge_margin_adjusted;
+
+ if (itemp32 < 0)
+ itemp32 = itemp32 * (-1);
+
+
+ if (itemp32 > ((int32_t)pconfig->single_xtalk_delta)) {
+ if ((int32_t)xtalk_offset_in >
+ ((int32_t)current_xtalk -
+ (int32_t)smudge_margin_adjusted)) {
+ pout->single_xtalk_delta_flag = 1;
+ } else {
+ pout->single_xtalk_delta_flag = 2;
+ }
+ }
+
+
+
+ pint->current_samples = pint->current_samples + 1;
+
+
+
+ if (pint->current_samples > pconfig->sample_limit) {
+ pout->sample_limit_exceeded_flag = 1;
+ continue_processing = CONT_RESET;
+ } else {
+
+ pint->accumulator = pint->accumulator +
+ xtalk_offset_in;
+ }
+
+ if (pint->current_samples < pint->required_samples)
+ continue_processing = CONT_NEXT_LOOP;
+
+
+
+ xtalk_offset_out =
+ (uint32_t)(do_division_u(pint->accumulator,
+ pint->current_samples));
+
+
+
+ itemp32 = xtalk_offset_out - current_xtalk +
+ smudge_margin_adjusted;
+
+ if (itemp32 < 0)
+ itemp32 = itemp32 * (-1);
+
+ if (continue_processing == CONT_CONTINUE &&
+ (itemp32 >= ((int32_t)(pconfig->averaged_xtalk_delta)))
+ ) {
+ if ((int32_t)xtalk_offset_out >
+ ((int32_t)current_xtalk -
+ (int32_t)smudge_margin_adjusted))
+ pout->averaged_xtalk_delta_flag = 1;
+ else
+ pout->averaged_xtalk_delta_flag = 2;
+ }
+
+ if (continue_processing == CONT_CONTINUE &&
+ (itemp32 < ((int32_t)(pconfig->averaged_xtalk_delta)))
+ )
+
+
+ continue_processing = CONT_RESET;
+
+
+
+
+ pout->smudge_corr_clipped = 0;
+ if ((continue_processing == CONT_CONTINUE) &&
+ (pconfig->smudge_corr_clip_limit != 0)) {
+ if (xtalk_offset_out >
+ (pconfig->smudge_corr_clip_limit * histo_merge_nb)) {
+ pout->smudge_corr_clipped = 1;
+ continue_processing = CONT_RESET;
+ }
+ }
+
+
+
+
+
+ if (pconfig->user_xtalk_offset_limit_hi &&
+ (xtalk_offset_out >
+ pconfig->user_xtalk_offset_limit))
+ xtalk_offset_out =
+ pconfig->user_xtalk_offset_limit;
+
+
+
+
+ if ((pconfig->user_xtalk_offset_limit_hi == 0) &&
+ (xtalk_offset_out <
+ pconfig->user_xtalk_offset_limit))
+ xtalk_offset_out =
+ pconfig->user_xtalk_offset_limit;
+
+
+
+
+ xtalk_offset_out = xtalk_offset_out >> 2;
+ if (xtalk_offset_out > 0x3FFFF)
+ xtalk_offset_out = 0x3FFFF;
+
+
+
+ if (continue_processing == CONT_CONTINUE) {
+
+
+ VL53L1_dynamic_xtalk_correction_calc_new_xtalk(
+ Dev,
+ xtalk_offset_out,
+ pconfig,
+ pout,
+ 1,
+
+ 0
+
+ );
+
+
+
+ continue_processing = CONT_RESET;
+ } else {
+
+
+ VL53L1_dynamic_xtalk_correction_calc_new_xtalk(
+ Dev,
+ xtalk_offset_out,
+ pconfig,
+ pout,
+ 1,
+
+ 1
+
+ );
+ }
+
+
+
+ if (continue_processing == CONT_RESET) {
+ pint->accumulator = 0;
+ pint->current_samples = 0;
+ pint->nodetect_counter = 0;
+ }
+
+ }
+
+ continue_processing = CONT_CONTINUE;
+ if (run_nodetect == 1) {
+
+
+ pint->nodetect_counter += 1;
+
+
+
+ if (pint->nodetect_counter < pconfig->nodetect_sample_limit)
+ continue_processing = CONT_NEXT_LOOP;
+
+
+
+ xtalk_offset_out = (uint32_t)(pconfig->nodetect_xtalk_offset);
+
+ if (continue_processing == CONT_CONTINUE) {
+
+
+ VL53L1_dynamic_xtalk_correction_calc_new_xtalk(
+ Dev,
+ xtalk_offset_out,
+ pconfig,
+ pout,
+ 0,
+
+ 0
+
+ );
+
+
+
+ pout->smudge_corr_valid = 2;
+
+
+
+ continue_processing = CONT_RESET;
+ } else {
+
+
+ VL53L1_dynamic_xtalk_correction_calc_new_xtalk(
+ Dev,
+ xtalk_offset_out,
+ pconfig,
+ pout,
+ 0,
+
+ 1
+
+ );
+ }
+
+
+
+ if (continue_processing == CONT_RESET) {
+ pint->accumulator = 0;
+ pint->current_samples = 0;
+ pint->nodetect_counter = 0;
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_data_init(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_LLDriverResults_t *pres = VL53L1DevStructGetLLResultsHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pdev->smudge_correct_config.smudge_corr_enabled = 1;
+ pdev->smudge_correct_config.smudge_corr_apply_enabled = 1;
+ pdev->smudge_correct_config.smudge_corr_single_apply =
+ VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_COR_SINGLE_APPLY_DEFAULT;
+
+ pdev->smudge_correct_config.smudge_margin =
+ VL53L1_TUNINGPARM_DYNXTALK_SMUDGE_MARGIN_DEFAULT;
+ pdev->smudge_correct_config.noise_margin =
+ VL53L1_TUNINGPARM_DYNXTALK_NOISE_MARGIN_DEFAULT;
+ pdev->smudge_correct_config.user_xtalk_offset_limit =
+ VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_DEFAULT;
+ pdev->smudge_correct_config.user_xtalk_offset_limit_hi =
+ VL53L1_TUNINGPARM_DYNXTALK_XTALK_OFFSET_LIMIT_HI_DEFAULT;
+ pdev->smudge_correct_config.sample_limit =
+ VL53L1_TUNINGPARM_DYNXTALK_SAMPLE_LIMIT_DEFAULT;
+ pdev->smudge_correct_config.single_xtalk_delta =
+ VL53L1_TUNINGPARM_DYNXTALK_SINGLE_XTALK_DELTA_DEFAULT;
+ pdev->smudge_correct_config.averaged_xtalk_delta =
+ VL53L1_TUNINGPARM_DYNXTALK_AVERAGED_XTALK_DELTA_DEFAULT;
+ pdev->smudge_correct_config.smudge_corr_clip_limit =
+ VL53L1_TUNINGPARM_DYNXTALK_CLIP_LIMIT_DEFAULT;
+ pdev->smudge_correct_config.smudge_corr_ambient_threshold =
+ VL53L1_TUNINGPARM_DYNXTALK_XTALK_AMB_THRESHOLD_DEFAULT;
+ pdev->smudge_correct_config.scaler_calc_method =
+ 0;
+
+ pdev->smudge_correct_config.x_gradient_scaler =
+ VL53L1_TUNINGPARM_DYNXTALK_XGRADIENT_SCALER_DEFAULT;
+ pdev->smudge_correct_config.y_gradient_scaler =
+ VL53L1_TUNINGPARM_DYNXTALK_YGRADIENT_SCALER_DEFAULT;
+ pdev->smudge_correct_config.user_scaler_set =
+ VL53L1_TUNINGPARM_DYNXTALK_USER_SCALER_SET_DEFAULT;
+ pdev->smudge_correct_config.nodetect_ambient_threshold =
+ VL53L1_TUNINGPARM_DYNXTALK_NODETECT_AMB_THRESHOLD_KCPS_DEFAULT;
+ pdev->smudge_correct_config.nodetect_sample_limit =
+ VL53L1_TUNINGPARM_DYNXTALK_NODETECT_SAMPLE_LIMIT_DEFAULT;
+ pdev->smudge_correct_config.nodetect_xtalk_offset =
+ VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS_DEFAULT;
+ pdev->smudge_correct_config.nodetect_min_range_mm =
+ VL53L1_TUNINGPARM_DYNXTALK_NODETECT_MIN_RANGE_MM_DEFAULT;
+
+
+
+ pdev->smudge_corrector_internals.current_samples = 0;
+ pdev->smudge_corrector_internals.required_samples = 0;
+ pdev->smudge_corrector_internals.accumulator = 0;
+ pdev->smudge_corrector_internals.nodetect_counter = 0;
+
+
+
+ VL53L1_dynamic_xtalk_correction_output_init(pres);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_dynamic_xtalk_correction_output_init(
+ VL53L1_LLDriverResults_t *pres
+ )
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_smudge_corrector_data_t *pdata;
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdata = &(pres->range_results.smudge_corrector_data);
+
+ pdata->smudge_corr_valid = 0;
+ pdata->smudge_corr_clipped = 0;
+ pdata->single_xtalk_delta_flag = 0;
+ pdata->averaged_xtalk_delta_flag = 0;
+ pdata->sample_limit_exceeded_flag = 0;
+ pdata->gradient_zero_flag = 0;
+ pdata->new_xtalk_applied_flag = 0;
+
+ pdata->algo__crosstalk_compensation_plane_offset_kcps = 0;
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps = 0;
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps = 0;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_xtalk_cal_data_init(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ pdev->xtalk_cal.algo__crosstalk_compensation_plane_offset_kcps = 0;
+ pdev->xtalk_cal.algo__crosstalk_compensation_x_plane_gradient_kcps = 0;
+ pdev->xtalk_cal.algo__crosstalk_compensation_y_plane_gradient_kcps = 0;
+ memset(&pdev->xtalk_cal.algo__xtalk_cpo_HistoMerge_kcps[0], 0, sizeof(pdev->xtalk_cal.algo__xtalk_cpo_HistoMerge_kcps));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+
+
+
+VL53L1_Error VL53L1_low_power_auto_data_init(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ pdev->low_power_auto_data.vhv_loop_bound =
+ VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND_DEFAULT;
+ pdev->low_power_auto_data.is_low_power_auto_mode = 0;
+ pdev->low_power_auto_data.low_power_auto_range_count = 0;
+ pdev->low_power_auto_data.saved_interrupt_config = 0;
+ pdev->low_power_auto_data.saved_vhv_init = 0;
+ pdev->low_power_auto_data.saved_vhv_timeout = 0;
+ pdev->low_power_auto_data.first_run_phasecal_result = 0;
+ pdev->low_power_auto_data.dss__total_rate_per_spad_mcps = 0;
+ pdev->low_power_auto_data.dss__required_spads = 0;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_low_power_auto_data_stop_range(
+ VL53L1_DEV Dev
+ )
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ pdev->low_power_auto_data.low_power_auto_range_count = 0xFF;
+
+ pdev->low_power_auto_data.first_run_phasecal_result = 0;
+ pdev->low_power_auto_data.dss__total_rate_per_spad_mcps = 0;
+ pdev->low_power_auto_data.dss__required_spads = 0;
+
+
+
+ if (pdev->low_power_auto_data.saved_vhv_init != 0)
+ pdev->stat_nvm.vhv_config__init =
+ pdev->low_power_auto_data.saved_vhv_init;
+ if (pdev->low_power_auto_data.saved_vhv_timeout != 0)
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound =
+ pdev->low_power_auto_data.saved_vhv_timeout;
+
+
+
+ pdev->gen_cfg.phasecal_config__override = 0x00;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_config_low_power_auto_mode(
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_dynamic_config_t *pdynamic,
+ VL53L1_low_power_auto_data_t *plpadata
+ )
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ plpadata->is_low_power_auto_mode = 1;
+
+
+
+ plpadata->low_power_auto_range_count = 0;
+
+
+
+ pdynamic->system__sequence_config =
+ VL53L1_SEQUENCE_VHV_EN |
+ VL53L1_SEQUENCE_PHASECAL_EN |
+ VL53L1_SEQUENCE_DSS1_EN |
+
+
+
+
+
+
+ VL53L1_SEQUENCE_RANGE_EN;
+
+
+
+ pgeneral->dss_config__manual_effective_spads_select = 200 << 8;
+ pgeneral->dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_low_power_auto_setup_manual_calibration(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+ pdev->low_power_auto_data.saved_vhv_init =
+ pdev->stat_nvm.vhv_config__init;
+ pdev->low_power_auto_data.saved_vhv_timeout =
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound;
+
+
+
+ pdev->stat_nvm.vhv_config__init &= 0x7F;
+
+
+ pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound =
+ (pdev->stat_nvm.vhv_config__timeout_macrop_loop_bound & 0x03) +
+ (pdev->low_power_auto_data.vhv_loop_bound << 2);
+
+
+ pdev->gen_cfg.phasecal_config__override = 0x01;
+ pdev->low_power_auto_data.first_run_phasecal_result =
+ pdev->dbg_results.phasecal_result__vcsel_start;
+ pdev->gen_cfg.cal_config__vcsel_start =
+ pdev->low_power_auto_data.first_run_phasecal_result;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+VL53L1_Error VL53L1_low_power_auto_update_DSS(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ VL53L1_system_results_t *pS = &(pdev->sys_results);
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint32_t utemp32a;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ utemp32a =
+ pS->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0
+ + pS->result__ambient_count_rate_mcps_sd0;
+
+
+
+ if (utemp32a > 0xFFFF)
+ utemp32a = 0xFFFF;
+
+
+
+
+
+ utemp32a = utemp32a << 16;
+
+
+
+ if (pdev->sys_results.result__dss_actual_effective_spads_sd0 == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+ else {
+
+
+ utemp32a = utemp32a /
+ pdev->sys_results.result__dss_actual_effective_spads_sd0;
+
+
+ pdev->low_power_auto_data.dss__total_rate_per_spad_mcps =
+ utemp32a;
+
+
+
+
+ utemp32a = pdev->stat_cfg.dss_config__target_total_rate_mcps <<
+ 16;
+
+
+
+ if (pdev->low_power_auto_data.dss__total_rate_per_spad_mcps
+ == 0)
+ status = VL53L1_ERROR_DIVISION_BY_ZERO;
+ else {
+
+
+
+ utemp32a = utemp32a /
+ pdev->low_power_auto_data.dss__total_rate_per_spad_mcps;
+
+
+
+ if (utemp32a > 0xFFFF)
+ utemp32a = 0xFFFF;
+
+
+
+ pdev->low_power_auto_data.dss__required_spads =
+ (uint16_t)utemp32a;
+
+
+
+ pdev->gen_cfg.dss_config__manual_effective_spads_select
+ = pdev->low_power_auto_data.dss__required_spads;
+ pdev->gen_cfg.dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+ }
+
+ }
+
+ if (status == VL53L1_ERROR_DIVISION_BY_ZERO) {
+
+
+
+
+
+
+ pdev->low_power_auto_data.dss__required_spads = 0x8000;
+
+
+
+ pdev->gen_cfg.dss_config__manual_effective_spads_select =
+ pdev->low_power_auto_data.dss__required_spads;
+ pdev->gen_cfg.dss_config__roi_mode_control =
+ VL53L1_DEVICEDSSMODE__REQUESTED_EFFFECTIVE_SPADS;
+
+
+
+ status = VL53L1_ERROR_NONE;
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+
+VL53L1_Error VL53L1_compute_histo_merge_nb(
+ VL53L1_DEV Dev, uint8_t *histo_merge_nb)
+{
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t i, timing;
+ uint8_t sum = 0;
+
+ timing = (pdev->hist_data.bin_seq[0] == 7 ? 1 : 0);
+ for (i = 0; i < VL53L1_BIN_REC_SIZE; i++)
+ if (pdev->multi_bins_rec[i][timing][7] > 0)
+ sum++;
+ *histo_merge_nb = sum;
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_core_support.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_core_support.c
new file mode 100644
index 000000000000..660b88488055
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_core_support.c
@@ -0,0 +1,941 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_core_support.h"
+#include "vl53l1_platform_user_data.h"
+#include "vl53l1_platform_user_defines.h"
+
+
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \
+ status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+uint32_t VL53L1_calc_pll_period_us(
+ uint16_t fast_osc_frequency)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (fast_osc_frequency > 0)
+ pll_period_us = (0x01 << 30) / fast_osc_frequency;
+
+
+
+
+
+
+
+ LOG_FUNCTION_END(0);
+
+ return pll_period_us;
+}
+
+
+uint32_t VL53L1_duration_maths(
+ uint32_t pll_period_us,
+ uint32_t vcsel_parm_pclks,
+ uint32_t window_vclks,
+ uint32_t elapsed_mclks)
+{
+
+
+
+
+
+
+
+
+
+
+ uint64_t tmp_long_int = 0;
+ uint32_t duration_us = 0;
+
+
+
+
+
+
+ duration_us = window_vclks * pll_period_us;
+
+
+
+
+
+ duration_us = duration_us >> 12;
+
+
+
+ tmp_long_int = (uint64_t)duration_us;
+
+
+
+
+
+
+ duration_us = elapsed_mclks * vcsel_parm_pclks;
+
+
+
+
+
+ duration_us = duration_us >> 4;
+
+
+
+
+
+ tmp_long_int = tmp_long_int * (uint64_t)duration_us;
+
+
+
+
+
+ tmp_long_int = tmp_long_int >> 12;
+
+
+
+ if (tmp_long_int > 0xFFFFFFFF)
+ tmp_long_int = 0xFFFFFFFF;
+
+ duration_us = (uint32_t)tmp_long_int;
+
+ return duration_us;
+}
+
+
+uint32_t VL53L1_events_per_spad_maths(
+ int32_t VL53L1_p_013,
+ uint16_t num_spads,
+ uint32_t duration)
+{
+ uint64_t total_hist_counts = 0;
+ uint64_t xtalk_per_spad = 0;
+ uint32_t rate_per_spad_kcps = 0;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ uint64_t dividend = ((uint64_t)VL53L1_p_013
+ * 1000 * 256);
+
+ if (num_spads != 0)
+ total_hist_counts = do_division_u(
+ dividend, (uint64_t)num_spads);
+
+
+
+
+ if (duration > 0) {
+
+
+
+
+
+
+
+
+ uint64_t dividend = (((uint64_t)(total_hist_counts << 11))
+ + ((uint64_t)duration / 2));
+
+ xtalk_per_spad = do_division_u(dividend, (uint64_t)duration);
+ } else {
+ xtalk_per_spad = (uint64_t)(total_hist_counts << 11);
+ }
+
+ rate_per_spad_kcps = (uint32_t)xtalk_per_spad;
+
+ return rate_per_spad_kcps;
+}
+
+
+uint32_t VL53L1_isqrt(uint32_t num)
+{
+
+
+
+
+
+
+
+
+ uint32_t res = 0;
+ uint32_t bit = 1 << 30;
+
+
+
+
+ while (bit > num)
+ bit >>= 2;
+
+ while (bit != 0) {
+ if (num >= res + bit) {
+ num -= res + bit;
+ res = (res >> 1) + bit;
+ } else {
+ res >>= 1;
+ }
+ bit >>= 2;
+ }
+
+ return res;
+}
+
+
+void VL53L1_hist_calc_zero_distance_phase(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ uint32_t period = 0;
+ uint32_t VL53L1_p_017 = 0;
+
+ LOG_FUNCTION_START("");
+
+ period = 2048 *
+ (uint32_t)VL53L1_decode_vcsel_period(pdata->VL53L1_p_009);
+
+ VL53L1_p_017 = period;
+ VL53L1_p_017 += (uint32_t)pdata->phasecal_result__reference_phase;
+ VL53L1_p_017 += (2048 * (uint32_t)pdata->phasecal_result__vcsel_start);
+ VL53L1_p_017 -= (2048 * (uint32_t)pdata->cal_config__vcsel_start);
+
+ VL53L1_p_017 = VL53L1_p_017 % period;
+
+ pdata->zero_distance_phase = (uint16_t)VL53L1_p_017;
+
+ LOG_FUNCTION_END(0);
+}
+
+
+void VL53L1_hist_estimate_ambient_from_thresholded_bins(
+ int32_t ambient_threshold_sigma,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+
+
+
+ uint8_t bin = 0;
+ int32_t VL53L1_p_032 = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ VL53L1_hist_find_min_max_bin_values(pdata);
+
+
+
+
+
+
+
+ VL53L1_p_032 =
+ (int32_t)VL53L1_isqrt((uint32_t)pdata->min_bin_value);
+ VL53L1_p_032 *= ambient_threshold_sigma;
+ VL53L1_p_032 += 0x07;
+ VL53L1_p_032 = VL53L1_p_032 >> 4;
+ VL53L1_p_032 += pdata->min_bin_value;
+
+
+
+
+
+
+ pdata->number_of_ambient_samples = 0;
+ pdata->ambient_events_sum = 0;
+
+ for (bin = 0; bin < pdata->VL53L1_p_024; bin++)
+ if (pdata->bin_data[bin] < VL53L1_p_032) {
+ pdata->ambient_events_sum += pdata->bin_data[bin];
+ pdata->number_of_ambient_samples++;
+ }
+
+
+
+
+
+
+ if (pdata->number_of_ambient_samples > 0) {
+ pdata->VL53L1_p_004 =
+ pdata->ambient_events_sum;
+ pdata->VL53L1_p_004 +=
+ ((int32_t)pdata->number_of_ambient_samples/2);
+ pdata->VL53L1_p_004 /=
+ (int32_t)pdata->number_of_ambient_samples;
+ }
+
+ LOG_FUNCTION_END(0);
+}
+
+
+void VL53L1_hist_remove_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+
+ uint8_t bin = 0;
+ uint8_t lc = 0;
+ uint8_t i = 0;
+
+
+
+
+ if ((pdata->bin_seq[0] & 0x07) == 0x07) {
+
+ i = 0;
+ for (lc = 0; lc < VL53L1_MAX_BIN_SEQUENCE_LENGTH; lc++) {
+ if ((pdata->bin_seq[lc] & 0x07) != 0x07) {
+ pdata->bin_seq[i] = pdata->bin_seq[lc];
+ pdata->bin_rep[i] = pdata->bin_rep[lc];
+ i++;
+ }
+ }
+
+
+
+
+
+
+ for (lc = i; lc < VL53L1_MAX_BIN_SEQUENCE_LENGTH; lc++) {
+ pdata->bin_seq[lc] = VL53L1_MAX_BIN_SEQUENCE_CODE + 1;
+ pdata->bin_rep[lc] = 0;
+ }
+ }
+
+ if (pdata->number_of_ambient_bins > 0) {
+
+
+
+ for (bin = pdata->number_of_ambient_bins;
+ bin < pdata->VL53L1_p_023; bin++) {
+ pdata->bin_data[bin-pdata->number_of_ambient_bins] =
+ pdata->bin_data[bin];
+ }
+
+
+
+ pdata->VL53L1_p_024 =
+ pdata->VL53L1_p_024 -
+ pdata->number_of_ambient_bins;
+ pdata->number_of_ambient_bins = 0;
+ }
+}
+
+
+uint32_t VL53L1_calc_pll_period_mm(
+ uint16_t fast_osc_frequency)
+{
+
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+ uint32_t pll_period_mm = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+
+
+ pll_period_mm =
+ VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8 *
+ (pll_period_us >> 2);
+
+
+
+ pll_period_mm = (pll_period_mm + (0x01<<15)) >> 16;
+
+ LOG_FUNCTION_END(0);
+
+ return pll_period_mm;
+}
+
+
+uint16_t VL53L1_rate_maths(
+ int32_t VL53L1_p_008,
+ uint32_t time_us)
+{
+
+
+
+
+
+
+
+
+
+
+
+
+ uint32_t tmp_int = 0;
+ uint32_t frac_bits = 7;
+ uint16_t rate_mcps = 0;
+
+
+
+
+
+
+
+ if (VL53L1_p_008 > VL53L1_SPAD_TOTAL_COUNT_MAX)
+ tmp_int = VL53L1_SPAD_TOTAL_COUNT_MAX;
+ else if (VL53L1_p_008 > 0)
+ tmp_int = (uint32_t)VL53L1_p_008;
+
+
+
+
+
+
+
+
+ if (VL53L1_p_008 > VL53L1_SPAD_TOTAL_COUNT_RES_THRES)
+ frac_bits = 3;
+ else
+ frac_bits = 7;
+
+
+
+
+
+
+
+ if (time_us > 0)
+ tmp_int = ((tmp_int << frac_bits) + (time_us / 2)) / time_us;
+
+
+
+
+
+ if (VL53L1_p_008 > VL53L1_SPAD_TOTAL_COUNT_RES_THRES)
+ tmp_int = tmp_int << 4;
+
+
+
+
+
+
+
+ if (tmp_int > 0xFFFF)
+ tmp_int = 0xFFFF;
+
+ rate_mcps = (uint16_t)tmp_int;
+
+ return rate_mcps;
+}
+
+
+uint16_t VL53L1_rate_per_spad_maths(
+ uint32_t frac_bits,
+ uint32_t peak_count_rate,
+ uint16_t num_spads,
+ uint32_t max_output_value)
+{
+
+ uint32_t tmp_int = 0;
+
+
+
+ uint16_t rate_per_spad = 0;
+
+
+
+
+
+
+
+
+
+ if (num_spads > 0) {
+ tmp_int = (peak_count_rate << 8) << frac_bits;
+ tmp_int = (tmp_int +
+ ((uint32_t)num_spads / 2)) /
+ (uint32_t)num_spads;
+ } else {
+ tmp_int = ((peak_count_rate) << frac_bits);
+ }
+
+
+
+
+ if (tmp_int > max_output_value)
+ tmp_int = max_output_value;
+
+ rate_per_spad = (uint16_t)tmp_int;
+
+ return rate_per_spad;
+}
+
+
+int32_t VL53L1_range_maths(
+ uint16_t fast_osc_frequency,
+ uint16_t VL53L1_p_017,
+ uint16_t zero_distance_phase,
+ uint8_t fractional_bits,
+ int32_t gain_factor,
+ int32_t range_offset_mm)
+{
+
+
+
+
+
+ uint32_t pll_period_us = 0;
+
+ int64_t tmp_long_int = 0;
+ int32_t range_mm = 0;
+ int32_t range_mm_10 = 0;
+
+
+
+
+ pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency);
+
+
+
+
+
+
+
+
+
+
+ tmp_long_int = (int64_t)VL53L1_p_017 - (int64_t)zero_distance_phase;
+
+
+
+
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int * (int64_t)pll_period_us;
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int / (0x01 << 9);
+
+
+
+
+
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int * VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8;
+
+
+
+
+
+
+ tmp_long_int = tmp_long_int / (0x01 << 22);
+
+
+
+ range_mm = (int32_t)tmp_long_int + range_offset_mm;
+
+
+
+ range_mm *= gain_factor;
+ range_mm += 0x0400;
+ range_mm /= 0x0800;
+
+
+
+ if (fractional_bits == 0) {
+ range_mm_10 = range_mm * 10;
+ range_mm_10 = range_mm_10 / (0x01 << 2);
+ if ((range_mm_10 % 10) < 5)
+ range_mm = (int16_t)(range_mm_10 / 10);
+ else
+ range_mm = (int16_t)(range_mm_10 / 10 + 1);
+ } else if (fractional_bits == 1)
+ range_mm = range_mm / (0x01 << 1);
+
+ return range_mm;
+}
+
+
+uint8_t VL53L1_decode_vcsel_period(uint8_t vcsel_period_reg)
+{
+
+
+
+
+
+
+ uint8_t VL53L1_p_031 = 0;
+
+ VL53L1_p_031 = (vcsel_period_reg + 1) << 1;
+
+ return VL53L1_p_031;
+}
+
+
+void VL53L1_copy_xtalk_bin_data_to_histogram_data_struct(
+ VL53L1_xtalk_histogram_shape_t *pxtalk,
+ VL53L1_histogram_bin_data_t *phist)
+{
+
+
+
+
+
+
+ phist->cal_config__vcsel_start =
+ pxtalk->cal_config__vcsel_start;
+ phist->VL53L1_p_019 =
+ pxtalk->VL53L1_p_019;
+ phist->VL53L1_p_022 =
+ pxtalk->VL53L1_p_022;
+
+ phist->phasecal_result__reference_phase =
+ pxtalk->phasecal_result__reference_phase;
+ phist->phasecal_result__vcsel_start =
+ pxtalk->phasecal_result__vcsel_start;
+
+ phist->vcsel_width =
+ pxtalk->vcsel_width;
+ phist->zero_distance_phase =
+ pxtalk->zero_distance_phase;
+
+ phist->zone_id = pxtalk->zone_id;
+ phist->VL53L1_p_023 = pxtalk->VL53L1_p_023;
+ phist->time_stamp = pxtalk->time_stamp;
+}
+
+
+void VL53L1_init_histogram_bin_data_struct(
+ int32_t bin_value,
+ uint16_t VL53L1_p_024,
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ uint16_t i = 0;
+
+ pdata->cfg_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+ pdata->rd_device_state = VL53L1_DEVICESTATE_SW_STANDBY;
+
+ pdata->zone_id = 0;
+ pdata->time_stamp = 0;
+
+ pdata->VL53L1_p_022 = 0;
+ pdata->VL53L1_p_023 = VL53L1_HISTOGRAM_BUFFER_SIZE;
+ pdata->VL53L1_p_024 = (uint8_t)VL53L1_p_024;
+ pdata->number_of_ambient_bins = 0;
+
+ pdata->result__interrupt_status = 0;
+ pdata->result__range_status = 0;
+ pdata->result__report_status = 0;
+ pdata->result__stream_count = 0;
+
+ pdata->result__dss_actual_effective_spads = 0;
+ pdata->phasecal_result__reference_phase = 0;
+ pdata->phasecal_result__vcsel_start = 0;
+ pdata->cal_config__vcsel_start = 0;
+
+ pdata->vcsel_width = 0;
+ pdata->VL53L1_p_009 = 0;
+ pdata->VL53L1_p_019 = 0;
+ pdata->total_periods_elapsed = 0;
+
+ pdata->min_bin_value = 0;
+ pdata->max_bin_value = 0;
+
+ pdata->zero_distance_phase = 0;
+ pdata->number_of_ambient_samples = 0;
+ pdata->ambient_events_sum = 0;
+ pdata->VL53L1_p_004 = 0;
+
+ for (i = 0; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH; i++)
+ pdata->bin_seq[i] = (uint8_t)i;
+
+ for (i = 0; i < VL53L1_MAX_BIN_SEQUENCE_LENGTH; i++)
+ pdata->bin_rep[i] = 1;
+
+
+ for (i = 0; i < VL53L1_HISTOGRAM_BUFFER_SIZE; i++)
+ if (i < VL53L1_p_024)
+ pdata->bin_data[i] = bin_value;
+ else
+ pdata->bin_data[i] = 0;
+
+
+}
+
+
+void VL53L1_decode_row_col(
+ uint8_t spad_number,
+ uint8_t *prow,
+ uint8_t *pcol)
+{
+
+
+
+
+
+
+
+ if (spad_number > 127) {
+ *prow = 8 + ((255-spad_number) & 0x07);
+ *pcol = (spad_number-128) >> 3;
+ } else {
+ *prow = spad_number & 0x07;
+ *pcol = (127-spad_number) >> 3;
+ }
+}
+
+
+void VL53L1_hist_find_min_max_bin_values(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+ uint8_t bin = 0;
+
+ LOG_FUNCTION_START("");
+
+ for (bin = 0; bin < pdata->VL53L1_p_024; bin++) {
+
+ if (bin == 0 || pdata->min_bin_value >= pdata->bin_data[bin])
+ pdata->min_bin_value = pdata->bin_data[bin];
+
+ if (bin == 0 || pdata->max_bin_value <= pdata->bin_data[bin])
+ pdata->max_bin_value = pdata->bin_data[bin];
+
+ }
+
+ LOG_FUNCTION_END(0);
+
+}
+
+
+void VL53L1_hist_estimate_ambient_from_ambient_bins(
+ VL53L1_histogram_bin_data_t *pdata)
+{
+
+
+
+
+
+
+ uint8_t bin = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdata->number_of_ambient_bins > 0) {
+
+ pdata->number_of_ambient_samples =
+ pdata->number_of_ambient_bins;
+
+
+
+
+ pdata->ambient_events_sum = 0;
+ for (bin = 0; bin < pdata->number_of_ambient_bins; bin++)
+ pdata->ambient_events_sum += pdata->bin_data[bin];
+
+ pdata->VL53L1_p_004 = pdata->ambient_events_sum;
+ pdata->VL53L1_p_004 +=
+ ((int32_t)pdata->number_of_ambient_bins / 2);
+ pdata->VL53L1_p_004 /=
+ (int32_t)pdata->number_of_ambient_bins;
+
+ }
+
+ LOG_FUNCTION_END(0);
+}
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_error_strings.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_error_strings.c
new file mode 100644
index 000000000000..f559233e2ae9
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_error_strings.c
@@ -0,0 +1,334 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_error_codes.h"
+#include "vl53l1_error_strings.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_ll_def.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, \
+ status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_get_pal_error_string(
+#ifndef VL53L1_USE_EMPTY_STRING
+ VL53L1_Error PalErrorCode,
+#endif
+ char *pPalErrorString)
+{
+ VL53L1_Error Status = VL53L1_ERROR_NONE;
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ SUPPRESS_UNUSED_WARNING(PalErrorCode);
+#endif
+
+ LOG_FUNCTION_START("");
+
+#ifdef VL53L1_USE_EMPTY_STRING
+ VL53L1_COPYSTRING(pPalErrorString, "");
+#else
+
+ switch (PalErrorCode) {
+ case VL53L1_ERROR_NONE:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_NONE);
+ break;
+ case VL53L1_ERROR_CALIBRATION_WARNING:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_CALIBRATION_WARNING);
+ break;
+ case VL53L1_ERROR_MIN_CLIPPED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_MIN_CLIPPED);
+ break;
+ case VL53L1_ERROR_UNDEFINED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_UNDEFINED);
+ break;
+ case VL53L1_ERROR_INVALID_PARAMS:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_INVALID_PARAMS);
+ break;
+ case VL53L1_ERROR_NOT_SUPPORTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_NOT_SUPPORTED);
+ break;
+ case VL53L1_ERROR_RANGE_ERROR:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_RANGE_ERROR);
+ break;
+ case VL53L1_ERROR_TIME_OUT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_TIME_OUT);
+ break;
+ case VL53L1_ERROR_MODE_NOT_SUPPORTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED);
+ break;
+ case VL53L1_ERROR_BUFFER_TOO_SMALL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_BUFFER_TOO_SMALL);
+ break;
+ case VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL);
+ break;
+ case VL53L1_ERROR_GPIO_NOT_EXISTING:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPIO_NOT_EXISTING);
+ break;
+ case VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED);
+ break;
+ case VL53L1_ERROR_CONTROL_INTERFACE:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_CONTROL_INTERFACE);
+ break;
+ case VL53L1_ERROR_INVALID_COMMAND:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_INVALID_COMMAND);
+ break;
+ case VL53L1_ERROR_DIVISION_BY_ZERO:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_DIVISION_BY_ZERO);
+ break;
+ case VL53L1_ERROR_REF_SPAD_INIT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_REF_SPAD_INIT);
+ break;
+ case VL53L1_ERROR_GPH_SYNC_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_GPH_ID_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL);
+ break;
+ case VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL);
+ break;
+
+ case VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL);
+ break;
+ case VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL);
+ break;
+
+ case VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL);
+ break;
+ case VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL);
+ break;
+ case VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL);
+ break;
+
+ case VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES);
+ break;
+ case VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW);
+ break;
+
+ case VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES);
+ break;
+ case VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH);
+ break;
+
+ case VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS);
+ break;
+ case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH);
+ break;
+ case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW);
+ break;
+
+ case VL53L1_WARNING_XTALK_MISSING_SAMPLES:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES);
+ break;
+ case VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT);
+ break;
+ case VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT);
+ break;
+
+ case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD);
+ break;
+ case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW);
+ break;
+ case VL53L1_ERROR_UNIT_TEST_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_UNIT_TEST_FAIL);
+ break;
+ case VL53L1_ERROR_FILE_READ_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_FILE_READ_FAIL);
+ break;
+ case VL53L1_ERROR_FILE_WRITE_FAIL:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_FILE_WRITE_FAIL);
+ break;
+ case VL53L1_ERROR_NOT_IMPLEMENTED:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_ERROR_NOT_IMPLEMENTED);
+ break;
+ default:
+ VL53L1_COPYSTRING(pPalErrorString,
+ VL53L1_STRING_UNKNOW_ERROR_CODE);
+ }
+
+#endif
+
+ LOG_FUNCTION_END(Status);
+
+ return Status;
+}
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_hist_char.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_hist_char.c
new file mode 100644
index 000000000000..e5b12c7fe3c6
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_hist_char.c
@@ -0,0 +1,282 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include
+
+#include
+
+
+
+
+
+
+
+#include "vl53l1_core.h"
+#include "vl53l1_register_settings.h"
+#include "vl53l1_hist_char.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_HISTOGRAM, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_HISTOGRAM, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_HISTOGRAM,\
+ status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_set_calib_config(
+ VL53L1_DEV Dev,
+ uint8_t vcsel_delay__a0,
+ uint8_t calib_1,
+ uint8_t calib_2,
+ uint8_t calib_3,
+ uint8_t calib_2__a0,
+ uint8_t spad_readout)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[3];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_enable_powerforce(Dev);
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__VCSEL_DELAY__A0,
+ vcsel_delay__a0);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE) {
+
+
+
+
+
+
+
+ comms_buffer[0] = calib_1;
+ comms_buffer[1] = calib_2;
+ comms_buffer[2] = calib_3;
+
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RANGING_CORE__CALIB_1,
+ comms_buffer,
+ 3);
+ }
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__CALIB_2__A0,
+ calib_2__a0);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__SPAD_READOUT,
+ spad_readout);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+VL53L1_Error VL53L1_set_hist_calib_pulse_delay(
+ VL53L1_DEV Dev,
+ uint8_t calib_delay)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status =
+ VL53L1_set_calib_config(
+ Dev,
+ 0x01,
+
+ calib_delay,
+
+ 0x04,
+
+ 0x08,
+
+ 0x14,
+
+ VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_disable_calib_pulse_delay(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ status =
+ VL53L1_set_calib_config(
+ Dev,
+ 0x00,
+
+ 0x00,
+
+ 0x00,
+
+ 0x00,
+
+ 0x00,
+
+ VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_nvm.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_nvm.c
new file mode 100644
index 000000000000..312f49b9c690
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_nvm.c
@@ -0,0 +1,1751 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_core.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm_map.h"
+#include "vl53l1_nvm.h"
+
+
+
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_NVM, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_NVM, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_NVM,\
+ status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NVM, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_nvm_enable(
+ VL53L1_DEV Dev,
+ uint16_t nvm_ctrl_pulse_width,
+ int32_t nvm_power_up_delay_us)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_powerforce(Dev);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(
+ Dev,
+ VL53L1_ENABLE_POWERFORCE_SETTLING_TIME_US);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__PDN,
+ 0x01);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__CLK_CTRL1,
+ 0x05);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(
+ Dev,
+ nvm_power_up_delay_us);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__MODE,
+ 0x01);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrWord(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__PULSE_WIDTH_MSB,
+ nvm_ctrl_pulse_width);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_nvm_read(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pdata)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t nvm_addr = 0;
+
+ LOG_FUNCTION_START("");
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%-12s = 0x%02X (%3u)\n",
+ "nvm_addr", nvm_addr, nvm_addr);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%-12s = 0x%02X (%3u)\n",
+ "count", count, count);
+
+ for (nvm_addr = start_address;
+ nvm_addr < (start_address+count) ; nvm_addr++) {
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__ADDR,
+ nvm_addr);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__READN,
+ 0x00);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WaitUs(
+ Dev,
+ VL53L1_NVM_READ_TRIGGER_DELAY_US);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__READN,
+ 0x01);
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__DATAOUT_MMM,
+ pdata,
+ 4);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "NVM address : 0x%02X = 0x%02X%02X%02X%02X\n",
+ nvm_addr, *pdata, *(pdata+1), *(pdata+2), *(pdata+3));
+
+
+
+
+ pdata = pdata + 4;
+
+
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_disable(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__READN,
+ 0x01);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WrByte(
+ Dev,
+ VL53L1_RANGING_CORE__NVM_CTRL__PDN,
+ 0x00);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_powerforce(Dev);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_nvm_format_decode(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_data_t *pdata)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i = 0;
+ uint8_t *ptmp = NULL;
+ int pptmp[VL53L1_NVM_MAX_FMT_RANGE_DATA];
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_NVM_SIZE_IN_BYTES)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->nvm__identification_model_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__MODEL_ID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__identification_module_type =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__MODULE_TYPE,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__identification_revision_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__REVISION_ID,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__identification_module_id =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__IDENTIFICATION__MODULE_ID,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__i2c_valid =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__I2C_VALID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__i2c_device_address_ews =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__I2C_SLAVE__DEVICE_ADDRESS,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ews__fast_osc_frequency =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__EWS__OSC_MEASURED__FAST_OSC_FREQUENCY,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__ews__fast_osc_trim_max =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__FAST_OSC_TRIM_MAX,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__ews__fast_osc_freq_set =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__FAST_OSC_FREQ_SET,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__ews__slow_osc_calibration =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__EWS__SLOW_OSC_CALIBRATION,
+ 0x000003FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__fast_osc_frequency =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__FMT__OSC_MEASURED__FAST_OSC_FREQUENCY,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__fast_osc_trim_max =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FAST_OSC_TRIM_MAX,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__fmt__fast_osc_freq_set =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FAST_OSC_FREQ_SET,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__fmt__slow_osc_calibration =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__SLOW_OSC_CALIBRATION,
+ 0x000003FF,
+ 0,
+ 0);
+ pdata->nvm__vhv_config_unlock =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG_UNLOCK,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ref_selvddpix =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REF_SELVDDPIX,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__ref_selvquench =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REF_SELVQUENCH,
+ 0x00000078,
+ 3,
+ 0);
+ pdata->nvm__regavdd1v2_sel =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL,
+ 0x0000000C,
+ 2,
+ 0);
+ pdata->nvm__regdvdd1v2_sel =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__REGAVDD1V2_SEL_REGDVDD1V2_SEL,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__vhv_timeout__macrop =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__vhv_loop_bound =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__VHV_CONFIG__TIMEOUT_MACROP_LOOP_BOUND,
+ 0x000000FC,
+ 2,
+ 0);
+ pdata->nvm__vhv_count_threshold =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__COUNT_THRESH,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__vhv_offset =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__OFFSET,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__vhv_init_enable =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__INIT,
+ 0x00000080,
+ 7,
+ 0);
+ pdata->nvm__vhv_init_value =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__VHV_CONFIG__INIT,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_trim_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LL,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_max_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_mult_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__MULT_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_clip_ll =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__CLIP_LL,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_trim_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_TRIM_LD,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_vcsel_selion_max_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__VCSEL_SELION_MAX_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_mult_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__MULT_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_clip_ld =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY__CLIP_LD,
+ 0x0000003F,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_lock_byte =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY_LOCK_BYTE,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__laser_safety_unlock_byte =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__LASER_SAFETY_UNLOCK_BYTE,
+ 0x000000FF,
+ 0,
+ 0);
+
+
+
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_RTN_0_;
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_rtn[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC1_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_ref__loc1[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC2_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_ref__loc2[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__EWS__SPAD_ENABLES_REF__LOC3_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__ews__spad_enables_ref__loc3[i] = *ptmp++;
+
+
+
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_RTN_0_;
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_rtn[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC1_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_ref__loc1[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC2_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_ref__loc2[i] = *ptmp++;
+
+ ptmp = pbuffer + VL53L1_NVM__FMT__SPAD_ENABLES_REF__LOC3_0_;
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++)
+ pdata->nvm__fmt__spad_enables_ref__loc3[i] = *ptmp++;
+
+
+ pdata->nvm__fmt__roi_config__mode_roi_centre_spad =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_CENTRE_SPAD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__roi_config__mode_roi_x_size =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE,
+ 0x000000F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__roi_config__mode_roi_y_size =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__ROI_CONFIG__MODE_ROI_XY_SIZE,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__fmt__ref_spad_apply__num_requested_ref_spad =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__FMT__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__ref_spad_man__ref_location =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__REF_SPAD_MAN__REF_LOCATION,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__fmt__mm_config__inner_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__MM_CONFIG__INNER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__mm_config__outer_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__MM_CONFIG__OUTER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo_part_to_part_range_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__FMT__ALGO__PART_TO_PART_RANGE_OFFSET_MM,
+ 0x00000FFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__FMT__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_0 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_1 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__FMT__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__customer_space_programmed =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUSTOMER_NVM_SPACE_PROGRAMMED,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__i2c_device_address =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__I2C_SLAVE__DEVICE_ADDRESS,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__ref_spad_apply__num_requested_ref_spad =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__CUST__REF_SPAD_APPLY__NUM_REQUESTED_REF_SPAD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__ref_spad_man__ref_location =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__REF_SPAD_MAN__REF_LOCATION,
+ 0x00000003,
+ 0,
+ 0);
+ pdata->nvm__cust__mm_config__inner_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__MM_CONFIG__INNER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__mm_config__outer_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__CUST__MM_CONFIG__OUTER_OFFSET_MM,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo_part_to_part_range_offset_mm =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__CUST__ALGO__PART_TO_PART_RANGE_OFFSET_MM,
+ 0x00000FFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo__crosstalk_compensation_plane_offset_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_PLANE_OFFSET_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_X_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer +
+ VL53L1_NVM__CUST__ALGO__CROSSTALK_COMPENSATION_Y_PLANE_GRADIENT_KCPS,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_0 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_0,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_1 =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer +
+ VL53L1_NVM__CUST__SPARE_HOST_CONFIG__NVM_CONFIG_SPARE_1,
+ 0x000000FF,
+ 0,
+ 0);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_optical_centre(
+ buf_size,
+ pbuffer + VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_INDEX,
+ &(pdata->fmt_optical_centre));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_cal_peak_rate_map(
+ buf_size,
+ pbuffer + VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX,
+ &(pdata->fmt_peak_rate_map));
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_additional_offset_cal_data(
+ buf_size,
+ pbuffer +
+ VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX,
+ &(pdata->fmt_add_offset_data));
+
+
+
+
+ pptmp[0] = VL53L1_NVM__FMT__RANGE_RESULTS__140MM_MM_PRE_RANGE;
+ pptmp[1] = VL53L1_NVM__FMT__RANGE_RESULTS__140MM_DARK;
+ pptmp[2] = VL53L1_NVM__FMT__RANGE_RESULTS__400MM_DARK;
+ pptmp[3] = VL53L1_NVM__FMT__RANGE_RESULTS__400MM_AMBIENT;
+
+ for (i = 0 ; i < VL53L1_NVM_MAX_FMT_RANGE_DATA ; i++) {
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_fmt_range_results_data(
+ buf_size,
+ pbuffer + pptmp[i],
+ &(pdata->fmt_range_data[i]));
+ }
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_fmt_info(
+ buf_size,
+ pbuffer,
+ &(pdata->fmt_info));
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_ews_info(
+ buf_size,
+ pbuffer,
+ &(pdata->ews_info));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_optical_centre(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_optical_centre_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint16_t tmp = 0;
+
+ if (buf_size < VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+
+
+
+
+ tmp = 0x0100;
+ tmp -= (uint16_t)*(pbuffer + 2);
+ if (tmp > 0x0FF)
+ tmp = 0;
+
+ pdata->x_centre = (uint8_t)tmp;
+ pdata->y_centre = *(pbuffer + 3);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_cal_peak_rate_map(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_cal_peak_rate_map_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t *ptmp = NULL;
+ uint8_t i = 0;
+
+ if (buf_size < VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->cal_distance_mm =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ pdata->cal_reflectance_pc =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 2);
+ pdata->cal_reflectance_pc =
+ pdata->cal_reflectance_pc >> 6;
+
+ pdata->max_samples = VL53L1_NVM_PEAK_RATE_MAP_SAMPLES;
+ pdata->width = VL53L1_NVM_PEAK_RATE_MAP_WIDTH;
+ pdata->height = VL53L1_NVM_PEAK_RATE_MAP_HEIGHT;
+
+ ptmp = pbuffer + 4;
+ for (i = 0 ; i < VL53L1_NVM_PEAK_RATE_MAP_SAMPLES ; i++) {
+ pdata->peak_rate_mcps[i] =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, ptmp);
+ ptmp += 2;
+ }
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_additional_offset_cal_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_additional_offset_cal_data_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (buf_size < VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->result__mm_inner_actual_effective_spads =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ pdata->result__mm_outer_actual_effective_spads =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 2);
+
+ pdata->result__mm_inner_peak_signal_count_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
+
+ pdata->result__mm_outer_peak_signal_count_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 6);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_range_results_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (buf_size < VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->result__actual_effective_rtn_spads =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer);
+
+ pdata->ref_spad_array__num_requested_ref_spads =
+ *(pbuffer+2);
+
+ pdata->ref_spad_array__ref_location =
+ *(pbuffer+3);
+
+ pdata->result__peak_signal_count_rate_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 4);
+
+ pdata->result__ambient_count_rate_rtn_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 6);
+
+ pdata->result__peak_signal_count_rate_ref_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 8);
+
+ pdata->result__ambient_count_rate_ref_mcps =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 10);
+
+ pdata->measured_distance_mm =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 12);
+
+ pdata->measured_distance_stdev_mm =
+ (uint16_t)VL53L1_i2c_decode_uint16_t(2, pbuffer + 14);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_fmt_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_fmt_info_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (buf_size < VL53L1_NVM_SIZE_IN_BYTES)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->nvm__fmt__fgc[0] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_0,
+ 0x000000FE,
+ 1,
+ 0);
+ pdata->nvm__fmt__fgc[1] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_1,
+ 0x000001FC,
+ 2,
+ 0);
+ pdata->nvm__fmt__fgc[2] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_2 - 1,
+ 0x000003F8,
+ 3,
+ 0);
+ pdata->nvm__fmt__fgc[3] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_3 - 1,
+ 0x000007F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__fgc[4] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_4 - 1,
+ 0x00000FE0,
+ 5,
+ 0);
+ pdata->nvm__fmt__fgc[5] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_5 - 1,
+ 0x00001FC0,
+ 6,
+ 0);
+ pdata->nvm__fmt__fgc[6] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_6 - 1,
+ 0x00003F80,
+ 7,
+ 0);
+ pdata->nvm__fmt__fgc[7] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_6,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__fmt__fgc[8] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_7,
+ 0x000000FE,
+ 1,
+ 0);
+ pdata->nvm__fmt__fgc[9] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_8,
+ 0x000001FC,
+ 2,
+ 0);
+ pdata->nvm__fmt__fgc[10] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_9 - 1,
+ 0x000003F8,
+ 3,
+ 0);
+ pdata->nvm__fmt__fgc[11] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_10 - 1,
+ 0x000007F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__fgc[12] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_11 - 1,
+ 0x00000FE0,
+ 5,
+ 0);
+ pdata->nvm__fmt__fgc[13] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_12 - 1,
+ 0x00001FC0,
+ 6,
+ 0);
+ pdata->nvm__fmt__fgc[14] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_13 - 1,
+ 0x00003F80,
+ 7,
+ 0);
+ pdata->nvm__fmt__fgc[15] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_13,
+ 0x0000007F,
+ 0,
+ 0);
+ pdata->nvm__fmt__fgc[16] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_14,
+ 0x000000FE,
+ 1,
+ 0);
+ pdata->nvm__fmt__fgc[17] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__FGC__BYTE_15,
+ 0x000001FC,
+ 2,
+ 0);
+ pdata->nvm__fmt__fgc[18] = 0x00;
+
+ pdata->nvm__fmt__test_program_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR,
+ 0x000000E0,
+ 5,
+ 0);
+ pdata->nvm__fmt__test_program_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__TEST_PROGRAM_MAJOR_MINOR,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__fmt__map_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__MAP_MAJOR_MINOR,
+ 0x000000E0,
+ 5,
+ 0);
+ pdata->nvm__fmt__map_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__MAP_MAJOR_MINOR,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__fmt__year =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__YEAR_MONTH,
+ 0x000000F0,
+ 4,
+ 0);
+ pdata->nvm__fmt__month =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__YEAR_MONTH,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__fmt__day =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE,
+ 0x000000F8,
+ 3,
+ 0);
+ pdata->nvm__fmt__module_date_phase =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__DAY_MODULE_DATE_PHASE,
+ 0x00000007,
+ 0,
+ 0);
+ pdata->nvm__fmt__time =
+ (uint16_t)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__FMT__TIME,
+ 0x0000FFFF,
+ 0,
+ 0);
+ pdata->nvm__fmt__tester_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__TESTER_ID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__fmt__site_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__FMT__SITE_ID,
+ 0x000000FF,
+ 0,
+ 0);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_nvm_decode_ews_info(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_decoded_nvm_ews_info_t *pdata)
+{
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ if (buf_size < VL53L1_NVM_SIZE_IN_BYTES)
+ return VL53L1_ERROR_BUFFER_TOO_SMALL;
+
+ pdata->nvm__ews__test_program_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR,
+ 0x000000E0,
+ 5,
+ 0);
+ pdata->nvm__ews__test_program_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__TEST_PROGRAM_MAJOR_MINOR,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__ews__probe_card_major =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR,
+ 0x000000F0,
+ 4,
+ 0);
+ pdata->nvm__ews__probe_card_minor =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__PROBE_CARD_MAJOR_MINOR,
+ 0x0000000F,
+ 0,
+ 0);
+ pdata->nvm__ews__tester_id =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__TESTER_ID,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ews__lot[0] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_0,
+ 0x000000FC,
+ 2,
+ 32);
+ pdata->nvm__ews__lot[1] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_1 - 1,
+ 0x000003F0,
+ 4,
+ 32);
+ pdata->nvm__ews__lot[2] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_2 - 1,
+ 0x00000FC0,
+ 6,
+ 32);
+ pdata->nvm__ews__lot[3] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_2,
+ 0x0000003F,
+ 0,
+ 32);
+ pdata->nvm__ews__lot[4] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_3,
+ 0x000000FC,
+ 2,
+ 32);
+ pdata->nvm__ews__lot[5] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_4 - 1,
+ 0x000003F0,
+ 4,
+ 32);
+ pdata->nvm__ews__lot[6] =
+ (char)VL53L1_i2c_decode_with_mask(
+ 2,
+ pbuffer + VL53L1_NVM__EWS__LOT__BYTE_5 - 1,
+ 0x00000FC0,
+ 6,
+ 32);
+
+ pdata->nvm__ews__lot[7] = 0x00;
+
+ pdata->nvm__ews__wafer =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__WAFER,
+ 0x0000001F,
+ 0,
+ 0);
+ pdata->nvm__ews__xcoord =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__XCOORD,
+ 0x000000FF,
+ 0,
+ 0);
+ pdata->nvm__ews__ycoord =
+ (uint8_t)VL53L1_i2c_decode_with_mask(
+ 1,
+ pbuffer + VL53L1_NVM__EWS__YCOORD,
+ 0x000000FF,
+ 0,
+ 0);
+
+ return status;
+
+}
+
+
+void VL53L1_nvm_format_encode(
+ VL53L1_decoded_nvm_data_t *pnvm_info,
+ uint8_t *pnvm_data)
+{
+ SUPPRESS_UNUSED_WARNING(pnvm_info);
+ SUPPRESS_UNUSED_WARNING(pnvm_data);
+}
+
+
+VL53L1_Error VL53L1_read_nvm_raw_data(
+ VL53L1_DEV Dev,
+ uint8_t start_address,
+ uint8_t count,
+ uint8_t *pnvm_raw_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_nvm_enable(
+ Dev,
+ 0x0004,
+ VL53L1_NVM_POWER_UP_DELAY_US);
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_read(
+ Dev,
+ start_address,
+ count,
+ pnvm_raw_data);
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_disable(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_read_nvm(
+ VL53L1_DEV Dev,
+ uint8_t nvm_format,
+ VL53L1_decoded_nvm_data_t *pnvm_info)
+{
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM_SIZE_IN_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ SUPPRESS_UNUSED_WARNING(nvm_format);
+
+
+
+
+ status = VL53L1_read_nvm_raw_data(
+ Dev,
+ 0,
+ VL53L1_NVM_SIZE_IN_BYTES >> 2,
+ nvm_data);
+
+
+
+
+
+
+
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_format_decode(
+ VL53L1_NVM_SIZE_IN_BYTES,
+ nvm_data,
+ pnvm_info);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_read_nvm_optical_centre(
+ VL53L1_DEV Dev,
+ VL53L1_optical_centre_t *pcentre)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_read_nvm_raw_data(
+ Dev,
+ (uint8_t)(VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_INDEX
+ >> 2),
+ (uint8_t)(VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE
+ >> 2),
+ nvm_data);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_optical_centre(
+ VL53L1_NVM__FMT__OPTICAL_CENTRE_DATA_SIZE,
+ nvm_data,
+ pcentre);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_read_nvm_cal_peak_rate_map(
+ VL53L1_DEV Dev,
+ VL53L1_cal_peak_rate_map_t *pcal_data)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_read_nvm_raw_data(
+ Dev,
+ (uint8_t)(VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_INDEX
+ >> 2),
+ (uint8_t)(VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE
+ >> 2),
+ nvm_data);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_cal_peak_rate_map(
+ VL53L1_NVM__FMT__CAL_PEAK_RATE_MAP_DATA_SIZE,
+ nvm_data,
+ pcal_data);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_read_nvm_additional_offset_cal_data(
+ VL53L1_DEV Dev,
+ VL53L1_additional_offset_cal_data_t *pcal_data)
+{
+
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_read_nvm_raw_data(
+ Dev,
+ (uint8_t)(
+ VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_INDEX >> 2),
+ (uint8_t)(
+ VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE >> 2),
+ nvm_data);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_nvm_decode_additional_offset_cal_data(
+ VL53L1_NVM__FMT__ADDITIONAL_OFFSET_CAL_DATA_SIZE,
+ nvm_data,
+ pcal_data);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_read_nvm_fmt_range_results_data(
+ VL53L1_DEV Dev,
+ uint16_t range_results_select,
+ VL53L1_decoded_nvm_fmt_range_data_t *prange_data)
+{
+
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+
+
+ uint8_t nvm_data[2*VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_read_nvm_raw_data(
+ Dev,
+ (uint8_t)(range_results_select >> 2),
+ (uint8_t)(VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES >> 2),
+ nvm_data);
+
+
+
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_nvm_decode_fmt_range_results_data(
+ VL53L1_NVM__FMT__RANGE_RESULTS__SIZE_BYTES,
+ nvm_data,
+ prange_data);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_nvm_debug.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_nvm_debug.c
new file mode 100644
index 000000000000..3ac30357e198
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_nvm_debug.c
@@ -0,0 +1,1126 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_api_debug.h"
+#include "vl53l1_nvm_structs.h"
+#include "vl53l1_nvm_debug.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_NVM, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_NVM, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_NVM,\
+ status, fmt, ##__VA_ARGS__)
+
+#define trace_print(level, ...) \
+ _LOG_TRACE_PRINT(trace_flags, \
+ level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
+
+#ifdef VL53L1_LOG_ENABLE
+
+void VL53L1_print_nvm_raw_data(
+ uint8_t *pnvm_raw_data,
+ uint32_t trace_flags)
+{
+
+
+
+
+
+ int i = 0;
+
+ LOG_FUNCTION_START("");
+
+ for (i = 0 ; i < VL53L1_NVM_SIZE_IN_BYTES ; i++) {
+ if (i % 4 == 0)
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n NVM Addr 0x%02X : 0x",
+ i/4);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%02X",
+ *pnvm_raw_data++);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "\n");
+
+ LOG_FUNCTION_END(0);
+}
+
+
+void VL53L1_print_decoded_nvm_data(
+ VL53L1_decoded_nvm_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+ char pre_text[VL53L1_MAX_STRING_LENGTH];
+ char *ppre_text = &(pre_text[0]);
+
+ uint8_t i = 0;
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_model_id",
+ pdata->nvm__identification_model_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_module_type",
+ pdata->nvm__identification_module_type);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_revision_id",
+ pdata->nvm__identification_revision_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__identification_module_id",
+ pdata->nvm__identification_module_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__i2c_valid",
+ pdata->nvm__i2c_valid);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__i2c_device_address_ews",
+ pdata->nvm__i2c_device_address_ews);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__ews__fast_osc_frequency,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__ews__fast_osc_frequency",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__fast_osc_trim_max",
+ pdata->nvm__ews__fast_osc_trim_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__fast_osc_freq_set",
+ pdata->nvm__ews__fast_osc_freq_set);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__slow_osc_calibration",
+ pdata->nvm__ews__slow_osc_calibration);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__fmt__fast_osc_frequency,
+ 12,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__fast_osc_frequency",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__fast_osc_trim_max",
+ pdata->nvm__fmt__fast_osc_trim_max);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__fast_osc_freq_set",
+ pdata->nvm__fmt__fast_osc_freq_set);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__slow_osc_calibration",
+ pdata->nvm__fmt__slow_osc_calibration);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_config_unlock",
+ pdata->nvm__vhv_config_unlock);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ref_selvddpix",
+ pdata->nvm__ref_selvddpix);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ref_selvquench",
+ pdata->nvm__ref_selvquench);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__regavdd1v2_sel",
+ pdata->nvm__regavdd1v2_sel);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__regdvdd1v2_sel",
+ pdata->nvm__regdvdd1v2_sel);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_timeout__macrop",
+ pdata->nvm__vhv_timeout__macrop);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_loop_bound",
+ pdata->nvm__vhv_loop_bound);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_count_threshold",
+ pdata->nvm__vhv_count_threshold);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_offset",
+ pdata->nvm__vhv_offset);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_init_enable",
+ pdata->nvm__vhv_init_enable);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__vhv_init_value",
+ pdata->nvm__vhv_init_value);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_trim_ll",
+ pdata->nvm__laser_safety_vcsel_trim_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_ll",
+ pdata->nvm__laser_safety_vcsel_selion_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_max_ll",
+ pdata->nvm__laser_safety_vcsel_selion_max_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_mult_ll",
+ pdata->nvm__laser_safety_mult_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_clip_ll",
+ pdata->nvm__laser_safety_clip_ll);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_trim_ld",
+ pdata->nvm__laser_safety_vcsel_trim_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_ld",
+ pdata->nvm__laser_safety_vcsel_selion_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_vcsel_selion_max_ld",
+ pdata->nvm__laser_safety_vcsel_selion_max_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_mult_ld",
+ pdata->nvm__laser_safety_mult_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_clip_ld",
+ pdata->nvm__laser_safety_clip_ld);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_lock_byte",
+ pdata->nvm__laser_safety_lock_byte);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__laser_safety_unlock_byte",
+ pdata->nvm__laser_safety_unlock_byte);
+
+
+
+
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_rtn[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_rtn[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_ref__loc1[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_ref__loc1[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_ref__loc2[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_ref__loc2[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__ews__spad_enables_ref__loc3[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__ews__spad_enables_ref__loc3[i]);
+ }
+
+
+
+
+
+ for (i = 0 ; i < VL53L1_RTN_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_rtn[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_rtn[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_ref__loc1[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_ref__loc1[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_ref__loc2[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_ref__loc2[i]);
+ }
+
+ for (i = 0 ; i < VL53L1_REF_SPAD_BUFFER_SIZE ; i++) {
+ sprintf(
+ ppre_text,
+ "%snvm__fmt__spad_enables_ref__loc3[%u]",
+ pprefix, i);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s = %u\n",
+ ppre_text,
+ pdata->nvm__fmt__spad_enables_ref__loc3[i]);
+ }
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__roi_config__mode_roi_centre_spad",
+ pdata->nvm__fmt__roi_config__mode_roi_centre_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__roi_config__mode_roi_x_size",
+ pdata->nvm__fmt__roi_config__mode_roi_x_size);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__roi_config__mode_roi_y_size",
+ pdata->nvm__fmt__roi_config__mode_roi_y_size);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__ref_spad_apply__num_requested_ref_spad",
+ pdata->nvm__fmt__ref_spad_apply__num_requested_ref_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__ref_spad_man__ref_location",
+ pdata->nvm__fmt__ref_spad_man__ref_location);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__fmt__mm_config__inner_offset_mm",
+ pdata->nvm__fmt__mm_config__inner_offset_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__fmt__mm_config__outer_offset_mm",
+ pdata->nvm__fmt__mm_config__outer_offset_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__fmt__algo_part_to_part_range_offset_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo_part_to_part_range_offset_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)(
+ pdata->nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps),
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)(
+ pdata->nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps),
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)(
+ pdata->nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps),
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__fmt__algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__spare__host_config__nvm_config_spare_0",
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_0);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__spare__host_config__nvm_config_spare_1",
+ pdata->nvm__fmt__spare__host_config__nvm_config_spare_1);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__customer_space_programmed",
+ pdata->nvm__customer_space_programmed);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__i2c_device_address",
+ pdata->nvm__cust__i2c_device_address);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__ref_spad_apply__num_requested_ref_spad",
+ pdata->nvm__cust__ref_spad_apply__num_requested_ref_spad);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__ref_spad_man__ref_location",
+ pdata->nvm__cust__ref_spad_man__ref_location);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__cust__mm_config__inner_offset_mm",
+ pdata->nvm__cust__mm_config__inner_offset_mm);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %d\n",
+ pprefix,
+ "nvm__cust__mm_config__outer_offset_mm",
+ pdata->nvm__cust__mm_config__outer_offset_mm);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->nvm__cust__algo_part_to_part_range_offset_mm,
+ 2,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo_part_to_part_range_offset_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (uint32_t)(
+ pdata->nvm__cust__algo__crosstalk_compensation_plane_offset_kcps),
+ 9,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo__crosstalk_compensation_plane_offset_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)(
+ pdata->nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps),
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo__crosstalk_compensation_x_plane_gradient_kcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)(
+ pdata->nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps),
+ 11,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "nvm__cust__algo__crosstalk_compensation_y_plane_gradient_kcps",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__spare__host_config__nvm_config_spare_0",
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_0);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__cust__spare__host_config__nvm_config_spare_1",
+ pdata->nvm__cust__spare__host_config__nvm_config_spare_1);
+
+
+
+
+ sprintf(
+ ppre_text,
+ "%sfmt_optical_centre.", pprefix);
+
+ VL53L1_print_optical_centre(
+ &(pdata->fmt_optical_centre),
+ ppre_text,
+ VL53L1_TRACE_MODULE_NVM_DATA);
+
+
+
+
+ sprintf(
+ ppre_text,
+ "%sfmt_peak_rate_map.", pprefix);
+
+ VL53L1_print_cal_peak_rate_map(
+ &(pdata->fmt_peak_rate_map),
+ ppre_text,
+ VL53L1_TRACE_MODULE_NVM_DATA);
+
+
+
+
+ sprintf(
+ ppre_text,
+ "%sfmt_add_offset_data.",
+ pprefix);
+
+ VL53L1_print_additional_offset_cal_data(
+ &(pdata->fmt_add_offset_data),
+ ppre_text,
+ VL53L1_TRACE_MODULE_NVM_DATA);
+
+
+
+
+ for (i = 0 ; i < VL53L1_NVM_MAX_FMT_RANGE_DATA ; i++) {
+ sprintf(
+ ppre_text,
+ "%sfmt_range_data[%u].",
+ pprefix, i);
+
+ VL53L1_print_decoded_nvm_fmt_range_data(
+ &(pdata->fmt_range_data[i]),
+ ppre_text,
+ trace_flags);
+ }
+
+ sprintf(
+ ppre_text,
+ "%sfmt_info.",
+ pprefix);
+
+ VL53L1_print_decoded_nvm_fmt_info(
+ &(pdata->fmt_info),
+ ppre_text,
+ trace_flags);
+
+ sprintf(
+ ppre_text,
+ "%sews_info.",
+ pprefix);
+
+ VL53L1_print_decoded_nvm_ews_info(
+ &(pdata->ews_info),
+ ppre_text,
+ trace_flags);
+}
+
+
+void VL53L1_print_decoded_nvm_fmt_range_data(
+ VL53L1_decoded_nvm_fmt_range_data_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ char fp_text[VL53L1_MAX_STRING_LENGTH];
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__actual_effective_rtn_spads,
+ 8,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__actual_effective_rtn_spads",
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_array__num_requested_ref_spads",
+ pdata->ref_spad_array__num_requested_ref_spads);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "ref_spad_array__ref_location",
+ pdata->ref_spad_array__ref_location);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__peak_signal_count_rate_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__peak_signal_count_rate_rtn_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__ambient_count_rate_rtn_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__ambient_count_rate_rtn_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__peak_signal_count_rate_ref_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "result__peak_signal_count_rate_ref_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->result__ambient_count_rate_ref_mcps,
+ 7,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "result__ambient_count_rate_ref_mcps",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (int32_t)pdata->measured_distance_mm,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "measured_distance_mm",
+ fp_text);
+
+ VL53L1_signed_fixed_point_sprintf(
+ (uint32_t)pdata->measured_distance_stdev_mm,
+ 4,
+ VL53L1_MAX_STRING_LENGTH,
+ fp_text);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %s\n",
+ pprefix,
+ "measured_distance_stdev_mm",
+ fp_text);
+}
+
+
+void VL53L1_print_decoded_nvm_fmt_info(
+ VL53L1_decoded_nvm_fmt_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = \"%s\"\n",
+ pprefix,
+ "nvm__fmt__fgc",
+ pdata->nvm__fmt__fgc);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__test_program_major",
+ pdata->nvm__fmt__test_program_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__test_program_minor",
+ pdata->nvm__fmt__test_program_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__map_major",
+ pdata->nvm__fmt__map_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__map_minor",
+ pdata->nvm__fmt__map_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__year",
+ pdata->nvm__fmt__year);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__month",
+ pdata->nvm__fmt__month);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__day",
+ pdata->nvm__fmt__day);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__module_date_phase",
+ pdata->nvm__fmt__module_date_phase);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__time",
+ pdata->nvm__fmt__time);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__tester_id",
+ pdata->nvm__fmt__tester_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__fmt__site_id",
+ pdata->nvm__fmt__site_id);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__test_program_major",
+ pdata->nvm__ews__test_program_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__test_program_minor",
+ pdata->nvm__ews__test_program_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__probe_card_major",
+ pdata->nvm__ews__probe_card_major);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__probe_card_minor",
+ pdata->nvm__ews__probe_card_minor);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__tester_id",
+ pdata->nvm__ews__tester_id);
+}
+
+
+void VL53L1_print_decoded_nvm_ews_info(
+ VL53L1_decoded_nvm_ews_info_t *pdata,
+ char *pprefix,
+ uint32_t trace_flags)
+{
+ trace_print(VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = \"%s\"\n",
+ pprefix,
+ "nvm__ews__lot",
+ pdata->nvm__ews__lot);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__wafer",
+ pdata->nvm__ews__wafer);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__xcoord",
+ pdata->nvm__ews__xcoord);
+
+ trace_print(
+ VL53L1_TRACE_LEVEL_INFO,
+ "%s%s = %u\n",
+ pprefix,
+ "nvm__ews__ycoord",
+ pdata->nvm__ews__ycoord);
+}
+
+#endif
+
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_register_funcs.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_register_funcs.c
new file mode 100644
index 000000000000..1738d2076ca7
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_register_funcs.c
@@ -0,0 +1,4596 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_core.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_register_structs.h"
+#include "vl53l1_register_funcs.h"
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_REGISTERS, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_REGISTERS, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_REGISTERS,\
+ status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_i2c_encode_static_nvm_managed(
+ VL53L1_static_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->i2c_slave__device_address & 0x7F;
+ *(pbuffer + 1) =
+ pdata->ana_config__vhv_ref_sel_vddpix & 0xF;
+ *(pbuffer + 2) =
+ pdata->ana_config__vhv_ref_sel_vquench & 0x7F;
+ *(pbuffer + 3) =
+ pdata->ana_config__reg_avdd1v2_sel & 0x3;
+ *(pbuffer + 4) =
+ pdata->ana_config__fast_osc__trim & 0x7F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->osc_measured__fast_osc__frequency,
+ 2,
+ pbuffer + 5);
+ *(pbuffer + 7) =
+ pdata->vhv_config__timeout_macrop_loop_bound;
+ *(pbuffer + 8) =
+ pdata->vhv_config__count_thresh;
+ *(pbuffer + 9) =
+ pdata->vhv_config__offset & 0x3F;
+ *(pbuffer + 10) =
+ pdata->vhv_config__init;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_static_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->i2c_slave__device_address =
+ (*(pbuffer + 0)) & 0x7F;
+ pdata->ana_config__vhv_ref_sel_vddpix =
+ (*(pbuffer + 1)) & 0xF;
+ pdata->ana_config__vhv_ref_sel_vquench =
+ (*(pbuffer + 2)) & 0x7F;
+ pdata->ana_config__reg_avdd1v2_sel =
+ (*(pbuffer + 3)) & 0x3;
+ pdata->ana_config__fast_osc__trim =
+ (*(pbuffer + 4)) & 0x7F;
+ pdata->osc_measured__fast_osc__frequency =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 5));
+ pdata->vhv_config__timeout_macrop_loop_bound =
+ (*(pbuffer + 7));
+ pdata->vhv_config__count_thresh =
+ (*(pbuffer + 8));
+ pdata->vhv_config__offset =
+ (*(pbuffer + 9)) & 0x3F;
+ pdata->vhv_config__init =
+ (*(pbuffer + 10));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_static_nvm_managed(
+ pdata,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_I2C_SLAVE__DEVICE_ADDRESS,
+ comms_buffer,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_static_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_static_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_I2C_SLAVE__DEVICE_ADDRESS,
+ comms_buffer,
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_static_nvm_managed(
+ VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_customer_nvm_managed(
+ VL53L1_customer_nvm_managed_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->global_config__spad_enables_ref_0;
+ *(pbuffer + 1) =
+ pdata->global_config__spad_enables_ref_1;
+ *(pbuffer + 2) =
+ pdata->global_config__spad_enables_ref_2;
+ *(pbuffer + 3) =
+ pdata->global_config__spad_enables_ref_3;
+ *(pbuffer + 4) =
+ pdata->global_config__spad_enables_ref_4;
+ *(pbuffer + 5) =
+ pdata->global_config__spad_enables_ref_5 & 0xF;
+ *(pbuffer + 6) =
+ pdata->global_config__ref_en_start_select;
+ *(pbuffer + 7) =
+ pdata->ref_spad_man__num_requested_ref_spads & 0x3F;
+ *(pbuffer + 8) =
+ pdata->ref_spad_man__ref_location & 0x3;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->algo__crosstalk_compensation_plane_offset_kcps,
+ 2,
+ pbuffer + 9);
+ VL53L1_i2c_encode_int16_t(
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps,
+ 2,
+ pbuffer + 11);
+ VL53L1_i2c_encode_int16_t(
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps,
+ 2,
+ pbuffer + 13);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->ref_spad_char__total_rate_target_mcps,
+ 2,
+ pbuffer + 15);
+ VL53L1_i2c_encode_int16_t(
+ pdata->algo__part_to_part_range_offset_mm & 0x1FFF,
+ 2,
+ pbuffer + 17);
+ VL53L1_i2c_encode_int16_t(
+ pdata->mm_config__inner_offset_mm,
+ 2,
+ pbuffer + 19);
+ VL53L1_i2c_encode_int16_t(
+ pdata->mm_config__outer_offset_mm,
+ 2,
+ pbuffer + 21);
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_customer_nvm_managed(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_customer_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->global_config__spad_enables_ref_0 =
+ (*(pbuffer + 0));
+ pdata->global_config__spad_enables_ref_1 =
+ (*(pbuffer + 1));
+ pdata->global_config__spad_enables_ref_2 =
+ (*(pbuffer + 2));
+ pdata->global_config__spad_enables_ref_3 =
+ (*(pbuffer + 3));
+ pdata->global_config__spad_enables_ref_4 =
+ (*(pbuffer + 4));
+ pdata->global_config__spad_enables_ref_5 =
+ (*(pbuffer + 5)) & 0xF;
+ pdata->global_config__ref_en_start_select =
+ (*(pbuffer + 6));
+ pdata->ref_spad_man__num_requested_ref_spads =
+ (*(pbuffer + 7)) & 0x3F;
+ pdata->ref_spad_man__ref_location =
+ (*(pbuffer + 8)) & 0x3;
+ pdata->algo__crosstalk_compensation_plane_offset_kcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 9));
+ pdata->algo__crosstalk_compensation_x_plane_gradient_kcps =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 11));
+ pdata->algo__crosstalk_compensation_y_plane_gradient_kcps =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 13));
+ pdata->ref_spad_char__total_rate_target_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 15));
+ pdata->algo__part_to_part_range_offset_mm =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 17)) & 0x1FFF;
+ pdata->mm_config__inner_offset_mm =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 19));
+ pdata->mm_config__outer_offset_mm =
+ (VL53L1_i2c_decode_int16_t(2, pbuffer + 21));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_customer_nvm_managed(
+ pdata,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0,
+ comms_buffer,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_customer_nvm_managed(
+ VL53L1_DEV Dev,
+ VL53L1_customer_nvm_managed_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0,
+ comms_buffer,
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_customer_nvm_managed(
+ VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_static_config(
+ VL53L1_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_config__target_total_rate_mcps,
+ 2,
+ pbuffer + 0);
+ *(pbuffer + 2) =
+ pdata->debug__ctrl & 0x1;
+ *(pbuffer + 3) =
+ pdata->test_mode__ctrl & 0xF;
+ *(pbuffer + 4) =
+ pdata->clk_gating__ctrl & 0xF;
+ *(pbuffer + 5) =
+ pdata->nvm_bist__ctrl & 0x1F;
+ *(pbuffer + 6) =
+ pdata->nvm_bist__num_nvm_words & 0x7F;
+ *(pbuffer + 7) =
+ pdata->nvm_bist__start_address & 0x7F;
+ *(pbuffer + 8) =
+ pdata->host_if__status & 0x1;
+ *(pbuffer + 9) =
+ pdata->pad_i2c_hv__config;
+ *(pbuffer + 10) =
+ pdata->pad_i2c_hv__extsup_config & 0x1;
+ *(pbuffer + 11) =
+ pdata->gpio_hv_pad__ctrl & 0x3;
+ *(pbuffer + 12) =
+ pdata->gpio_hv_mux__ctrl & 0x1F;
+ *(pbuffer + 13) =
+ pdata->gpio__tio_hv_status & 0x3;
+ *(pbuffer + 14) =
+ pdata->gpio__fio_hv_status & 0x3;
+ *(pbuffer + 15) =
+ pdata->ana_config__spad_sel_pswidth & 0x7;
+ *(pbuffer + 16) =
+ pdata->ana_config__vcsel_pulse_width_offset & 0x1F;
+ *(pbuffer + 17) =
+ pdata->ana_config__fast_osc__config_ctrl & 0x1;
+ *(pbuffer + 18) =
+ pdata->sigma_estimator__effective_pulse_width_ns;
+ *(pbuffer + 19) =
+ pdata->sigma_estimator__effective_ambient_width_ns;
+ *(pbuffer + 20) =
+ pdata->sigma_estimator__sigma_ref_mm;
+ *(pbuffer + 21) =
+ pdata->algo__crosstalk_compensation_valid_height_mm;
+ *(pbuffer + 22) =
+ pdata->spare_host_config__static_config_spare_0;
+ *(pbuffer + 23) =
+ pdata->spare_host_config__static_config_spare_1;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->algo__range_ignore_threshold_mcps,
+ 2,
+ pbuffer + 24);
+ *(pbuffer + 26) =
+ pdata->algo__range_ignore_valid_height_mm;
+ *(pbuffer + 27) =
+ pdata->algo__range_min_clip;
+ *(pbuffer + 28) =
+ pdata->algo__consistency_check__tolerance & 0xF;
+ *(pbuffer + 29) =
+ pdata->spare_host_config__static_config_spare_2;
+ *(pbuffer + 30) =
+ pdata->sd_config__reset_stages_msb & 0xF;
+ *(pbuffer + 31) =
+ pdata->sd_config__reset_stages_lsb;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->dss_config__target_total_rate_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0));
+ pdata->debug__ctrl =
+ (*(pbuffer + 2)) & 0x1;
+ pdata->test_mode__ctrl =
+ (*(pbuffer + 3)) & 0xF;
+ pdata->clk_gating__ctrl =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->nvm_bist__ctrl =
+ (*(pbuffer + 5)) & 0x1F;
+ pdata->nvm_bist__num_nvm_words =
+ (*(pbuffer + 6)) & 0x7F;
+ pdata->nvm_bist__start_address =
+ (*(pbuffer + 7)) & 0x7F;
+ pdata->host_if__status =
+ (*(pbuffer + 8)) & 0x1;
+ pdata->pad_i2c_hv__config =
+ (*(pbuffer + 9));
+ pdata->pad_i2c_hv__extsup_config =
+ (*(pbuffer + 10)) & 0x1;
+ pdata->gpio_hv_pad__ctrl =
+ (*(pbuffer + 11)) & 0x3;
+ pdata->gpio_hv_mux__ctrl =
+ (*(pbuffer + 12)) & 0x1F;
+ pdata->gpio__tio_hv_status =
+ (*(pbuffer + 13)) & 0x3;
+ pdata->gpio__fio_hv_status =
+ (*(pbuffer + 14)) & 0x3;
+ pdata->ana_config__spad_sel_pswidth =
+ (*(pbuffer + 15)) & 0x7;
+ pdata->ana_config__vcsel_pulse_width_offset =
+ (*(pbuffer + 16)) & 0x1F;
+ pdata->ana_config__fast_osc__config_ctrl =
+ (*(pbuffer + 17)) & 0x1;
+ pdata->sigma_estimator__effective_pulse_width_ns =
+ (*(pbuffer + 18));
+ pdata->sigma_estimator__effective_ambient_width_ns =
+ (*(pbuffer + 19));
+ pdata->sigma_estimator__sigma_ref_mm =
+ (*(pbuffer + 20));
+ pdata->algo__crosstalk_compensation_valid_height_mm =
+ (*(pbuffer + 21));
+ pdata->spare_host_config__static_config_spare_0 =
+ (*(pbuffer + 22));
+ pdata->spare_host_config__static_config_spare_1 =
+ (*(pbuffer + 23));
+ pdata->algo__range_ignore_threshold_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->algo__range_ignore_valid_height_mm =
+ (*(pbuffer + 26));
+ pdata->algo__range_min_clip =
+ (*(pbuffer + 27));
+ pdata->algo__consistency_check__tolerance =
+ (*(pbuffer + 28)) & 0xF;
+ pdata->spare_host_config__static_config_spare_2 =
+ (*(pbuffer + 29));
+ pdata->sd_config__reset_stages_msb =
+ (*(pbuffer + 30)) & 0xF;
+ pdata->sd_config__reset_stages_lsb =
+ (*(pbuffer + 31));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_static_config(
+ pdata,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS,
+ comms_buffer,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS,
+ comms_buffer,
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_static_config(
+ VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_general_config(
+ VL53L1_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->gph_config__stream_count_update_value;
+ *(pbuffer + 1) =
+ pdata->global_config__stream_divider;
+ *(pbuffer + 2) =
+ pdata->system__interrupt_config_gpio;
+ *(pbuffer + 3) =
+ pdata->cal_config__vcsel_start & 0x7F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->cal_config__repeat_rate & 0xFFF,
+ 2,
+ pbuffer + 4);
+ *(pbuffer + 6) =
+ pdata->global_config__vcsel_width & 0x7F;
+ *(pbuffer + 7) =
+ pdata->phasecal_config__timeout_macrop;
+ *(pbuffer + 8) =
+ pdata->phasecal_config__target;
+ *(pbuffer + 9) =
+ pdata->phasecal_config__override & 0x1;
+ *(pbuffer + 11) =
+ pdata->dss_config__roi_mode_control & 0x7;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_rate_high,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_rate_low,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_config__manual_effective_spads_select,
+ 2,
+ pbuffer + 16);
+ *(pbuffer + 18) =
+ pdata->dss_config__manual_block_select;
+ *(pbuffer + 19) =
+ pdata->dss_config__aperture_attenuation;
+ *(pbuffer + 20) =
+ pdata->dss_config__max_spads_limit;
+ *(pbuffer + 21) =
+ pdata->dss_config__min_spads_limit;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph_config__stream_count_update_value =
+ (*(pbuffer + 0));
+ pdata->global_config__stream_divider =
+ (*(pbuffer + 1));
+ pdata->system__interrupt_config_gpio =
+ (*(pbuffer + 2));
+ pdata->cal_config__vcsel_start =
+ (*(pbuffer + 3)) & 0x7F;
+ pdata->cal_config__repeat_rate =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)) & 0xFFF;
+ pdata->global_config__vcsel_width =
+ (*(pbuffer + 6)) & 0x7F;
+ pdata->phasecal_config__timeout_macrop =
+ (*(pbuffer + 7));
+ pdata->phasecal_config__target =
+ (*(pbuffer + 8));
+ pdata->phasecal_config__override =
+ (*(pbuffer + 9)) & 0x1;
+ pdata->dss_config__roi_mode_control =
+ (*(pbuffer + 11)) & 0x7;
+ pdata->system__thresh_rate_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->system__thresh_rate_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->dss_config__manual_effective_spads_select =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->dss_config__manual_block_select =
+ (*(pbuffer + 18));
+ pdata->dss_config__aperture_attenuation =
+ (*(pbuffer + 19));
+ pdata->dss_config__max_spads_limit =
+ (*(pbuffer + 20));
+ pdata->dss_config__min_spads_limit =
+ (*(pbuffer + 21));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_general_config(
+ pdata,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE,
+ comms_buffer,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE,
+ comms_buffer,
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_general_config(
+ VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_timing_config(
+ VL53L1_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->mm_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 1) =
+ pdata->mm_config__timeout_macrop_a_lo;
+ *(pbuffer + 2) =
+ pdata->mm_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 3) =
+ pdata->mm_config__timeout_macrop_b_lo;
+ *(pbuffer + 4) =
+ pdata->range_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 5) =
+ pdata->range_config__timeout_macrop_a_lo;
+ *(pbuffer + 6) =
+ pdata->range_config__vcsel_period_a & 0x3F;
+ *(pbuffer + 7) =
+ pdata->range_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 8) =
+ pdata->range_config__timeout_macrop_b_lo;
+ *(pbuffer + 9) =
+ pdata->range_config__vcsel_period_b & 0x3F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->range_config__sigma_thresh,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->range_config__min_count_rate_rtn_limit_mcps,
+ 2,
+ pbuffer + 12);
+ *(pbuffer + 14) =
+ pdata->range_config__valid_phase_low;
+ *(pbuffer + 15) =
+ pdata->range_config__valid_phase_high;
+ VL53L1_i2c_encode_uint32_t(
+ pdata->system__intermeasurement_period,
+ 4,
+ pbuffer + 18);
+ *(pbuffer + 22) =
+ pdata->system__fractional_enable & 0x1;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->mm_config__timeout_macrop_a_hi =
+ (*(pbuffer + 0)) & 0xF;
+ pdata->mm_config__timeout_macrop_a_lo =
+ (*(pbuffer + 1));
+ pdata->mm_config__timeout_macrop_b_hi =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->mm_config__timeout_macrop_b_lo =
+ (*(pbuffer + 3));
+ pdata->range_config__timeout_macrop_a_hi =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->range_config__timeout_macrop_a_lo =
+ (*(pbuffer + 5));
+ pdata->range_config__vcsel_period_a =
+ (*(pbuffer + 6)) & 0x3F;
+ pdata->range_config__timeout_macrop_b_hi =
+ (*(pbuffer + 7)) & 0xF;
+ pdata->range_config__timeout_macrop_b_lo =
+ (*(pbuffer + 8));
+ pdata->range_config__vcsel_period_b =
+ (*(pbuffer + 9)) & 0x3F;
+ pdata->range_config__sigma_thresh =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->range_config__min_count_rate_rtn_limit_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->range_config__valid_phase_low =
+ (*(pbuffer + 14));
+ pdata->range_config__valid_phase_high =
+ (*(pbuffer + 15));
+ pdata->system__intermeasurement_period =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 18));
+ pdata->system__fractional_enable =
+ (*(pbuffer + 22)) & 0x1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_timing_config(
+ pdata,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_timing_config(
+ VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_dynamic_config(
+ VL53L1_dynamic_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->system__grouped_parameter_hold_0 & 0x3;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_high,
+ 2,
+ pbuffer + 1);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->system__thresh_low,
+ 2,
+ pbuffer + 3);
+ *(pbuffer + 5) =
+ pdata->system__enable_xtalk_per_quadrant & 0x1;
+ *(pbuffer + 6) =
+ pdata->system__seed_config & 0x7;
+ *(pbuffer + 7) =
+ pdata->sd_config__woi_sd0;
+ *(pbuffer + 8) =
+ pdata->sd_config__woi_sd1;
+ *(pbuffer + 9) =
+ pdata->sd_config__initial_phase_sd0 & 0x7F;
+ *(pbuffer + 10) =
+ pdata->sd_config__initial_phase_sd1 & 0x7F;
+ *(pbuffer + 11) =
+ pdata->system__grouped_parameter_hold_1 & 0x3;
+ *(pbuffer + 12) =
+ pdata->sd_config__first_order_select & 0x3;
+ *(pbuffer + 13) =
+ pdata->sd_config__quantifier & 0xF;
+ *(pbuffer + 14) =
+ pdata->roi_config__user_roi_centre_spad;
+ *(pbuffer + 15) =
+ pdata->roi_config__user_roi_requested_global_xy_size;
+ *(pbuffer + 16) =
+ pdata->system__sequence_config;
+ *(pbuffer + 17) =
+ pdata->system__grouped_parameter_hold & 0x3;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_dynamic_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_dynamic_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->system__grouped_parameter_hold_0 =
+ (*(pbuffer + 0)) & 0x3;
+ pdata->system__thresh_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1));
+ pdata->system__thresh_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3));
+ pdata->system__enable_xtalk_per_quadrant =
+ (*(pbuffer + 5)) & 0x1;
+ pdata->system__seed_config =
+ (*(pbuffer + 6)) & 0x7;
+ pdata->sd_config__woi_sd0 =
+ (*(pbuffer + 7));
+ pdata->sd_config__woi_sd1 =
+ (*(pbuffer + 8));
+ pdata->sd_config__initial_phase_sd0 =
+ (*(pbuffer + 9)) & 0x7F;
+ pdata->sd_config__initial_phase_sd1 =
+ (*(pbuffer + 10)) & 0x7F;
+ pdata->system__grouped_parameter_hold_1 =
+ (*(pbuffer + 11)) & 0x3;
+ pdata->sd_config__first_order_select =
+ (*(pbuffer + 12)) & 0x3;
+ pdata->sd_config__quantifier =
+ (*(pbuffer + 13)) & 0xF;
+ pdata->roi_config__user_roi_centre_spad =
+ (*(pbuffer + 14));
+ pdata->roi_config__user_roi_requested_global_xy_size =
+ (*(pbuffer + 15));
+ pdata->system__sequence_config =
+ (*(pbuffer + 16));
+ pdata->system__grouped_parameter_hold =
+ (*(pbuffer + 17)) & 0x3;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_dynamic_config(
+ pdata,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0,
+ comms_buffer,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_dynamic_config(
+ VL53L1_DEV Dev,
+ VL53L1_dynamic_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0,
+ comms_buffer,
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_dynamic_config(
+ VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_system_control(
+ VL53L1_system_control_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->power_management__go1_power_force & 0x1;
+ *(pbuffer + 1) =
+ pdata->system__stream_count_ctrl & 0x1;
+ *(pbuffer + 2) =
+ pdata->firmware__enable & 0x1;
+ *(pbuffer + 3) =
+ pdata->system__interrupt_clear & 0x3;
+ *(pbuffer + 4) =
+ pdata->system__mode_start;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_system_control(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_control_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->power_management__go1_power_force =
+ (*(pbuffer + 0)) & 0x1;
+ pdata->system__stream_count_ctrl =
+ (*(pbuffer + 1)) & 0x1;
+ pdata->firmware__enable =
+ (*(pbuffer + 2)) & 0x1;
+ pdata->system__interrupt_clear =
+ (*(pbuffer + 3)) & 0x3;
+ pdata->system__mode_start =
+ (*(pbuffer + 4));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_system_control(
+ pdata,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE,
+ comms_buffer,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_system_control(
+ VL53L1_DEV Dev,
+ VL53L1_system_control_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE,
+ comms_buffer,
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_system_control(
+ VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_system_results(
+ VL53L1_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->result__interrupt_status & 0x3F;
+ *(pbuffer + 1) =
+ pdata->result__range_status;
+ *(pbuffer + 2) =
+ pdata->result__report_status & 0xF;
+ *(pbuffer + 3) =
+ pdata->result__stream_count;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__dss_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 4);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__peak_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 6);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__ambient_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__sigma_sd0,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__phase_sd0,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__final_crosstalk_corrected_range_mm_sd0,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0,
+ 2,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__mm_inner_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__mm_outer_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 20);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__avg_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__dss_actual_effective_spads_sd1,
+ 2,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__peak_signal_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 26);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__ambient_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 28);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__sigma_sd1,
+ 2,
+ pbuffer + 30);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__phase_sd1,
+ 2,
+ pbuffer + 32);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__final_crosstalk_corrected_range_mm_sd1,
+ 2,
+ pbuffer + 34);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__spare_0_sd1,
+ 2,
+ pbuffer + 36);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__spare_1_sd1,
+ 2,
+ pbuffer + 38);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__spare_2_sd1,
+ 2,
+ pbuffer + 40);
+ *(pbuffer + 42) =
+ pdata->result__spare_3_sd1;
+ *(pbuffer + 43) =
+ pdata->result__thresh_info;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->result__interrupt_status =
+ (*(pbuffer + 0)) & 0x3F;
+ pdata->result__range_status =
+ (*(pbuffer + 1));
+ pdata->result__report_status =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->result__stream_count =
+ (*(pbuffer + 3));
+ pdata->result__dss_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4));
+ pdata->result__peak_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6));
+ pdata->result__ambient_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8));
+ pdata->result__sigma_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->result__phase_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->result__final_crosstalk_corrected_range_mm_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->result__mm_inner_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18));
+ pdata->result__mm_outer_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20));
+ pdata->result__avg_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->result__dss_actual_effective_spads_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->result__peak_signal_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26));
+ pdata->result__ambient_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28));
+ pdata->result__sigma_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30));
+ pdata->result__phase_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32));
+ pdata->result__final_crosstalk_corrected_range_mm_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34));
+ pdata->result__spare_0_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36));
+ pdata->result__spare_1_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38));
+ pdata->result__spare_2_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40));
+ pdata->result__spare_3_sd1 =
+ (*(pbuffer + 42));
+ pdata->result__thresh_info =
+ (*(pbuffer + 43));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_system_results(
+ pdata,
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_system_results(
+ VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_core_results(
+ VL53L1_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_CORE_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ambient_window_events_sd0,
+ 4,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ranging_total_events_sd0,
+ 4,
+ pbuffer + 4);
+ VL53L1_i2c_encode_int32_t(
+ pdata->result_core__signal_total_events_sd0,
+ 4,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__total_periods_elapsed_sd0,
+ 4,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ambient_window_events_sd1,
+ 4,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__ranging_total_events_sd1,
+ 4,
+ pbuffer + 20);
+ VL53L1_i2c_encode_int32_t(
+ pdata->result_core__signal_total_events_sd1,
+ 4,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->result_core__total_periods_elapsed_sd1,
+ 4,
+ pbuffer + 28);
+ *(pbuffer + 32) =
+ pdata->result_core__spare_0;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_CORE_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->result_core__ambient_window_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0));
+ pdata->result_core__ranging_total_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4));
+ pdata->result_core__signal_total_events_sd0 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 8));
+ pdata->result_core__total_periods_elapsed_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12));
+ pdata->result_core__ambient_window_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16));
+ pdata->result_core__ranging_total_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20));
+ pdata->result_core__signal_total_events_sd1 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 24));
+ pdata->result_core__total_periods_elapsed_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28));
+ pdata->result_core__spare_0 =
+ (*(pbuffer + 32));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_core_results(
+ pdata,
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_core_results(
+ VL53L1_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_debug_results(
+ VL53L1_debug_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint16_t(
+ pdata->phasecal_result__reference_phase,
+ 2,
+ pbuffer + 0);
+ *(pbuffer + 2) =
+ pdata->phasecal_result__vcsel_start & 0x7F;
+ *(pbuffer + 3) =
+ pdata->ref_spad_char_result__num_actual_ref_spads & 0x3F;
+ *(pbuffer + 4) =
+ pdata->ref_spad_char_result__ref_location & 0x3;
+ *(pbuffer + 5) =
+ pdata->vhv_result__coldboot_status & 0x1;
+ *(pbuffer + 6) =
+ pdata->vhv_result__search_result & 0x3F;
+ *(pbuffer + 7) =
+ pdata->vhv_result__latest_setting & 0x3F;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->result__osc_calibrate_val & 0x3FF,
+ 2,
+ pbuffer + 8);
+ *(pbuffer + 10) =
+ pdata->ana_config__powerdown_go1 & 0x3;
+ *(pbuffer + 11) =
+ pdata->ana_config__ref_bg_ctrl & 0x3;
+ *(pbuffer + 12) =
+ pdata->ana_config__regdvdd1v2_ctrl & 0xF;
+ *(pbuffer + 13) =
+ pdata->ana_config__osc_slow_ctrl & 0x7;
+ *(pbuffer + 14) =
+ pdata->test_mode__status & 0x1;
+ *(pbuffer + 15) =
+ pdata->firmware__system_status & 0x3;
+ *(pbuffer + 16) =
+ pdata->firmware__mode_status;
+ *(pbuffer + 17) =
+ pdata->firmware__secondary_mode_status;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->firmware__cal_repeat_rate_counter & 0xFFF,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_high,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_low,
+ 2,
+ pbuffer + 24);
+ *(pbuffer + 26) =
+ pdata->gph__system__enable_xtalk_per_quadrant & 0x1;
+ *(pbuffer + 27) =
+ pdata->gph__spare_0 & 0x7;
+ *(pbuffer + 28) =
+ pdata->gph__sd_config__woi_sd0;
+ *(pbuffer + 29) =
+ pdata->gph__sd_config__woi_sd1;
+ *(pbuffer + 30) =
+ pdata->gph__sd_config__initial_phase_sd0 & 0x7F;
+ *(pbuffer + 31) =
+ pdata->gph__sd_config__initial_phase_sd1 & 0x7F;
+ *(pbuffer + 32) =
+ pdata->gph__sd_config__first_order_select & 0x3;
+ *(pbuffer + 33) =
+ pdata->gph__sd_config__quantifier & 0xF;
+ *(pbuffer + 34) =
+ pdata->gph__roi_config__user_roi_centre_spad;
+ *(pbuffer + 35) =
+ pdata->gph__roi_config__user_roi_requested_global_xy_size;
+ *(pbuffer + 36) =
+ pdata->gph__system__sequence_config;
+ *(pbuffer + 37) =
+ pdata->gph__gph_id & 0x1;
+ *(pbuffer + 38) =
+ pdata->system__interrupt_set & 0x3;
+ *(pbuffer + 39) =
+ pdata->interrupt_manager__enables & 0x1F;
+ *(pbuffer + 40) =
+ pdata->interrupt_manager__clear & 0x1F;
+ *(pbuffer + 41) =
+ pdata->interrupt_manager__status & 0x1F;
+ *(pbuffer + 42) =
+ pdata->mcu_to_host_bank__wr_access_en & 0x1;
+ *(pbuffer + 43) =
+ pdata->power_management__go1_reset_status & 0x1;
+ *(pbuffer + 44) =
+ pdata->pad_startup_mode__value_ro & 0x3;
+ *(pbuffer + 45) =
+ pdata->pad_startup_mode__value_ctrl & 0x3F;
+ VL53L1_i2c_encode_uint32_t(
+ pdata->pll_period_us & 0x3FFFF,
+ 4,
+ pbuffer + 46);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->interrupt_scheduler__data_out,
+ 4,
+ pbuffer + 50);
+ *(pbuffer + 54) =
+ pdata->nvm_bist__complete & 0x1;
+ *(pbuffer + 55) =
+ pdata->nvm_bist__status & 0x1;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_debug_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_debug_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->phasecal_result__reference_phase =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0));
+ pdata->phasecal_result__vcsel_start =
+ (*(pbuffer + 2)) & 0x7F;
+ pdata->ref_spad_char_result__num_actual_ref_spads =
+ (*(pbuffer + 3)) & 0x3F;
+ pdata->ref_spad_char_result__ref_location =
+ (*(pbuffer + 4)) & 0x3;
+ pdata->vhv_result__coldboot_status =
+ (*(pbuffer + 5)) & 0x1;
+ pdata->vhv_result__search_result =
+ (*(pbuffer + 6)) & 0x3F;
+ pdata->vhv_result__latest_setting =
+ (*(pbuffer + 7)) & 0x3F;
+ pdata->result__osc_calibrate_val =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)) & 0x3FF;
+ pdata->ana_config__powerdown_go1 =
+ (*(pbuffer + 10)) & 0x3;
+ pdata->ana_config__ref_bg_ctrl =
+ (*(pbuffer + 11)) & 0x3;
+ pdata->ana_config__regdvdd1v2_ctrl =
+ (*(pbuffer + 12)) & 0xF;
+ pdata->ana_config__osc_slow_ctrl =
+ (*(pbuffer + 13)) & 0x7;
+ pdata->test_mode__status =
+ (*(pbuffer + 14)) & 0x1;
+ pdata->firmware__system_status =
+ (*(pbuffer + 15)) & 0x3;
+ pdata->firmware__mode_status =
+ (*(pbuffer + 16));
+ pdata->firmware__secondary_mode_status =
+ (*(pbuffer + 17));
+ pdata->firmware__cal_repeat_rate_counter =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)) & 0xFFF;
+ pdata->gph__system__thresh_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->gph__system__thresh_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->gph__system__enable_xtalk_per_quadrant =
+ (*(pbuffer + 26)) & 0x1;
+ pdata->gph__spare_0 =
+ (*(pbuffer + 27)) & 0x7;
+ pdata->gph__sd_config__woi_sd0 =
+ (*(pbuffer + 28));
+ pdata->gph__sd_config__woi_sd1 =
+ (*(pbuffer + 29));
+ pdata->gph__sd_config__initial_phase_sd0 =
+ (*(pbuffer + 30)) & 0x7F;
+ pdata->gph__sd_config__initial_phase_sd1 =
+ (*(pbuffer + 31)) & 0x7F;
+ pdata->gph__sd_config__first_order_select =
+ (*(pbuffer + 32)) & 0x3;
+ pdata->gph__sd_config__quantifier =
+ (*(pbuffer + 33)) & 0xF;
+ pdata->gph__roi_config__user_roi_centre_spad =
+ (*(pbuffer + 34));
+ pdata->gph__roi_config__user_roi_requested_global_xy_size =
+ (*(pbuffer + 35));
+ pdata->gph__system__sequence_config =
+ (*(pbuffer + 36));
+ pdata->gph__gph_id =
+ (*(pbuffer + 37)) & 0x1;
+ pdata->system__interrupt_set =
+ (*(pbuffer + 38)) & 0x3;
+ pdata->interrupt_manager__enables =
+ (*(pbuffer + 39)) & 0x1F;
+ pdata->interrupt_manager__clear =
+ (*(pbuffer + 40)) & 0x1F;
+ pdata->interrupt_manager__status =
+ (*(pbuffer + 41)) & 0x1F;
+ pdata->mcu_to_host_bank__wr_access_en =
+ (*(pbuffer + 42)) & 0x1;
+ pdata->power_management__go1_reset_status =
+ (*(pbuffer + 43)) & 0x1;
+ pdata->pad_startup_mode__value_ro =
+ (*(pbuffer + 44)) & 0x3;
+ pdata->pad_startup_mode__value_ctrl =
+ (*(pbuffer + 45)) & 0x3F;
+ pdata->pll_period_us =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 46)) & 0x3FFFF;
+ pdata->interrupt_scheduler__data_out =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 50));
+ pdata->nvm_bist__complete =
+ (*(pbuffer + 54)) & 0x1;
+ pdata->nvm_bist__status =
+ (*(pbuffer + 55)) & 0x1;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_debug_results(
+ pdata,
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_PHASECAL_RESULT__REFERENCE_PHASE,
+ comms_buffer,
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_debug_results(
+ VL53L1_DEV Dev,
+ VL53L1_debug_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PHASECAL_RESULT__REFERENCE_PHASE,
+ comms_buffer,
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_debug_results(
+ VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_nvm_copy_data(
+ VL53L1_nvm_copy_data_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->identification__model_id;
+ *(pbuffer + 1) =
+ pdata->identification__module_type;
+ *(pbuffer + 2) =
+ pdata->identification__revision_id;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->identification__module_id,
+ 2,
+ pbuffer + 3);
+ *(pbuffer + 5) =
+ pdata->ana_config__fast_osc__trim_max & 0x7F;
+ *(pbuffer + 6) =
+ pdata->ana_config__fast_osc__freq_set & 0x7;
+ *(pbuffer + 7) =
+ pdata->ana_config__vcsel_trim & 0x7;
+ *(pbuffer + 8) =
+ pdata->ana_config__vcsel_selion & 0x3F;
+ *(pbuffer + 9) =
+ pdata->ana_config__vcsel_selion_max & 0x3F;
+ *(pbuffer + 10) =
+ pdata->protected_laser_safety__lock_bit & 0x1;
+ *(pbuffer + 11) =
+ pdata->laser_safety__key & 0x7F;
+ *(pbuffer + 12) =
+ pdata->laser_safety__key_ro & 0x1;
+ *(pbuffer + 13) =
+ pdata->laser_safety__clip & 0x3F;
+ *(pbuffer + 14) =
+ pdata->laser_safety__mult & 0x3F;
+ *(pbuffer + 15) =
+ pdata->global_config__spad_enables_rtn_0;
+ *(pbuffer + 16) =
+ pdata->global_config__spad_enables_rtn_1;
+ *(pbuffer + 17) =
+ pdata->global_config__spad_enables_rtn_2;
+ *(pbuffer + 18) =
+ pdata->global_config__spad_enables_rtn_3;
+ *(pbuffer + 19) =
+ pdata->global_config__spad_enables_rtn_4;
+ *(pbuffer + 20) =
+ pdata->global_config__spad_enables_rtn_5;
+ *(pbuffer + 21) =
+ pdata->global_config__spad_enables_rtn_6;
+ *(pbuffer + 22) =
+ pdata->global_config__spad_enables_rtn_7;
+ *(pbuffer + 23) =
+ pdata->global_config__spad_enables_rtn_8;
+ *(pbuffer + 24) =
+ pdata->global_config__spad_enables_rtn_9;
+ *(pbuffer + 25) =
+ pdata->global_config__spad_enables_rtn_10;
+ *(pbuffer + 26) =
+ pdata->global_config__spad_enables_rtn_11;
+ *(pbuffer + 27) =
+ pdata->global_config__spad_enables_rtn_12;
+ *(pbuffer + 28) =
+ pdata->global_config__spad_enables_rtn_13;
+ *(pbuffer + 29) =
+ pdata->global_config__spad_enables_rtn_14;
+ *(pbuffer + 30) =
+ pdata->global_config__spad_enables_rtn_15;
+ *(pbuffer + 31) =
+ pdata->global_config__spad_enables_rtn_16;
+ *(pbuffer + 32) =
+ pdata->global_config__spad_enables_rtn_17;
+ *(pbuffer + 33) =
+ pdata->global_config__spad_enables_rtn_18;
+ *(pbuffer + 34) =
+ pdata->global_config__spad_enables_rtn_19;
+ *(pbuffer + 35) =
+ pdata->global_config__spad_enables_rtn_20;
+ *(pbuffer + 36) =
+ pdata->global_config__spad_enables_rtn_21;
+ *(pbuffer + 37) =
+ pdata->global_config__spad_enables_rtn_22;
+ *(pbuffer + 38) =
+ pdata->global_config__spad_enables_rtn_23;
+ *(pbuffer + 39) =
+ pdata->global_config__spad_enables_rtn_24;
+ *(pbuffer + 40) =
+ pdata->global_config__spad_enables_rtn_25;
+ *(pbuffer + 41) =
+ pdata->global_config__spad_enables_rtn_26;
+ *(pbuffer + 42) =
+ pdata->global_config__spad_enables_rtn_27;
+ *(pbuffer + 43) =
+ pdata->global_config__spad_enables_rtn_28;
+ *(pbuffer + 44) =
+ pdata->global_config__spad_enables_rtn_29;
+ *(pbuffer + 45) =
+ pdata->global_config__spad_enables_rtn_30;
+ *(pbuffer + 46) =
+ pdata->global_config__spad_enables_rtn_31;
+ *(pbuffer + 47) =
+ pdata->roi_config__mode_roi_centre_spad;
+ *(pbuffer + 48) =
+ pdata->roi_config__mode_roi_xy_size;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_nvm_copy_data(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_nvm_copy_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->identification__model_id =
+ (*(pbuffer + 0));
+ pdata->identification__module_type =
+ (*(pbuffer + 1));
+ pdata->identification__revision_id =
+ (*(pbuffer + 2));
+ pdata->identification__module_id =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3));
+ pdata->ana_config__fast_osc__trim_max =
+ (*(pbuffer + 5)) & 0x7F;
+ pdata->ana_config__fast_osc__freq_set =
+ (*(pbuffer + 6)) & 0x7;
+ pdata->ana_config__vcsel_trim =
+ (*(pbuffer + 7)) & 0x7;
+ pdata->ana_config__vcsel_selion =
+ (*(pbuffer + 8)) & 0x3F;
+ pdata->ana_config__vcsel_selion_max =
+ (*(pbuffer + 9)) & 0x3F;
+ pdata->protected_laser_safety__lock_bit =
+ (*(pbuffer + 10)) & 0x1;
+ pdata->laser_safety__key =
+ (*(pbuffer + 11)) & 0x7F;
+ pdata->laser_safety__key_ro =
+ (*(pbuffer + 12)) & 0x1;
+ pdata->laser_safety__clip =
+ (*(pbuffer + 13)) & 0x3F;
+ pdata->laser_safety__mult =
+ (*(pbuffer + 14)) & 0x3F;
+ pdata->global_config__spad_enables_rtn_0 =
+ (*(pbuffer + 15));
+ pdata->global_config__spad_enables_rtn_1 =
+ (*(pbuffer + 16));
+ pdata->global_config__spad_enables_rtn_2 =
+ (*(pbuffer + 17));
+ pdata->global_config__spad_enables_rtn_3 =
+ (*(pbuffer + 18));
+ pdata->global_config__spad_enables_rtn_4 =
+ (*(pbuffer + 19));
+ pdata->global_config__spad_enables_rtn_5 =
+ (*(pbuffer + 20));
+ pdata->global_config__spad_enables_rtn_6 =
+ (*(pbuffer + 21));
+ pdata->global_config__spad_enables_rtn_7 =
+ (*(pbuffer + 22));
+ pdata->global_config__spad_enables_rtn_8 =
+ (*(pbuffer + 23));
+ pdata->global_config__spad_enables_rtn_9 =
+ (*(pbuffer + 24));
+ pdata->global_config__spad_enables_rtn_10 =
+ (*(pbuffer + 25));
+ pdata->global_config__spad_enables_rtn_11 =
+ (*(pbuffer + 26));
+ pdata->global_config__spad_enables_rtn_12 =
+ (*(pbuffer + 27));
+ pdata->global_config__spad_enables_rtn_13 =
+ (*(pbuffer + 28));
+ pdata->global_config__spad_enables_rtn_14 =
+ (*(pbuffer + 29));
+ pdata->global_config__spad_enables_rtn_15 =
+ (*(pbuffer + 30));
+ pdata->global_config__spad_enables_rtn_16 =
+ (*(pbuffer + 31));
+ pdata->global_config__spad_enables_rtn_17 =
+ (*(pbuffer + 32));
+ pdata->global_config__spad_enables_rtn_18 =
+ (*(pbuffer + 33));
+ pdata->global_config__spad_enables_rtn_19 =
+ (*(pbuffer + 34));
+ pdata->global_config__spad_enables_rtn_20 =
+ (*(pbuffer + 35));
+ pdata->global_config__spad_enables_rtn_21 =
+ (*(pbuffer + 36));
+ pdata->global_config__spad_enables_rtn_22 =
+ (*(pbuffer + 37));
+ pdata->global_config__spad_enables_rtn_23 =
+ (*(pbuffer + 38));
+ pdata->global_config__spad_enables_rtn_24 =
+ (*(pbuffer + 39));
+ pdata->global_config__spad_enables_rtn_25 =
+ (*(pbuffer + 40));
+ pdata->global_config__spad_enables_rtn_26 =
+ (*(pbuffer + 41));
+ pdata->global_config__spad_enables_rtn_27 =
+ (*(pbuffer + 42));
+ pdata->global_config__spad_enables_rtn_28 =
+ (*(pbuffer + 43));
+ pdata->global_config__spad_enables_rtn_29 =
+ (*(pbuffer + 44));
+ pdata->global_config__spad_enables_rtn_30 =
+ (*(pbuffer + 45));
+ pdata->global_config__spad_enables_rtn_31 =
+ (*(pbuffer + 46));
+ pdata->roi_config__mode_roi_centre_spad =
+ (*(pbuffer + 47));
+ pdata->roi_config__mode_roi_xy_size =
+ (*(pbuffer + 48));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_nvm_copy_data(
+ pdata,
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_IDENTIFICATION__MODEL_ID,
+ comms_buffer,
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_nvm_copy_data(
+ VL53L1_DEV Dev,
+ VL53L1_nvm_copy_data_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_IDENTIFICATION__MODEL_ID,
+ comms_buffer,
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_nvm_copy_data(
+ VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_system_results(
+ VL53L1_prev_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->prev_shadow_result__interrupt_status & 0x3F;
+ *(pbuffer + 1) =
+ pdata->prev_shadow_result__range_status;
+ *(pbuffer + 2) =
+ pdata->prev_shadow_result__report_status & 0xF;
+ *(pbuffer + 3) =
+ pdata->prev_shadow_result__stream_count;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 4);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 6);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__sigma_sd0,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__phase_sd0,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->psr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0,
+ 2,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 20);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd1,
+ 2,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 26);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 28);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__sigma_sd1,
+ 2,
+ pbuffer + 30);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__phase_sd1,
+ 2,
+ pbuffer + 32);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1,
+ 2,
+ pbuffer + 34);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_0_sd1,
+ 2,
+ pbuffer + 36);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_1_sd1,
+ 2,
+ pbuffer + 38);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_2_sd1,
+ 2,
+ pbuffer + 40);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->prev_shadow_result__spare_3_sd1,
+ 2,
+ pbuffer + 42);
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->prev_shadow_result__interrupt_status =
+ (*(pbuffer + 0)) & 0x3F;
+ pdata->prev_shadow_result__range_status =
+ (*(pbuffer + 1));
+ pdata->prev_shadow_result__report_status =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->prev_shadow_result__stream_count =
+ (*(pbuffer + 3));
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4));
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6));
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8));
+ pdata->prev_shadow_result__sigma_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->prev_shadow_result__phase_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->psr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18));
+ pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20));
+ pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->prev_shadow_result__dss_actual_effective_spads_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26));
+ pdata->prev_shadow_result__ambient_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28));
+ pdata->prev_shadow_result__sigma_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30));
+ pdata->prev_shadow_result__phase_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32));
+ pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34));
+ pdata->prev_shadow_result__spare_0_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36));
+ pdata->prev_shadow_result__spare_1_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38));
+ pdata->prev_shadow_result__spare_2_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40));
+ pdata->prev_shadow_result__spare_3_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_prev_shadow_system_results(
+ pdata,
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_prev_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_prev_shadow_system_results(
+ VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_prev_shadow_core_results(
+ VL53L1_prev_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ambient_window_events_sd0,
+ 4,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ranging_total_events_sd0,
+ 4,
+ pbuffer + 4);
+ VL53L1_i2c_encode_int32_t(
+ pdata->prev_shadow_result_core__signal_total_events_sd0,
+ 4,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd0,
+ 4,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ambient_window_events_sd1,
+ 4,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__ranging_total_events_sd1,
+ 4,
+ pbuffer + 20);
+ VL53L1_i2c_encode_int32_t(
+ pdata->prev_shadow_result_core__signal_total_events_sd1,
+ 4,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd1,
+ 4,
+ pbuffer + 28);
+ *(pbuffer + 32) =
+ pdata->prev_shadow_result_core__spare_0;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_prev_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_prev_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->prev_shadow_result_core__ambient_window_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0));
+ pdata->prev_shadow_result_core__ranging_total_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4));
+ pdata->prev_shadow_result_core__signal_total_events_sd0 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 8));
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12));
+ pdata->prev_shadow_result_core__ambient_window_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16));
+ pdata->prev_shadow_result_core__ranging_total_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20));
+ pdata->prev_shadow_result_core__signal_total_events_sd1 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 24));
+ pdata->prev_shadow_result_core__total_periods_elapsed_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28));
+ pdata->prev_shadow_result_core__spare_0 =
+ (*(pbuffer + 32));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_prev_shadow_core_results(
+ pdata,
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_prev_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_prev_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_prev_shadow_core_results(
+ VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_debug(
+ VL53L1_patch_debug_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->result__debug_status;
+ *(pbuffer + 1) =
+ pdata->result__debug_stage;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_debug(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_debug_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->result__debug_status =
+ (*(pbuffer + 0));
+ pdata->result__debug_stage =
+ (*(pbuffer + 1));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_patch_debug(
+ pdata,
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_RESULT__DEBUG_STATUS,
+ comms_buffer,
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_patch_debug(
+ VL53L1_DEV Dev,
+ VL53L1_patch_debug_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_RESULT__DEBUG_STATUS,
+ comms_buffer,
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_patch_debug(
+ VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_general_config(
+ VL53L1_gph_general_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_rate_high,
+ 2,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__system__thresh_rate_low,
+ 2,
+ pbuffer + 2);
+ *(pbuffer + 4) =
+ pdata->gph__system__interrupt_config_gpio;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_general_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph__system__thresh_rate_high =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0));
+ pdata->gph__system__thresh_rate_low =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 2));
+ pdata->gph__system__interrupt_config_gpio =
+ (*(pbuffer + 4));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_gph_general_config(
+ pdata,
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH,
+ comms_buffer,
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_gph_general_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_general_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH,
+ comms_buffer,
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_gph_general_config(
+ VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_static_config(
+ VL53L1_gph_static_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->gph__dss_config__roi_mode_control & 0x7;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__dss_config__manual_effective_spads_select,
+ 2,
+ pbuffer + 1);
+ *(pbuffer + 3) =
+ pdata->gph__dss_config__manual_block_select;
+ *(pbuffer + 4) =
+ pdata->gph__dss_config__max_spads_limit;
+ *(pbuffer + 5) =
+ pdata->gph__dss_config__min_spads_limit;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_static_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph__dss_config__roi_mode_control =
+ (*(pbuffer + 0)) & 0x7;
+ pdata->gph__dss_config__manual_effective_spads_select =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1));
+ pdata->gph__dss_config__manual_block_select =
+ (*(pbuffer + 3));
+ pdata->gph__dss_config__max_spads_limit =
+ (*(pbuffer + 4));
+ pdata->gph__dss_config__min_spads_limit =
+ (*(pbuffer + 5));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_gph_static_config(
+ pdata,
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL,
+ comms_buffer,
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_gph_static_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_static_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL,
+ comms_buffer,
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_gph_static_config(
+ VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_gph_timing_config(
+ VL53L1_gph_timing_config_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->gph__mm_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 1) =
+ pdata->gph__mm_config__timeout_macrop_a_lo;
+ *(pbuffer + 2) =
+ pdata->gph__mm_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 3) =
+ pdata->gph__mm_config__timeout_macrop_b_lo;
+ *(pbuffer + 4) =
+ pdata->gph__range_config__timeout_macrop_a_hi & 0xF;
+ *(pbuffer + 5) =
+ pdata->gph__range_config__timeout_macrop_a_lo;
+ *(pbuffer + 6) =
+ pdata->gph__range_config__vcsel_period_a & 0x3F;
+ *(pbuffer + 7) =
+ pdata->gph__range_config__vcsel_period_b & 0x3F;
+ *(pbuffer + 8) =
+ pdata->gph__range_config__timeout_macrop_b_hi & 0xF;
+ *(pbuffer + 9) =
+ pdata->gph__range_config__timeout_macrop_b_lo;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__range_config__sigma_thresh,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->gph__range_config__min_count_rate_rtn_limit_mcps,
+ 2,
+ pbuffer + 12);
+ *(pbuffer + 14) =
+ pdata->gph__range_config__valid_phase_low;
+ *(pbuffer + 15) =
+ pdata->gph__range_config__valid_phase_high;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_gph_timing_config(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_gph_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->gph__mm_config__timeout_macrop_a_hi =
+ (*(pbuffer + 0)) & 0xF;
+ pdata->gph__mm_config__timeout_macrop_a_lo =
+ (*(pbuffer + 1));
+ pdata->gph__mm_config__timeout_macrop_b_hi =
+ (*(pbuffer + 2)) & 0xF;
+ pdata->gph__mm_config__timeout_macrop_b_lo =
+ (*(pbuffer + 3));
+ pdata->gph__range_config__timeout_macrop_a_hi =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->gph__range_config__timeout_macrop_a_lo =
+ (*(pbuffer + 5));
+ pdata->gph__range_config__vcsel_period_a =
+ (*(pbuffer + 6)) & 0x3F;
+ pdata->gph__range_config__vcsel_period_b =
+ (*(pbuffer + 7)) & 0x3F;
+ pdata->gph__range_config__timeout_macrop_b_hi =
+ (*(pbuffer + 8)) & 0xF;
+ pdata->gph__range_config__timeout_macrop_b_lo =
+ (*(pbuffer + 9));
+ pdata->gph__range_config__sigma_thresh =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->gph__range_config__min_count_rate_rtn_limit_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->gph__range_config__valid_phase_low =
+ (*(pbuffer + 14));
+ pdata->gph__range_config__valid_phase_high =
+ (*(pbuffer + 15));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_gph_timing_config(
+ pdata,
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_gph_timing_config(
+ VL53L1_DEV Dev,
+ VL53L1_gph_timing_config_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI,
+ comms_buffer,
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_gph_timing_config(
+ VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_fw_internal(
+ VL53L1_fw_internal_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_FW_INTERNAL_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->firmware__internal_stream_count_div;
+ *(pbuffer + 1) =
+ pdata->firmware__internal_stream_counter_val;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_fw_internal(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_fw_internal_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_FW_INTERNAL_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->firmware__internal_stream_count_div =
+ (*(pbuffer + 0));
+ pdata->firmware__internal_stream_counter_val =
+ (*(pbuffer + 1));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_fw_internal(
+ pdata,
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV,
+ comms_buffer,
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_fw_internal(
+ VL53L1_DEV Dev,
+ VL53L1_fw_internal_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV,
+ comms_buffer,
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_fw_internal(
+ VL53L1_FW_INTERNAL_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_patch_results(
+ VL53L1_patch_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->dss_calc__roi_ctrl & 0x3;
+ *(pbuffer + 1) =
+ pdata->dss_calc__spare_1;
+ *(pbuffer + 2) =
+ pdata->dss_calc__spare_2;
+ *(pbuffer + 3) =
+ pdata->dss_calc__spare_3;
+ *(pbuffer + 4) =
+ pdata->dss_calc__spare_4;
+ *(pbuffer + 5) =
+ pdata->dss_calc__spare_5;
+ *(pbuffer + 6) =
+ pdata->dss_calc__spare_6;
+ *(pbuffer + 7) =
+ pdata->dss_calc__spare_7;
+ *(pbuffer + 8) =
+ pdata->dss_calc__user_roi_spad_en_0;
+ *(pbuffer + 9) =
+ pdata->dss_calc__user_roi_spad_en_1;
+ *(pbuffer + 10) =
+ pdata->dss_calc__user_roi_spad_en_2;
+ *(pbuffer + 11) =
+ pdata->dss_calc__user_roi_spad_en_3;
+ *(pbuffer + 12) =
+ pdata->dss_calc__user_roi_spad_en_4;
+ *(pbuffer + 13) =
+ pdata->dss_calc__user_roi_spad_en_5;
+ *(pbuffer + 14) =
+ pdata->dss_calc__user_roi_spad_en_6;
+ *(pbuffer + 15) =
+ pdata->dss_calc__user_roi_spad_en_7;
+ *(pbuffer + 16) =
+ pdata->dss_calc__user_roi_spad_en_8;
+ *(pbuffer + 17) =
+ pdata->dss_calc__user_roi_spad_en_9;
+ *(pbuffer + 18) =
+ pdata->dss_calc__user_roi_spad_en_10;
+ *(pbuffer + 19) =
+ pdata->dss_calc__user_roi_spad_en_11;
+ *(pbuffer + 20) =
+ pdata->dss_calc__user_roi_spad_en_12;
+ *(pbuffer + 21) =
+ pdata->dss_calc__user_roi_spad_en_13;
+ *(pbuffer + 22) =
+ pdata->dss_calc__user_roi_spad_en_14;
+ *(pbuffer + 23) =
+ pdata->dss_calc__user_roi_spad_en_15;
+ *(pbuffer + 24) =
+ pdata->dss_calc__user_roi_spad_en_16;
+ *(pbuffer + 25) =
+ pdata->dss_calc__user_roi_spad_en_17;
+ *(pbuffer + 26) =
+ pdata->dss_calc__user_roi_spad_en_18;
+ *(pbuffer + 27) =
+ pdata->dss_calc__user_roi_spad_en_19;
+ *(pbuffer + 28) =
+ pdata->dss_calc__user_roi_spad_en_20;
+ *(pbuffer + 29) =
+ pdata->dss_calc__user_roi_spad_en_21;
+ *(pbuffer + 30) =
+ pdata->dss_calc__user_roi_spad_en_22;
+ *(pbuffer + 31) =
+ pdata->dss_calc__user_roi_spad_en_23;
+ *(pbuffer + 32) =
+ pdata->dss_calc__user_roi_spad_en_24;
+ *(pbuffer + 33) =
+ pdata->dss_calc__user_roi_spad_en_25;
+ *(pbuffer + 34) =
+ pdata->dss_calc__user_roi_spad_en_26;
+ *(pbuffer + 35) =
+ pdata->dss_calc__user_roi_spad_en_27;
+ *(pbuffer + 36) =
+ pdata->dss_calc__user_roi_spad_en_28;
+ *(pbuffer + 37) =
+ pdata->dss_calc__user_roi_spad_en_29;
+ *(pbuffer + 38) =
+ pdata->dss_calc__user_roi_spad_en_30;
+ *(pbuffer + 39) =
+ pdata->dss_calc__user_roi_spad_en_31;
+ *(pbuffer + 40) =
+ pdata->dss_calc__user_roi_0;
+ *(pbuffer + 41) =
+ pdata->dss_calc__user_roi_1;
+ *(pbuffer + 42) =
+ pdata->dss_calc__mode_roi_0;
+ *(pbuffer + 43) =
+ pdata->dss_calc__mode_roi_1;
+ *(pbuffer + 44) =
+ pdata->sigma_estimator_calc__spare_0;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->vhv_result__peak_signal_rate_mcps,
+ 2,
+ pbuffer + 46);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->vhv_result__signal_total_events_ref,
+ 4,
+ pbuffer + 48);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->phasecal_result__phase_output_ref,
+ 2,
+ pbuffer + 52);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_result__total_rate_per_spad,
+ 2,
+ pbuffer + 54);
+ *(pbuffer + 56) =
+ pdata->dss_result__enabled_blocks;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->dss_result__num_requested_spads,
+ 2,
+ pbuffer + 58);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->mm_result__inner_intersection_rate,
+ 2,
+ pbuffer + 62);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->mm_result__outer_complement_rate,
+ 2,
+ pbuffer + 64);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->mm_result__total_offset,
+ 2,
+ pbuffer + 66);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_calc__xtalk_for_enabled_spads & 0xFFFFFF,
+ 4,
+ pbuffer + 68);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_result__avg_xtalk_user_roi_kcps & 0xFFFFFF,
+ 4,
+ pbuffer + 72);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps & 0xFFFFFF,
+ 4,
+ pbuffer + 76);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps & 0xFFFFFF,
+ 4,
+ pbuffer + 80);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->range_result__accum_phase,
+ 4,
+ pbuffer + 84);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->range_result__offset_corrected_range,
+ 2,
+ pbuffer + 88);
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_patch_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_patch_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->dss_calc__roi_ctrl =
+ (*(pbuffer + 0)) & 0x3;
+ pdata->dss_calc__spare_1 =
+ (*(pbuffer + 1));
+ pdata->dss_calc__spare_2 =
+ (*(pbuffer + 2));
+ pdata->dss_calc__spare_3 =
+ (*(pbuffer + 3));
+ pdata->dss_calc__spare_4 =
+ (*(pbuffer + 4));
+ pdata->dss_calc__spare_5 =
+ (*(pbuffer + 5));
+ pdata->dss_calc__spare_6 =
+ (*(pbuffer + 6));
+ pdata->dss_calc__spare_7 =
+ (*(pbuffer + 7));
+ pdata->dss_calc__user_roi_spad_en_0 =
+ (*(pbuffer + 8));
+ pdata->dss_calc__user_roi_spad_en_1 =
+ (*(pbuffer + 9));
+ pdata->dss_calc__user_roi_spad_en_2 =
+ (*(pbuffer + 10));
+ pdata->dss_calc__user_roi_spad_en_3 =
+ (*(pbuffer + 11));
+ pdata->dss_calc__user_roi_spad_en_4 =
+ (*(pbuffer + 12));
+ pdata->dss_calc__user_roi_spad_en_5 =
+ (*(pbuffer + 13));
+ pdata->dss_calc__user_roi_spad_en_6 =
+ (*(pbuffer + 14));
+ pdata->dss_calc__user_roi_spad_en_7 =
+ (*(pbuffer + 15));
+ pdata->dss_calc__user_roi_spad_en_8 =
+ (*(pbuffer + 16));
+ pdata->dss_calc__user_roi_spad_en_9 =
+ (*(pbuffer + 17));
+ pdata->dss_calc__user_roi_spad_en_10 =
+ (*(pbuffer + 18));
+ pdata->dss_calc__user_roi_spad_en_11 =
+ (*(pbuffer + 19));
+ pdata->dss_calc__user_roi_spad_en_12 =
+ (*(pbuffer + 20));
+ pdata->dss_calc__user_roi_spad_en_13 =
+ (*(pbuffer + 21));
+ pdata->dss_calc__user_roi_spad_en_14 =
+ (*(pbuffer + 22));
+ pdata->dss_calc__user_roi_spad_en_15 =
+ (*(pbuffer + 23));
+ pdata->dss_calc__user_roi_spad_en_16 =
+ (*(pbuffer + 24));
+ pdata->dss_calc__user_roi_spad_en_17 =
+ (*(pbuffer + 25));
+ pdata->dss_calc__user_roi_spad_en_18 =
+ (*(pbuffer + 26));
+ pdata->dss_calc__user_roi_spad_en_19 =
+ (*(pbuffer + 27));
+ pdata->dss_calc__user_roi_spad_en_20 =
+ (*(pbuffer + 28));
+ pdata->dss_calc__user_roi_spad_en_21 =
+ (*(pbuffer + 29));
+ pdata->dss_calc__user_roi_spad_en_22 =
+ (*(pbuffer + 30));
+ pdata->dss_calc__user_roi_spad_en_23 =
+ (*(pbuffer + 31));
+ pdata->dss_calc__user_roi_spad_en_24 =
+ (*(pbuffer + 32));
+ pdata->dss_calc__user_roi_spad_en_25 =
+ (*(pbuffer + 33));
+ pdata->dss_calc__user_roi_spad_en_26 =
+ (*(pbuffer + 34));
+ pdata->dss_calc__user_roi_spad_en_27 =
+ (*(pbuffer + 35));
+ pdata->dss_calc__user_roi_spad_en_28 =
+ (*(pbuffer + 36));
+ pdata->dss_calc__user_roi_spad_en_29 =
+ (*(pbuffer + 37));
+ pdata->dss_calc__user_roi_spad_en_30 =
+ (*(pbuffer + 38));
+ pdata->dss_calc__user_roi_spad_en_31 =
+ (*(pbuffer + 39));
+ pdata->dss_calc__user_roi_0 =
+ (*(pbuffer + 40));
+ pdata->dss_calc__user_roi_1 =
+ (*(pbuffer + 41));
+ pdata->dss_calc__mode_roi_0 =
+ (*(pbuffer + 42));
+ pdata->dss_calc__mode_roi_1 =
+ (*(pbuffer + 43));
+ pdata->sigma_estimator_calc__spare_0 =
+ (*(pbuffer + 44));
+ pdata->vhv_result__peak_signal_rate_mcps =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 46));
+ pdata->vhv_result__signal_total_events_ref =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 48));
+ pdata->phasecal_result__phase_output_ref =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 52));
+ pdata->dss_result__total_rate_per_spad =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 54));
+ pdata->dss_result__enabled_blocks =
+ (*(pbuffer + 56));
+ pdata->dss_result__num_requested_spads =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 58));
+ pdata->mm_result__inner_intersection_rate =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 62));
+ pdata->mm_result__outer_complement_rate =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 64));
+ pdata->mm_result__total_offset =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 66));
+ pdata->xtalk_calc__xtalk_for_enabled_spads =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 68)) & 0xFFFFFF;
+ pdata->xtalk_result__avg_xtalk_user_roi_kcps =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 72)) & 0xFFFFFF;
+ pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 76)) & 0xFFFFFF;
+ pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 80)) & 0xFFFFFF;
+ pdata->range_result__accum_phase =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 84));
+ pdata->range_result__offset_corrected_range =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 88));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_patch_results(
+ pdata,
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_DSS_CALC__ROI_CTRL,
+ comms_buffer,
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_patch_results(
+ VL53L1_DEV Dev,
+ VL53L1_patch_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_DSS_CALC__ROI_CTRL,
+ comms_buffer,
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_patch_results(
+ VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_system_results(
+ VL53L1_shadow_system_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ *(pbuffer + 0) =
+ pdata->shadow_phasecal_result__vcsel_start;
+ *(pbuffer + 2) =
+ pdata->shadow_result__interrupt_status & 0x3F;
+ *(pbuffer + 3) =
+ pdata->shadow_result__range_status;
+ *(pbuffer + 4) =
+ pdata->shadow_result__report_status & 0xF;
+ *(pbuffer + 5) =
+ pdata->shadow_result__stream_count;
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__dss_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 6);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__ambient_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 10);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__sigma_sd0,
+ 2,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__phase_sd0,
+ 2,
+ pbuffer + 14);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0,
+ 2,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0,
+ 2,
+ pbuffer + 18);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__mm_inner_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 20);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__mm_outer_actual_effective_spads_sd0,
+ 2,
+ pbuffer + 22);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__avg_signal_count_rate_mcps_sd0,
+ 2,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__dss_actual_effective_spads_sd1,
+ 2,
+ pbuffer + 26);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 28);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__ambient_count_rate_mcps_sd1,
+ 2,
+ pbuffer + 30);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__sigma_sd1,
+ 2,
+ pbuffer + 32);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__phase_sd1,
+ 2,
+ pbuffer + 34);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1,
+ 2,
+ pbuffer + 36);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__spare_0_sd1,
+ 2,
+ pbuffer + 38);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__spare_1_sd1,
+ 2,
+ pbuffer + 40);
+ VL53L1_i2c_encode_uint16_t(
+ pdata->shadow_result__spare_2_sd1,
+ 2,
+ pbuffer + 42);
+ *(pbuffer + 44) =
+ pdata->shadow_result__spare_3_sd1;
+ *(pbuffer + 45) =
+ pdata->shadow_result__thresh_info;
+ *(pbuffer + 80) =
+ pdata->shadow_phasecal_result__reference_phase_hi;
+ *(pbuffer + 81) =
+ pdata->shadow_phasecal_result__reference_phase_lo;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_system_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->shadow_phasecal_result__vcsel_start =
+ (*(pbuffer + 0));
+ pdata->shadow_result__interrupt_status =
+ (*(pbuffer + 2)) & 0x3F;
+ pdata->shadow_result__range_status =
+ (*(pbuffer + 3));
+ pdata->shadow_result__report_status =
+ (*(pbuffer + 4)) & 0xF;
+ pdata->shadow_result__stream_count =
+ (*(pbuffer + 5));
+ pdata->shadow_result__dss_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6));
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8));
+ pdata->shadow_result__ambient_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10));
+ pdata->shadow_result__sigma_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12));
+ pdata->shadow_result__phase_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14));
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16));
+ pdata->shr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18));
+ pdata->shadow_result__mm_inner_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20));
+ pdata->shadow_result__mm_outer_actual_effective_spads_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22));
+ pdata->shadow_result__avg_signal_count_rate_mcps_sd0 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24));
+ pdata->shadow_result__dss_actual_effective_spads_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26));
+ pdata->shadow_result__peak_signal_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28));
+ pdata->shadow_result__ambient_count_rate_mcps_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30));
+ pdata->shadow_result__sigma_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32));
+ pdata->shadow_result__phase_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34));
+ pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36));
+ pdata->shadow_result__spare_0_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38));
+ pdata->shadow_result__spare_1_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40));
+ pdata->shadow_result__spare_2_sd1 =
+ (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42));
+ pdata->shadow_result__spare_3_sd1 =
+ (*(pbuffer + 44));
+ pdata->shadow_result__thresh_info =
+ (*(pbuffer + 45));
+ pdata->shadow_phasecal_result__reference_phase_hi =
+ (*(pbuffer + 80));
+ pdata->shadow_phasecal_result__reference_phase_lo =
+ (*(pbuffer + 81));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_shadow_system_results(
+ pdata,
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START,
+ comms_buffer,
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_shadow_system_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_system_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START,
+ comms_buffer,
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_shadow_system_results(
+ VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_encode_shadow_core_results(
+ VL53L1_shadow_core_results_t *pdata,
+ uint16_t buf_size,
+ uint8_t *pbuffer)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ambient_window_events_sd0,
+ 4,
+ pbuffer + 0);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ranging_total_events_sd0,
+ 4,
+ pbuffer + 4);
+ VL53L1_i2c_encode_int32_t(
+ pdata->shadow_result_core__signal_total_events_sd0,
+ 4,
+ pbuffer + 8);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__total_periods_elapsed_sd0,
+ 4,
+ pbuffer + 12);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ambient_window_events_sd1,
+ 4,
+ pbuffer + 16);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__ranging_total_events_sd1,
+ 4,
+ pbuffer + 20);
+ VL53L1_i2c_encode_int32_t(
+ pdata->shadow_result_core__signal_total_events_sd1,
+ 4,
+ pbuffer + 24);
+ VL53L1_i2c_encode_uint32_t(
+ pdata->shadow_result_core__total_periods_elapsed_sd1,
+ 4,
+ pbuffer + 28);
+ *(pbuffer + 32) =
+ pdata->shadow_result_core__spare_0;
+ LOG_FUNCTION_END(status);
+
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_i2c_decode_shadow_core_results(
+ uint16_t buf_size,
+ uint8_t *pbuffer,
+ VL53L1_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+ if (buf_size < VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES)
+ return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL;
+
+ pdata->shadow_result_core__ambient_window_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0));
+ pdata->shadow_result_core__ranging_total_events_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4));
+ pdata->shadow_result_core__signal_total_events_sd0 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 8));
+ pdata->shadow_result_core__total_periods_elapsed_sd0 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12));
+ pdata->shadow_result_core__ambient_window_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16));
+ pdata->shadow_result_core__ranging_total_events_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20));
+ pdata->shadow_result_core__signal_total_events_sd1 =
+ (VL53L1_i2c_decode_int32_t(4, pbuffer + 24));
+ pdata->shadow_result_core__total_periods_elapsed_sd1 =
+ (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28));
+ pdata->shadow_result_core__spare_0 =
+ (*(pbuffer + 32));
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_set_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_i2c_encode_shadow_core_results(
+ pdata,
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_WriteMulti(
+ Dev,
+ VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_get_shadow_core_results(
+ VL53L1_DEV Dev,
+ VL53L1_shadow_core_results_t *pdata)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES];
+
+ LOG_FUNCTION_START("");
+
+ if (status == VL53L1_ERROR_NONE)
+
+ status = VL53L1_disable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0,
+ comms_buffer,
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_enable_firmware(Dev);
+
+ if (status == VL53L1_ERROR_NONE)
+ status = VL53L1_i2c_decode_shadow_core_results(
+ VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES,
+ comms_buffer,
+ pdata);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_silicon_core.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_silicon_core.c
new file mode 100644
index 000000000000..14387ec03a04
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_silicon_core.c
@@ -0,0 +1,187 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_register_map.h"
+#include "vl53l1_core.h"
+#include "vl53l1_silicon_core.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE,\
+ status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_is_firmware_ready_silicon(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t comms_buffer[5];
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status = VL53L1_ReadMulti(
+ Dev,
+ VL53L1_INTERRUPT_MANAGER__ENABLES,
+ comms_buffer,
+ 5);
+
+ if (status != VL53L1_ERROR_NONE)
+ goto ENDFUNC;
+
+ pdev->dbg_results.interrupt_manager__enables =
+ comms_buffer[0];
+ pdev->dbg_results.interrupt_manager__clear =
+ comms_buffer[1];
+ pdev->dbg_results.interrupt_manager__status =
+ comms_buffer[2];
+ pdev->dbg_results.mcu_to_host_bank__wr_access_en =
+ comms_buffer[3];
+ pdev->dbg_results.power_management__go1_reset_status =
+ comms_buffer[4];
+
+ if ((pdev->sys_ctrl.power_management__go1_power_force & 0x01)
+ == 0x01) {
+
+ if (((pdev->dbg_results.interrupt_manager__enables &
+ 0x1F) == 0x1F) &&
+ ((pdev->dbg_results.interrupt_manager__clear
+ & 0x1F) == 0x1F))
+ *pready = 0x01;
+ else
+ *pready = 0x00;
+
+ } else {
+
+
+
+ if ((pdev->dbg_results.power_management__go1_reset_status
+ & 0x01) == 0x00)
+ *pready = 0x01;
+ else
+ *pready = 0x00;
+ }
+
+
+ENDFUNC:
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_wait.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_wait.c
new file mode 100644
index 000000000000..7ae89b9219eb
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_wait.c
@@ -0,0 +1,621 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform.h"
+#include "vl53l1_core.h"
+#include "vl53l1_silicon_core.h"
+#include "vl53l1_wait.h"
+#include "vl53l1_register_settings.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
+ fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_wait_for_boot_completion(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t fw_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_boot_completion(
+ Dev,
+ VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ fw_ready = 0;
+ while (fw_ready == 0x00 && status == VL53L1_ERROR_NONE) {
+ status = VL53L1_is_boot_complete(
+ Dev,
+ &fw_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+
+}
+
+
+VL53L1_Error VL53L1_wait_for_firmware_ready(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t fw_ready = 0;
+ uint8_t mode_start = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+ mode_start =
+ pdev->sys_ctrl.system__mode_start &
+ VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK;
+
+
+
+
+
+
+
+ if ((mode_start == VL53L1_DEVICEMEASUREMENTMODE_TIMED) ||
+ (mode_start == VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT)) {
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_firmware_ready(
+ Dev,
+ VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ fw_ready = 0;
+ while (fw_ready == 0x00 && status ==
+ VL53L1_ERROR_NONE) {
+ status = VL53L1_is_firmware_ready(
+ Dev,
+ &fw_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_wait_for_range_completion(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t data_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_range_completion(
+ Dev,
+ VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ data_ready = 0;
+ while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
+ status = VL53L1_is_new_data_ready(
+ Dev,
+ &data_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_wait_for_test_completion(
+ VL53L1_DEV Dev)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t data_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
+
+
+
+
+ status =
+ VL53L1_poll_for_range_completion(
+ Dev,
+ VL53L1_TEST_COMPLETION_POLLING_TIMEOUT_MS);
+
+ } else {
+
+
+
+
+ data_ready = 0;
+ while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
+ status = VL53L1_is_new_data_ready(
+ Dev,
+ &data_ready);
+
+ if (status == VL53L1_ERROR_NONE) {
+ status = VL53L1_WaitMs(
+ Dev,
+ VL53L1_POLLING_DELAY_MS);
+ }
+ }
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_is_boot_complete(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ uint8_t firmware__system_status = 0;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+ status =
+ VL53L1_RdByte(
+ Dev,
+ VL53L1_FIRMWARE__SYSTEM_STATUS,
+ &firmware__system_status);
+
+
+
+
+
+
+ if ((firmware__system_status & 0x01) == 0x01) {
+ *pready = 0x01;
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_SW_STANDBY);
+ } else {
+ *pready = 0x00;
+ VL53L1_init_ll_driver_state(
+ Dev,
+ VL53L1_DEVICESTATE_FW_COLDBOOT);
+ }
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_is_firmware_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ LOG_FUNCTION_START("");
+
+ status = VL53L1_is_firmware_ready_silicon(
+ Dev,
+ pready);
+
+ pdev->fw_ready = *pready;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_is_new_data_ready(
+ VL53L1_DEV Dev,
+ uint8_t *pready)
+{
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t gpio__mux_active_high_hv = 0;
+ uint8_t gpio__tio_hv_status = 0;
+ uint8_t interrupt_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ gpio__mux_active_high_hv =
+ pdev->stat_cfg.gpio_hv_mux__ctrl &
+ VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
+
+ if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
+ interrupt_ready = 0x01;
+ else
+ interrupt_ready = 0x00;
+
+
+
+
+ status = VL53L1_RdByte(
+ Dev,
+ VL53L1_GPIO__TIO_HV_STATUS,
+ &gpio__tio_hv_status);
+
+
+
+
+ if ((gpio__tio_hv_status & 0x01) == interrupt_ready)
+ *pready = 0x01;
+ else
+ *pready = 0x00;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+
+
+VL53L1_Error VL53L1_poll_for_boot_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+
+
+ status = VL53L1_WaitUs(
+ Dev,
+ VL53L1_FIRMWARE_BOOT_TIME_US);
+
+ if (status == VL53L1_ERROR_NONE)
+ status =
+ VL53L1_WaitValueMaskEx(
+ Dev,
+ timeout_ms,
+ VL53L1_FIRMWARE__SYSTEM_STATUS,
+ 0x01,
+ 0x01,
+ VL53L1_POLLING_DELAY_MS);
+
+ if (status == VL53L1_ERROR_NONE)
+ VL53L1_init_ll_driver_state(Dev, VL53L1_DEVICESTATE_SW_STANDBY);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_poll_for_firmware_ready(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint32_t start_time_ms = 0;
+ uint32_t current_time_ms = 0;
+ int32_t poll_delay_ms = VL53L1_POLLING_DELAY_MS;
+ uint8_t fw_ready = 0;
+
+
+
+
+ VL53L1_GetTickCount(&start_time_ms);
+
+ pdev->fw_ready_poll_duration_ms = 0;
+
+
+
+
+ while ((status == VL53L1_ERROR_NONE) &&
+ (pdev->fw_ready_poll_duration_ms < timeout_ms) &&
+ (fw_ready == 0)) {
+
+ status = VL53L1_is_firmware_ready(
+ Dev,
+ &fw_ready);
+
+ if (status == VL53L1_ERROR_NONE &&
+ fw_ready == 0 &&
+ poll_delay_ms > 0) {
+ status = VL53L1_WaitMs(
+ Dev,
+ poll_delay_ms);
+ }
+
+
+
+
+
+
+ VL53L1_GetTickCount(¤t_time_ms);
+
+ pdev->fw_ready_poll_duration_ms =
+ current_time_ms - start_time_ms;
+ }
+
+ if (fw_ready == 0 && status == VL53L1_ERROR_NONE)
+ status = VL53L1_ERROR_TIME_OUT;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_poll_for_range_completion(
+ VL53L1_DEV Dev,
+ uint32_t timeout_ms)
+{
+
+
+
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+ VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
+
+ uint8_t gpio__mux_active_high_hv = 0;
+ uint8_t interrupt_ready = 0;
+
+ LOG_FUNCTION_START("");
+
+ gpio__mux_active_high_hv =
+ pdev->stat_cfg.gpio_hv_mux__ctrl &
+ VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
+
+ if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
+ interrupt_ready = 0x01;
+ else
+ interrupt_ready = 0x00;
+
+ status =
+ VL53L1_WaitValueMaskEx(
+ Dev,
+ timeout_ms,
+ VL53L1_GPIO__TIO_HV_STATUS,
+ interrupt_ready,
+ 0x01,
+ VL53L1_POLLING_DELAY_MS);
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
diff --git a/drivers/input/misc/vl53L1/kona/src/vl53l1_zone_presets.c b/drivers/input/misc/vl53L1/kona/src/vl53l1_zone_presets.c
new file mode 100644
index 000000000000..98378cbff3ea
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/src/vl53l1_zone_presets.c
@@ -0,0 +1,253 @@
+
+/*******************************************************************************
+ * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+
+ This file is part of VL53L1 Core and is dual licensed,
+ either 'STMicroelectronics
+ Proprietary license'
+ or 'BSD 3-clause "New" or "Revised" License' , at your option.
+
+********************************************************************************
+
+ 'STMicroelectronics Proprietary license'
+
+********************************************************************************
+
+ License terms: STMicroelectronics Proprietary in accordance with licensing
+ terms at www.st.com/sla0081
+
+ STMicroelectronics confidential
+ Reproduction and Communication of this document is strictly prohibited unless
+ specifically authorized in writing by STMicroelectronics.
+
+
+********************************************************************************
+
+ Alternatively, VL53L1 Core may be distributed under the terms of
+ 'BSD 3-clause "New" or "Revised" License', in which case the following
+ provisions apply instead of the ones
+ mentioned above :
+
+********************************************************************************
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+********************************************************************************
+
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#include "vl53l1_ll_def.h"
+#include "vl53l1_ll_device.h"
+#include "vl53l1_platform_log.h"
+#include "vl53l1_zone_presets.h"
+
+
+#define LOG_FUNCTION_START(fmt, ...) \
+ _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
+#define LOG_FUNCTION_END(status, ...) \
+ _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
+#define LOG_FUNCTION_END_FMT(status, fmt, ...) \
+ _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE,\
+ status, fmt, ##__VA_ARGS__)
+
+
+VL53L1_Error VL53L1_init_zone_config_structure(
+ uint8_t x_off,
+ uint8_t x_inc,
+ uint8_t x_zones,
+ uint8_t y_off,
+ uint8_t y_inc,
+ uint8_t y_zones,
+ uint8_t width,
+ uint8_t height,
+ VL53L1_zone_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t x = 0;
+ uint8_t y = 0;
+ uint16_t i = 0;
+
+ LOG_FUNCTION_START("");
+
+ pdata->max_zones = VL53L1_MAX_USER_ZONES;
+
+ i = 0;
+
+ for (x = 0 ; x < x_zones ; x++) {
+ for (y = 0 ; y < y_zones ; y++) {
+
+ if (i < VL53L1_MAX_USER_ZONES) {
+
+ pdata->active_zones = (uint8_t)i;
+ pdata->user_zones[i].height = height;
+ pdata->user_zones[i].width = width;
+ pdata->user_zones[i].x_centre =
+ x_off + (x * x_inc);
+ pdata->user_zones[i].y_centre =
+ y_off + (y * y_inc);
+ }
+
+ i++;
+ }
+ }
+
+ status = VL53L1_init_zone_config_histogram_bins(pdata);
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_zone_preset_xtalk_planar(
+ VL53L1_general_config_t *pgeneral,
+ VL53L1_zone_config_t *pzone_cfg)
+{
+
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ LOG_FUNCTION_START("");
+
+
+
+
+
+
+ pgeneral->global_config__stream_divider = 0x05;
+
+
+
+ pzone_cfg->active_zones = 0x04;
+
+ pzone_cfg->user_zones[0].height = 15;
+ pzone_cfg->user_zones[0].width = 7;
+ pzone_cfg->user_zones[0].x_centre = 4;
+ pzone_cfg->user_zones[0].y_centre = 8;
+
+ pzone_cfg->user_zones[1].height = 15;
+ pzone_cfg->user_zones[1].width = 7;
+ pzone_cfg->user_zones[1].x_centre = 12;
+ pzone_cfg->user_zones[1].y_centre = 8;
+
+ pzone_cfg->user_zones[2].height = 7;
+ pzone_cfg->user_zones[2].width = 15;
+ pzone_cfg->user_zones[2].x_centre = 8;
+ pzone_cfg->user_zones[2].y_centre = 4;
+
+ pzone_cfg->user_zones[3].height = 7;
+ pzone_cfg->user_zones[3].width = 15;
+ pzone_cfg->user_zones[3].x_centre = 8;
+ pzone_cfg->user_zones[3].y_centre = 12;
+
+
+
+
+ pzone_cfg->user_zones[4].height = 15;
+ pzone_cfg->user_zones[4].width = 15;
+ pzone_cfg->user_zones[4].x_centre = 8;
+ pzone_cfg->user_zones[4].y_centre = 8;
+
+ status = VL53L1_init_zone_config_histogram_bins(pzone_cfg);
+
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
+
+VL53L1_Error VL53L1_init_zone_config_histogram_bins(
+ VL53L1_zone_config_t *pdata)
+{
+
+
+
+
+
+ VL53L1_Error status = VL53L1_ERROR_NONE;
+
+ uint8_t i;
+
+ LOG_FUNCTION_START("");
+
+ for (i = 0; i < pdata->max_zones; i++)
+ pdata->bin_config[i] = VL53L1_ZONECONFIG_BINCONFIG__LOWAMB;
+
+ LOG_FUNCTION_END(status);
+
+ return status;
+}
+
diff --git a/drivers/input/misc/vl53L1/kona/st,stmvl53l1.txt b/drivers/input/misc/vl53L1/kona/st,stmvl53l1.txt
new file mode 100644
index 000000000000..3f81932590c2
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/st,stmvl53l1.txt
@@ -0,0 +1,26 @@
+StMicroelectronis vl53l1
+
+Requires properties:
+- compatible: must be "st,stmvl53l1".
+- reg: I2C address of the chip.
+- xsdn-gpio: gpio number connected to vl53l1 reset pin.
+
+Optional properties:
+- intr-gpio: gpio number connected to vl53l1 irq pin.
+- vdd: a phandle for the regulator supplying power for vl53l1.
+- pwren-gpio: gpio number use to control vl53l1 power.
+
+Example:
+ &i2c1 {
+ /* ... */
+
+ stmvl53l1: stmvl53l1@29 {
+ compatible = "st,stmvl53l1";
+ reg = <0x29>;
+ xsdn-gpio = <19>;
+ pwren-gpio = <12>;
+ intr-gpio = <16>;
+ };
+
+ /* ... */
+ };
diff --git a/drivers/input/misc/vl53L1/kona/stmvl53l1-i2c.h b/drivers/input/misc/vl53L1/kona/stmvl53l1-i2c.h
new file mode 100644
index 000000000000..e7a84bc20eeb
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/stmvl53l1-i2c.h
@@ -0,0 +1,118 @@
+/**************************************************************************
+ * Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ****************************************************************************/
+
+/** @file stmvl53l1-i2c.h
+ * Linux kernel i2c/cci wrapper for ST VL53L1 sensor i2c interface
+ **/
+
+#ifndef STMVL53L1_I2C_H
+#define STMVL53L1_I2C_H
+#include
+#include "stmvl53l1.h"
+
+struct i2c_data {
+ struct i2c_client *client;
+ /** back link to driver for interrupt and clean-up */
+ struct stmvl53l1_data *vl53l1_data;
+
+ /* reference counter */
+ struct kref ref;
+
+ /*!< if null no regulator use for power ctrl */
+ struct regulator *vdd;
+ struct regulator *xsd;
+
+ /*!< power enable gpio number
+ *
+ * if -1 no gpio if vdd not avl pwr is not controllable
+ */
+ int pwren_gpio;
+
+ /*!< xsdn reset (low active) gpio number to device
+ *
+ * -1 mean none assume no "resetable"
+ */
+ int xsdn_gpio;
+
+ /*!< intr gpio number to device
+ *
+ * intr is active/low negative edge by default
+ *
+ * -1 mean none assume use polling
+ * @warning if the dev tree and intr gpio is require please adapt code
+ */
+ int intr_gpio;
+
+ int ver_gpio;
+ /*!< device boot i2c register address
+ *
+ * boot_reg is the value of device i2c address after it is bring out
+ * of reset.
+ */
+ int boot_reg;
+
+ /*!< is set if above irq gpio got acquired */
+ struct i2d_data_flags_t {
+ unsigned pwr_owned:1; /*!< set if pwren gpio is owned*/
+ unsigned xsdn_owned:1; /*!< set if sxdn gpio is owned*/
+ unsigned intr_owned:1; /*!< set if intr gpio is owned*/
+ unsigned intr_started:1; /*!< set if irq is hanlde */
+ } io_flag;
+
+ /** the irq vectore assigned to gpio
+ * -1 if no irq hanled
+ */
+ int irq;
+
+ struct msgtctrl_t {
+ unsigned unhandled_irq_vec:1;
+ } msg_flag;
+};
+
+#ifdef USE_CAMERA_CCI
+int __init stmvl53l1_init_cci(void);
+void __exit stmvl53l1_exit_cci(void*);
+int stmvl53l1_enable_pinctrl(void);
+int stmvl53l1_disable_pinctrl(void);
+#else
+int stmvl53l1_init_i2c(void);
+void __exit stmvl53l1_exit_i2c(void *arg);
+#endif
+int stmvl53l1_power_up_i2c(void *arg);
+int stmvl53l1_power_down_i2c(void *arg);
+int stmvl53l1_reset_release_i2c(void *arg);
+int stmvl53l1_reset_hold_i2c(void *arg);
+void stmvl53l1_clean_up_i2c(void);
+int stmvl53l1_start_intr(void *object, int *poll_mode);
+void *stmvl53l1_get(void *arg);
+void stmvl53l1_put(void *arg);
+
+#endif /* STMVL53L1_I2C_H */
diff --git a/drivers/input/misc/vl53L1/kona/stmvl53l1.h b/drivers/input/misc/vl53L1/kona/stmvl53l1.h
new file mode 100644
index 000000000000..51712edf6679
--- /dev/null
+++ b/drivers/input/misc/vl53L1/kona/stmvl53l1.h
@@ -0,0 +1,391 @@
+/**************************************************************************
+ * Copyright (c) 2016, STMicroelectronics - All Rights Reserved
+
+ License terms: BSD 3-clause "New" or "Revised" License.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ****************************************************************************/
+/**
+ * @file stmvl53l1.h header for vl53l1 sensor driver
+ */
+#ifndef STMVL53L1_H
+#define STMVL53L1_H
+
+#include
+#include
+#include
+#include
+#include
+
+#include "vl53l1_api.h"
+
+/**
+ * IPP adapt
+ */
+#ifdef DEBUG
+# define IPP_PRINT(...) printk(__VA_ARGS__)
+#else
+# define IPP_PRINT(...) (void)0
+#endif
+
+#include "stmvl53l1_ipp.h"
+#include "stmvl53l1_if.h"
+
+/**
+ * Configure the Netlink-id use
+ */
+#define STMVL531_CFG_NETLINK_USER 31
+
+#define STMVL53L1_MAX_CCI_XFER_SZ 256
+#define STMVL53L1_DRV_NAME "stmvl53l1"
+
+/**
+ * configure usage of regulator device from device tree info
+ * to enable/disable sensor power
+ * see module-i2c or module-cci file
+ */
+/* define CFG_STMVL53L1_HAVE_REGULATOR */
+
+#define DRIVER_VERSION "13.4.2"
+
+/** @ingroup vl53l1_config
+ * @{
+ */
+/**
+ * Configure max number of device the driver can support
+ */
+#define STMVL53L1_CFG_MAX_DEV 2
+/** @} */ /* ingroup vl53l1_config */
+
+/** @ingroup vl53l1_mod_dbg
+ * @{
+ */
+#if 0
+#define DEBUG 1
+#endif
+#if 0
+#define FORCE_CONSOLE_DEBUG
+#endif
+
+extern int stmvl53l1_enable_debug;
+
+#ifdef DEBUG
+# ifdef FORCE_CONSOLE_DEBUG
+#define vl53l1_dbgmsg(str, ...) do { \
+ if (stmvl53l1_enable_debug) \
+ pr_info("%s: " str, __func__, ##__VA_ARGS__); \
+} while (0)
+# else
+#define vl53l1_dbgmsg(str, ...) do { \
+ if (stmvl53l1_enable_debug) \
+ pr_debug("%s: " str, __func__, ##__VA_ARGS__); \
+} while (0)
+# endif
+#else
+# define vl53l1_dbgmsg(...) (void)0
+#endif
+
+/**
+ * set to 0 1 activate or not debug from work (data interrupt/polling)
+ */
+#define WORK_DEBUG 0
+#if WORK_DEBUG
+# define work_dbg(msg, ...)\
+ printk("[D WK53L1] :" msg "\n", ##__VA_ARGS__)
+#else
+# define work_dbg(...) (void)0
+#endif
+
+#define vl53l1_info(str, args...) \
+ pr_info("%s: " str "\n", __func__, ##args)
+
+#define vl53l1_errmsg(str, args...) \
+ pr_err("%s: " str, __func__, ##args)
+
+#define vl53l1_wanrmsg(str, args...) \
+ pr_warn("%s: " str, __func__, ##args)
+
+/* turn off poll log if not defined */
+#ifndef STMVL53L1_LOG_POLL_TIMING
+# define STMVL53L1_LOG_POLL_TIMING 0
+#endif
+/* turn off cci log timing if not defined */
+#ifndef STMVL53L1_LOG_CCI_TIMING
+# define STMVL53L1_LOG_CCI_TIMING 0
+#endif
+
+/**@} */ /* ingroup mod_dbg*/
+
+#include
+#include
+#include
+
+/** if set to 1 enable ipp execution timing (if debug enabled)
+ * @ingroup vl53l1_mod_dbg
+ */
+#define IPP_LOG_TIMING 1
+
+struct ipp_data_t {
+ struct ipp_work_t work;
+ struct ipp_work_t work_out;
+ int test_n;
+ /*!< buzy state 0 is idle
+ *any other value do not try to use (state value defined in source)
+ */
+ int buzy;
+ int waited_xfer_id;
+ /*!< when buzy is set that is the id we are expecting
+ * note that value 0 is reserved and stand for "not waiting"
+ * as such never id 0 will be in any round trip exchange
+ * it's ok for daemon to use 0 in "ping" when it identify himself
+ */
+ int status; /** if that is not 0 do not look at out work data */
+ wait_queue_head_t waitq;
+ /*!< ipp caller are put in that queue wait while job is posted to user
+ * @warning ipp and dev mutex will be released before waiting
+ * see @ref ipp_abort
+ */
+#if IPP_LOG_TIMING
+ struct timeval start_tv, stop_tv;
+#endif
+};
+
+struct stmvl53l1_waiters {
+ struct list_head list;
+ pid_t pid;
+};
+
+/*
+ * driver data structs
+ */
+struct stmvl53l1_data {
+ int id; /*!< multiple device id 0 based*/
+ char name[64]; /*!< misc device name */
+
+ VL53L1_DevData_t stdev; /*!