From: Andrew Lunn <andrew@lunn.ch>
To: Tristram.Ha@microchip.com
Cc: Woojung Huh <woojung.huh@microchip.com>,
Vladimir Oltean <olteanv@gmail.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Marek Vasut <marex@denx.de>,
UNGLinuxDriver@microchip.com, devicetree@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v4 3/7] net: dsa: microchip: Transform register for use with KSZ8463
Date: Sun, 20 Jul 2025 17:56:52 +0200 [thread overview]
Message-ID: <4dd544ad-fa71-4759-bc23-d1dd7f554eb8@lunn.ch> (raw)
In-Reply-To: <20250719012106.257968-4-Tristram.Ha@microchip.com>
> +static inline bool ksz_is_ksz8463(struct ksz_device *dev)
> +{
> + return dev->chip_id == KSZ8463_CHIP_ID;
> +}
> +
> +static inline u32 reg8(struct ksz_device *dev, u32 reg)
> +{
> + if (ksz_is_ksz8463(dev))
> + return ((reg >> 2) << 4) | (1 << (reg & 3));
> + return reg;
> +}
> +
> +static inline u32 reg16(struct ksz_device *dev, u32 reg)
> +{
> + if (ksz_is_ksz8463(dev))
> + return ((reg >> 2) << 4) | (reg & 2 ? 0x0c : 0x03);
> + return reg;
> +}
> +
> +static inline u32 reg32(struct ksz_device *dev, u32 reg)
> +{
> + if (ksz_is_ksz8463(dev))
> + return ((reg >> 2) << 4) | 0xf;
> + return reg;
> +}
> +
> static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
> {
> unsigned int value;
> - int ret = regmap_read(ksz_regmap_8(dev), reg, &value);
> + int ret = regmap_read(ksz_regmap_8(dev), reg8(dev, reg), &value);
I'm wondering if there is a less intrusive way to do this. When you
create a regmap, you can optionally pass it methods to use for
read/write/update etc.
struct regmap_config {
...
int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
int (*reg_write)(void *context, unsigned int reg, unsigned int val);
int (*reg_update_bits)(void *context, unsigned int reg,
unsigned int mask, unsigned int val);
Could you provide your own methods for the ksz8463 which perform the
register modification, and then call the normal regmap SPI function to
do the operation?
If you cannot get direct access to the regmap SPI functions, you can
stack one regmap on top of another regmap. Have the top regmap do the
register modifications, and then call a normal SPI regmap to do the
read/write.
What i don't like about the current code is that developers adding new
code could miss they need to add reg8().. to all regmap calls. So
ideally you want to hide that away so they don't need to care, it just
works.
Andrew
next prev parent reply other threads:[~2025-07-20 15:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-19 1:20 [PATCH net-next v4 0/7] net: dsa: microchip: Add KSZ8463 switch support Tristram.Ha
2025-07-19 1:21 ` [PATCH net-next v4 1/7] dt-bindings: " Tristram.Ha
2025-07-19 1:21 ` [PATCH net-next v4 2/7] net: dsa: microchip: Add KSZ8463 switch support to KSZ DSA driver Tristram.Ha
2025-07-20 10:24 ` Simon Horman
2025-07-19 1:21 ` [PATCH net-next v4 3/7] net: dsa: microchip: Transform register for use with KSZ8463 Tristram.Ha
2025-07-20 15:56 ` Andrew Lunn [this message]
2025-07-19 1:21 ` [PATCH net-next v4 4/7] net: dsa: microchip: Use different registers for KSZ8463 Tristram.Ha
2025-07-20 10:17 ` Simon Horman
2025-07-20 10:22 ` Simon Horman
2025-07-23 2:25 ` Tristram.Ha
2025-07-23 16:21 ` Simon Horman
2025-07-24 2:28 ` Tristram.Ha
2025-07-24 21:35 ` Simon Horman
2025-07-25 0:17 ` Tristram.Ha
2025-07-25 7:29 ` Simon Horman
2025-07-19 1:21 ` [PATCH net-next v4 5/7] net: dsa: microchip: Write switch MAC address differently " Tristram.Ha
2025-07-19 1:21 ` [PATCH net-next v4 6/7] net: dsa: microchip: Setup fiber ports " Tristram.Ha
2025-07-19 1:21 ` [PATCH net-next v4 7/7] net: dsa: microchip: Disable PTP function of KSZ8463 Tristram.Ha
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=4dd544ad-fa71-4759-bc23-d1dd7f554eb8@lunn.ch \
--to=andrew@lunn.ch \
--cc=Tristram.Ha@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marex@denx.de \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
--cc=woojung.huh@microchip.com \
/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).