|
@@ -32,17 +32,42 @@ enum aan_cmd {
|
|
|
AAN_READ_REG_RESP = 0x1a,
|
|
AAN_READ_REG_RESP = 0x1a,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+static void aan_spi_parse_rx(struct spi_port *);
|
|
|
|
|
+
|
|
|
static
|
|
static
|
|
|
-bool aan_spi_cmd(struct spi_port * const spi, const uint8_t cmd, const uint8_t chip, const struct timeval * const tvp_timeout)
|
|
|
|
|
|
|
+void aan_spi_cmd_queue(struct spi_port * const spi, const uint8_t cmd, const uint8_t chip, const void * const data, const size_t datalen)
|
|
|
{
|
|
{
|
|
|
const struct aan_hooks * const hooks = spi->userp;
|
|
const struct aan_hooks * const hooks = spi->userp;
|
|
|
const uint8_t cmdbuf[2] = {cmd, chip};
|
|
const uint8_t cmdbuf[2] = {cmd, chip};
|
|
|
hooks->precmd(spi);
|
|
hooks->precmd(spi);
|
|
|
spi_emit_buf(spi, cmdbuf, sizeof(cmdbuf));
|
|
spi_emit_buf(spi, cmdbuf, sizeof(cmdbuf));
|
|
|
|
|
+ if (datalen)
|
|
|
|
|
+ spi_emit_buf(spi, data, datalen);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static
|
|
|
|
|
+bool aan_spi_txrx(struct spi_port * const spi)
|
|
|
|
|
+{
|
|
|
if (unlikely(!spi_txrx(spi)))
|
|
if (unlikely(!spi_txrx(spi)))
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ aan_spi_parse_rx(spi);
|
|
|
spi_clear_buf(spi);
|
|
spi_clear_buf(spi);
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static
|
|
|
|
|
+bool aan_spi_cmd_send(struct spi_port * const spi, const uint8_t cmd, const uint8_t chip, const void * const data, const size_t datalen)
|
|
|
|
|
+{
|
|
|
|
|
+ aan_spi_cmd_queue(spi, cmd, chip, data, datalen);
|
|
|
|
|
+ return aan_spi_txrx(spi);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static
|
|
|
|
|
+bool aan_spi_cmd_resp(struct spi_port * const spi, const uint8_t cmd, const uint8_t chip, const struct timeval * const tvp_timeout)
|
|
|
|
|
+{
|
|
|
|
|
+ const uint8_t cmdbuf[2] = {cmd, chip};
|
|
|
|
|
+
|
|
|
spi_emit_nop(spi, 2);
|
|
spi_emit_nop(spi, 2);
|
|
|
|
|
|
|
|
uint8_t * const rx = spi_getrxbuf(spi);
|
|
uint8_t * const rx = spi_getrxbuf(spi);
|
|
@@ -52,6 +77,7 @@ bool aan_spi_cmd(struct spi_port * const spi, const uint8_t cmd, const uint8_t c
|
|
|
return false;
|
|
return false;
|
|
|
if (!memcmp(rx, cmdbuf, 2))
|
|
if (!memcmp(rx, cmdbuf, 2))
|
|
|
break;
|
|
break;
|
|
|
|
|
+ aan_spi_parse_rx(spi);
|
|
|
if (unlikely(tvp_timeout && timer_passed(tvp_timeout, NULL)))
|
|
if (unlikely(tvp_timeout && timer_passed(tvp_timeout, NULL)))
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -60,10 +86,20 @@ bool aan_spi_cmd(struct spi_port * const spi, const uint8_t cmd, const uint8_t c
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static
|
|
|
|
|
+bool aan_spi_cmd(struct spi_port * const spi, const uint8_t cmd, const uint8_t chip, const void * const data, const size_t datalen, const struct timeval * const tvp_timeout)
|
|
|
|
|
+{
|
|
|
|
|
+ if (!aan_spi_cmd_send(spi, cmd, chip, data, datalen))
|
|
|
|
|
+ return false;
|
|
|
|
|
+ if (!aan_spi_cmd_resp(spi, cmd, chip, tvp_timeout))
|
|
|
|
|
+ return false;
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static
|
|
static
|
|
|
int aan_spi_autoaddress(struct spi_port * const spi, const struct timeval * const tvp_timeout)
|
|
int aan_spi_autoaddress(struct spi_port * const spi, const struct timeval * const tvp_timeout)
|
|
|
{
|
|
{
|
|
|
- if (!aan_spi_cmd(spi, AAN_BIST_START, AAN_ALL_CHIPS, tvp_timeout))
|
|
|
|
|
|
|
+ if (!aan_spi_cmd(spi, AAN_BIST_START, AAN_ALL_CHIPS, NULL, 0, tvp_timeout))
|
|
|
applogr(-1, LOG_DEBUG, "%s: %s failed", __func__, "AAN_BIST_START");
|
|
applogr(-1, LOG_DEBUG, "%s: %s failed", __func__, "AAN_BIST_START");
|
|
|
spi_emit_nop(spi, 2);
|
|
spi_emit_nop(spi, 2);
|
|
|
if (!spi_txrx(spi))
|
|
if (!spi_txrx(spi))
|
|
@@ -76,7 +112,13 @@ int aan_detect_spi(struct spi_port * const spi)
|
|
|
{
|
|
{
|
|
|
struct timeval tv_timeout;
|
|
struct timeval tv_timeout;
|
|
|
timer_set_delay_from_now(&tv_timeout, AAN_PROBE_TIMEOUT_US);
|
|
timer_set_delay_from_now(&tv_timeout, AAN_PROBE_TIMEOUT_US);
|
|
|
- if (!aan_spi_cmd(spi, AAN_RESET, AAN_ALL_CHIPS, &tv_timeout))
|
|
|
|
|
|
|
+ if (!aan_spi_cmd(spi, AAN_RESET, AAN_ALL_CHIPS, NULL, 0, &tv_timeout))
|
|
|
return -1;
|
|
return -1;
|
|
|
return aan_spi_autoaddress(spi, &tv_timeout);
|
|
return aan_spi_autoaddress(spi, &tv_timeout);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+static
|
|
|
|
|
+void aan_spi_parse_rx(struct spi_port * const spi)
|
|
|
|
|
+{
|
|
|
|
|
+ // TODO
|
|
|
|
|
+}
|