kernel: backport fixes for realtek r8152
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 771-v6.0-14-net-dsa-qca8k-move-read_switch_id-function-to-common.patch
1 From 9d1bcb1f293f1391302a109c9819c3705c804700 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 27 Jul 2022 13:35:23 +0200
4 Subject: [PATCH 14/14] net: dsa: qca8k: move read_switch_id function to common
5 code
6
7 The same function to read the switch id is used by drivers based on
8 qca8k family switch. Move them to common code to make them accessible
9 also by other drivers.
10
11 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
12 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
13 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
14 ---
15 drivers/net/dsa/qca/qca8k-8xxx.c | 29 -----------------------------
16 drivers/net/dsa/qca/qca8k-common.c | 29 +++++++++++++++++++++++++++++
17 drivers/net/dsa/qca/qca8k.h | 1 +
18 3 files changed, 30 insertions(+), 29 deletions(-)
19
20 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
21 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
22 @@ -1822,35 +1822,6 @@ static const struct dsa_switch_ops qca8k
23 .connect_tag_protocol = qca8k_connect_tag_protocol,
24 };
25
26 -static int qca8k_read_switch_id(struct qca8k_priv *priv)
27 -{
28 - u32 val;
29 - u8 id;
30 - int ret;
31 -
32 - if (!priv->info)
33 - return -ENODEV;
34 -
35 - ret = qca8k_read(priv, QCA8K_REG_MASK_CTRL, &val);
36 - if (ret < 0)
37 - return -ENODEV;
38 -
39 - id = QCA8K_MASK_CTRL_DEVICE_ID(val);
40 - if (id != priv->info->id) {
41 - dev_err(priv->dev,
42 - "Switch id detected %x but expected %x",
43 - id, priv->info->id);
44 - return -ENODEV;
45 - }
46 -
47 - priv->switch_id = id;
48 -
49 - /* Save revision to communicate to the internal PHY driver */
50 - priv->switch_revision = QCA8K_MASK_CTRL_REV_ID(val);
51 -
52 - return 0;
53 -}
54 -
55 static int
56 qca8k_sw_probe(struct mdio_device *mdiodev)
57 {
58 --- a/drivers/net/dsa/qca/qca8k-common.c
59 +++ b/drivers/net/dsa/qca/qca8k-common.c
60 @@ -1175,3 +1175,32 @@ int qca8k_port_lag_leave(struct dsa_swit
61 {
62 return qca8k_lag_refresh_portmap(ds, port, lag, true);
63 }
64 +
65 +int qca8k_read_switch_id(struct qca8k_priv *priv)
66 +{
67 + u32 val;
68 + u8 id;
69 + int ret;
70 +
71 + if (!priv->info)
72 + return -ENODEV;
73 +
74 + ret = qca8k_read(priv, QCA8K_REG_MASK_CTRL, &val);
75 + if (ret < 0)
76 + return -ENODEV;
77 +
78 + id = QCA8K_MASK_CTRL_DEVICE_ID(val);
79 + if (id != priv->info->id) {
80 + dev_err(priv->dev,
81 + "Switch id detected %x but expected %x",
82 + id, priv->info->id);
83 + return -ENODEV;
84 + }
85 +
86 + priv->switch_id = id;
87 +
88 + /* Save revision to communicate to the internal PHY driver */
89 + priv->switch_revision = QCA8K_MASK_CTRL_REV_ID(val);
90 +
91 + return 0;
92 +}
93 --- a/drivers/net/dsa/qca/qca8k.h
94 +++ b/drivers/net/dsa/qca/qca8k.h
95 @@ -424,6 +424,7 @@ extern const struct qca8k_mib_desc ar832
96 extern const struct regmap_access_table qca8k_readable_table;
97 int qca8k_mib_init(struct qca8k_priv *priv);
98 void qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable);
99 +int qca8k_read_switch_id(struct qca8k_priv *priv);
100
101 /* Common read/write/rmw function */
102 int qca8k_read(struct qca8k_priv *priv, u32 reg, u32 *val);