staticint mpf_read_status(struct mpf_priv *priv)
{ /* * HW status is returned on MISO in the first byte after CS went * active. However, first reading can be inadequate, so we submit * two identical SPI transfers and use result of the later one.
*/ struct spi_transfer xfers[2] = {
{
.tx_buf = &priv->tx,
.rx_buf = &priv->rx,
.len = 1,
.cs_change = 1,
}, {
.tx_buf = &priv->tx,
.rx_buf = &priv->rx,
.len = 1,
},
};
u8 status; int ret;
priv->tx = MPF_SPI_READ_STATUS;
ret = spi_sync_transfer(priv->spi, xfers, 2); if (ret) return ret;
status = priv->rx;
if ((status & MPF_STATUS_SPI_VIOLATION) ||
(status & MPF_STATUS_SPI_ERROR)) return -EIO;
/* * Go through look-up table to find out where actual bitstream starts * and where sizes of components of the bitstream lies.
*/
blocks_num = *(buf + header_size - 1);
block_id_offset = header_size + MPF_LOOKUP_TABLE_BLOCK_ID_OFFSET;
block_start_offset = header_size + MPF_LOOKUP_TABLE_BLOCK_START_OFFSET;
if (!bitstream_start || !components_size_start) {
dev_err(&mgr->dev, "Failed to parse header look-up table\n"); return -EFAULT;
}
/* * Parse bitstream size. * Sizes of components of the bitstream are 22-bits long placed next * to each other. Image header should be extended by now up to where * actual bitstream starts, so no need for overflow check anymore.
*/
components_num = get_unaligned_le16(buf + MPF_DATA_SIZE_OFFSET);
for (i = 0; i < components_num; i++) {
component_size_byte_num =
(i * MPF_BITS_PER_COMPONENT_SIZE) / BITS_PER_BYTE;
component_size_byte_off =
(i * MPF_BITS_PER_COMPONENT_SIZE) % BITS_PER_BYTE;
staticint mpf_poll_status(struct mpf_priv *priv, u8 mask)
{ int ret, status;
/* * Busy poll HW status. Polling stops if any of the following * conditions are met: * - timeout is reached * - mpf_read_status() returns an error * - busy bit is cleared AND mask bits are set
*/
ret = read_poll_timeout(mpf_read_status, status,
(status < 0) ||
((status & (MPF_STATUS_BUSY | mask)) == mask),
0, MPF_STATUS_POLL_TIMEOUT, false, priv); if (ret < 0) return ret;
return status;
}
staticint mpf_spi_write(struct mpf_priv *priv, constvoid *buf, size_t buf_size)
{ int status = mpf_poll_status(priv, 0);
if (count % MPF_SPI_FRAME_SIZE) {
dev_err(dev, "Bitstream size is not a multiple of %d\n",
MPF_SPI_FRAME_SIZE); return -EINVAL;
}
for (i = 0; i < count / MPF_SPI_FRAME_SIZE; i++) {
ret = mpf_spi_frame_write(priv, buf + i * MPF_SPI_FRAME_SIZE); if (ret) {
dev_err(dev, "Failed to write bitstream frame %d/%zu\n",
i, count / MPF_SPI_FRAME_SIZE); return ret;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.