diff options
-rw-r--r-- | common/fpsensor/fpsensor.c | 25 | ||||
-rw-r--r-- | common/fpsensor/fpsensor_state.c | 31 | ||||
-rw-r--r-- | include/fpsensor_state.h | 9 |
3 files changed, 49 insertions, 16 deletions
diff --git a/common/fpsensor/fpsensor.c b/common/fpsensor/fpsensor.c index f1b31e43c7..1e384e5a5f 100644 --- a/common/fpsensor/fpsensor.c +++ b/common/fpsensor/fpsensor.c @@ -593,12 +593,23 @@ static void upload_pgm_image(uint8_t *frame) CPRINTF("\x04"); /* End Of Transmission */ } -static int fp_console_action(uint32_t mode) +static enum ec_error_list fp_console_action(uint32_t mode) { int tries = 200; - ccprintf("Waiting for finger ...\n"); - sensor_mode = mode; - task_set_event(TASK_ID_FPSENSOR, TASK_EVENT_UPDATE_CONFIG, 0); + uint32_t mode_output = 0; + int rc = 0; + + CPRINTS("Waiting for finger ..."); + + rc = fp_set_sensor_mode(mode, &mode_output); + + if (rc != EC_RES_SUCCESS) { + /* + * EC host command errors do not directly map to console command + * errors. + */ + return EC_ERROR_UNKNOWN; + } while (tries--) { if (!(sensor_mode & FP_MODE_ANY_CAPTURE)) { @@ -614,7 +625,7 @@ int command_fpcapture(int argc, char **argv) { int capture_type = FP_CAPTURE_SIMPLE_IMAGE; uint32_t mode; - int rc; + enum ec_error_list rc; if (system_is_locked()) return EC_RES_ACCESS_DENIED; @@ -639,7 +650,7 @@ DECLARE_CONSOLE_COMMAND(fpcapture, command_fpcapture, "", ""); int command_fpenroll(int argc, char **argv) { - int rc; + enum ec_error_list rc; int percent = 0; uint32_t event; static const char * const enroll_str[] = {"OK", "Low Quality", @@ -675,7 +686,7 @@ DECLARE_CONSOLE_COMMAND(fpenroll, command_fpenroll, "", ""); int command_fpmatch(int argc, char **argv) { - int rc = fp_console_action(FP_MODE_MATCH); + enum ec_error_list rc = fp_console_action(FP_MODE_MATCH); uint32_t event = atomic_read_clear(&fp_events); if (rc == EC_SUCCESS && event & EC_MKBP_FP_MATCH) { diff --git a/common/fpsensor/fpsensor_state.c b/common/fpsensor/fpsensor_state.c index 2b546191a3..9767ed71dc 100644 --- a/common/fpsensor/fpsensor_state.c +++ b/common/fpsensor/fpsensor_state.c @@ -139,27 +139,40 @@ static int validate_fp_mode(const uint32_t mode) return EC_SUCCESS; } -static int fp_command_mode(struct host_cmd_handler_args *args) +int fp_set_sensor_mode(uint32_t mode, uint32_t *mode_output) { - const struct ec_params_fp_mode *p = args->params; - struct ec_response_fp_mode *r = args->response; int ret; - ret = validate_fp_mode(p->mode); + if (mode_output == NULL) + return EC_RES_INVALID_PARAM; + + ret = validate_fp_mode(mode); if (ret != EC_SUCCESS) { - CPRINTS("Invalid FP mode 0x%x", p->mode); + CPRINTS("Invalid FP mode 0x%x", mode); return EC_RES_INVALID_PARAM; } - if (!(p->mode & FP_MODE_DONT_CHANGE)) { - sensor_mode = p->mode; + if (!(mode & FP_MODE_DONT_CHANGE)) { + sensor_mode = mode; task_set_event(TASK_ID_FPSENSOR, TASK_EVENT_UPDATE_CONFIG, 0); } - r->mode = sensor_mode; - args->response_size = sizeof(*r); + *mode_output = sensor_mode; return EC_RES_SUCCESS; } + +static int fp_command_mode(struct host_cmd_handler_args *args) +{ + const struct ec_params_fp_mode *p = args->params; + struct ec_response_fp_mode *r = args->response; + + int ret = fp_set_sensor_mode(p->mode, &r->mode); + + if (ret == EC_RES_SUCCESS) + args->response_size = sizeof(*r); + + return ret; +} DECLARE_HOST_COMMAND(EC_CMD_FP_MODE, fp_command_mode, EC_VER_MASK(0)); static int fp_command_context(struct host_cmd_handler_args *args) diff --git a/include/fpsensor_state.h b/include/fpsensor_state.h index a07f7a683d..d11af693b5 100644 --- a/include/fpsensor_state.h +++ b/include/fpsensor_state.h @@ -96,4 +96,13 @@ int fp_get_next_event(uint8_t *out); */ int fp_tpm_seed_is_set(void); +/** + * Change the sensor mode. + * + * @param mode new mode to change to + * @param mode_output resulting mode + * @return EC_RES_SUCCESS on success. Error code on failure. + */ +int fp_set_sensor_mode(uint32_t mode, uint32_t *mode_output); + #endif /* __CROS_EC_FPSENSOR_STATE_H */ |