drivers: Use SSM delayed actions when possible

This commit is contained in:
Marco Trevisan (Treviño) 2019-11-22 18:39:02 +01:00
parent e12978f402
commit bac6382f67
3 changed files with 29 additions and 59 deletions

View file

@ -829,26 +829,6 @@ enum rebootpwr_states {
REBOOTPWR_NUM_STATES, REBOOTPWR_NUM_STATES,
}; };
static void
rebootpwr_pause_cb (FpDevice *dev,
void *data)
{
FpiSsm *ssm = data;
FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev);
if (!--self->rebootpwr_ctr)
{
fp_err ("could not reboot device power");
fpi_ssm_mark_failed (ssm,
fpi_device_error_new_msg (FP_DEVICE_ERROR,
"Could not reboot device"));
}
else
{
fpi_ssm_jump_to_state (ssm, REBOOTPWR_GET_HWSTAT);
}
}
static void static void
rebootpwr_run_state (FpiSsm *ssm, FpDevice *_dev) rebootpwr_run_state (FpiSsm *ssm, FpDevice *_dev)
{ {
@ -875,7 +855,17 @@ rebootpwr_run_state (FpiSsm *ssm, FpDevice *_dev)
break; break;
case REBOOTPWR_PAUSE: case REBOOTPWR_PAUSE:
fpi_device_add_timeout (_dev, 10, rebootpwr_pause_cb, ssm, NULL); if (!--self->rebootpwr_ctr)
{
fp_err ("could not reboot device power");
fpi_ssm_mark_failed (ssm,
fpi_device_error_new_msg (FP_DEVICE_ERROR,
"Could not reboot device"));
}
else
{
fpi_ssm_jump_to_state_delayed (ssm, 10, REBOOTPWR_GET_HWSTAT);
}
break; break;
} }
} }
@ -916,30 +906,6 @@ enum powerup_states {
POWERUP_NUM_STATES, POWERUP_NUM_STATES,
}; };
static void
powerup_pause_cb (FpDevice *dev,
void *data)
{
FpiSsm *ssm = data;
FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev);
if (!--self->powerup_ctr)
{
fp_err ("could not power device up");
fpi_ssm_mark_failed (ssm,
fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
"could not power device up"));
}
else if (!self->profile->auth_cr)
{
fpi_ssm_jump_to_state (ssm, POWERUP_SET_HWSTAT);
}
else
{
fpi_ssm_next_state (ssm);
}
}
static void static void
powerup_run_state (FpiSsm *ssm, FpDevice *_dev) powerup_run_state (FpiSsm *ssm, FpDevice *_dev)
{ {
@ -971,7 +937,21 @@ powerup_run_state (FpiSsm *ssm, FpDevice *_dev)
break; break;
case POWERUP_PAUSE: case POWERUP_PAUSE:
fpi_device_add_timeout (_dev, 10, powerup_pause_cb, ssm, NULL); if (!--self->powerup_ctr)
{
fp_err ("could not power device up");
fpi_ssm_mark_failed (ssm,
fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL,
"could not power device up"));
}
else if (!self->profile->auth_cr)
{
fpi_ssm_jump_to_state_delayed (ssm, POWERUP_SET_HWSTAT, 10);
}
else
{
fpi_ssm_next_state_delayed (ssm, 10);
}
break; break;
case POWERUP_CHALLENGE_RESPONSE: case POWERUP_CHALLENGE_RESPONSE:

View file

@ -479,16 +479,6 @@ receive_callback (FpiUsbTransfer *transfer, FpDevice *device,
} }
} }
/* SSM stub to prepare device to another scan after orange light was on */
static void
another_scan (FpDevice *dev,
void *data)
{
FpiSsm *ssm = data;
fpi_ssm_jump_to_state (ssm, SSM_TURN_ON);
}
/* Main SSM loop */ /* Main SSM loop */
static void static void
activate_ssm (FpiSsm *ssm, FpDevice *dev) activate_ssm (FpiSsm *ssm, FpDevice *dev)
@ -637,8 +627,7 @@ activate_ssm (FpiSsm *ssm, FpDevice *dev)
case SSM_WAIT_ANOTHER_SCAN: case SSM_WAIT_ANOTHER_SCAN:
/* Orange light is on now */ /* Orange light is on now */
fpi_device_add_timeout (dev, VFS_SSM_ORANGE_TIMEOUT, fpi_ssm_jump_to_state_delayed (ssm, SSM_TURN_ON, VFS_SSM_ORANGE_TIMEOUT);
another_scan, ssm, NULL);
break; break;
default: default:

View file

@ -168,6 +168,8 @@ fpi_ssm_free (FpiSsm *machine)
if (!machine) if (!machine)
return; return;
BUG_ON (machine->timeout != NULL);
if (machine->ssm_data_destroy) if (machine->ssm_data_destroy)
g_clear_pointer (&machine->ssm_data, machine->ssm_data_destroy); g_clear_pointer (&machine->ssm_data, machine->ssm_data_destroy);
g_clear_pointer (&machine->error, g_error_free); g_clear_pointer (&machine->error, g_error_free);
@ -250,7 +252,6 @@ void
fpi_ssm_mark_completed (FpiSsm *machine) fpi_ssm_mark_completed (FpiSsm *machine)
{ {
BUG_ON (machine->completed); BUG_ON (machine->completed);
BUG_ON (machine->timeout);
BUG_ON (machine->timeout != NULL); BUG_ON (machine->timeout != NULL);
g_clear_pointer (&machine->timeout, g_source_destroy); g_clear_pointer (&machine->timeout, g_source_destroy);