1 From 6e82a457e06252b59102486767539cc9c2aba60b Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Fri, 14 May 2021 22:59:59 +0200
4 Subject: [PATCH] net: dsa: qca8k: add support for qca8327 switch
6 qca8327 switch is a low tier version of the more recent qca8337.
7 It does share the same regs used by the qca8k driver and can be
8 supported with minimal change.
10 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
11 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
12 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
13 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 drivers/net/dsa/qca8k.c | 23 ++++++++++++++++++++---
17 drivers/net/dsa/qca8k.h | 6 ++++++
18 2 files changed, 26 insertions(+), 3 deletions(-)
20 --- a/drivers/net/dsa/qca8k.c
21 +++ b/drivers/net/dsa/qca8k.c
22 @@ -1533,6 +1533,7 @@ static const struct dsa_switch_ops qca8k
24 qca8k_sw_probe(struct mdio_device *mdiodev)
26 + const struct qca8k_match_data *data;
27 struct qca8k_priv *priv;
30 @@ -1560,6 +1561,11 @@ qca8k_sw_probe(struct mdio_device *mdiod
31 gpiod_set_value_cansleep(priv->reset_gpio, 0);
34 + /* get the switches ID from the compatible */
35 + data = of_device_get_match_data(&mdiodev->dev);
39 /* read the switches ID register */
40 id = qca8k_read(priv, QCA8K_REG_MASK_CTRL);
42 @@ -1567,8 +1573,10 @@ qca8k_sw_probe(struct mdio_device *mdiod
44 id >>= QCA8K_MASK_CTRL_ID_S;
45 id &= QCA8K_MASK_CTRL_ID_M;
46 - if (id != QCA8K_ID_QCA8337)
47 + if (id != data->id) {
48 + dev_err(&mdiodev->dev, "Switch id detected %x but expected %x", id, data->id);
52 priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL);
54 @@ -1634,9 +1642,18 @@ static int qca8k_resume(struct device *d
55 static SIMPLE_DEV_PM_OPS(qca8k_pm_ops,
56 qca8k_suspend, qca8k_resume);
58 +static const struct qca8k_match_data qca832x = {
59 + .id = QCA8K_ID_QCA8327,
62 +static const struct qca8k_match_data qca833x = {
63 + .id = QCA8K_ID_QCA8337,
66 static const struct of_device_id qca8k_of_match[] = {
67 - { .compatible = "qca,qca8334" },
68 - { .compatible = "qca,qca8337" },
69 + { .compatible = "qca,qca8327", .data = &qca832x },
70 + { .compatible = "qca,qca8334", .data = &qca833x },
71 + { .compatible = "qca,qca8337", .data = &qca833x },
75 --- a/drivers/net/dsa/qca8k.h
76 +++ b/drivers/net/dsa/qca8k.h
78 #define QCA8K_NUM_PORTS 7
79 #define QCA8K_MAX_MTU 9000
81 +#define PHY_ID_QCA8327 0x004dd034
82 +#define QCA8K_ID_QCA8327 0x12
83 #define PHY_ID_QCA8337 0x004dd036
84 #define QCA8K_ID_QCA8337 0x13
86 @@ -213,6 +215,10 @@ struct ar8xxx_port_status {
90 +struct qca8k_match_data {
95 struct regmap *regmap;