xref: /rk3399_rockchip-uboot/drivers/phy/phy-rockchip-naneng-combphy.c (revision dbf89912a42ce800d4e5f12bf4c2643a4e3d3773)
1925c5749SYifeng Zhao // SPDX-License-Identifier: GPL-2.0
2925c5749SYifeng Zhao /*
3925c5749SYifeng Zhao  * Rockchip USB3.0/PCIe Gen2/SATA/SGMII combphy driver
4925c5749SYifeng Zhao  *
5925c5749SYifeng Zhao  * Copyright (C) 2021 Rockchip Electronics Co., Ltd.
6925c5749SYifeng Zhao  */
7925c5749SYifeng Zhao 
8925c5749SYifeng Zhao #include <common.h>
9925c5749SYifeng Zhao #include <clk.h>
10925c5749SYifeng Zhao #include <dm.h>
11925c5749SYifeng Zhao #include <dm/lists.h>
12925c5749SYifeng Zhao #include <dt-bindings/phy/phy.h>
13925c5749SYifeng Zhao #include <generic-phy.h>
14925c5749SYifeng Zhao #include <syscon.h>
15925c5749SYifeng Zhao #include <asm/io.h>
16925c5749SYifeng Zhao #include <asm/arch/clock.h>
17925c5749SYifeng Zhao #include <regmap.h>
18925c5749SYifeng Zhao #include <reset-uclass.h>
19925c5749SYifeng Zhao 
20925c5749SYifeng Zhao #define BIT_WRITEABLE_SHIFT		16
21925c5749SYifeng Zhao 
22925c5749SYifeng Zhao struct rockchip_combphy_priv;
23925c5749SYifeng Zhao 
24925c5749SYifeng Zhao struct combphy_reg {
25925c5749SYifeng Zhao 	u16 offset;
26925c5749SYifeng Zhao 	u16 bitend;
27925c5749SYifeng Zhao 	u16 bitstart;
28925c5749SYifeng Zhao 	u16 disable;
29925c5749SYifeng Zhao 	u16 enable;
30925c5749SYifeng Zhao };
31925c5749SYifeng Zhao 
32925c5749SYifeng Zhao struct rockchip_combphy_grfcfg {
33925c5749SYifeng Zhao 	struct combphy_reg pcie_mode_set;
34925c5749SYifeng Zhao 	struct combphy_reg usb_mode_set;
35925c5749SYifeng Zhao 	struct combphy_reg sgmii_mode_set;
36925c5749SYifeng Zhao 	struct combphy_reg qsgmii_mode_set;
37925c5749SYifeng Zhao 	struct combphy_reg pipe_rxterm_set;
38925c5749SYifeng Zhao 	struct combphy_reg pipe_txelec_set;
39925c5749SYifeng Zhao 	struct combphy_reg pipe_txcomp_set;
40925c5749SYifeng Zhao 	struct combphy_reg pipe_clk_25m;
41925c5749SYifeng Zhao 	struct combphy_reg pipe_clk_100m;
42925c5749SYifeng Zhao 	struct combphy_reg pipe_phymode_sel;
43925c5749SYifeng Zhao 	struct combphy_reg pipe_rate_sel;
44925c5749SYifeng Zhao 	struct combphy_reg pipe_rxterm_sel;
45925c5749SYifeng Zhao 	struct combphy_reg pipe_txelec_sel;
46925c5749SYifeng Zhao 	struct combphy_reg pipe_txcomp_sel;
47925c5749SYifeng Zhao 	struct combphy_reg pipe_clk_ext;
48925c5749SYifeng Zhao 	struct combphy_reg pipe_sel_usb;
49925c5749SYifeng Zhao 	struct combphy_reg pipe_sel_qsgmii;
50925c5749SYifeng Zhao 	struct combphy_reg pipe_phy_status;
51925c5749SYifeng Zhao 	struct combphy_reg con0_for_pcie;
52925c5749SYifeng Zhao 	struct combphy_reg con1_for_pcie;
53925c5749SYifeng Zhao 	struct combphy_reg con2_for_pcie;
54925c5749SYifeng Zhao 	struct combphy_reg con3_for_pcie;
55925c5749SYifeng Zhao 	struct combphy_reg con0_for_sata;
56925c5749SYifeng Zhao 	struct combphy_reg con1_for_sata;
57925c5749SYifeng Zhao 	struct combphy_reg con2_for_sata;
58925c5749SYifeng Zhao 	struct combphy_reg con3_for_sata;
59925c5749SYifeng Zhao 	struct combphy_reg pipe_con0_for_sata;
60925c5749SYifeng Zhao 	struct combphy_reg pipe_sgmii_mac_sel;
61925c5749SYifeng Zhao 	struct combphy_reg pipe_xpcs_phy_ready;
62925c5749SYifeng Zhao 	struct combphy_reg u3otg0_port_en;
63925c5749SYifeng Zhao 	struct combphy_reg u3otg1_port_en;
64925c5749SYifeng Zhao };
65925c5749SYifeng Zhao 
66925c5749SYifeng Zhao struct rockchip_combphy_cfg {
67925c5749SYifeng Zhao 	const struct rockchip_combphy_grfcfg *grfcfg;
68925c5749SYifeng Zhao 	int (*combphy_cfg)(struct rockchip_combphy_priv *priv);
69925c5749SYifeng Zhao };
70925c5749SYifeng Zhao 
71925c5749SYifeng Zhao struct rockchip_combphy_priv {
72925c5749SYifeng Zhao 	u32 mode;
73925c5749SYifeng Zhao 	void __iomem *mmio;
74925c5749SYifeng Zhao 	struct udevice *dev;
75925c5749SYifeng Zhao 	struct regmap *pipe_grf;
76925c5749SYifeng Zhao 	struct regmap *phy_grf;
77925c5749SYifeng Zhao 	struct phy *phy;
78925c5749SYifeng Zhao 	struct reset_ctl phy_rst;
79925c5749SYifeng Zhao 	struct clk ref_clk;
80925c5749SYifeng Zhao 	const struct rockchip_combphy_cfg *cfg;
81925c5749SYifeng Zhao };
82925c5749SYifeng Zhao 
83925c5749SYifeng Zhao static int param_write(struct regmap *base,
84925c5749SYifeng Zhao 		       const struct combphy_reg *reg, bool en)
85925c5749SYifeng Zhao {
86925c5749SYifeng Zhao 	u32 val, mask, tmp;
87925c5749SYifeng Zhao 
88925c5749SYifeng Zhao 	tmp = en ? reg->enable : reg->disable;
89925c5749SYifeng Zhao 	mask = GENMASK(reg->bitend, reg->bitstart);
90925c5749SYifeng Zhao 	val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);
91925c5749SYifeng Zhao 
92925c5749SYifeng Zhao 	return regmap_write(base, reg->offset, val);
93925c5749SYifeng Zhao }
94925c5749SYifeng Zhao 
95925c5749SYifeng Zhao static int rockchip_combphy_pcie_init(struct rockchip_combphy_priv *priv)
96925c5749SYifeng Zhao {
97925c5749SYifeng Zhao 	int ret = 0;
98925c5749SYifeng Zhao 
99925c5749SYifeng Zhao 	if (priv->cfg->combphy_cfg) {
100925c5749SYifeng Zhao 		ret = priv->cfg->combphy_cfg(priv);
101925c5749SYifeng Zhao 		if (ret) {
102925c5749SYifeng Zhao 			dev_err(priv->dev, "failed to init phy for pcie\n");
103925c5749SYifeng Zhao 			return ret;
104925c5749SYifeng Zhao 		}
105925c5749SYifeng Zhao 	}
106925c5749SYifeng Zhao 
107925c5749SYifeng Zhao 	return ret;
108925c5749SYifeng Zhao }
109925c5749SYifeng Zhao 
110925c5749SYifeng Zhao static int rockchip_combphy_usb3_init(struct rockchip_combphy_priv *priv)
111925c5749SYifeng Zhao {
112925c5749SYifeng Zhao 	int ret = 0;
113925c5749SYifeng Zhao 
114925c5749SYifeng Zhao 	if (priv->cfg->combphy_cfg) {
115925c5749SYifeng Zhao 		ret = priv->cfg->combphy_cfg(priv);
116925c5749SYifeng Zhao 		if (ret) {
117925c5749SYifeng Zhao 			dev_err(priv->dev, "failed to init phy for usb3\n");
118925c5749SYifeng Zhao 			return ret;
119925c5749SYifeng Zhao 		}
120925c5749SYifeng Zhao 	}
121925c5749SYifeng Zhao 
122925c5749SYifeng Zhao 	return ret;
123925c5749SYifeng Zhao }
124925c5749SYifeng Zhao 
125925c5749SYifeng Zhao static int rockchip_combphy_sata_init(struct rockchip_combphy_priv *priv)
126925c5749SYifeng Zhao {
127925c5749SYifeng Zhao 	int ret = 0;
128925c5749SYifeng Zhao 
129925c5749SYifeng Zhao 	if (priv->cfg->combphy_cfg) {
130925c5749SYifeng Zhao 		ret = priv->cfg->combphy_cfg(priv);
131925c5749SYifeng Zhao 		if (ret) {
132925c5749SYifeng Zhao 			dev_err(priv->dev, "failed to init phy for sata\n");
133925c5749SYifeng Zhao 			return ret;
134925c5749SYifeng Zhao 		}
135925c5749SYifeng Zhao 	}
136925c5749SYifeng Zhao 
137925c5749SYifeng Zhao 	return ret;
138925c5749SYifeng Zhao }
139925c5749SYifeng Zhao 
140925c5749SYifeng Zhao static int rockchip_combphy_sgmii_init(struct rockchip_combphy_priv *priv)
141925c5749SYifeng Zhao {
142925c5749SYifeng Zhao 	int ret = 0;
143925c5749SYifeng Zhao 
144925c5749SYifeng Zhao 	if (priv->cfg->combphy_cfg) {
145925c5749SYifeng Zhao 		ret = priv->cfg->combphy_cfg(priv);
146925c5749SYifeng Zhao 		if (ret) {
147925c5749SYifeng Zhao 			dev_err(priv->dev, "failed to init phy for sgmii\n");
148925c5749SYifeng Zhao 			return ret;
149925c5749SYifeng Zhao 		}
150925c5749SYifeng Zhao 	}
151925c5749SYifeng Zhao 
152925c5749SYifeng Zhao 	return ret;
153925c5749SYifeng Zhao }
154925c5749SYifeng Zhao 
155925c5749SYifeng Zhao static int rockchip_combphy_set_mode(struct rockchip_combphy_priv *priv)
156925c5749SYifeng Zhao {
157925c5749SYifeng Zhao 	switch (priv->mode) {
158925c5749SYifeng Zhao 	case PHY_TYPE_PCIE:
159925c5749SYifeng Zhao 		rockchip_combphy_pcie_init(priv);
160925c5749SYifeng Zhao 		break;
161925c5749SYifeng Zhao 	case PHY_TYPE_USB3:
162925c5749SYifeng Zhao 		rockchip_combphy_usb3_init(priv);
163925c5749SYifeng Zhao 		break;
164925c5749SYifeng Zhao 	case PHY_TYPE_SATA:
165925c5749SYifeng Zhao 		rockchip_combphy_sata_init(priv);
166925c5749SYifeng Zhao 		break;
167925c5749SYifeng Zhao 	case PHY_TYPE_SGMII:
168925c5749SYifeng Zhao 	case PHY_TYPE_QSGMII:
169925c5749SYifeng Zhao 		return rockchip_combphy_sgmii_init(priv);
170925c5749SYifeng Zhao 	default:
171925c5749SYifeng Zhao 		dev_err(priv->dev, "incompatible PHY type\n");
172925c5749SYifeng Zhao 		return -EINVAL;
173925c5749SYifeng Zhao 	}
174925c5749SYifeng Zhao 
175925c5749SYifeng Zhao 	return 0;
176925c5749SYifeng Zhao }
177925c5749SYifeng Zhao 
178925c5749SYifeng Zhao static int rockchip_combphy_init(struct phy *phy)
179925c5749SYifeng Zhao {
180925c5749SYifeng Zhao 	struct rockchip_combphy_priv *priv = dev_get_priv(phy->dev);
181925c5749SYifeng Zhao 	int ret;
182925c5749SYifeng Zhao 
183925c5749SYifeng Zhao 	ret = clk_enable(&priv->ref_clk);
184925c5749SYifeng Zhao 	if (ret < 0 && ret != -ENOSYS)
185925c5749SYifeng Zhao 		return ret;
186925c5749SYifeng Zhao 
187925c5749SYifeng Zhao 	ret = rockchip_combphy_set_mode(priv);
188925c5749SYifeng Zhao 	if (ret)
189925c5749SYifeng Zhao 		goto err_clk;
190925c5749SYifeng Zhao 
191925c5749SYifeng Zhao 	reset_deassert(&priv->phy_rst);
192925c5749SYifeng Zhao 
193925c5749SYifeng Zhao 	return 0;
194925c5749SYifeng Zhao 
195925c5749SYifeng Zhao err_clk:
196925c5749SYifeng Zhao 	clk_disable(&priv->ref_clk);
197925c5749SYifeng Zhao 
198925c5749SYifeng Zhao 	return ret;
199925c5749SYifeng Zhao }
200925c5749SYifeng Zhao 
201925c5749SYifeng Zhao static int rockchip_combphy_exit(struct phy *phy)
202925c5749SYifeng Zhao {
203925c5749SYifeng Zhao 	struct rockchip_combphy_priv *priv = dev_get_priv(phy->dev);
204925c5749SYifeng Zhao 
205925c5749SYifeng Zhao 	clk_disable(&priv->ref_clk);
206925c5749SYifeng Zhao 	reset_assert(&priv->phy_rst);
207925c5749SYifeng Zhao 
208925c5749SYifeng Zhao 	return 0;
209925c5749SYifeng Zhao }
210925c5749SYifeng Zhao 
211925c5749SYifeng Zhao static int rockchip_combphy_xlate(struct phy *phy, struct ofnode_phandle_args *args)
212925c5749SYifeng Zhao {
213925c5749SYifeng Zhao 	struct rockchip_combphy_priv *priv = dev_get_priv(phy->dev);
214925c5749SYifeng Zhao 
215925c5749SYifeng Zhao 	if (args->args_count != 1) {
216925c5749SYifeng Zhao 		pr_err("invalid number of arguments\n");
217925c5749SYifeng Zhao 		return -EINVAL;
218925c5749SYifeng Zhao 	}
219925c5749SYifeng Zhao 
220925c5749SYifeng Zhao 	priv->mode = args->args[0];
221925c5749SYifeng Zhao 
222925c5749SYifeng Zhao 	return 0;
223925c5749SYifeng Zhao }
224925c5749SYifeng Zhao 
225925c5749SYifeng Zhao static const struct phy_ops rochchip_combphy_ops = {
226925c5749SYifeng Zhao 	.init = rockchip_combphy_init,
227925c5749SYifeng Zhao 	.exit = rockchip_combphy_exit,
228925c5749SYifeng Zhao 	.of_xlate = rockchip_combphy_xlate,
229925c5749SYifeng Zhao };
230925c5749SYifeng Zhao 
231925c5749SYifeng Zhao static int rockchip_combphy_parse_dt(struct udevice *dev,
232925c5749SYifeng Zhao 				     struct rockchip_combphy_priv *priv)
233925c5749SYifeng Zhao {
234925c5749SYifeng Zhao 	struct udevice *syscon;
235925c5749SYifeng Zhao 	int ret;
236925c5749SYifeng Zhao 
237925c5749SYifeng Zhao 	ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,pipe-grf", &syscon);
238925c5749SYifeng Zhao 	if (ret) {
239925c5749SYifeng Zhao 		dev_err(dev, "failed to find peri_ctrl pipe-grf regmap");
240925c5749SYifeng Zhao 		return ret;
241925c5749SYifeng Zhao 	}
242925c5749SYifeng Zhao 	priv->pipe_grf = syscon_get_regmap(syscon);
243925c5749SYifeng Zhao 
244925c5749SYifeng Zhao 	ret = uclass_get_device_by_phandle(UCLASS_SYSCON, dev, "rockchip,pipe-phy-grf", &syscon);
245925c5749SYifeng Zhao 	if (ret) {
246925c5749SYifeng Zhao 		dev_err(dev, "failed to find peri_ctrl pipe-phy-grf regmap\n");
247925c5749SYifeng Zhao 		return ret;
248925c5749SYifeng Zhao 	}
249925c5749SYifeng Zhao 	priv->phy_grf = syscon_get_regmap(syscon);
250925c5749SYifeng Zhao 
251925c5749SYifeng Zhao 	ret = clk_get_by_index(dev, 0, &priv->ref_clk);
252925c5749SYifeng Zhao 	if (ret) {
253925c5749SYifeng Zhao 		dev_err(dev, "failed to find ref clock\n");
254925c5749SYifeng Zhao 		return PTR_ERR(&priv->ref_clk);
255925c5749SYifeng Zhao 	}
256925c5749SYifeng Zhao 
257*dbf89912SRen Jianing 	ret = reset_get_by_name(dev, "combphy", &priv->phy_rst);
258925c5749SYifeng Zhao 	if (ret) {
259925c5749SYifeng Zhao 		dev_err(dev, "no phy reset control specified\n");
260925c5749SYifeng Zhao 		return ret;
261925c5749SYifeng Zhao 	}
262925c5749SYifeng Zhao 
263925c5749SYifeng Zhao 	return 0;
264925c5749SYifeng Zhao }
265925c5749SYifeng Zhao 
266925c5749SYifeng Zhao static int rockchip_combphy_probe(struct udevice *udev)
267925c5749SYifeng Zhao {
268925c5749SYifeng Zhao 	struct rockchip_combphy_priv *priv = dev_get_priv(udev);
269925c5749SYifeng Zhao 	const struct rockchip_combphy_cfg *phy_cfg;
270925c5749SYifeng Zhao 	int ret;
271925c5749SYifeng Zhao 
272925c5749SYifeng Zhao 	priv->mmio = (void __iomem *)dev_read_addr(udev);
273925c5749SYifeng Zhao 	if (IS_ERR(priv->mmio))
274925c5749SYifeng Zhao 		return PTR_ERR(priv->mmio);
275925c5749SYifeng Zhao 
276925c5749SYifeng Zhao 	phy_cfg = (const struct rockchip_combphy_cfg *)dev_get_driver_data(udev);
277925c5749SYifeng Zhao 	if (!phy_cfg) {
278925c5749SYifeng Zhao 		dev_err(udev, "No OF match data provided\n");
279925c5749SYifeng Zhao 		return -EINVAL;
280925c5749SYifeng Zhao 	}
281925c5749SYifeng Zhao 
282925c5749SYifeng Zhao 	priv->dev = udev;
283925c5749SYifeng Zhao 	priv->mode = PHY_TYPE_SATA;
284925c5749SYifeng Zhao 	priv->cfg = phy_cfg;
285925c5749SYifeng Zhao 
286925c5749SYifeng Zhao 	ret = rockchip_combphy_parse_dt(udev, priv);
287925c5749SYifeng Zhao 	if (ret)
288925c5749SYifeng Zhao 		return ret;
289925c5749SYifeng Zhao 
290925c5749SYifeng Zhao 	ret = rockchip_combphy_set_mode(priv);
291925c5749SYifeng Zhao 
292925c5749SYifeng Zhao 	return ret;
293925c5749SYifeng Zhao }
294925c5749SYifeng Zhao 
295925c5749SYifeng Zhao static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)
296925c5749SYifeng Zhao {
297925c5749SYifeng Zhao 	const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg;
298925c5749SYifeng Zhao 	u32 val;
299925c5749SYifeng Zhao 
300925c5749SYifeng Zhao 	switch (priv->mode) {
301925c5749SYifeng Zhao 	case PHY_TYPE_PCIE:
302925c5749SYifeng Zhao 		/* Set SSC downward spread spectrum */
303925c5749SYifeng Zhao 		val = readl(priv->mmio + (0x1f << 2));
304925c5749SYifeng Zhao 		val &= ~GENMASK(5, 4);
305925c5749SYifeng Zhao 		val |= 0x01 << 4;
306925c5749SYifeng Zhao 		writel(val, priv->mmio + 0x7c);
307925c5749SYifeng Zhao 
308925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con0_for_pcie, true);
309925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con1_for_pcie, true);
310925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con2_for_pcie, true);
311925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con3_for_pcie, true);
312925c5749SYifeng Zhao 		break;
313925c5749SYifeng Zhao 	case PHY_TYPE_USB3:
314925c5749SYifeng Zhao 		/* Set SSC downward spread spectrum */
315925c5749SYifeng Zhao 		val = readl(priv->mmio + (0x1f << 2));
316925c5749SYifeng Zhao 		val &= ~GENMASK(5, 4);
317925c5749SYifeng Zhao 		val |= 0x01 << 4;
318925c5749SYifeng Zhao 		writel(val, priv->mmio + 0x7c);
319925c5749SYifeng Zhao 
320925c5749SYifeng Zhao 		/* Enable adaptive CTLE for USB3.0 Rx */
321925c5749SYifeng Zhao 		val = readl(priv->mmio + (0x0e << 2));
322925c5749SYifeng Zhao 		val &= ~GENMASK(0, 0);
323925c5749SYifeng Zhao 		val |= 0x01;
324925c5749SYifeng Zhao 		writel(val, priv->mmio + (0x0e << 2));
325925c5749SYifeng Zhao 
326925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_sel_usb, true);
327925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false);
328925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false);
329925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->usb_mode_set, true);
330925c5749SYifeng Zhao 		break;
331925c5749SYifeng Zhao 	case PHY_TYPE_SATA:
332925c5749SYifeng Zhao 		writel(0x41, priv->mmio + 0x38);
333925c5749SYifeng Zhao 		writel(0x8F, priv->mmio + 0x18);
334925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con0_for_sata, true);
335925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con1_for_sata, true);
336925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con2_for_sata, true);
337925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->con3_for_sata, true);
338925c5749SYifeng Zhao 		param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true);
339925c5749SYifeng Zhao 		break;
340925c5749SYifeng Zhao 	case PHY_TYPE_SGMII:
341925c5749SYifeng Zhao 		param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true);
342925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true);
343925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true);
344925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->sgmii_mode_set, true);
345925c5749SYifeng Zhao 		break;
346925c5749SYifeng Zhao 	case PHY_TYPE_QSGMII:
347925c5749SYifeng Zhao 		param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true);
348925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true);
349925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_rate_sel, true);
350925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true);
351925c5749SYifeng Zhao 		param_write(priv->phy_grf, &cfg->qsgmii_mode_set, true);
352925c5749SYifeng Zhao 		break;
353925c5749SYifeng Zhao 	default:
354925c5749SYifeng Zhao 		pr_err("%s, phy-type %d\n", __func__, priv->mode);
355925c5749SYifeng Zhao 		return -EINVAL;
356925c5749SYifeng Zhao 	}
357925c5749SYifeng Zhao 
358*dbf89912SRen Jianing 	/* The default ref clock is 25Mhz */
359*dbf89912SRen Jianing 	param_write(priv->phy_grf, &cfg->pipe_clk_25m, true);
360925c5749SYifeng Zhao 
361925c5749SYifeng Zhao 	if (dev_read_bool(priv->dev, "rockchip,enable-ssc")) {
362925c5749SYifeng Zhao 		val = readl(priv->mmio + (0x7 << 2));
363925c5749SYifeng Zhao 		val |= BIT(4);
364925c5749SYifeng Zhao 		writel(val, priv->mmio + (0x7 << 2));
365925c5749SYifeng Zhao 	}
366925c5749SYifeng Zhao 
367925c5749SYifeng Zhao 	return 0;
368925c5749SYifeng Zhao }
369925c5749SYifeng Zhao 
370925c5749SYifeng Zhao static const struct rockchip_combphy_grfcfg rk3568_combphy_grfcfgs = {
371925c5749SYifeng Zhao 	/* pipe-phy-grf */
372925c5749SYifeng Zhao 	.pcie_mode_set		= { 0x0000, 5, 0, 0x00, 0x11 },
373925c5749SYifeng Zhao 	.usb_mode_set		= { 0x0000, 5, 0, 0x00, 0x04 },
374925c5749SYifeng Zhao 	.sgmii_mode_set		= { 0x0000, 5, 0, 0x00, 0x01 },
375925c5749SYifeng Zhao 	.qsgmii_mode_set	= { 0x0000, 5, 0, 0x00, 0x21 },
376925c5749SYifeng Zhao 	.pipe_rxterm_set	= { 0x0000, 12, 12, 0x00, 0x01 },
377925c5749SYifeng Zhao 	.pipe_txelec_set	= { 0x0004, 1, 1, 0x00, 0x01 },
378925c5749SYifeng Zhao 	.pipe_txcomp_set	= { 0x0004, 4, 4, 0x00, 0x01 },
379925c5749SYifeng Zhao 	.pipe_clk_25m		= { 0x0004, 14, 13, 0x00, 0x01 },
380925c5749SYifeng Zhao 	.pipe_clk_100m		= { 0x0004, 14, 13, 0x00, 0x02 },
381925c5749SYifeng Zhao 	.pipe_phymode_sel	= { 0x0008, 1, 1, 0x00, 0x01 },
382925c5749SYifeng Zhao 	.pipe_rate_sel		= { 0x0008, 2, 2, 0x00, 0x01 },
383925c5749SYifeng Zhao 	.pipe_rxterm_sel	= { 0x0008, 8, 8, 0x00, 0x01 },
384925c5749SYifeng Zhao 	.pipe_txelec_sel	= { 0x0008, 12, 12, 0x00, 0x01 },
385925c5749SYifeng Zhao 	.pipe_txcomp_sel	= { 0x0008, 15, 15, 0x00, 0x01 },
386925c5749SYifeng Zhao 	.pipe_clk_ext		= { 0x000c, 9, 8, 0x02, 0x01 },
387925c5749SYifeng Zhao 	.pipe_sel_usb		= { 0x000c, 14, 13, 0x00, 0x01 },
388925c5749SYifeng Zhao 	.pipe_sel_qsgmii	= { 0x000c, 15, 13, 0x00, 0x07 },
389925c5749SYifeng Zhao 	.pipe_phy_status	= { 0x0034, 6, 6, 0x01, 0x00 },
390925c5749SYifeng Zhao 	.con0_for_pcie		= { 0x0000, 15, 0, 0x00, 0x1000 },
391925c5749SYifeng Zhao 	.con1_for_pcie		= { 0x0004, 15, 0, 0x00, 0x0000 },
392925c5749SYifeng Zhao 	.con2_for_pcie		= { 0x0008, 15, 0, 0x00, 0x0101 },
393925c5749SYifeng Zhao 	.con3_for_pcie		= { 0x000c, 15, 0, 0x00, 0x0200 },
394925c5749SYifeng Zhao 	.con0_for_sata		= { 0x0000, 15, 0, 0x00, 0x0119 },
395925c5749SYifeng Zhao 	.con1_for_sata		= { 0x0004, 15, 0, 0x00, 0x0040 },
396925c5749SYifeng Zhao 	.con2_for_sata		= { 0x0008, 15, 0, 0x00, 0x80c3 },
397925c5749SYifeng Zhao 	.con3_for_sata		= { 0x000c, 15, 0, 0x00, 0x4407 },
398925c5749SYifeng Zhao 	/* pipe-grf */
399925c5749SYifeng Zhao 	.pipe_con0_for_sata	= { 0x0000, 15, 0, 0x00, 0x2220 },
400925c5749SYifeng Zhao 	.pipe_sgmii_mac_sel	= { 0x0040, 1, 1, 0x00, 0x01 },
401925c5749SYifeng Zhao 	.pipe_xpcs_phy_ready	= { 0x0040, 2, 2, 0x00, 0x01 },
402925c5749SYifeng Zhao 	.u3otg0_port_en		= { 0x0104, 15, 0, 0x0181, 0x1100 },
403925c5749SYifeng Zhao 	.u3otg1_port_en		= { 0x0144, 15, 0, 0x0181, 0x1100 },
404925c5749SYifeng Zhao };
405925c5749SYifeng Zhao 
406925c5749SYifeng Zhao static const struct rockchip_combphy_cfg rk3568_combphy_cfgs = {
407925c5749SYifeng Zhao 	.grfcfg		= &rk3568_combphy_grfcfgs,
408925c5749SYifeng Zhao 	.combphy_cfg	= rk3568_combphy_cfg,
409925c5749SYifeng Zhao };
410925c5749SYifeng Zhao 
411925c5749SYifeng Zhao static const struct udevice_id rockchip_combphy_ids[] = {
412925c5749SYifeng Zhao 	{
413925c5749SYifeng Zhao 		.compatible = "rockchip,rk3568-naneng-combphy",
414925c5749SYifeng Zhao 		.data = (ulong)&rk3568_combphy_cfgs
415925c5749SYifeng Zhao 	},
416925c5749SYifeng Zhao 	{ }
417925c5749SYifeng Zhao };
418925c5749SYifeng Zhao 
419925c5749SYifeng Zhao U_BOOT_DRIVER(rockchip_naneng_combphy) = {
420925c5749SYifeng Zhao 	.name		= "naneng-combphy",
421925c5749SYifeng Zhao 	.id		= UCLASS_PHY,
422925c5749SYifeng Zhao 	.of_match	= rockchip_combphy_ids,
423925c5749SYifeng Zhao 	.ops		= &rochchip_combphy_ops,
424925c5749SYifeng Zhao 	.probe		= rockchip_combphy_probe,
425925c5749SYifeng Zhao 	.priv_auto_alloc_size = sizeof(struct rockchip_combphy_priv),
426925c5749SYifeng Zhao };
427