generic: 5.15: copy config and patch from 5.10
[openwrt/staging/stintel.git] / target / linux / generic / backport-5.15 / 735-v5.14-09-net-dsa-qca8k-add-support-for-qca8327-switch.patch
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
5
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.
9
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>
15 ---
16 drivers/net/dsa/qca8k.c | 23 ++++++++++++++++++++---
17 drivers/net/dsa/qca8k.h | 6 ++++++
18 2 files changed, 26 insertions(+), 3 deletions(-)
19
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
23 static int
24 qca8k_sw_probe(struct mdio_device *mdiodev)
25 {
26 + const struct qca8k_match_data *data;
27 struct qca8k_priv *priv;
28 u32 id;
29
30 @@ -1560,6 +1561,11 @@ qca8k_sw_probe(struct mdio_device *mdiod
31 gpiod_set_value_cansleep(priv->reset_gpio, 0);
32 }
33
34 + /* get the switches ID from the compatible */
35 + data = of_device_get_match_data(&mdiodev->dev);
36 + if (!data)
37 + return -ENODEV;
38 +
39 /* read the switches ID register */
40 id = qca8k_read(priv, QCA8K_REG_MASK_CTRL);
41 if (id < 0)
42 @@ -1567,8 +1573,10 @@ qca8k_sw_probe(struct mdio_device *mdiod
43
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);
49 return -ENODEV;
50 + }
51
52 priv->ds = devm_kzalloc(&mdiodev->dev, sizeof(*priv->ds), GFP_KERNEL);
53 if (!priv->ds)
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);
57
58 +static const struct qca8k_match_data qca832x = {
59 + .id = QCA8K_ID_QCA8327,
60 +};
61 +
62 +static const struct qca8k_match_data qca833x = {
63 + .id = QCA8K_ID_QCA8337,
64 +};
65 +
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 },
72 { /* sentinel */ },
73 };
74
75 --- a/drivers/net/dsa/qca8k.h
76 +++ b/drivers/net/dsa/qca8k.h
77 @@ -15,6 +15,8 @@
78 #define QCA8K_NUM_PORTS 7
79 #define QCA8K_MAX_MTU 9000
80
81 +#define PHY_ID_QCA8327 0x004dd034
82 +#define QCA8K_ID_QCA8327 0x12
83 #define PHY_ID_QCA8337 0x004dd036
84 #define QCA8K_ID_QCA8337 0x13
85
86 @@ -213,6 +215,10 @@ struct ar8xxx_port_status {
87 int enabled;
88 };
89
90 +struct qca8k_match_data {
91 + u8 id;
92 +};
93 +
94 struct qca8k_priv {
95 struct regmap *regmap;
96 struct mii_bus *bus;