1 From 6fb760972c49490b03f3db2ad64cf30bdd28c54a Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Mon, 29 Jan 2024 15:15:20 +0100
4 Subject: [PATCH 2/5] net: phy: qcom: create and move functions to shared
7 Create and move functions to shared library in preparation for qca83xx
8 PHY Family to be detached from at803x driver.
10 Only the shared defines are moved to the shared qcom.h header.
12 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
13 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
14 Link: https://lore.kernel.org/r/20240129141600.2592-3-ansuelsmth@gmail.com
15 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 drivers/net/phy/qcom/Kconfig | 4 ++
18 drivers/net/phy/qcom/Makefile | 1 +
19 drivers/net/phy/qcom/at803x.c | 69 +----------------------------
20 drivers/net/phy/qcom/qcom-phy-lib.c | 53 ++++++++++++++++++++++
21 drivers/net/phy/qcom/qcom.h | 34 ++++++++++++++
22 5 files changed, 94 insertions(+), 67 deletions(-)
23 create mode 100644 drivers/net/phy/qcom/qcom-phy-lib.c
24 create mode 100644 drivers/net/phy/qcom/qcom.h
26 --- a/drivers/net/phy/qcom/Kconfig
27 +++ b/drivers/net/phy/qcom/Kconfig
29 # SPDX-License-Identifier: GPL-2.0-only
30 +config QCOM_NET_PHYLIB
34 tristate "Qualcomm Atheros AR803X PHYs and QCA833x PHYs"
35 + select QCOM_NET_PHYLIB
38 Currently supports the AR8030, AR8031, AR8033, AR8035 and internal
39 --- a/drivers/net/phy/qcom/Makefile
40 +++ b/drivers/net/phy/qcom/Makefile
42 # SPDX-License-Identifier: GPL-2.0
43 +obj-$(CONFIG_QCOM_NET_PHYLIB) += qcom-phy-lib.o
44 obj-$(CONFIG_AT803X_PHY) += at803x.o
45 --- a/drivers/net/phy/qcom/at803x.c
46 +++ b/drivers/net/phy/qcom/at803x.c
48 #include <linux/sfp.h>
49 #include <dt-bindings/net/qca-ar803x.h>
53 #define AT803X_SPECIFIC_FUNCTION_CONTROL 0x10
54 #define AT803X_SFC_ASSERT_CRS BIT(11)
55 #define AT803X_SFC_FORCE_LINK BIT(10)
57 #define AT803X_REG_CHIP_CONFIG 0x1f
58 #define AT803X_BT_BX_REG_SEL 0x8000
60 -#define AT803X_DEBUG_ADDR 0x1D
61 -#define AT803X_DEBUG_DATA 0x1E
63 #define AT803X_MODE_CFG_MASK 0x0F
64 #define AT803X_MODE_CFG_BASET_RGMII 0x00
65 #define AT803X_MODE_CFG_BASET_SGMII 0x01
67 #define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/
68 #define AT803X_PSSR_MR_AN_COMPLETE 0x0200
70 -#define AT803X_DEBUG_ANALOG_TEST_CTRL 0x00
71 -#define QCA8327_DEBUG_MANU_CTRL_EN BIT(2)
72 -#define QCA8337_DEBUG_MANU_CTRL_EN GENMASK(3, 2)
73 -#define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15)
75 -#define AT803X_DEBUG_SYSTEM_CTRL_MODE 0x05
76 -#define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8)
78 -#define AT803X_DEBUG_REG_HIB_CTRL 0x0b
79 -#define AT803X_DEBUG_HIB_CTRL_SEL_RST_80U BIT(10)
80 -#define AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE BIT(13)
81 -#define AT803X_DEBUG_HIB_CTRL_PS_HIB_EN BIT(15)
83 #define AT803X_DEBUG_REG_3C 0x3C
85 #define AT803X_DEBUG_REG_GREEN 0x3D
86 @@ -393,18 +379,6 @@ MODULE_DESCRIPTION("Qualcomm Atheros AR8
87 MODULE_AUTHOR("Matus Ujhelyi");
88 MODULE_LICENSE("GPL");
90 -enum stat_access_type {
95 -struct at803x_hw_stat {
99 - enum stat_access_type access_type;
102 static struct at803x_hw_stat qca83xx_hw_stats[] = {
103 { "phy_idle_errors", 0xa, GENMASK(7, 0), PHY},
104 { "phy_receive_errors", 0x15, GENMASK(15, 0), PHY},
105 @@ -439,45 +413,6 @@ struct at803x_context {
109 -static int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data)
113 - ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
117 - return phy_write(phydev, AT803X_DEBUG_DATA, data);
120 -static int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
124 - ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
128 - return phy_read(phydev, AT803X_DEBUG_DATA);
131 -static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
132 - u16 clear, u16 set)
137 - ret = at803x_debug_reg_read(phydev, reg);
141 - val = ret & 0xffff;
145 - return phy_write(phydev, AT803X_DEBUG_DATA, val);
148 static int at803x_write_page(struct phy_device *phydev, int page)
152 +++ b/drivers/net/phy/qcom/qcom-phy-lib.c
154 +// SPDX-License-Identifier: GPL-2.0
156 +#include <linux/phy.h>
157 +#include <linux/module.h>
161 +MODULE_DESCRIPTION("Qualcomm PHY driver Common Functions");
162 +MODULE_AUTHOR("Matus Ujhelyi");
163 +MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
164 +MODULE_LICENSE("GPL");
166 +int at803x_debug_reg_read(struct phy_device *phydev, u16 reg)
170 + ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
174 + return phy_read(phydev, AT803X_DEBUG_DATA);
176 +EXPORT_SYMBOL_GPL(at803x_debug_reg_read);
178 +int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
179 + u16 clear, u16 set)
184 + ret = at803x_debug_reg_read(phydev, reg);
188 + val = ret & 0xffff;
192 + return phy_write(phydev, AT803X_DEBUG_DATA, val);
194 +EXPORT_SYMBOL_GPL(at803x_debug_reg_mask);
196 +int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data)
200 + ret = phy_write(phydev, AT803X_DEBUG_ADDR, reg);
204 + return phy_write(phydev, AT803X_DEBUG_DATA, data);
206 +EXPORT_SYMBOL_GPL(at803x_debug_reg_write);
208 +++ b/drivers/net/phy/qcom/qcom.h
210 +/* SPDX-License-Identifier: GPL-2.0 */
212 +#define AT803X_DEBUG_ADDR 0x1D
213 +#define AT803X_DEBUG_DATA 0x1E
215 +#define AT803X_DEBUG_ANALOG_TEST_CTRL 0x00
216 +#define QCA8327_DEBUG_MANU_CTRL_EN BIT(2)
217 +#define QCA8337_DEBUG_MANU_CTRL_EN GENMASK(3, 2)
218 +#define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15)
220 +#define AT803X_DEBUG_SYSTEM_CTRL_MODE 0x05
221 +#define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8)
223 +#define AT803X_DEBUG_REG_HIB_CTRL 0x0b
224 +#define AT803X_DEBUG_HIB_CTRL_SEL_RST_80U BIT(10)
225 +#define AT803X_DEBUG_HIB_CTRL_EN_ANY_CHANGE BIT(13)
226 +#define AT803X_DEBUG_HIB_CTRL_PS_HIB_EN BIT(15)
228 +enum stat_access_type {
233 +struct at803x_hw_stat {
234 + const char *string;
237 + enum stat_access_type access_type;
240 +int at803x_debug_reg_read(struct phy_device *phydev, u16 reg);
241 +int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
242 + u16 clear, u16 set);
243 +int at803x_debug_reg_write(struct phy_device *phydev, u16 reg, u16 data);