From 69bab88511023f0742aa2794698b3cab7f816eb6 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 12 Jun 2020 11:47:20 -0700 Subject: driver/fingerprint: Add a common sensor maintenance function Add a new console command "fpmaintenance" for testing. BRANCH=none BUG=b:76037094 TEST=With dragonclaw v0.2 connected to Segger J-Trace and servo micro: ./util/flash_jlink.py On FP console: > fpmaintenance Signed-off-by: Tom Hughes Change-Id: I7125f8783d3dd7e815612d20742c9d949d00ba71 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2323709 Reviewed-by: Yicheng Li --- driver/fingerprint/fpc/bep/fpc_private.c | 5 ++++ driver/fingerprint/fpc/build.mk | 8 ++++++ driver/fingerprint/fpc/fpc_sensor.c | 44 ++++++++++++++++++++++++++++++ driver/fingerprint/fpc/fpc_sensor.h | 2 ++ driver/fingerprint/fpc/libfp/fpc_private.c | 5 ++++ 5 files changed, 64 insertions(+) create mode 100644 driver/fingerprint/fpc/fpc_sensor.c (limited to 'driver/fingerprint') diff --git a/driver/fingerprint/fpc/bep/fpc_private.c b/driver/fingerprint/fpc/bep/fpc_private.c index 7621edabd3..36ca0fe1b9 100644 --- a/driver/fingerprint/fpc/bep/fpc_private.c +++ b/driver/fingerprint/fpc/bep/fpc_private.c @@ -267,3 +267,8 @@ int fp_finger_enroll(uint8_t *image, int *completion) return rc; } + +int fp_maintenance(void) +{ + return fpc_fp_maintenance(&errors); +} diff --git a/driver/fingerprint/fpc/build.mk b/driver/fingerprint/fpc/build.mk index ab6a6a4b9c..d5e3ede14e 100644 --- a/driver/fingerprint/fpc/build.mk +++ b/driver/fingerprint/fpc/build.mk @@ -14,3 +14,11 @@ include $(_fpc_cur_dir)bep/build.mk else ifeq ($(CONFIG_FP_SENSOR_FPC1035),rw) include $(_fpc_cur_dir)bep/build.mk endif + +ifeq ($(CONFIG_FP_SENSOR),rw) +# Make sure output directory is created (in build directory) +dirs-y+="$(_fpc_cur_dir)" + +# Only build these objects for the RW image +all-obj-rw+=$(_fpc_cur_dir)fpc_sensor.o +endif diff --git a/driver/fingerprint/fpc/fpc_sensor.c b/driver/fingerprint/fpc/fpc_sensor.c new file mode 100644 index 0000000000..92a3db51c9 --- /dev/null +++ b/driver/fingerprint/fpc/fpc_sensor.c @@ -0,0 +1,44 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include +#include +#include +#include +#if defined(CONFIG_FP_SENSOR_FPC1025) || defined(CONFIG_FP_SENSOR_FPC1035) +#include "bep/fpc_private.h" +#elif defined(CONFIG_FP_SENSOR_FPC1145) +#include "libfp/fpc_private.h" +#else +#error "Sensor type not defined!" +#endif +#include "fpc_sensor.h" + +int fpc_fp_maintenance(uint16_t *error_state) +{ + int rv; + fp_sensor_info_t sensor_info; + timestamp_t start = get_time(); + + if (error_state == NULL) + return EC_ERROR_INVAL; + + rv = fp_sensor_maintenance(fp_buffer, &sensor_info); + CPRINTS("Maintenance took %d ms", time_since32(start) / MSEC); + + if (rv != 0) { + /* + * Failure can occur if any of the fingerprint detection zones + * are covered (i.e., finger is on sensor). + */ + CPRINTS("Failed to run maintenance: %d", rv); + return EC_ERROR_HW_INTERNAL; + } + + *error_state |= FP_ERROR_DEAD_PIXELS(sensor_info.num_defective_pixels); + CPRINTS("num_defective_pixels: %d", sensor_info.num_defective_pixels); + + return EC_SUCCESS; +} diff --git a/driver/fingerprint/fpc/fpc_sensor.h b/driver/fingerprint/fpc/fpc_sensor.h index da67696a0c..2ab9248eeb 100644 --- a/driver/fingerprint/fpc/fpc_sensor.h +++ b/driver/fingerprint/fpc/fpc_sensor.h @@ -18,4 +18,6 @@ #error "Sensor type not defined!" #endif +int fpc_fp_maintenance(uint16_t *error_state); + #endif /* __CROS_EC_DRIVER_FINGERPRINT_FPC_FPC_SENSOR_H_ */ diff --git a/driver/fingerprint/fpc/libfp/fpc_private.c b/driver/fingerprint/fpc/libfp/fpc_private.c index e734a94734..8c11849c8f 100644 --- a/driver/fingerprint/fpc/libfp/fpc_private.c +++ b/driver/fingerprint/fpc/libfp/fpc_private.c @@ -313,3 +313,8 @@ int fp_finger_enroll(uint8_t *image, int *completion) *completion = bio_enrollment_get_percent_complete(enroll_ctx); return rc; } + +int fp_maintenance(void) +{ + return fpc_fp_maintenance(&errors); +} -- cgit v1.2.1