From: Marek Vasut <marex@denx.de>
To: netdev@vger.kernel.org
Cc: Marek Vasut <marex@denx.de>, Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Tristram Ha <Tristram.Ha@microchip.com>,
Woojung Huh <Woojung.Huh@microchip.com>
Subject: [PATCH V3 06/10] net: dsa: microchip: Factor out register access opcode generation
Date: Mon, 24 Jun 2019 00:35:04 +0200 [thread overview]
Message-ID: <20190623223508.2713-7-marex@denx.de> (raw)
In-Reply-To: <20190623223508.2713-1-marex@denx.de>
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>
---
V2: New patch
V3: - Rebase on next/master
- Test on KSZ9477EVB
---
drivers/net/dsa/microchip/ksz9477_spi.c | 22 ++++++++++++----------
1 file 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 @@
/* Enough to read all switch port registers. */
#define SPI_TX_BUF_LEN 0x100
-static int ksz9477_spi_read_reg(struct spi_device *spi, u32 reg, u8 *val,
- unsigned int len)
+static u32 ksz9477_spi_cmd(u32 reg, bool read)
{
u32 txbuf;
- int ret;
txbuf = reg & SPI_ADDR_MASK;
- txbuf |= KS_SPIOP_RD << SPI_ADDR_SHIFT;
+ txbuf |= (read ? KS_SPIOP_RD : KS_SPIOP_WR) << SPI_ADDR_SHIFT;
txbuf <<= SPI_TURNAROUND_SHIFT;
txbuf = cpu_to_be32(txbuf);
- ret = spi_write_then_read(spi, &txbuf, 4, val, len);
- return ret;
+ return txbuf;
+}
+
+static int ksz9477_spi_read_reg(struct spi_device *spi, u32 reg, u8 *val,
+ unsigned int len)
+{
+ u32 txbuf = ksz9477_spi_cmd(reg, true);
+
+ return spi_write_then_read(spi, &txbuf, 4, val, len);
}
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,
{
u32 *txbuf = (u32 *)val;
- *txbuf = reg & SPI_ADDR_MASK;
- *txbuf |= (KS_SPIOP_WR << SPI_ADDR_SHIFT);
- *txbuf <<= SPI_TURNAROUND_SHIFT;
- *txbuf = cpu_to_be32(*txbuf);
+ *txbuf = ksz9477_spi_cmd(reg, false);
return spi_write(spi, txbuf, 4 + len);
}
--
2.20.1
next prev parent reply other threads:[~2019-06-24 3:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-23 22:34 [PATCH V3 00/10] net: dsa: microchip: Convert to regmap Marek Vasut
2019-06-23 22:34 ` [PATCH V3 01/10] net: dsa: microchip: Remove ksz_{read,write}24() Marek Vasut
2019-06-24 3:11 ` Andrew Lunn
2019-06-23 22:35 ` [PATCH V3 02/10] net: dsa: microchip: Remove ksz_{get,set}() Marek Vasut
2019-06-24 3:12 ` Andrew Lunn
2019-06-23 22:35 ` [PATCH V3 03/10] net: dsa: microchip: Inline ksz_spi.h Marek Vasut
2019-06-24 3:16 ` Andrew Lunn
2019-06-23 22:35 ` [PATCH V3 04/10] net: dsa: microchip: Move ksz_cfg and ksz_port_cfg to ksz9477.c Marek Vasut
2019-06-24 3:17 ` Andrew Lunn
2019-06-23 22:35 ` [PATCH V3 05/10] net: dsa: microchip: Use PORT_CTRL_ADDR() instead of indirect function call Marek Vasut
2019-06-24 3:20 ` Andrew Lunn
2019-06-24 22:12 ` Marek Vasut
2019-06-23 22:35 ` Marek Vasut [this message]
2019-06-24 3:22 ` [PATCH V3 06/10] net: dsa: microchip: Factor out register access opcode generation Andrew Lunn
2019-06-23 22:35 ` [PATCH V3 07/10] net: dsa: microchip: Initial SPI regmap support Marek Vasut
2019-06-24 19:39 ` kbuild test robot
2019-06-24 22:03 ` Marek Vasut
2019-06-24 23:59 ` Vladimir Oltean
2019-06-25 12:06 ` Marek Vasut
2019-06-25 12:40 ` Vladimir Oltean
2019-06-25 15:18 ` Marek Vasut
2019-06-25 10:03 ` kbuild test robot
2019-06-23 22:35 ` [PATCH V3 08/10] net: dsa: microchip: Dispose of ksz_io_ops Marek Vasut
2019-06-23 22:35 ` [PATCH V3 09/10] net: dsa: microchip: Factor out regmap config generation into common header Marek Vasut
2019-06-23 22:35 ` [PATCH V3 10/10] net: dsa: microchip: Replace ad-hoc bit manipulation with regmap Marek Vasut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190623223508.2713-7-marex@denx.de \
--to=marex@denx.de \
--cc=Tristram.Ha@microchip.com \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--cc=f.fainelli@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).