@@ -167,14 +167,19 @@ static int machxo2_cleanup(struct fpga_manager *mgr)
return ret;
}
+static bool machxo2_status_done(unsigned long status)
+{
+ return !test_bit(BUSY, &status) && test_bit(DONE, &status) &&
+ get_err(&status) == ENOERR;
+}
+
static enum fpga_mgr_states machxo2_spi_state(struct fpga_manager *mgr)
{
struct spi_device *spi = mgr->priv;
unsigned long status;
get_status(spi, &status);
- if (!test_bit(BUSY, &status) && test_bit(DONE, &status) &&
- get_err(&status) == ENOERR)
+ if (machxo2_status_done(status))
return FPGA_MGR_STATE_OPERATING;
return FPGA_MGR_STATE_UNKNOWN;
@@ -329,8 +334,7 @@ static int machxo2_write_complete(struct fpga_manager *mgr,
/* check refresh status */
get_status(spi, &status);
dump_status_reg(&status);
- if (!test_bit(BUSY, &status) && test_bit(DONE, &status) &&
- get_err(&status) == ENOERR)
+ if (machxo2_status_done(status))
break;
if (++refreshloop == MACHXO2_MAX_REFRESH_LOOP) {
machxo2_cleanup(mgr);
We have the same sequence at two different places, so factor it out into a helper to improve readability. Signed-off-by: Johannes Zink <j.zink@pengutronix.de> --- drivers/fpga/machxo2-spi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)