lkml.org 
[lkml]   [2021]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 47/50] wilc1000: factor SPI DMA command initialization code into a function
Date
Introduce wilc_spi_dma_init_cmd() as a helper function as this will
come in handy later.

Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
---
drivers/net/wireless/microchip/wilc1000/spi.c | 41 +++++++++++++------
1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c
index 189907580d921..3e2022b43ee70 100644
--- a/drivers/net/wireless/microchip/wilc1000/spi.c
+++ b/drivers/net/wireless/microchip/wilc1000/spi.c
@@ -650,21 +650,14 @@ static int wilc_spi_write_cmd(struct wilc *wilc, u8 cmd, u32 adr, u32 data,
return 0;
}

-static int wilc_spi_dma_rw(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz)
+static int wilc_spi_dma_init_cmd(struct wilc *wilc, struct wilc_spi_cmd *c,
+ u8 cmd, u32 adr, u32 sz)
{
struct spi_device *spi = to_spi_device(wilc->dev);
struct wilc_spi *spi_priv = wilc->bus_data;
- u16 crc_recv, crc_calc;
- u8 wb[32], rb[32];
- int cmd_len, resp_len;
- int retry, ix = 0;
- u8 crc[2], *crc7;
- struct wilc_spi_cmd *c;
- struct wilc_spi_rsp_data *r;
+ int cmd_len;
+ u8 *crc7;

- memset(wb, 0x0, sizeof(wb));
- memset(rb, 0x0, sizeof(rb));
- c = (struct wilc_spi_cmd *)wb;
c->cmd_type = cmd;
if (cmd == CMD_DMA_WRITE || cmd == CMD_DMA_READ) {
c->u.dma_cmd.addr[0] = adr >> 16;
@@ -687,10 +680,32 @@ static int wilc_spi_dma_rw(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz)
return -EINVAL;
}
if (spi_priv->crc7_enabled) {
- crc7 = wb + cmd_len;
- *crc7 = wilc_get_crc7(wb, cmd_len);
+ crc7 = (u8 *)c + cmd_len;
+ *crc7 = wilc_get_crc7((u8 *)c, cmd_len);
cmd_len += 1;
}
+ return cmd_len;
+}
+
+static int wilc_spi_dma_rw(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz)
+{
+ struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
+ u16 crc_recv, crc_calc;
+ u8 wb[32], rb[32];
+ int cmd_len, resp_len;
+ int retry, ix = 0;
+ u8 crc[2];
+ struct wilc_spi_cmd *c;
+ struct wilc_spi_rsp_data *r;
+
+ memset(wb, 0x0, sizeof(wb));
+ memset(rb, 0x0, sizeof(rb));
+ c = (struct wilc_spi_cmd *)wb;
+
+ cmd_len = wilc_spi_dma_init_cmd(wilc, c, cmd, adr, sz);
+ if (cmd_len < 0)
+ return -EINVAL;

resp_len = sizeof(*r);

--
2.25.1
\
 
 \ /
  Last update: 2021-12-23 02:16    [W:0.213 / U:0.792 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site