diff options
author | Marek Vasut <marex@denx.de> | 2019-06-25 19:43:44 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-06-27 14:00:31 -0400 |
commit | ff509dab43763899bff796c8ae5e57261ff18edc (patch) | |
tree | 94df87913db41060bfa95f39c0a43c113c09565e | |
parent | 5ce9676e8b42fbe8030972e5631990545b34e2f3 (diff) |
net: dsa: microchip: Factor out register access opcode generation
Factor out the code which sends out the register read/write opcodes
to the switch, since the code differs in single bit between read and
write.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Tristram Ha <Tristram.Ha@microchip.com>
Cc: Woojung Huh <Woojung.Huh@microchip.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/dsa/microchip/ksz9477_spi.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c index a34e66eccbcd..49aeb92d36fc 100644 --- a/drivers/net/dsa/microchip/ksz9477_spi.c +++ b/drivers/net/dsa/microchip/ksz9477_spi.c | |||
@@ -25,19 +25,24 @@ | |||
25 | /* Enough to read all switch port registers. */ | 25 | /* Enough to read all switch port registers. */ |
26 | #define SPI_TX_BUF_LEN 0x100 | 26 | #define SPI_TX_BUF_LEN 0x100 |
27 | 27 | ||
28 | static int ksz9477_spi_read_reg(struct spi_device *spi, u32 reg, u8 *val, | 28 | static u32 ksz9477_spi_cmd(u32 reg, bool read) |
29 | unsigned int len) | ||
30 | { | 29 | { |
31 | u32 txbuf; | 30 | u32 txbuf; |
32 | int ret; | ||
33 | 31 | ||
34 | txbuf = reg & SPI_ADDR_MASK; | 32 | txbuf = reg & SPI_ADDR_MASK; |
35 | txbuf |= KS_SPIOP_RD << SPI_ADDR_SHIFT; | 33 | txbuf |= (read ? KS_SPIOP_RD : KS_SPIOP_WR) << SPI_ADDR_SHIFT; |
36 | txbuf <<= SPI_TURNAROUND_SHIFT; | 34 | txbuf <<= SPI_TURNAROUND_SHIFT; |
37 | txbuf = cpu_to_be32(txbuf); | 35 | txbuf = cpu_to_be32(txbuf); |
38 | 36 | ||
39 | ret = spi_write_then_read(spi, &txbuf, 4, val, len); | 37 | return txbuf; |
40 | return ret; | 38 | } |
39 | |||
40 | static int ksz9477_spi_read_reg(struct spi_device *spi, u32 reg, u8 *val, | ||
41 | unsigned int len) | ||
42 | { | ||
43 | u32 txbuf = ksz9477_spi_cmd(reg, true); | ||
44 | |||
45 | return spi_write_then_read(spi, &txbuf, 4, val, len); | ||
41 | } | 46 | } |
42 | 47 | ||
43 | static int ksz9477_spi_write_reg(struct spi_device *spi, u32 reg, u8 *val, | 48 | static int ksz9477_spi_write_reg(struct spi_device *spi, u32 reg, u8 *val, |
@@ -45,10 +50,7 @@ static int ksz9477_spi_write_reg(struct spi_device *spi, u32 reg, u8 *val, | |||
45 | { | 50 | { |
46 | u32 *txbuf = (u32 *)val; | 51 | u32 *txbuf = (u32 *)val; |
47 | 52 | ||
48 | *txbuf = reg & SPI_ADDR_MASK; | 53 | *txbuf = ksz9477_spi_cmd(reg, false); |
49 | *txbuf |= (KS_SPIOP_WR << SPI_ADDR_SHIFT); | ||
50 | *txbuf <<= SPI_TURNAROUND_SHIFT; | ||
51 | *txbuf = cpu_to_be32(*txbuf); | ||
52 | 54 | ||
53 | return spi_write(spi, txbuf, 4 + len); | 55 | return spi_write(spi, txbuf, 4 + len); |
54 | } | 56 | } |