diff options
author | Marek Vasut <marex@denx.de> | 2019-06-25 19:43:47 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-06-27 14:00:32 -0400 |
commit | 255b59ad0db213d693028e52a4b69a98f2381db7 (patch) | |
tree | 9f6e925bd577c274be93c1eab95b0d5d5197b65e | |
parent | ee394fea6f0671fc2bb7e63161129a5d73d8d6e1 (diff) |
net: dsa: microchip: Factor out regmap config generation into common header
The regmap config tables are rather similar for various generations of
the KSZ8xxx/KSZ9xxx switches. Introduce a macro which allows generating
those tables without duplication. Note that $regalign parameter is not
used right now, but will be used in KSZ87xx series switches.
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/dsa/microchip/ksz9477_spi.c | 29 | ||||
-rw-r--r-- | drivers/net/dsa/microchip/ksz_common.h | 32 |
2 files changed, 35 insertions, 26 deletions
diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c index d1ffdf51d58c..5a9e27b337a8 100644 --- a/drivers/net/dsa/microchip/ksz9477_spi.c +++ b/drivers/net/dsa/microchip/ksz9477_spi.c | |||
@@ -14,37 +14,14 @@ | |||
14 | #include <linux/spi/spi.h> | 14 | #include <linux/spi/spi.h> |
15 | 15 | ||
16 | #include "ksz_priv.h" | 16 | #include "ksz_priv.h" |
17 | #include "ksz_common.h" | ||
17 | 18 | ||
18 | #define SPI_ADDR_SHIFT 24 | 19 | #define SPI_ADDR_SHIFT 24 |
19 | #define SPI_ADDR_ALIGN 3 | 20 | #define SPI_ADDR_ALIGN 3 |
20 | #define SPI_TURNAROUND_SHIFT 5 | 21 | #define SPI_TURNAROUND_SHIFT 5 |
21 | 22 | ||
22 | /* SPI frame opcodes */ | 23 | KSZ_REGMAP_TABLE(ksz9477, 32, SPI_ADDR_SHIFT, |
23 | #define KS_SPIOP_RD 3 | 24 | SPI_TURNAROUND_SHIFT, SPI_ADDR_ALIGN); |
24 | #define KS_SPIOP_WR 2 | ||
25 | |||
26 | #define KS_SPIOP_FLAG_MASK(opcode) \ | ||
27 | swab32((opcode) << (SPI_ADDR_SHIFT + SPI_TURNAROUND_SHIFT)) | ||
28 | |||
29 | #define KSZ_REGMAP_COMMON(width) \ | ||
30 | { \ | ||
31 | .val_bits = (width), \ | ||
32 | .reg_stride = (width) / 8, \ | ||
33 | .reg_bits = SPI_ADDR_SHIFT + SPI_ADDR_ALIGN, \ | ||
34 | .pad_bits = SPI_TURNAROUND_SHIFT, \ | ||
35 | .max_register = BIT(SPI_ADDR_SHIFT) - 1, \ | ||
36 | .cache_type = REGCACHE_NONE, \ | ||
37 | .read_flag_mask = KS_SPIOP_FLAG_MASK(KS_SPIOP_RD), \ | ||
38 | .write_flag_mask = KS_SPIOP_FLAG_MASK(KS_SPIOP_WR), \ | ||
39 | .reg_format_endian = REGMAP_ENDIAN_BIG, \ | ||
40 | .val_format_endian = REGMAP_ENDIAN_BIG \ | ||
41 | } | ||
42 | |||
43 | static const struct regmap_config ksz9477_regmap_config[] = { | ||
44 | KSZ_REGMAP_COMMON(8), | ||
45 | KSZ_REGMAP_COMMON(16), | ||
46 | KSZ_REGMAP_COMMON(32), | ||
47 | }; | ||
48 | 25 | ||
49 | static int ksz9477_spi_probe(struct spi_device *spi) | 26 | static int ksz9477_spi_probe(struct spi_device *spi) |
50 | { | 27 | { |
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index c3871ed9b097..745318424f71 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h | |||
@@ -133,4 +133,36 @@ static inline u32 ksz_pread32_poll(struct ksz_poll_ctx *ctx) | |||
133 | return data; | 133 | return data; |
134 | } | 134 | } |
135 | 135 | ||
136 | /* Regmap tables generation */ | ||
137 | #define KSZ_SPI_OP_RD 3 | ||
138 | #define KSZ_SPI_OP_WR 2 | ||
139 | |||
140 | #define KSZ_SPI_OP_FLAG_MASK(opcode, swp, regbits, regpad) \ | ||
141 | swab##swp((opcode) << ((regbits) + (regpad))) | ||
142 | |||
143 | #define KSZ_REGMAP_ENTRY(width, swp, regbits, regpad, regalign) \ | ||
144 | { \ | ||
145 | .val_bits = (width), \ | ||
146 | .reg_stride = (width) / 8, \ | ||
147 | .reg_bits = (regbits) + (regalign), \ | ||
148 | .pad_bits = (regpad), \ | ||
149 | .max_register = BIT(regbits) - 1, \ | ||
150 | .cache_type = REGCACHE_NONE, \ | ||
151 | .read_flag_mask = \ | ||
152 | KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_RD, swp, \ | ||
153 | regbits, regpad), \ | ||
154 | .write_flag_mask = \ | ||
155 | KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_WR, swp, \ | ||
156 | regbits, regpad), \ | ||
157 | .reg_format_endian = REGMAP_ENDIAN_BIG, \ | ||
158 | .val_format_endian = REGMAP_ENDIAN_BIG \ | ||
159 | } | ||
160 | |||
161 | #define KSZ_REGMAP_TABLE(ksz, swp, regbits, regpad, regalign) \ | ||
162 | static const struct regmap_config ksz##_regmap_config[] = { \ | ||
163 | KSZ_REGMAP_ENTRY(8, swp, (regbits), (regpad), (regalign)), \ | ||
164 | KSZ_REGMAP_ENTRY(16, swp, (regbits), (regpad), (regalign)), \ | ||
165 | KSZ_REGMAP_ENTRY(32, swp, (regbits), (regpad), (regalign)), \ | ||
166 | } | ||
167 | |||
136 | #endif | 168 | #endif |