Skip to content

Instantly share code, notes, and snippets.

@Leo-PL
Last active June 5, 2022 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leo-PL/9862ffd73bf5bfc510d118107440d42f to your computer and use it in GitHub Desktop.
Save Leo-PL/9862ffd73bf5bfc510d118107440d42f to your computer and use it in GitHub Desktop.
From 0ca34dcb70a1d17b472e3e8e4711306af4387d9d Mon Sep 17 00:00:00 2001
From: Lech Perczak <lech.perczak@gmail.com>
Date: Sun, 5 Jun 2022 18:54:03 +0200
Subject: [PATCH 2/2] net: dsa: ar9331: support AR9344 tag format
AR9344 and newer SoC's use different tag format format, handled by
AR9344 tagger. Allow selection of this driver through matching
"qca,ar9344-switch" compatible string.
Signed-off-by: Lech Perczak <lech.perczak@gmail.com>
---
drivers/net/dsa/qca/Kconfig | 1 +
drivers/net/dsa/qca/ar9331.c | 39 ++++++++++++++++++++++++++++++------
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/drivers/net/dsa/qca/Kconfig b/drivers/net/dsa/qca/Kconfig
index 13b7e679b8b5..591071b58200 100644
--- a/drivers/net/dsa/qca/Kconfig
+++ b/drivers/net/dsa/qca/Kconfig
@@ -3,6 +3,7 @@ config NET_DSA_AR9331
tristate "Qualcomm Atheros AR9331 Ethernet switch support"
depends on NET_DSA
select NET_DSA_TAG_AR9331
+ select NET_DSA_TAG_AR9344
select REGMAP
help
This enables support for the Qualcomm Atheros AR9331 built-in Ethernet
diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c
index 5d476f452396..7c582d46b9c4 100644
--- a/drivers/net/dsa/qca/ar9331.c
+++ b/drivers/net/dsa/qca/ar9331.c
@@ -234,10 +234,15 @@ struct ar9331_sw_port {
struct spinlock stats_lock;
};
+struct ar9331_sw_device_data {
+ enum dsa_tag_protocol protocol;
+};
+
struct ar9331_sw_priv {
struct device *dev;
struct dsa_switch ds;
struct dsa_switch_ops ops;
+ const struct ar9331_sw_device_data *data;
struct irq_domain *irqdomain;
u32 irq_mask;
struct mutex lock_irq;
@@ -496,7 +501,8 @@ static enum dsa_tag_protocol ar9331_sw_get_tag_protocol(struct dsa_switch *ds,
int port,
enum dsa_tag_protocol m)
{
- return DSA_TAG_PROTO_AR9331;
+ struct ar9331_sw_priv *priv = (struct ar9331_sw_priv *)ds->priv;
+ return priv->data->protocol;
}
static void ar9331_sw_phylink_validate(struct dsa_switch *ds, int port,
@@ -1019,12 +1025,38 @@ static struct regmap_bus ar9331_sw_bus = {
.max_raw_write = 4,
};
+static const struct ar9331_sw_device_data ar9331_data = {
+ .protocol = DSA_TAG_PROTO_AR9331
+};
+
+static const struct ar9331_sw_device_data ar9344_data = {
+ .protocol = DSA_TAG_PROTO_AR9344
+};
+
+static const struct of_device_id ar9331_sw_of_match[] = {
+ { .compatible = "qca,ar9331-switch", .data = &ar9331_data },
+ { .compatible = "qca,ar9344-switch", .data = &ar9344_data },
+ { },
+};
+MODULE_DEVICE_TABLE(of, ar9331_sw_of_match);
+
static int ar9331_sw_probe(struct mdio_device *mdiodev)
{
+ const struct of_device_id *of_id;
+ struct device_node *dn = mdiodev->dev.of_node;
struct ar9331_sw_priv *priv;
struct dsa_switch *ds;
int ret, i;
+ if (!dn)
+ return -EINVAL;
+
+ of_id = of_match_node(ar9331_sw_of_match, dn);
+ if (!of_id || !of_id->data)
+ return -EINVAL;
+
+ priv->data = of_id->data;
+
priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
@@ -1112,11 +1144,6 @@ static void ar9331_sw_shutdown(struct mdio_device *mdiodev)
dev_set_drvdata(&mdiodev->dev, NULL);
}
-static const struct of_device_id ar9331_sw_of_match[] = {
- { .compatible = "qca,ar9331-switch" },
- { },
-};
-
static struct mdio_driver ar9331_sw_mdio_driver = {
.probe = ar9331_sw_probe,
.remove = ar9331_sw_remove,
--
2.30.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment