* [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength
@ 2023-09-05 12:43 Oleksij Rempel
2023-09-05 12:43 ` [RFC net-next v1 2/2] net: dsa: microchip: ksz9477: Add drive strength configuration Oleksij Rempel
2023-09-05 18:28 ` [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength Rob Herring
0 siblings, 2 replies; 4+ messages in thread
From: Oleksij Rempel @ 2023-09-05 12:43 UTC (permalink / raw)
To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
Arun Ramadoss, Conor Dooley, Krzysztof Kozlowski, Rob Herring
Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
Russell King (Oracle), devicetree
Extend device tree bindings to support drive strength configuration for the
ksz* switches. Introduced properties:
- microchip,hi-drive-strength-microamp: Controls the drive strength for
high-speed interfaces like GMII/RGMII and more.
- microchip,lo-drive-strength-microamp: Governs the drive strength for
low-speed interfaces such as LEDs, PME_N, and others.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
.../bindings/net/dsa/microchip,ksz.yaml | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml b/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml
index e51be1ac03623..97d655eb01b6f 100644
--- a/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml
+++ b/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml
@@ -49,6 +49,22 @@ properties:
Set if the output SYNCLKO clock should be disabled. Do not mix with
microchip,synclko-125.
+ microchip,hi-drive-strength-microamp:
+ description:
+ High Speed Drive Strength. Controls drive strength of GMII / RGMII /
+ MII / RMII (except TX_CLK/REFCLKI, COL and CRS) and CLKO_25_125 lines.
+ minimum: 2000
+ maximum: 28000
+ default: 24000
+
+ microchip,lo-drive-strength-microamp:
+ description:
+ Low Speed Drive Strength. Controls drive strength of TX_CLK / REFCLKI,
+ COL, CRS, LEDs, PME_N, NTRP_N, SDO and SDI/SDA/MDIO lines.
+ minimum: 2000
+ maximum: 28000
+ default: 8000
+
required:
- compatible
- reg
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC net-next v1 2/2] net: dsa: microchip: ksz9477: Add drive strength configuration
2023-09-05 12:43 [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength Oleksij Rempel
@ 2023-09-05 12:43 ` Oleksij Rempel
2023-09-05 12:54 ` Andrew Lunn
2023-09-05 18:28 ` [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength Rob Herring
1 sibling, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2023-09-05 12:43 UTC (permalink / raw)
To: David S. Miller, Andrew Lunn, Eric Dumazet, Florian Fainelli,
Jakub Kicinski, Paolo Abeni, Vladimir Oltean, Woojung Huh,
Arun Ramadoss, Conor Dooley, Krzysztof Kozlowski, Rob Herring
Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
Russell King (Oracle), devicetree
Add device tree based drive strength configuration support. It is needed to
pass EMI validation on our hardware.
Configuration values are based on the vendor's reference driver.
Tested on KSZ9563R.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/dsa/microchip/ksz9477.c | 120 ++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 83b7f2d5c1ea6..04582d3fcbe14 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -19,6 +19,30 @@
#include "ksz_common.h"
#include "ksz9477.h"
+/**
+ * struct ksz9477_drive_strength - drive strength mapping
+ * @reg_val: register value
+ * @milliamp: milliamp value
+ */
+struct ksz9477_drive_strength {
+ u32 reg_val;
+ u32 milliamp;
+};
+
+/* Drive strength mapping.
+ * This values are not documented and taken from vendor's reference driver.
+ */
+static const struct ksz9477_drive_strength ksz9477_drive_strengths[] = {
+ { SW_DRIVE_STRENGTH_2MA, 2000 },
+ { SW_DRIVE_STRENGTH_4MA, 4000 },
+ { SW_DRIVE_STRENGTH_8MA, 8000 },
+ { SW_DRIVE_STRENGTH_12MA, 12000 },
+ { SW_DRIVE_STRENGTH_16MA, 16000 },
+ { SW_DRIVE_STRENGTH_20MA, 20000 },
+ { SW_DRIVE_STRENGTH_24MA, 24000 },
+ { SW_DRIVE_STRENGTH_28MA, 28000 },
+};
+
static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set)
{
regmap_update_bits(ksz_regmap_8(dev), addr, bits, set ? bits : 0);
@@ -1097,11 +1121,107 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
return 0;
}
+/**
+ * ksz9477_drive_strength_to_reg() - convert milliamp value to register value
+ * @milliamp: milliamp value
+ *
+ * Return: register value
+ */
+static u32 ksz9477_drive_strength_to_reg(u32 milliamp)
+{
+ size_t array_size = ARRAY_SIZE(ksz9477_drive_strengths);
+ int i;
+
+ for (i = 0; i < array_size; i++) {
+ if (ksz9477_drive_strengths[i].milliamp >= milliamp)
+ return ksz9477_drive_strengths[i].reg_val;
+ }
+
+ /* return the highest value if the requested value is too high */
+ return ksz9477_drive_strengths[array_size - 1].reg_val;
+}
+
+/**
+ * ksz9477_parse_drive_strength() - parse drive strength from device tree
+ * @dev: ksz device
+ *
+ * Return: 0 on success, error code otherwise
+ */
+static int ksz9477_parse_drive_strength(struct ksz_device *dev)
+{
+ struct of_prop {
+ const char *name;
+ int offset;
+ int value;
+ } of_props[] = {
+ {
+ "microchip,hi-drive-strength-microamp",
+ SW_HI_SPEED_DRIVE_STRENGTH_S,
+ -1
+ },
+ {
+ "microchip,lo-drive-strength-microamp",
+ SW_LO_SPEED_DRIVE_STRENGTH_S,
+ -1
+ },
+ };
+ struct device_node *np = dev->dev->of_node;
+ bool found = false;
+ int ret;
+ u8 val;
+
+ if (!np)
+ return 0;
+
+ for (int i = 0; i < ARRAY_SIZE(of_props); i++) {
+ ret = of_property_read_u32(np, of_props[i].name,
+ &of_props[i].value);
+ if (ret && ret != -EINVAL)
+ dev_warn(dev->dev, "Failed to read %s\n",
+ of_props[i].name);
+ if (ret)
+ continue;
+
+ if (of_props[i].value > 28000 || of_props[i].value < 2000) {
+ dev_warn(dev->dev, "Drive strength value is out of range: %d. Supported values are (2000 - 28000)\n",
+ of_props[i].value);
+ continue;
+ }
+
+ found = true;
+ }
+
+ if (!found)
+ return 0;
+
+ ret = ksz_read8(dev, REG_SW_IO_STRENGTH__1, &val);
+ if (ret)
+ return ret;
+
+ for (int i = 0; i < ARRAY_SIZE(of_props); i++) {
+ int strength_val;
+
+ if (of_props[i].value == -1)
+ continue;
+
+ strength_val = ksz9477_drive_strength_to_reg(of_props[i].value);
+
+ val &= ~(SW_DRIVE_STRENGTH_M << of_props[i].offset);
+ val |= strength_val << of_props[i].offset;
+ }
+
+ return ksz_write8(dev, REG_SW_IO_STRENGTH__1, val);
+}
+
int ksz9477_setup(struct dsa_switch *ds)
{
struct ksz_device *dev = ds->priv;
int ret = 0;
+ ret = ksz9477_parse_drive_strength(dev);
+ if (ret)
+ return ret;
+
ds->mtu_enforcement_ingress = true;
/* Required for port partitioning. */
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC net-next v1 2/2] net: dsa: microchip: ksz9477: Add drive strength configuration
2023-09-05 12:43 ` [RFC net-next v1 2/2] net: dsa: microchip: ksz9477: Add drive strength configuration Oleksij Rempel
@ 2023-09-05 12:54 ` Andrew Lunn
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2023-09-05 12:54 UTC (permalink / raw)
To: Oleksij Rempel
Cc: David S. Miller, Eric Dumazet, Florian Fainelli, Jakub Kicinski,
Paolo Abeni, Vladimir Oltean, Woojung Huh, Arun Ramadoss,
Conor Dooley, Krzysztof Kozlowski, Rob Herring, kernel,
linux-kernel, netdev, UNGLinuxDriver, Russell King (Oracle),
devicetree
> +static const struct ksz9477_drive_strength ksz9477_drive_strengths[] = {
> + { SW_DRIVE_STRENGTH_2MA, 2000 },
> + { SW_DRIVE_STRENGTH_4MA, 4000 },
> + { SW_DRIVE_STRENGTH_8MA, 8000 },
> + { SW_DRIVE_STRENGTH_12MA, 12000 },
> + { SW_DRIVE_STRENGTH_16MA, 16000 },
> + { SW_DRIVE_STRENGTH_20MA, 20000 },
> + { SW_DRIVE_STRENGTH_24MA, 24000 },
> + { SW_DRIVE_STRENGTH_28MA, 28000 },
These SW_DRIVE_STRENGTH_ values appear in both ksz8795_reg.h and
ksz9477_reg.h. Can the code be made common?
> +static u32 ksz9477_drive_strength_to_reg(u32 milliamp)
> +{
> + size_t array_size = ARRAY_SIZE(ksz9477_drive_strengths);
> + int i;
> +
> + for (i = 0; i < array_size; i++) {
> + if (ksz9477_drive_strengths[i].milliamp >= milliamp)
> + return ksz9477_drive_strengths[i].reg_val;
Normally an exact match is used, not the nearest value.
Andrew
---
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength
2023-09-05 12:43 [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength Oleksij Rempel
2023-09-05 12:43 ` [RFC net-next v1 2/2] net: dsa: microchip: ksz9477: Add drive strength configuration Oleksij Rempel
@ 2023-09-05 18:28 ` Rob Herring
1 sibling, 0 replies; 4+ messages in thread
From: Rob Herring @ 2023-09-05 18:28 UTC (permalink / raw)
To: Oleksij Rempel
Cc: kernel, Andrew Lunn, linux-kernel, Florian Fainelli, Eric Dumazet,
UNGLinuxDriver, Paolo Abeni, Rob Herring, Woojung Huh, netdev,
David S. Miller, Arun Ramadoss, Vladimir Oltean,
Krzysztof Kozlowski, Russell King (Oracle), Jakub Kicinski,
Conor Dooley, devicetree
On Tue, 05 Sep 2023 14:43:39 +0200, Oleksij Rempel wrote:
> Extend device tree bindings to support drive strength configuration for the
> ksz* switches. Introduced properties:
> - microchip,hi-drive-strength-microamp: Controls the drive strength for
> high-speed interfaces like GMII/RGMII and more.
> - microchip,lo-drive-strength-microamp: Governs the drive strength for
> low-speed interfaces such as LEDs, PME_N, and others.
>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> .../bindings/net/dsa/microchip,ksz.yaml | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
./Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml:54:9: [warning] wrong indentation: expected 6 but found 8 (indentation)
./Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml:62:9: [warning] wrong indentation: expected 6 but found 8 (indentation)
dtschema/dtc warnings/errors:
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230905124340.4116542-1-o.rempel@pengutronix.de
The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-05 20:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-05 12:43 [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength Oleksij Rempel
2023-09-05 12:43 ` [RFC net-next v1 2/2] net: dsa: microchip: ksz9477: Add drive strength configuration Oleksij Rempel
2023-09-05 12:54 ` Andrew Lunn
2023-09-05 18:28 ` [RFC net-next v1 1/2] dt-bindings: net: dsa: microchip: Update ksz device tree bindings for drive strength Rob Herring
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).