d003291f755aea01411052eded0617c85e77f625
[openwrt/staging/jow.git] / target / linux / generic / hack-5.15 / 722-net-phy-aquantia-enable-AQR112-and-AQR412.patch
1 From 5f62951fba63a9f9cfff564209426bdea5fcc371 Mon Sep 17 00:00:00 2001
2 From: Alex Marginean <alexandru.marginean@nxp.com>
3 Date: Tue, 27 Aug 2019 15:16:56 +0300
4 Subject: [PATCH] drivers: net: phy: aquantia: enable AQR112 and AQR412
5
6 Adds support for AQR112 and AQR412 which is mostly based on existing code
7 with the addition of code configuring the protocol on system side.
8 This allows changing the system side protocol without having to deploy a
9 different firmware on the PHY.
10
11 Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
12 ---
13 drivers/net/phy/aquantia/aquantia_main.c | 88 +++++++++++++++++++++++++++++++++++++++++
14 1 file changed, 88 insertions(+)
15
16 --- a/drivers/net/phy/aquantia/aquantia_main.c
17 +++ b/drivers/net/phy/aquantia/aquantia_main.c
18 @@ -27,6 +27,8 @@
19 #define PHY_ID_AQR113 0x31c31c40
20 #define PHY_ID_AQR113C 0x31c31c12
21 #define PHY_ID_AQR813 0x31c31cb2
22 +#define PHY_ID_AQR112 0x03a1b662
23 +#define PHY_ID_AQR412 0x03a1b712
24
25 #define MDIO_PHYXS_VEND_IF_STATUS 0xe812
26 #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_MASK GENMASK(7, 3)
27 @@ -99,6 +101,29 @@
28 #define AQR107_OP_IN_PROG_SLEEP 1000
29 #define AQR107_OP_IN_PROG_TIMEOUT 100000
30
31 +/* registers in MDIO_MMD_VEND1 region */
32 +#define AQUANTIA_VND1_GLOBAL_SC 0x000
33 +#define AQUANTIA_VND1_GLOBAL_SC_LP BIT(0xb)
34 +
35 +/* global start rate, the protocol associated with this speed is used by default
36 + * on SI.
37 + */
38 +#define AQUANTIA_VND1_GSTART_RATE 0x31a
39 +#define AQUANTIA_VND1_GSTART_RATE_OFF 0
40 +#define AQUANTIA_VND1_GSTART_RATE_100M 1
41 +#define AQUANTIA_VND1_GSTART_RATE_1G 2
42 +#define AQUANTIA_VND1_GSTART_RATE_10G 3
43 +#define AQUANTIA_VND1_GSTART_RATE_2_5G 4
44 +#define AQUANTIA_VND1_GSTART_RATE_5G 5
45 +
46 +/* SYSCFG registers for 100M, 1G, 2.5G, 5G, 10G */
47 +#define AQUANTIA_VND1_GSYSCFG_BASE 0x31b
48 +#define AQUANTIA_VND1_GSYSCFG_100M 0
49 +#define AQUANTIA_VND1_GSYSCFG_1G 1
50 +#define AQUANTIA_VND1_GSYSCFG_2_5G 2
51 +#define AQUANTIA_VND1_GSYSCFG_5G 3
52 +#define AQUANTIA_VND1_GSYSCFG_10G 4
53 +
54 struct aqr107_hw_stat {
55 const char *name;
56 int reg;
57 @@ -230,6 +255,51 @@ static int aqr_config_aneg(struct phy_de
58 return genphy_c45_check_and_restart_aneg(phydev, changed);
59 }
60
61 +static struct {
62 + u16 syscfg;
63 + int cnt;
64 + u16 start_rate;
65 +} aquantia_syscfg[PHY_INTERFACE_MODE_MAX] = {
66 + [PHY_INTERFACE_MODE_SGMII] = {0x04b, AQUANTIA_VND1_GSYSCFG_1G,
67 + AQUANTIA_VND1_GSTART_RATE_1G},
68 + [PHY_INTERFACE_MODE_2500BASEX] = {0x144, AQUANTIA_VND1_GSYSCFG_2_5G,
69 + AQUANTIA_VND1_GSTART_RATE_2_5G},
70 + [PHY_INTERFACE_MODE_XGMII] = {0x100, AQUANTIA_VND1_GSYSCFG_10G,
71 + AQUANTIA_VND1_GSTART_RATE_10G},
72 + [PHY_INTERFACE_MODE_USXGMII] = {0x080, AQUANTIA_VND1_GSYSCFG_10G,
73 + AQUANTIA_VND1_GSTART_RATE_10G},
74 +};
75 +
76 +/* Sets up protocol on system side before calling aqr_config_aneg */
77 +static int aqr_config_aneg_set_prot(struct phy_device *phydev)
78 +{
79 + int if_type = phydev->interface;
80 + int i;
81 +
82 + if (!aquantia_syscfg[if_type].cnt)
83 + return 0;
84 +
85 + /* set PHY in low power mode so we can configure protocols */
86 + phy_write_mmd(phydev, MDIO_MMD_VEND1, AQUANTIA_VND1_GLOBAL_SC,
87 + AQUANTIA_VND1_GLOBAL_SC_LP);
88 + mdelay(10);
89 +
90 + /* set the default rate to enable the SI link */
91 + phy_write_mmd(phydev, MDIO_MMD_VEND1, AQUANTIA_VND1_GSTART_RATE,
92 + aquantia_syscfg[if_type].start_rate);
93 +
94 + for (i = 0; i <= aquantia_syscfg[if_type].cnt; i++)
95 + phy_write_mmd(phydev, MDIO_MMD_VEND1,
96 + AQUANTIA_VND1_GSYSCFG_BASE + i,
97 + aquantia_syscfg[if_type].syscfg);
98 +
99 + /* wake PHY back up */
100 + phy_write_mmd(phydev, MDIO_MMD_VEND1, AQUANTIA_VND1_GLOBAL_SC, 0);
101 + mdelay(10);
102 +
103 + return aqr_config_aneg(phydev);
104 +}
105 +
106 static int aqr_config_intr(struct phy_device *phydev)
107 {
108 bool en = phydev->interrupts == PHY_INTERRUPT_ENABLED;
109 @@ -858,6 +928,30 @@ static struct phy_driver aqr_driver[] =
110 .get_stats = aqr107_get_stats,
111 .link_change_notify = aqr107_link_change_notify,
112 },
113 +{
114 + PHY_ID_MATCH_MODEL(PHY_ID_AQR112),
115 + .name = "Aquantia AQR112",
116 + .probe = aqr107_probe,
117 + .config_aneg = aqr_config_aneg_set_prot,
118 + .config_intr = aqr_config_intr,
119 + .handle_interrupt = aqr_handle_interrupt,
120 + .read_status = aqr107_read_status,
121 + .get_sset_count = aqr107_get_sset_count,
122 + .get_strings = aqr107_get_strings,
123 + .get_stats = aqr107_get_stats,
124 +},
125 +{
126 + PHY_ID_MATCH_MODEL(PHY_ID_AQR412),
127 + .name = "Aquantia AQR412",
128 + .probe = aqr107_probe,
129 + .config_aneg = aqr_config_aneg_set_prot,
130 + .config_intr = aqr_config_intr,
131 + .handle_interrupt = aqr_handle_interrupt,
132 + .read_status = aqr107_read_status,
133 + .get_sset_count = aqr107_get_sset_count,
134 + .get_strings = aqr107_get_strings,
135 + .get_stats = aqr107_get_stats,
136 +},
137 };
138
139 module_phy_driver(aqr_driver);
140 @@ -875,6 +969,8 @@ static struct mdio_device_id __maybe_unu
141 { PHY_ID_MATCH_MODEL(PHY_ID_AQR113) },
142 { PHY_ID_MATCH_MODEL(PHY_ID_AQR113C) },
143 { PHY_ID_MATCH_MODEL(PHY_ID_AQR813) },
144 + { PHY_ID_MATCH_MODEL(PHY_ID_AQR112) },
145 + { PHY_ID_MATCH_MODEL(PHY_ID_AQR412) },
146 { }
147 };
148