only:MC33810 extracting check_comm() method

This commit is contained in:
rusefi 2023-12-26 18:57:15 -05:00
parent 33a6b1fe15
commit 42315a55e6
1 changed files with 19 additions and 11 deletions

View File

@ -103,6 +103,7 @@ struct Mc33810 : public GpioChip {
int update_output_and_diag(); int update_output_and_diag();
int chip_init(); int chip_init();
int check_comm();
void wake_driver(); void wake_driver();
int bind_io(); int bind_io();
@ -297,6 +298,23 @@ int Mc33810::bind_io() {
return ret; return ret;
} }
int Mc33810::check_comm() {
/* check SPI communication */
/* 0. set echo mode, chip number - don't care */
int ret = spi_rw(MC_CMD_SPI_CHECK, NULL);
/* 1. check loopback */
uint16_t rx;
ret |= spi_rw(MC_CMD_READ_REG(REG_REV), &rx);
if (ret) {
efiPrintf(DRIVER_NAME " first SPI RX failed");
return -7;
}
if (rx != SPI_CHECK_ACK) {
return -2;
}
return ret;
}
/** /**
* @brief MC33810 chip init. * @brief MC33810 chip init.
* @details Checks communication. Check chip presence. * @details Checks communication. Check chip presence.
@ -317,18 +335,8 @@ int Mc33810::chip_init()
goto err_gpios; goto err_gpios;
} }
/* check SPI communication */ ret = check_comm();
/* 0. set echo mode, chip number - don't care */
ret = spi_rw(MC_CMD_SPI_CHECK, NULL);
/* 1. check loopback */
ret |= spi_rw(MC_CMD_READ_REG(REG_REV), &rx);
if (ret) { if (ret) {
ret = -7;
efiPrintf(DRIVER_NAME " first SPI RX failed");
goto err_gpios;
}
if (rx != SPI_CHECK_ACK) {
ret = -2;
goto err_gpios; goto err_gpios;
} }