generic: phy-mediatek-xfi-tphy: fix SGMII issue
[openwrt/staging/stintel.git] / target / linux / generic / pending-6.1 / 739-02-phy-add-driver-for-MediaTek-XFI-T-PHY.patch
1 From patchwork Thu Feb 1 21:53:06 2024
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 X-Patchwork-Submitter: Daniel Golle <daniel@makrotopia.org>
6 X-Patchwork-Id: 13541843
7 Date: Thu, 1 Feb 2024 21:53:06 +0000
8 From: Daniel Golle <daniel@makrotopia.org>
9 To: Bc-bocun Chen <bc-bocun.chen@mediatek.com>,
10 Chunfeng Yun <chunfeng.yun@mediatek.com>,
11 Vinod Koul <vkoul@kernel.org>,
12 Kishon Vijay Abraham I <kishon@kernel.org>,
13 Rob Herring <robh@kernel.org>,
14 Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
15 Conor Dooley <conor+dt@kernel.org>,
16 Daniel Golle <daniel@makrotopia.org>,
17 Qingfang Deng <dqfext@gmail.com>,
18 SkyLake Huang <SkyLake.Huang@mediatek.com>,
19 Matthias Brugger <matthias.bgg@gmail.com>,
20 AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>,
21 Philipp Zabel <p.zabel@pengutronix.de>,
22 linux-arm-kernel@lists.infradead.org,
23 linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org,
24 devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
25 netdev@vger.kernel.org
26 Subject: [PATCH 2/2] phy: add driver for MediaTek XFI T-PHY
27 Message-ID:
28 <dd6b40ea1f7f8459a9a2cfe7fa60c1108332ade6.1706823233.git.daniel@makrotopia.org>
29 References:
30 <702afb0c1246d95c90b22e57105304028bdd3083.1706823233.git.daniel@makrotopia.org>
31 MIME-Version: 1.0
32 Content-Disposition: inline
33 In-Reply-To:
34 <702afb0c1246d95c90b22e57105304028bdd3083.1706823233.git.daniel@makrotopia.org>
35 List-Id: Linux Phy Mailing list <linux-phy.lists.infradead.org>
36
37 Add driver for MediaTek's XFI T-PHY, 10 Gigabit/s Ethernet SerDes PHY
38 which can be found in the MT7988 SoC.
39
40 The PHY can operates only in PHY_MODE_ETHERNET, the submode is one of
41 PHY_INTERFACE_MODE_* corresponding to the supported modes:
42
43 * USXGMII \
44 * 10GBase-R }- USXGMII PCS - XGDM \
45 * 5GBase-R / \
46 }- Ethernet MAC
47 * 2500Base-X \ /
48 * 1000Base-X }- LynxI PCS - GDM /
49 * Cisco SGMII (MAC side) /
50
51 In order to work-around a performance issue present on the first of
52 two XFI T-PHYs present in MT7988, special tuning is applied which can be
53 selected by adding the 'mediatek,usxgmii-performance-errata' property to
54 the device tree node.
55
56 There is no documentation for most registers used for the
57 analog/tuning part, however, most of the registers have been partially
58 reverse-engineered from MediaTek's SDK implementation (an opaque
59 sequence of 32-bit register writes) and descriptions for all relevant
60 digital registers and bits such as resets and muxes have been supplied
61 by MediaTek.
62
63 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
64 ---
65 MAINTAINERS | 1 +
66 drivers/phy/mediatek/Kconfig | 12 +
67 drivers/phy/mediatek/Makefile | 1 +
68 drivers/phy/mediatek/phy-mtk-xfi-tphy.c | 392 ++++++++++++++++++++++++
69 4 files changed, 406 insertions(+)
70 create mode 100644 drivers/phy/mediatek/phy-mtk-xfi-tphy.c
71
72 --- a/drivers/phy/mediatek/Kconfig
73 +++ b/drivers/phy/mediatek/Kconfig
74 @@ -13,6 +13,18 @@ config PHY_MTK_PCIE
75 callback for PCIe GEN3 port, it supports software efuse
76 initialization.
77
78 +config PHY_MTK_XFI_TPHY
79 + tristate "MediaTek XFI T-PHY Driver"
80 + depends on ARCH_MEDIATEK || COMPILE_TEST
81 + depends on OF && OF_ADDRESS
82 + depends on HAS_IOMEM
83 + select GENERIC_PHY
84 + help
85 + Say 'Y' here to add support for MediaTek XFI T-PHY driver.
86 + The driver provides access to the Ethernet SerDes T-PHY supporting
87 + 1GE and 2.5GE modes via the LynxI PCS, and 5GE and 10GE modes
88 + via the USXGMII PCS found in MediaTek SoCs with 10G Ethernet.
89 +
90 config PHY_MTK_TPHY
91 tristate "MediaTek T-PHY Driver"
92 depends on ARCH_MEDIATEK || COMPILE_TEST
93 --- a/drivers/phy/mediatek/Makefile
94 +++ b/drivers/phy/mediatek/Makefile
95 @@ -8,6 +8,7 @@ obj-$(CONFIG_PHY_MTK_PCIE) += phy-mtk-p
96 obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
97 obj-$(CONFIG_PHY_MTK_UFS) += phy-mtk-ufs.o
98 obj-$(CONFIG_PHY_MTK_XSPHY) += phy-mtk-xsphy.o
99 +obj-$(CONFIG_PHY_MTK_XFI_TPHY) += phy-mtk-xfi-tphy.o
100
101 phy-mtk-hdmi-drv-y := phy-mtk-hdmi.o
102 phy-mtk-hdmi-drv-y += phy-mtk-hdmi-mt2701.o
103 --- /dev/null
104 +++ b/drivers/phy/mediatek/phy-mtk-xfi-tphy.c
105 @@ -0,0 +1,393 @@
106 +// SPDX-License-Identifier: GPL-2.0-or-later
107 +/* MediaTek 10GE SerDes PHY driver
108 + *
109 + * Copyright (c) 2024 Daniel Golle <daniel@makrotopia.org>
110 + * Bc-bocun Chen <bc-bocun.chen@mediatek.com>
111 + * based on mtk_usxgmii.c found in MediaTek's SDK released under GPL-2.0
112 + * Copyright (c) 2022 MediaTek Inc.
113 + * Author: Henry Yen <henry.yen@mediatek.com>
114 + */
115 +
116 +#include <linux/module.h>
117 +#include <linux/device.h>
118 +#include <linux/platform_device.h>
119 +#include <linux/of.h>
120 +#include <linux/io.h>
121 +#include <linux/clk.h>
122 +#include <linux/reset.h>
123 +#include <linux/phy.h>
124 +#include <linux/phy/phy.h>
125 +
126 +#define MTK_XFI_TPHY_NUM_CLOCKS 2
127 +
128 +#define REG_DIG_GLB_70 0x0070
129 +#define XTP_PCS_RX_EQ_IN_PROGRESS(x) FIELD_PREP(GENMASK(25, 24), (x))
130 +#define XTP_PCS_MODE_MASK GENMASK(17, 16)
131 +#define XTP_PCS_MODE(x) FIELD_PREP(GENMASK(17, 16), (x))
132 +#define XTP_PCS_RST_B BIT(15)
133 +#define XTP_FRC_PCS_RST_B BIT(14)
134 +#define XTP_PCS_PWD_SYNC_MASK GENMASK(13, 12)
135 +#define XTP_PCS_PWD_SYNC(x) FIELD_PREP(XTP_PCS_PWD_SYNC_MASK, (x))
136 +#define XTP_PCS_PWD_ASYNC_MASK GENMASK(11, 10)
137 +#define XTP_PCS_PWD_ASYNC(x) FIELD_PREP(XTP_PCS_PWD_ASYNC_MASK, (x))
138 +#define XTP_FRC_PCS_PWD_ASYNC BIT(8)
139 +#define XTP_PCS_UPDT BIT(4)
140 +#define XTP_PCS_IN_FR_RG BIT(0)
141 +
142 +#define REG_DIG_GLB_F4 0x00f4
143 +#define XFI_DPHY_PCS_SEL BIT(0)
144 +#define XFI_DPHY_PCS_SEL_SGMII FIELD_PREP(XFI_DPHY_PCS_SEL, 1)
145 +#define XFI_DPHY_PCS_SEL_USXGMII FIELD_PREP(XFI_DPHY_PCS_SEL, 0)
146 +#define XFI_DPHY_AD_SGDT_FRC_EN BIT(5)
147 +
148 +#define REG_DIG_LN_TRX_40 0x3040
149 +#define XTP_LN_FRC_TX_DATA_EN BIT(29)
150 +#define XTP_LN_TX_DATA_EN BIT(28)
151 +
152 +#define REG_DIG_LN_TRX_B0 0x30b0
153 +#define XTP_LN_FRC_TX_MACCK_EN BIT(5)
154 +#define XTP_LN_TX_MACCK_EN BIT(4)
155 +
156 +#define REG_ANA_GLB_D0 0x90d0
157 +#define XTP_GLB_USXGMII_SEL_MASK GENMASK(3, 1)
158 +#define XTP_GLB_USXGMII_SEL(x) FIELD_PREP(GENMASK(3, 1), (x))
159 +#define XTP_GLB_USXGMII_EN BIT(0)
160 +
161 +struct mtk_xfi_tphy {
162 + void __iomem *base;
163 + struct device *dev;
164 + struct reset_control *reset;
165 + struct clk_bulk_data clocks[MTK_XFI_TPHY_NUM_CLOCKS];
166 + bool da_war;
167 +};
168 +
169 +static void mtk_xfi_tphy_write(struct mtk_xfi_tphy *xfi_tphy, u16 reg,
170 + u32 value)
171 +{
172 + iowrite32(value, xfi_tphy->base + reg);
173 +}
174 +
175 +static void mtk_xfi_tphy_rmw(struct mtk_xfi_tphy *xfi_tphy, u16 reg,
176 + u32 clr, u32 set)
177 +{
178 + u32 val;
179 +
180 + val = ioread32(xfi_tphy->base + reg);
181 + val &= ~clr;
182 + val |= set;
183 + iowrite32(val, xfi_tphy->base + reg);
184 +}
185 +
186 +static void mtk_xfi_tphy_set(struct mtk_xfi_tphy *xfi_tphy, u16 reg,
187 + u32 set)
188 +{
189 + mtk_xfi_tphy_rmw(xfi_tphy, reg, 0, set);
190 +}
191 +
192 +static void mtk_xfi_tphy_clear(struct mtk_xfi_tphy *xfi_tphy, u16 reg,
193 + u32 clr)
194 +{
195 + mtk_xfi_tphy_rmw(xfi_tphy, reg, clr, 0);
196 +}
197 +
198 +static void mtk_xfi_tphy_setup(struct mtk_xfi_tphy *xfi_tphy,
199 + phy_interface_t interface)
200 +{
201 + bool is_2p5g = (interface == PHY_INTERFACE_MODE_2500BASEX);
202 + bool is_1g = (interface == PHY_INTERFACE_MODE_1000BASEX ||
203 + interface == PHY_INTERFACE_MODE_SGMII);
204 + bool is_10g = (interface == PHY_INTERFACE_MODE_10GBASER ||
205 + interface == PHY_INTERFACE_MODE_USXGMII);
206 + bool is_5g = (interface == PHY_INTERFACE_MODE_5GBASER);
207 + bool is_xgmii = (is_10g || is_5g);
208 +
209 + dev_dbg(xfi_tphy->dev, "setting up for mode %s\n", phy_modes(interface));
210 +
211 + /* Setup PLL setting */
212 + mtk_xfi_tphy_rmw(xfi_tphy, 0x9024, 0x100000, is_10g ? 0x0 : 0x100000);
213 + mtk_xfi_tphy_rmw(xfi_tphy, 0x2020, 0x202000, is_5g ? 0x202000 : 0x0);
214 + mtk_xfi_tphy_rmw(xfi_tphy, 0x2030, 0x500, is_1g ? 0x0 : 0x500);
215 + mtk_xfi_tphy_rmw(xfi_tphy, 0x2034, 0xa00, is_1g ? 0x0 : 0xa00);
216 + mtk_xfi_tphy_rmw(xfi_tphy, 0x2040, 0x340000, is_1g ? 0x200000 :
217 + 0x140000);
218 +
219 + /* Setup RXFE BW setting */
220 + mtk_xfi_tphy_rmw(xfi_tphy, 0x50f0, 0xc10, is_1g ? 0x410 :
221 + is_5g ? 0x800 : 0x400);
222 + mtk_xfi_tphy_rmw(xfi_tphy, 0x50e0, 0x4000, is_5g ? 0x0 : 0x4000);
223 +
224 + /* Setup RX CDR setting */
225 + mtk_xfi_tphy_rmw(xfi_tphy, 0x506c, 0x30000, is_5g ? 0x0 : 0x30000);
226 + mtk_xfi_tphy_rmw(xfi_tphy, 0x5070, 0x670000, is_5g ? 0x620000 : 0x50000);
227 + mtk_xfi_tphy_rmw(xfi_tphy, 0x5074, 0x180000, is_5g ? 0x180000 : 0x0);
228 + mtk_xfi_tphy_rmw(xfi_tphy, 0x5078, 0xf000400, is_5g ? 0x8000000 :
229 + 0x7000400);
230 + mtk_xfi_tphy_rmw(xfi_tphy, 0x507c, 0x5000500, is_5g ? 0x4000400 :
231 + 0x1000100);
232 + mtk_xfi_tphy_rmw(xfi_tphy, 0x5080, 0x1410, is_1g ? 0x400 :
233 + is_5g ? 0x1010 : 0x0);
234 + mtk_xfi_tphy_rmw(xfi_tphy, 0x5084, 0x30300, is_1g ? 0x30300 :
235 + is_5g ? 0x30100 :
236 + 0x100);
237 + mtk_xfi_tphy_rmw(xfi_tphy, 0x5088, 0x60200, is_1g ? 0x20200 :
238 + is_5g ? 0x40000 :
239 + 0x20000);
240 +
241 + /* Setting RXFE adaptation range setting */
242 + mtk_xfi_tphy_rmw(xfi_tphy, 0x50e4, 0xc0000, is_5g ? 0x0 : 0xc0000);
243 + mtk_xfi_tphy_rmw(xfi_tphy, 0x50e8, 0x40000, is_5g ? 0x0 : 0x40000);
244 + mtk_xfi_tphy_rmw(xfi_tphy, 0x50ec, 0xa00, is_1g ? 0x200 : 0x800);
245 + mtk_xfi_tphy_rmw(xfi_tphy, 0x50a8, 0xee0000, is_5g ? 0x800000 :
246 + 0x6e0000);
247 + mtk_xfi_tphy_rmw(xfi_tphy, 0x6004, 0x190000, is_5g ? 0x0 : 0x190000);
248 + if (is_10g)
249 + mtk_xfi_tphy_write(xfi_tphy, 0x00f8, 0x01423342);
250 + else if (is_5g)
251 + mtk_xfi_tphy_write(xfi_tphy, 0x00f8, 0x00a132a1);
252 + else if (is_2p5g)
253 + mtk_xfi_tphy_write(xfi_tphy, 0x00f8, 0x009c329c);
254 + else
255 + mtk_xfi_tphy_write(xfi_tphy, 0x00f8, 0x00fa32fa);
256 +
257 + /* Force SGDT_OUT off and select PCS */
258 + mtk_xfi_tphy_rmw(xfi_tphy, REG_DIG_GLB_F4,
259 + XFI_DPHY_AD_SGDT_FRC_EN | XFI_DPHY_PCS_SEL,
260 + XFI_DPHY_AD_SGDT_FRC_EN |
261 + (is_xgmii ? XFI_DPHY_PCS_SEL_USXGMII :
262 + XFI_DPHY_PCS_SEL_SGMII));
263 +
264 +
265 + /* Force GLB_CKDET_OUT */
266 + mtk_xfi_tphy_set(xfi_tphy, 0x0030, 0xc00);
267 +
268 + /* Force AEQ on */
269 + mtk_xfi_tphy_write(xfi_tphy, REG_DIG_GLB_70,
270 + XTP_PCS_RX_EQ_IN_PROGRESS(2) |
271 + XTP_PCS_PWD_SYNC(2) |
272 + XTP_PCS_PWD_ASYNC(2));
273 +
274 + usleep_range(1, 5);
275 + writel(XTP_LN_FRC_TX_DATA_EN, xfi_tphy->base + REG_DIG_LN_TRX_40);
276 +
277 + /* Setup TX DA default value */
278 + mtk_xfi_tphy_rmw(xfi_tphy, 0x30b0, 0x30, 0x20);
279 + mtk_xfi_tphy_write(xfi_tphy, 0x3028, 0x00008a01);
280 + mtk_xfi_tphy_write(xfi_tphy, 0x302c, 0x0000a884);
281 + mtk_xfi_tphy_write(xfi_tphy, 0x3024, 0x00083002);
282 +
283 + /* Setup RG default value */
284 + if (is_xgmii) {
285 + mtk_xfi_tphy_write(xfi_tphy, 0x3010, 0x00022220);
286 + mtk_xfi_tphy_write(xfi_tphy, 0x5064, 0x0f020a01);
287 + mtk_xfi_tphy_write(xfi_tphy, 0x50b4, 0x06100600);
288 + if (interface == PHY_INTERFACE_MODE_USXGMII)
289 + mtk_xfi_tphy_write(xfi_tphy, 0x3048, 0x40704000);
290 + else
291 + mtk_xfi_tphy_write(xfi_tphy, 0x3048, 0x47684100);
292 + } else {
293 + mtk_xfi_tphy_write(xfi_tphy, 0x3010, 0x00011110);
294 + mtk_xfi_tphy_write(xfi_tphy, 0x3048, 0x40704000);
295 + }
296 +
297 + if (is_1g)
298 + mtk_xfi_tphy_write(xfi_tphy, 0x3064, 0x0000c000);
299 +
300 + /* Setup RX EQ initial value */
301 + mtk_xfi_tphy_rmw(xfi_tphy, 0x3050, 0xa8000000,
302 + (interface != PHY_INTERFACE_MODE_10GBASER) ?
303 + 0xa8000000 : 0x0);
304 + mtk_xfi_tphy_rmw(xfi_tphy, 0x3054, 0xaa,
305 + (interface != PHY_INTERFACE_MODE_10GBASER) ?
306 + 0xaa : 0x0);
307 +
308 + if (is_xgmii)
309 + mtk_xfi_tphy_write(xfi_tphy, 0x306c, 0x00000f00);
310 + else if (is_2p5g)
311 + mtk_xfi_tphy_write(xfi_tphy, 0x306c, 0x22000f00);
312 + else
313 + mtk_xfi_tphy_write(xfi_tphy, 0x306c, 0x20200f00);
314 +
315 + if (interface == PHY_INTERFACE_MODE_10GBASER && xfi_tphy->da_war)
316 + mtk_xfi_tphy_rmw(xfi_tphy, 0xa008, 0x10000, 0x10000);
317 +
318 + mtk_xfi_tphy_rmw(xfi_tphy, 0xa060, 0x50000, is_xgmii ? 0x40000 :
319 + 0x50000);
320 +
321 + /* Setup PHYA speed */
322 + mtk_xfi_tphy_rmw(xfi_tphy, REG_ANA_GLB_D0,
323 + XTP_GLB_USXGMII_SEL_MASK | XTP_GLB_USXGMII_EN,
324 + is_10g ? XTP_GLB_USXGMII_SEL(0) :
325 + is_5g ? XTP_GLB_USXGMII_SEL(1) :
326 + is_2p5g ? XTP_GLB_USXGMII_SEL(2) :
327 + XTP_GLB_USXGMII_SEL(3));
328 + mtk_xfi_tphy_set(xfi_tphy, REG_ANA_GLB_D0, XTP_GLB_USXGMII_EN);
329 +
330 + /* Release reset */
331 + mtk_xfi_tphy_set(xfi_tphy, REG_DIG_GLB_70,
332 + XTP_PCS_RST_B | XTP_FRC_PCS_RST_B);
333 + usleep_range(150, 500);
334 +
335 + /* Switch to P0 */
336 + mtk_xfi_tphy_rmw(xfi_tphy, REG_DIG_GLB_70,
337 + XTP_PCS_PWD_SYNC_MASK |
338 + XTP_PCS_PWD_ASYNC_MASK,
339 + XTP_FRC_PCS_PWD_ASYNC |
340 + XTP_PCS_UPDT | XTP_PCS_IN_FR_RG);
341 + usleep_range(1, 5);
342 +
343 + mtk_xfi_tphy_clear(xfi_tphy, REG_DIG_GLB_70, XTP_PCS_UPDT);
344 + usleep_range(15, 50);
345 +
346 + if (is_xgmii) {
347 + /* Switch to Gen3 */
348 + mtk_xfi_tphy_rmw(xfi_tphy, REG_DIG_GLB_70,
349 + XTP_PCS_MODE_MASK | XTP_PCS_UPDT,
350 + XTP_PCS_MODE(2) | XTP_PCS_UPDT);
351 + } else {
352 + /* Switch to Gen2 */
353 + mtk_xfi_tphy_rmw(xfi_tphy, REG_DIG_GLB_70,
354 + XTP_PCS_MODE_MASK | XTP_PCS_UPDT,
355 + XTP_PCS_MODE(1) | XTP_PCS_UPDT);
356 + }
357 + usleep_range(1, 5);
358 +
359 + mtk_xfi_tphy_clear(xfi_tphy, REG_DIG_GLB_70, XTP_PCS_UPDT);
360 +
361 + usleep_range(100, 500);
362 +
363 + /* Enable MAC CK */
364 + mtk_xfi_tphy_set(xfi_tphy, REG_DIG_LN_TRX_B0, XTP_LN_TX_MACCK_EN);
365 + mtk_xfi_tphy_clear(xfi_tphy, REG_DIG_GLB_F4, XFI_DPHY_AD_SGDT_FRC_EN);
366 +
367 + /* Enable TX data */
368 + mtk_xfi_tphy_set(xfi_tphy, REG_DIG_LN_TRX_40,
369 + XTP_LN_FRC_TX_DATA_EN | XTP_LN_TX_DATA_EN);
370 + usleep_range(400, 1000);
371 +}
372 +
373 +static int mtk_xfi_tphy_set_mode(struct phy *phy, enum phy_mode mode, int
374 + submode)
375 +{
376 + struct mtk_xfi_tphy *xfi_tphy = phy_get_drvdata(phy);
377 +
378 + if (mode != PHY_MODE_ETHERNET)
379 + return -EINVAL;
380 +
381 + switch (submode) {
382 + case PHY_INTERFACE_MODE_1000BASEX:
383 + case PHY_INTERFACE_MODE_2500BASEX:
384 + case PHY_INTERFACE_MODE_SGMII:
385 + case PHY_INTERFACE_MODE_5GBASER:
386 + case PHY_INTERFACE_MODE_10GBASER:
387 + case PHY_INTERFACE_MODE_USXGMII:
388 + mtk_xfi_tphy_setup(xfi_tphy, submode);
389 + return 0;
390 + default:
391 + return -EINVAL;
392 + }
393 +}
394 +
395 +static int mtk_xfi_tphy_reset(struct phy *phy)
396 +{
397 + struct mtk_xfi_tphy *xfi_tphy = phy_get_drvdata(phy);
398 +
399 + reset_control_assert(xfi_tphy->reset);
400 + usleep_range(100, 500);
401 + reset_control_deassert(xfi_tphy->reset);
402 + usleep_range(1, 10);
403 +
404 + return 0;
405 +}
406 +
407 +static int mtk_xfi_tphy_power_on(struct phy *phy)
408 +{
409 + struct mtk_xfi_tphy *xfi_tphy = phy_get_drvdata(phy);
410 +
411 + return clk_bulk_prepare_enable(MTK_XFI_TPHY_NUM_CLOCKS, xfi_tphy->clocks);
412 +}
413 +
414 +static int mtk_xfi_tphy_power_off(struct phy *phy)
415 +{
416 + struct mtk_xfi_tphy *xfi_tphy = phy_get_drvdata(phy);
417 +
418 + clk_bulk_disable_unprepare(MTK_XFI_TPHY_NUM_CLOCKS, xfi_tphy->clocks);
419 +
420 + return 0;
421 +}
422 +
423 +static const struct phy_ops mtk_xfi_tphy_ops = {
424 + .power_on = mtk_xfi_tphy_power_on,
425 + .power_off = mtk_xfi_tphy_power_off,
426 + .set_mode = mtk_xfi_tphy_set_mode,
427 + .reset = mtk_xfi_tphy_reset,
428 + .owner = THIS_MODULE,
429 +};
430 +
431 +static int mtk_xfi_tphy_probe(struct platform_device *pdev)
432 +{
433 + struct device_node *np = pdev->dev.of_node;
434 + struct phy_provider *phy_provider;
435 + struct mtk_xfi_tphy *xfi_tphy;
436 + struct phy *phy;
437 +
438 + if (!np)
439 + return -ENODEV;
440 +
441 + xfi_tphy = devm_kzalloc(&pdev->dev, sizeof(*xfi_tphy), GFP_KERNEL);
442 + if (!xfi_tphy)
443 + return -ENOMEM;
444 +
445 + xfi_tphy->base = devm_of_iomap(&pdev->dev, np, 0, NULL);
446 + if (!xfi_tphy->base)
447 + return -EIO;
448 +
449 + xfi_tphy->dev = &pdev->dev;
450 +
451 + xfi_tphy->clocks[0].id = "topxtal";
452 + xfi_tphy->clocks[0].clk = devm_clk_get(&pdev->dev, xfi_tphy->clocks[0].id);
453 + if (IS_ERR(xfi_tphy->clocks[0].clk))
454 + return PTR_ERR(xfi_tphy->clocks[0].clk);
455 +
456 + xfi_tphy->clocks[1].id = "xfipll";
457 + xfi_tphy->clocks[1].clk = devm_clk_get(&pdev->dev, xfi_tphy->clocks[1].id);
458 + if (IS_ERR(xfi_tphy->clocks[1].clk))
459 + return PTR_ERR(xfi_tphy->clocks[1].clk);
460 +
461 + xfi_tphy->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
462 + if (IS_ERR(xfi_tphy->reset))
463 + return PTR_ERR(xfi_tphy->reset);
464 +
465 + xfi_tphy->da_war = of_property_read_bool(np,
466 + "mediatek,usxgmii-performance-errata");
467 +
468 + phy = devm_phy_create(&pdev->dev, NULL, &mtk_xfi_tphy_ops);
469 + if (IS_ERR(phy))
470 + return PTR_ERR(phy);
471 +
472 + phy_set_drvdata(phy, xfi_tphy);
473 +
474 + phy_provider = devm_of_phy_provider_register(&pdev->dev,
475 + of_phy_simple_xlate);
476 +
477 + return PTR_ERR_OR_ZERO(phy_provider);
478 +}
479 +
480 +static const struct of_device_id mtk_xfi_tphy_match[] = {
481 + { .compatible = "mediatek,mt7988-xfi-tphy", },
482 + { }
483 +};
484 +MODULE_DEVICE_TABLE(of, mtk_xfi_tphy_match);
485 +
486 +static struct platform_driver mtk_xfi_tphy_driver = {
487 + .probe = mtk_xfi_tphy_probe,
488 + .driver = {
489 + .name = "mtk-xfi-tphy",
490 + .of_match_table = mtk_xfi_tphy_match,
491 + },
492 +};
493 +module_platform_driver(mtk_xfi_tphy_driver);
494 +
495 +MODULE_DESCRIPTION("MediaTek XFI T-PHY driver");
496 +MODULE_AUTHOR("Daniel Golle <daniel@makrotopia.org>");
497 +MODULE_AUTHOR("Bc-bocun Chen <bc-bocun.chen@mediatek.com>");
498 +MODULE_LICENSE("GPL");