summaryrefslogtreecommitdiff
path: root/driver/fingerprint/fpc/bep
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2019-10-17 16:29:26 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-28 23:06:14 +0000
commit5ef39980a07bd60c9f39052f9dda6af350e41823 (patch)
tree39ed18545dfb54d0bd6186a153505ff1c17776e6 /driver/fingerprint/fpc/bep
parentc58ea116e8d0bfca98b2b208eb9dc40f01832579 (diff)
downloadchrome-ec-5ef39980a07bd60c9f39052f9dda6af350e41823.tar.gz
fpsensor: Copy BEP and libfp source files from private repo
These source files have been approved to be released publicly (see http://b/137848573#comment20). There were no source changes in the move, except for small changes to the Makefiles to adjust for the move. For future "git blame"s refer to the history of the files in the private repo if you need to access the full history. BRANCH=none BUG=b:137848573 TEST=make buildall -j Cq-Depend: chrome-internal:2005127 Change-Id: I1a809ac5a4d95637840ee47712e9c80a40a445c5 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1869531
Diffstat (limited to 'driver/fingerprint/fpc/bep')
-rw-r--r--driver/fingerprint/fpc/bep/build.mk23
-rw-r--r--driver/fingerprint/fpc/bep/fpc1025_private.h52
-rw-r--r--driver/fingerprint/fpc/bep/fpc1035_private.h52
-rw-r--r--driver/fingerprint/fpc/bep/fpc_bio_algorithm.h136
-rw-r--r--driver/fingerprint/fpc/bep/fpc_misc.c51
-rw-r--r--driver/fingerprint/fpc/bep/fpc_private.c260
-rw-r--r--driver/fingerprint/fpc/bep/fpc_sensor_spi.c94
-rw-r--r--driver/fingerprint/fpc/bep/fpc_sensor_spi.h98
-rw-r--r--driver/fingerprint/fpc/bep/fpc_timebase.c29
-rw-r--r--driver/fingerprint/fpc/bep/fpc_timebase.h48
10 files changed, 843 insertions, 0 deletions
diff --git a/driver/fingerprint/fpc/bep/build.mk b/driver/fingerprint/fpc/bep/build.mk
new file mode 100644
index 0000000000..fc704e172a
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/build.mk
@@ -0,0 +1,23 @@
+# Copyright 2019 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.
+
+# FPC BEP source files build
+
+# Note that this variable includes the trailing "/"
+_bep_cur_dir:=$(dir $(lastword $(MAKEFILE_LIST)))
+
+# Make sure output directory is created (in build directory)
+dirs-y+="$(_bep_cur_dir)"
+
+sensor-$(CONFIG_FP_SENSOR_FPC1025)=fpc1025
+sensor-$(CONFIG_FP_SENSOR_FPC1035)=fpc1035
+
+# Only build for these objects for the RW image
+all-obj-rw+=$(_bep_cur_dir)fpc_misc.o \
+ $(_bep_cur_dir)fpc_private.o \
+ $(_bep_cur_dir)fpc_sensor_spi.o \
+ $(_bep_cur_dir)fpc_timebase.o
+fp_sensor_header-rw=$(_bep_cur_dir)$(sensor-rw)_private.h
+
+CPPFLAGS+=-DFP_SENSOR_PRIVATE=$(fp_sensor_header-rw)
diff --git a/driver/fingerprint/fpc/bep/fpc1025_private.h b/driver/fingerprint/fpc/bep/fpc1025_private.h
new file mode 100644
index 0000000000..eddb435d4a
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc1025_private.h
@@ -0,0 +1,52 @@
+/* Copyright 2019 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.
+ */
+
+#ifndef __CROS_EC_FPC1025_PRIVATE_H
+#define __CROS_EC_FPC1025_PRIVATE_H
+
+/* Define sensor type */
+#define FP_SENSOR_CONFIG_FPC1025
+
+/* The 16-bit hardware ID is 0x021y */
+#define FP_SENSOR_HWID 0x021
+
+/* Sensor type name */
+#define FP_SENSOR_NAME "FPC1025"
+
+/* Sensor pixel resolution */
+#define FP_SENSOR_RES_X (160) /**< Sensor width */
+#define FP_SENSOR_RES_Y (160) /**< Sensor height */
+#define FP_SENSOR_RES_BPP (8) /**< Resolution bits per pixel */
+
+/*
+ * Sensor image size
+ *
+ * Value from fpc_bep_image_get_buffer_size(): (160*160)+660
+ */
+#define FP_SENSOR_IMAGE_SIZE (26260)
+#define FP_SENSOR_REAL_IMAGE_SIZE (FP_SENSOR_RES_X * FP_SENSOR_RES_Y)
+/* Offset of image data in fp_buffer */
+#define FP_SENSOR_IMAGE_OFFSET (400)
+
+/*
+ * Constant value for the enrollment data size
+ *
+ * Size of private fp_bio_enrollment_t
+ */
+#define FP_ALGORITHM_ENROLLMENT_SIZE (4)
+
+/*
+ * Constant value corresponding to the maximum template size
+ * for FPC1025 sensor. Client template memory allocation must
+ * have this size. This includes extra memory for template update.
+ *
+ * Template size + alignment padding + size of template size variable
+ */
+#define FP_ALGORITHM_TEMPLATE_SIZE (5088 + 0 + 4)
+
+/* Max number of templates stored / matched against */
+#define FP_MAX_FINGER_COUNT (5)
+
+#endif /* __CROS_EC_FPC1025_PRIVATE_H */
diff --git a/driver/fingerprint/fpc/bep/fpc1035_private.h b/driver/fingerprint/fpc/bep/fpc1035_private.h
new file mode 100644
index 0000000000..61c423c6b8
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc1035_private.h
@@ -0,0 +1,52 @@
+/* Copyright 2019 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.
+ */
+
+#ifndef __CROS_EC_FPC1035_PRIVATE_H
+#define __CROS_EC_FPC1035_PRIVATE_H
+
+/* Define sensor type */
+#define FP_SENSOR_CONFIG_FPC1035
+
+/* The 16-bit hardware ID is 0x011y */
+#define FP_SENSOR_HWID 0x011
+
+/* Sensor type name */
+#define FP_SENSOR_NAME "FPC1035"
+
+/* Sensor pixel resolution */
+#define FP_SENSOR_RES_X (112) /**< Sensor width */
+#define FP_SENSOR_RES_Y (88) /**< Sensor height */
+#define FP_SENSOR_RES_BPP (8) /**< Resolution bits per pixel */
+
+/*
+ * Sensor image size
+ *
+ * Value from fpc_bep_image_get_buffer_size(): (112*88)+660
+ */
+#define FP_SENSOR_IMAGE_SIZE (10516)
+#define FP_SENSOR_REAL_IMAGE_SIZE (FP_SENSOR_RES_X * FP_SENSOR_RES_Y)
+/* Offset of image data in fp_buffer */
+#define FP_SENSOR_IMAGE_OFFSET (400)
+
+/*
+ * Constant value for the enrollment data size
+ *
+ * Size of private fp_bio_enrollment_t
+ */
+#define FP_ALGORITHM_ENROLLMENT_SIZE (4)
+
+/*
+ * Constant value corresponding to the maximum template size
+ * for FPC1035 sensor. Client template memory allocation must
+ * have this size. This includes extra memory for template update.
+ *
+ * Template size + alignment padding + size of template size variable
+ */
+#define FP_ALGORITHM_TEMPLATE_SIZE (14373 + 3 + 4)
+
+/* Max number of templates stored / matched against */
+#define FP_MAX_FINGER_COUNT (5)
+
+#endif /* __CROS_EC_FPC1035_PRIVATE_H */
diff --git a/driver/fingerprint/fpc/bep/fpc_bio_algorithm.h b/driver/fingerprint/fpc/bep/fpc_bio_algorithm.h
new file mode 100644
index 0000000000..1bf598a3ee
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc_bio_algorithm.h
@@ -0,0 +1,136 @@
+/* Copyright 2019 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.
+ */
+
+#ifndef __CROS_EC_FPC_BIO_ALGORITHM_H
+#define __CROS_EC_FPC_BIO_ALGORITHM_H
+
+#include <stdint.h>
+
+/*
+ * An opaque pointer representing an image (scan).
+ */
+typedef void *bio_image_t;
+/*
+ * An opaque pointer representing/uniquely identifying an (serialized) enrolled
+ * template.
+ */
+typedef void *bio_template_t;
+/*
+ * An opaque pointer representing/uniquely identifying enrollment attempt.
+ */
+typedef void *bio_enrollment_t;
+/*
+ * An opaque struct representing algorithm.
+ */
+typedef struct fpc_bep_algorithm fpc_bep_algorithm_t;
+/*
+ * Struct with biometric algorithm information.
+ */
+typedef struct {
+ const fpc_bep_algorithm_t *algorithm;
+ uint32_t template_size;
+} fpc_bio_info_t;
+/*
+ * Initializes biometric algorithm library. Should be the very first function
+ * to be invoked by the biometric daemon.
+ *
+ * Returns 0 on success, negative error code (such as -ENOMEM) on failure.
+ */
+int bio_algorithm_init(void);
+/*
+ * Instructs the biometric library to release all resources in preparation
+ * for the process termination (or unloading the library). Regardless of
+ * the returned error code the action is considered unrecoverable.
+ *
+ * Returns 0 on success, negative error code (such as -ENOMEM) on failure.
+ */
+int bio_algorithm_exit(void);
+/*
+ * Compares given biometric image against a list of enrolled template(s).
+ * In case the image match a template the match_index will indicate which
+ * template in the list that matched.
+ * The algorithm library can update templates with additional biometric data
+ * from the image, if it chooses to do so. The updated template(s) will be
+ * indicated by the out parameter 'updated_templates', a bit-field where
+ * updated template(s) indicated by the corresponding bit being set
+ * Returns:
+ * - negative value on error
+ * - BIO_TEMPLATE_NO_MATCH on non-match
+ * - BIO_TEMPLATE_MATCH for match when template was not updated with new data
+ * - BIO_TEMPLATE_MATCH_UPDATED for match when template was updated
+ * - BIO_TEMPLATE_MATCH_UPDATE_FAILED match, but update failed (do not save)
+ * - BIO_TEMPLATE_LOW_QUALITY when matching could not be performed due to low
+ * image quality
+ * - BIO_TEMPLATE_LOW_COVERAGE when matching could not be performed due to
+ * finger covering too little area of the sensor
+ */
+#define BIO_TEMPLATE_NO_MATCH 0
+#define BIO_TEMPLATE_MATCH 1
+#define BIO_TEMPLATE_MATCH_UPDATED 3
+#define BIO_TEMPLATE_MATCH_UPDATE_FAILED 5
+#define BIO_TEMPLATE_LOW_QUALITY 2
+#define BIO_TEMPLATE_LOW_COVERAGE 4
+
+int bio_template_image_match_list(bio_template_t templ, uint32_t num_templ,
+ bio_image_t image, int32_t *match_index,
+ uint32_t *updated_templ);
+/*
+ * Initiates biometric data enrollment process. Algorithm library returns
+ * 'enrollment handle' that is used for all subsequent enrollment operations.
+ *
+ * Returns 0 on success, negative error code (such as -ENOMEM) on failure.
+ */
+int bio_enrollment_begin(bio_enrollment_t *enrollment);
+/*
+ * Adds fingerprint image to an enrollment.
+ *
+ * The library should expect to copy any relevant data from the “image”
+ * as it is likely to be destroyed (via bio_image_destroy() call) shortly after
+ * this call completes.
+ *
+ * Returns:
+ * - negative value on error
+ * - BIO_ENROLLMENT_OK when image was successfully enrolled
+ * - BIO_ENROLLMENT_LOW_QUALITY when image could not be used due to low
+ * image quality
+ * - BIO_ENROLLMENT_IMMOBILE when image added, but user should be advised
+ * to move finger
+ * - BIO_ENROLLMENT_LOW_COVERAGE when image could not be used due to
+ * finger covering too little area of the sensor
+ * - BIO_ENROLLMENT_INTERNAL_ERROR when an internal error occurred
+ */
+#define BIO_ENROLLMENT_OK 0
+#define BIO_ENROLLMENT_LOW_QUALITY 1
+#define BIO_ENROLLMENT_IMMOBILE 2
+#define BIO_ENROLLMENT_LOW_COVERAGE 3
+#define BIO_ENROLLMENT_INTERNAL_ERROR 5
+
+/* Can be used to detect if image was usable for enrollment or not. */
+#define BIO_ENROLLMENT_PROBLEM_MASK 1
+int bio_enrollment_add_image(bio_enrollment_t enrollment, bio_image_t image);
+/*
+ * Returns percent of coverage accumulated during enrollment process.
+ * Optional method. Regardless of value returned by this call user should call
+ * bio_enrollment_is_complete() to check if algorithm library accumulated enough
+ * data to create a template.
+ *
+ * Returns value in the range 0..100, or negative error (such as -EINVAL);
+ */
+int bio_enrollment_get_percent_complete(bio_enrollment_t enrollment);
+/*
+ * Indicates that given enrollment process is complete, and algorithm library
+ * should generate an active template that can be used in subsequent calls
+ * to bio_image_match() and bio_template_serialize() from enrollment data.
+ * After the template is created the library should release all resources
+ * associated with this enrollment.
+ *
+ * Argument 'templ' is optional and can be set to NULL if caller wishes to
+ * abort enrollment process.
+ *
+ * Returns 0 on success, negative error code (such as -EINVAL) on failure.
+ */
+int bio_enrollment_finish(bio_enrollment_t enrollment, bio_template_t *templ);
+
+#endif /* __CROS_EC_FPC_BIO_ALGORITHM_H */
diff --git a/driver/fingerprint/fpc/bep/fpc_misc.c b/driver/fingerprint/fpc/bep/fpc_misc.c
new file mode 100644
index 0000000000..c4c779b702
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc_misc.c
@@ -0,0 +1,51 @@
+/* Copyright 2019 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.
+ */
+
+/* FPC Platform Abstraction Layer */
+
+#include <stdint.h>
+#include <stddef.h>
+
+#include "shared_mem.h"
+#include "uart.h"
+
+void __unused *fpc_malloc(uint32_t size)
+{
+ char *data;
+ int rc;
+
+ rc = shared_mem_acquire(size, (char **)&data);
+
+ if (rc == 0)
+ return data;
+ else
+ return NULL;
+}
+
+void __unused fpc_free(void *data)
+{
+ shared_mem_release(data);
+}
+
+/* Not in release */
+void __unused fpc_assert_fail(const char *file, uint32_t line, const char *func,
+ const char *expr)
+{
+}
+
+void __unused fpc_log_var(const char *source, uint8_t level, const char *format,
+ ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ uart_vprintf(format, args);
+ va_end(args);
+}
+
+uint32_t abs(int32_t a)
+{
+ return (a < 0) ? (uint32_t)(-a) : (uint32_t)a;
+}
diff --git a/driver/fingerprint/fpc/bep/fpc_private.c b/driver/fingerprint/fpc/bep/fpc_private.c
new file mode 100644
index 0000000000..f69cffb0ce
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc_private.c
@@ -0,0 +1,260 @@
+/* Copyright 2019 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 <stdint.h>
+#include <stddef.h>
+
+#include "fpc_bio_algorithm.h"
+#include "fpsensor.h"
+#include "spi.h"
+#include "system.h"
+#include "util.h"
+
+#include STRINGIFY(FP_SENSOR_PRIVATE)
+
+/* Console output macros */
+#define CPRINTF(format, args...) cprintf(CC_FP, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_FP, format, ## args)
+
+static uint8_t enroll_ctx[FP_ALGORITHM_ENROLLMENT_SIZE] = {0};
+
+/* Recorded error flags */
+static uint16_t errors;
+
+/* FPC specific initialization and de-initialization functions */
+int fp_sensor_open(void);
+int fp_sensor_close(void);
+
+/* Get FPC library version code.*/
+const char *fp_sensor_get_version(void);
+
+/* Get FPC library build info.*/
+const char *fp_sensor_get_build_info(void);
+
+/* Sensor description */
+static struct ec_response_fp_info ec_fp_sensor_info = {
+ /* Sensor identification */
+ .vendor_id = FOURCC('F', 'P', 'C', ' '),
+ .product_id = 9,
+ .model_id = 1,
+ .version = 1,
+ /* Image frame characteristics */
+ .frame_size = FP_SENSOR_IMAGE_SIZE,
+ .pixel_format = V4L2_PIX_FMT_GREY,
+ .width = FP_SENSOR_RES_X,
+ .height = FP_SENSOR_RES_Y,
+ .bpp = FP_SENSOR_RES_BPP,
+};
+
+typedef struct fpc_bep_sensor fpc_bep_sensor_t;
+
+typedef struct {
+ const fpc_bep_sensor_t *sensor;
+ uint32_t image_buffer_size;
+} fpc_sensor_info_t;
+
+#if defined(FP_SENSOR_CONFIG_FPC1025)
+
+extern const fpc_bep_sensor_t fpc_bep_sensor_1025;
+extern const fpc_bep_algorithm_t fpc_bep_algorithm_pfe_1025;
+
+const fpc_sensor_info_t fpc_sensor_info = {
+ .sensor = &fpc_bep_sensor_1025,
+ .image_buffer_size = FP_SENSOR_IMAGE_SIZE,
+};
+
+const fpc_bio_info_t fpc_bio_info = {
+ .algorithm = &fpc_bep_algorithm_pfe_1025,
+ .template_size = FP_ALGORITHM_TEMPLATE_SIZE,
+};
+
+#elif defined(FP_SENSOR_CONFIG_FPC1035)
+
+extern const fpc_bep_sensor_t fpc_bep_sensor_1035;
+extern const fpc_bep_algorithm_t fpc_bep_algorithm_pfe_1035;
+
+const fpc_sensor_info_t fpc_sensor_info = {
+ .sensor = &fpc_bep_sensor_1035,
+ .image_buffer_size = FP_SENSOR_IMAGE_SIZE,
+};
+
+const fpc_bio_info_t fpc_bio_info = {
+ .algorithm = &fpc_bep_algorithm_pfe_1035,
+ .template_size = FP_ALGORITHM_TEMPLATE_SIZE,
+};
+#else
+#error "Sensor type not defined!"
+#endif
+
+/* Sensor IC commands */
+enum fpc_cmd {
+ FPC_CMD_DEEPSLEEP = 0x2C,
+ FPC_CMD_HW_ID = 0xFC,
+};
+
+/* Maximum size of a sensor command SPI transfer */
+#define MAX_CMD_SPI_TRANSFER_SIZE 3
+
+/* Memory for the SPI transfer buffer */
+static uint8_t spi_buf[MAX_CMD_SPI_TRANSFER_SIZE];
+
+static int fpc_send_cmd(const uint8_t cmd)
+{
+ spi_buf[0] = cmd;
+
+ return spi_transaction(SPI_FP_DEVICE, spi_buf, 1, spi_buf,
+ SPI_READBACK_ALL);
+}
+
+void fp_sensor_low_power(void)
+{
+ fpc_send_cmd(FPC_CMD_DEEPSLEEP);
+}
+
+static int fpc_check_hwid(void)
+{
+ uint16_t id;
+ int rc;
+
+ spi_buf[0] = FPC_CMD_HW_ID;
+
+ rc = spi_transaction(SPI_FP_DEVICE, spi_buf, 3, spi_buf,
+ SPI_READBACK_ALL);
+ if (rc) {
+ CPRINTS("FPC HW ID read failed %d", rc);
+ return FP_ERROR_SPI_COMM;
+ }
+
+ id = (spi_buf[1] << 8) | spi_buf[2];
+ if ((id >> 4) != FP_SENSOR_HWID) {
+ CPRINTS("FPC unknown silicon 0x%04x", id);
+ return FP_ERROR_BAD_HWID;
+ }
+ CPRINTS(FP_SENSOR_NAME " id 0x%04x", id);
+
+ return EC_SUCCESS;
+}
+
+/* Reset and initialize the sensor IC */
+int fp_sensor_init(void)
+{
+ int rc;
+
+ /* Print the binary libfpbep.a library version */
+ CPRINTS("FPC libfpbep.a %s", fp_sensor_get_version());
+
+ /* Print the BEP version and build time of the library */
+ CPRINTS("Build information - %s", fp_sensor_get_build_info());
+
+ rc = fp_sensor_open();
+ if (rc) {
+ errors |= FP_ERROR_INIT_FAIL;
+ CPRINTS("Error: fp_sensor_open() failed, result=%d", rc);
+ }
+
+ errors |= fpc_check_hwid();
+
+ rc = bio_algorithm_init();
+ if (rc < 0) {
+ errors |= FP_ERROR_INIT_FAIL;
+ CPRINTS("Error: bio_algorithm_init() failed, result=%d", rc);
+ }
+
+ /* Go back to low power */
+ fp_sensor_low_power();
+
+ return EC_SUCCESS;
+}
+
+/* Deinitialize the sensor IC */
+int fp_sensor_deinit(void)
+{
+ int rc;
+
+ rc = bio_algorithm_exit();
+ if (rc < 0)
+ CPRINTS("Error: bio_algorithm_exit() failed, result=%d", rc);
+
+ rc = fp_sensor_close();
+ if (rc < 0)
+ CPRINTS("Error: fp_sensor_close() failed, result=%d", rc);
+
+ return rc;
+}
+
+int fp_sensor_get_info(struct ec_response_fp_info *resp)
+{
+ int rc;
+
+ spi_buf[0] = FPC_CMD_HW_ID;
+
+ memcpy(resp, &ec_fp_sensor_info, sizeof(struct ec_response_fp_info));
+
+ rc = spi_transaction(SPI_FP_DEVICE, spi_buf, 3, spi_buf,
+ SPI_READBACK_ALL);
+ if (rc)
+ return EC_RES_ERROR;
+
+ resp->model_id = (spi_buf[1] << 8) | spi_buf[2];
+ resp->errors = errors;
+
+ return EC_SUCCESS;
+}
+
+int fp_finger_match(void *templ, uint32_t templ_count, uint8_t *image,
+ int32_t *match_index, uint32_t *update_bitmap)
+{
+ int rc;
+
+ rc = bio_template_image_match_list(templ, templ_count, image,
+ match_index, update_bitmap);
+ if (rc < 0)
+ CPRINTS("Error: bio_template_image_match_list() failed, result=%d",
+ rc);
+
+ return rc;
+}
+
+int fp_enrollment_begin(void)
+{
+ int rc;
+ bio_enrollment_t bio_enroll = enroll_ctx;
+
+ rc = bio_enrollment_begin(&bio_enroll);
+ if (rc < 0)
+ CPRINTS("Error: bio_enrollment_begin() failed, result=%d", rc);
+
+ return rc;
+}
+
+int fp_enrollment_finish(void *templ)
+{
+ int rc;
+ bio_enrollment_t bio_enroll = enroll_ctx;
+ bio_template_t bio_templ = templ;
+
+ rc = bio_enrollment_finish(bio_enroll, templ ? &bio_templ : NULL);
+ if (rc < 0)
+ CPRINTS("Error: bio_enrollment_finish() failed, result=%d", rc);
+
+ return rc;
+}
+
+int fp_finger_enroll(uint8_t *image, int *completion)
+{
+ int rc;
+ bio_enrollment_t bio_enroll = enroll_ctx;
+
+ rc = bio_enrollment_add_image(bio_enroll, image);
+ if (rc < 0) {
+ CPRINTS("Error: bio_enrollment_add_image() failed, result=%d",
+ rc);
+ return rc;
+ }
+
+ *completion = bio_enrollment_get_percent_complete(bio_enroll);
+
+ return rc;
+}
diff --git a/driver/fingerprint/fpc/bep/fpc_sensor_spi.c b/driver/fingerprint/fpc/bep/fpc_sensor_spi.c
new file mode 100644
index 0000000000..3db3713702
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc_sensor_spi.c
@@ -0,0 +1,94 @@
+/* Copyright 2019 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.
+ */
+
+/* FPC Platform Abstraction Layer */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "console.h"
+#include "fpsensor.h"
+#include "fpc_sensor_spi.h"
+#include "gpio.h"
+#include "spi.h"
+#include "util.h"
+
+#include STRINGIFY(FP_SENSOR_PRIVATE)
+
+/* Console output macros */
+#define CPRINTF(format, args...) cprintf(CC_FP, format, ##args)
+#define CPRINTS(format, args...) cprints(CC_FP, format, ##args)
+
+#define SPI_BUF_SIZE (1024)
+
+#define FPC_RESULT_OK (0)
+#define FPC_RESULT_IO_ERROR (-8)
+
+static uint8_t spi_buf[SPI_BUF_SIZE] FP_FRAME_SECTION __aligned(4);
+
+int __unused fpc_sensor_spi_write_read(uint8_t *write, uint8_t *read,
+ size_t size, bool leave_cs_asserted)
+{
+ int rc = 0;
+
+ if (size == FP_SENSOR_REAL_IMAGE_SIZE) {
+ rc |= spi_transaction(SPI_FP_DEVICE, write, size, read,
+ SPI_READBACK_ALL);
+ spi_transaction_flush(SPI_FP_DEVICE);
+ } else if (size <= SPI_BUF_SIZE) {
+ memcpy(spi_buf, write, size);
+ rc |= spi_transaction_async(SPI_FP_DEVICE, spi_buf, size,
+ spi_buf, SPI_READBACK_ALL);
+
+ /* De-asserting the sensor chip-select will clear the sensor
+ * internal command state. To run multiple sensor transactions
+ * in the same command state (typically image capture), leave
+ * chip-select asserted. Make sure chip-select is de-asserted
+ * when all transactions are finished.
+ */
+ if (!leave_cs_asserted)
+ spi_transaction_flush(SPI_FP_DEVICE);
+ else
+ spi_transaction_wait(SPI_FP_DEVICE);
+
+ memcpy(read, spi_buf, size);
+ } else {
+ rc = -1;
+ }
+
+ if (rc == 0) {
+ return FPC_RESULT_OK;
+ } else {
+ CPRINTS("Error: spi_transaction()/spi_transaction_async() failed, result=%d",
+ rc);
+ return FPC_RESULT_IO_ERROR;
+ }
+}
+
+bool __unused fpc_sensor_spi_check_irq(void)
+{
+ return (gpio_get_level(GPIO_FPS_INT) == 1);
+}
+
+bool __unused fpc_sensor_spi_read_irq(void)
+{
+ return (gpio_get_level(GPIO_FPS_INT) == 1);
+}
+
+void __unused fpc_sensor_spi_reset(bool state)
+{
+ gpio_set_level(GPIO_FP_RST_ODL, state ? 0 : 1);
+}
+
+void __unused fpc_sensor_spi_init(uint32_t speed_hz)
+{
+}
+
+int __unused fpc_sensor_wfi(uint16_t timeout_ms, fpc_wfi_check_t enter_wfi,
+ bool enter_wfi_mode)
+{
+ return FPC_RESULT_OK;
+}
diff --git a/driver/fingerprint/fpc/bep/fpc_sensor_spi.h b/driver/fingerprint/fpc/bep/fpc_sensor_spi.h
new file mode 100644
index 0000000000..4b9bcd63a8
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc_sensor_spi.h
@@ -0,0 +1,98 @@
+/* Copyright 2019 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.
+ */
+
+#ifndef __CROS_EC_FPC_SENSOR_SPI_H
+#define __CROS_EC_FPC_SENSOR_SPI_H
+
+/**
+ * @file fpc_sensor_spi.h
+ * @brief Driver for SPI master.
+ *
+ * Driver for SPI master. Intended for communication with fingerprint sensor.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef bool (*fpc_wfi_check_t)(void);
+
+/**
+ * @brief Writes and reads SPI data.
+ *
+ * Writes data to SPI interface and reads data from SPI interface, with chip
+ * select control. The caller is blocked until the operation is complete. By use
+ * of the chip select control parameter a single SPI transaction can be split in
+ * several calls.
+ *
+ * @param[in] write Data to write. Must not be NULL if size > 0.
+ * @param[in,out] read Receive data buffer. The caller is responsible for
+ * allocating buffer. NULL => response is thrown away.
+ * @param[in] size Number of bytes to write (same as bytes received).
+ * 0 => Only chip select control.
+ * @param[in] leave_cs_asserted True => chip select is left in asserted
+ * state.
+ * False => chip select is de-asserted before
+ * return.
+ * @return ::fpc_bep_result_t
+ */
+int __unused fpc_sensor_spi_write_read(uint8_t *write, uint8_t *read,
+ size_t size, bool leave_cs_asserted);
+
+/**
+ * @brief Read sensor IRQ status.
+ *
+ * Returns status of the sensor IRQ.
+ *
+ * @return true if the sensor IRQ is currently active, otherwise false.
+ */
+bool __unused fpc_sensor_spi_check_irq(void);
+
+/**
+ * @brief Read sensor IRQ status and then set status to false.
+ *
+ * Returns status of the sensor IRQ and sets the status to false.
+ *
+ * @return true if the sensor IRQ has been active, otherwise false.
+ */
+bool __unused fpc_sensor_spi_read_irq(void);
+
+/**
+ * @brief Set sensor reset state.
+ *
+ * Set sensor reset state.
+ *
+ * @param[in] state Reset state.
+ * true => reset sensor, i.e. low GPIO state
+ * false => normal operation, i.e. high GPIO state
+ */
+void __unused fpc_sensor_spi_reset(bool state);
+
+/**
+ * @brief Initializes SPI master.
+ *
+ * @param[in] speed_hz Maximum SPI clock speed according to sensor HW spec
+ * (unit Hz).
+ *
+ */
+void __unused fpc_sensor_spi_init(uint32_t speed_hz);
+
+/**
+ * @brief Set system in WFI mode while waiting sensor IRQ.
+ *
+ * @note This mode only requires the system to be able to wake up from Sensor
+ * IRQ pin, all other peripheral can be turned off.
+ *
+ * @note The system time must be adjusted upon WFI return.
+ *
+ * @param[in] timeout_ms Time in ms before waking up, 0 if no timeout.
+ * @param[in] enter_wfi Function pointer to check WFI entry.
+ * @param[in] enter_wfi_mode Bool that is used when comparing the value returned
+ * by enter_wfi.
+ * @return FPC_RESULT_OK, FPC_RESULT_TIMEOUT
+ */
+int __unused fpc_sensor_wfi(uint16_t timeout_ms, fpc_wfi_check_t enter_wfi,
+ bool enter_wfi_mode);
+
+#endif /* __CROS_EC_FPC_SENSOR_SPI_H */
diff --git a/driver/fingerprint/fpc/bep/fpc_timebase.c b/driver/fingerprint/fpc/bep/fpc_timebase.c
new file mode 100644
index 0000000000..113e150ed9
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc_timebase.c
@@ -0,0 +1,29 @@
+/* Copyright 2019 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.
+ */
+
+/* FPC Platform Abstraction Layer */
+
+#include <stdint.h>
+
+#include "fpc_timebase.h"
+#include "timer.h"
+
+uint32_t __unused fpc_timebase_get_tick(void)
+{
+ clock_t time;
+
+ time = clock();
+
+ return (uint32_t)time;
+}
+
+void __unused fpc_timebase_busy_wait(uint32_t ms)
+{
+ udelay(ms * 1000);
+}
+
+void __unused fpc_timebase_init(void)
+{
+}
diff --git a/driver/fingerprint/fpc/bep/fpc_timebase.h b/driver/fingerprint/fpc/bep/fpc_timebase.h
new file mode 100644
index 0000000000..388d13293e
--- /dev/null
+++ b/driver/fingerprint/fpc/bep/fpc_timebase.h
@@ -0,0 +1,48 @@
+/* Copyright 2019 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.
+ */
+
+#ifndef __CROS_EC_FPC_TIMEBASE_H
+#define __CROS_EC_FPC_TIMEBASE_H
+
+/**
+ * @file fpc_timebase.h
+ * @brief Timebase based on a system tick.
+ *
+ * Supplies tick counter and wait operation(s).
+ */
+
+#include <stdint.h>
+
+#include "common.h"
+
+/**
+ * @brief Reads the system tick counter.
+ *
+ * @details To handle tick counter wrap around when checking for timeout, make
+ * sure to do the calculation in the following manner:
+ * "if ((current_tick - old_tick) > timeout) {"
+ * Example: current time (uint32_t) = 10 ticks
+ * old time (uint32_t) = 30 ticks before overflow of uint32_t
+ * current_time - old_time = 10 - (2**32 - 30) -> wraps around to 40
+ *
+ * @return Tick count since fpc_timebase_init() call. [ms]
+ */
+uint32_t __unused fpc_timebase_get_tick(void);
+
+/**
+ * @brief Busy wait.
+ *
+ * @param[in] ms Time to wait [ms].
+ * 0 => return immediately
+ * 1 => wait at least 1ms etc.
+ */
+void __unused fpc_timebase_busy_wait(uint32_t ms);
+
+/**
+ * @brief Initializes timebase. Starts system tick counter.
+ */
+void __unused fpc_timebase_init(void);
+
+#endif /* __CROS_EC_FPC_TIMEBASE_H */