can: mcp251xfd: mcp251xfd_regmap_crc_read_one(): Factor out crc check into separate function
This patch factors out the crc check into a separate function. This is preparation for the next patch. Link: https://lore.kernel.org/r/20210406110617.1865592-4-mkl@pengutronix.de Cc: Manivannan Sadhasivam <mani@kernel.org> Cc: Thomas Kopp <thomas.kopp@microchip.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
parent
0084e298ac
commit
ef7a8c3e75
|
@ -233,20 +233,11 @@ mcp251xfd_regmap_crc_write(void *context,
|
|||
}
|
||||
|
||||
static int
|
||||
mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv,
|
||||
struct spi_message *msg, unsigned int data_len)
|
||||
mcp251xfd_regmap_crc_read_check_crc(const struct mcp251xfd_map_buf_crc * const buf_rx,
|
||||
const struct mcp251xfd_map_buf_crc * const buf_tx,
|
||||
unsigned int data_len)
|
||||
{
|
||||
const struct mcp251xfd_map_buf_crc *buf_rx = priv->map_buf_crc_rx;
|
||||
const struct mcp251xfd_map_buf_crc *buf_tx = priv->map_buf_crc_tx;
|
||||
u16 crc_received, crc_calculated;
|
||||
int err;
|
||||
|
||||
BUILD_BUG_ON(sizeof(buf_rx->cmd) != sizeof(__be16) + sizeof(u8));
|
||||
BUILD_BUG_ON(sizeof(buf_tx->cmd) != sizeof(__be16) + sizeof(u8));
|
||||
|
||||
err = spi_sync(priv->spi, msg);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
crc_received = get_unaligned_be16(buf_rx->data + data_len);
|
||||
crc_calculated = mcp251xfd_crc16_compute2(&buf_tx->cmd,
|
||||
|
@ -259,6 +250,25 @@ mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
mcp251xfd_regmap_crc_read_one(struct mcp251xfd_priv *priv,
|
||||
struct spi_message *msg, unsigned int data_len)
|
||||
{
|
||||
const struct mcp251xfd_map_buf_crc *buf_rx = priv->map_buf_crc_rx;
|
||||
const struct mcp251xfd_map_buf_crc *buf_tx = priv->map_buf_crc_tx;
|
||||
int err;
|
||||
|
||||
BUILD_BUG_ON(sizeof(buf_rx->cmd) != sizeof(__be16) + sizeof(u8));
|
||||
BUILD_BUG_ON(sizeof(buf_tx->cmd) != sizeof(__be16) + sizeof(u8));
|
||||
|
||||
err = spi_sync(priv->spi, msg);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return mcp251xfd_regmap_crc_read_check_crc(buf_rx, buf_tx, data_len);
|
||||
}
|
||||
|
||||
static int
|
||||
mcp251xfd_regmap_crc_read(void *context,
|
||||
const void *reg_p, size_t reg_len,
|
||||
|
|
Loading…
Reference in New Issue