Lines Matching +full:phy +full:- +full:grf

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DOC: dwmac-rk.c - Rockchip RK3288 DWMAC specific glue layer
5 * Copyright (C) 2014 Chen-Zhi (Roger Chen)
7 * Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>
13 #include <linux/phy.h>
70 struct regmap *grf; member
94 struct device *dev = &bsp_priv->pdev->dev; in px30_set_to_rmii()
96 if (IS_ERR(bsp_priv->grf)) { in px30_set_to_rmii()
97 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in px30_set_to_rmii()
101 regmap_write(bsp_priv->grf, PX30_GRF_GMAC_CON1, in px30_set_to_rmii()
107 struct device *dev = &bsp_priv->pdev->dev; in px30_set_rmii_speed()
110 if (IS_ERR(bsp_priv->clk_mac_speed)) { in px30_set_rmii_speed()
116 regmap_write(bsp_priv->grf, PX30_GRF_GMAC_CON1, in px30_set_rmii_speed()
119 ret = clk_set_rate(bsp_priv->clk_mac_speed, 2500000); in px30_set_rmii_speed()
124 regmap_write(bsp_priv->grf, PX30_GRF_GMAC_CON1, in px30_set_rmii_speed()
127 ret = clk_set_rate(bsp_priv->clk_mac_speed, 25000000); in px30_set_rmii_speed()
173 struct device *dev = &bsp_priv->pdev->dev; in rk3128_set_to_rgmii()
175 if (IS_ERR(bsp_priv->grf)) { in rk3128_set_to_rgmii()
176 dev_err(dev, "Missing rockchip,grf property\n"); in rk3128_set_to_rgmii()
180 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON1, in rk3128_set_to_rgmii()
183 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON0, in rk3128_set_to_rgmii()
191 struct device *dev = &bsp_priv->pdev->dev; in rk3128_set_to_rmii()
193 if (IS_ERR(bsp_priv->grf)) { in rk3128_set_to_rmii()
194 dev_err(dev, "Missing rockchip,grf property\n"); in rk3128_set_to_rmii()
198 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON1, in rk3128_set_to_rmii()
204 struct device *dev = &bsp_priv->pdev->dev; in rk3128_set_rgmii_speed()
206 if (IS_ERR(bsp_priv->grf)) { in rk3128_set_rgmii_speed()
207 dev_err(dev, "Missing rockchip,grf property\n"); in rk3128_set_rgmii_speed()
212 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON1, in rk3128_set_rgmii_speed()
215 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON1, in rk3128_set_rgmii_speed()
218 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON1, in rk3128_set_rgmii_speed()
226 struct device *dev = &bsp_priv->pdev->dev; in rk3128_set_rmii_speed()
228 if (IS_ERR(bsp_priv->grf)) { in rk3128_set_rmii_speed()
229 dev_err(dev, "Missing rockchip,grf property\n"); in rk3128_set_rmii_speed()
234 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON1, in rk3128_set_rmii_speed()
238 regmap_write(bsp_priv->grf, RK3128_GRF_MAC_CON1, in rk3128_set_rmii_speed()
289 struct device *dev = &bsp_priv->pdev->dev; in rk3228_set_to_rgmii()
291 if (IS_ERR(bsp_priv->grf)) { in rk3228_set_to_rgmii()
292 dev_err(dev, "Missing rockchip,grf property\n"); in rk3228_set_to_rgmii()
296 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, in rk3228_set_to_rgmii()
301 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON0, in rk3228_set_to_rgmii()
308 struct device *dev = &bsp_priv->pdev->dev; in rk3228_set_to_rmii()
310 if (IS_ERR(bsp_priv->grf)) { in rk3228_set_to_rmii()
311 dev_err(dev, "Missing rockchip,grf property\n"); in rk3228_set_to_rmii()
315 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, in rk3228_set_to_rmii()
320 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, GRF_BIT(11)); in rk3228_set_to_rmii()
325 struct device *dev = &bsp_priv->pdev->dev; in rk3228_set_rgmii_speed()
327 if (IS_ERR(bsp_priv->grf)) { in rk3228_set_rgmii_speed()
328 dev_err(dev, "Missing rockchip,grf property\n"); in rk3228_set_rgmii_speed()
333 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, in rk3228_set_rgmii_speed()
336 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, in rk3228_set_rgmii_speed()
339 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, in rk3228_set_rgmii_speed()
347 struct device *dev = &bsp_priv->pdev->dev; in rk3228_set_rmii_speed()
349 if (IS_ERR(bsp_priv->grf)) { in rk3228_set_rmii_speed()
350 dev_err(dev, "Missing rockchip,grf property\n"); in rk3228_set_rmii_speed()
355 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, in rk3228_set_rmii_speed()
359 regmap_write(bsp_priv->grf, RK3228_GRF_MAC_CON1, in rk3228_set_rmii_speed()
368 regmap_write(priv->grf, RK3228_GRF_CON_MUX, in rk3228_integrated_phy_powerup()
411 struct device *dev = &bsp_priv->pdev->dev; in rk3288_set_to_rgmii()
413 if (IS_ERR(bsp_priv->grf)) { in rk3288_set_to_rgmii()
414 dev_err(dev, "Missing rockchip,grf property\n"); in rk3288_set_to_rgmii()
418 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, in rk3288_set_to_rgmii()
421 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON3, in rk3288_set_to_rgmii()
429 struct device *dev = &bsp_priv->pdev->dev; in rk3288_set_to_rmii()
431 if (IS_ERR(bsp_priv->grf)) { in rk3288_set_to_rmii()
432 dev_err(dev, "Missing rockchip,grf property\n"); in rk3288_set_to_rmii()
436 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, in rk3288_set_to_rmii()
442 struct device *dev = &bsp_priv->pdev->dev; in rk3288_set_rgmii_speed()
444 if (IS_ERR(bsp_priv->grf)) { in rk3288_set_rgmii_speed()
445 dev_err(dev, "Missing rockchip,grf property\n"); in rk3288_set_rgmii_speed()
450 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, in rk3288_set_rgmii_speed()
453 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, in rk3288_set_rgmii_speed()
456 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, in rk3288_set_rgmii_speed()
464 struct device *dev = &bsp_priv->pdev->dev; in rk3288_set_rmii_speed()
466 if (IS_ERR(bsp_priv->grf)) { in rk3288_set_rmii_speed()
467 dev_err(dev, "Missing rockchip,grf property\n"); in rk3288_set_rmii_speed()
472 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, in rk3288_set_rmii_speed()
476 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, in rk3288_set_rmii_speed()
503 struct device *dev = &bsp_priv->pdev->dev; in rk3308_set_to_rmii()
505 if (IS_ERR(bsp_priv->grf)) { in rk3308_set_to_rmii()
506 dev_err(dev, "Missing rockchip,grf property\n"); in rk3308_set_to_rmii()
510 regmap_write(bsp_priv->grf, RK3308_GRF_MAC_CON0, in rk3308_set_to_rmii()
516 struct device *dev = &bsp_priv->pdev->dev; in rk3308_set_rmii_speed()
518 if (IS_ERR(bsp_priv->grf)) { in rk3308_set_rmii_speed()
519 dev_err(dev, "Missing rockchip,grf property\n"); in rk3308_set_rmii_speed()
524 regmap_write(bsp_priv->grf, RK3308_GRF_MAC_CON0, in rk3308_set_rmii_speed()
527 regmap_write(bsp_priv->grf, RK3308_GRF_MAC_CON0, in rk3308_set_rmii_speed()
575 struct device *dev = &bsp_priv->pdev->dev; in rk3328_set_to_rgmii()
577 if (IS_ERR(bsp_priv->grf)) { in rk3328_set_to_rgmii()
578 dev_err(dev, "Missing rockchip,grf property\n"); in rk3328_set_to_rgmii()
582 regmap_write(bsp_priv->grf, RK3328_GRF_MAC_CON1, in rk3328_set_to_rgmii()
588 regmap_write(bsp_priv->grf, RK3328_GRF_MAC_CON0, in rk3328_set_to_rgmii()
595 struct device *dev = &bsp_priv->pdev->dev; in rk3328_set_to_rmii()
598 if (IS_ERR(bsp_priv->grf)) { in rk3328_set_to_rmii()
599 dev_err(dev, "Missing rockchip,grf property\n"); in rk3328_set_to_rmii()
603 reg = bsp_priv->integrated_phy ? RK3328_GRF_MAC_CON2 : in rk3328_set_to_rmii()
606 regmap_write(bsp_priv->grf, reg, in rk3328_set_to_rmii()
613 struct device *dev = &bsp_priv->pdev->dev; in rk3328_set_rgmii_speed()
615 if (IS_ERR(bsp_priv->grf)) { in rk3328_set_rgmii_speed()
616 dev_err(dev, "Missing rockchip,grf property\n"); in rk3328_set_rgmii_speed()
621 regmap_write(bsp_priv->grf, RK3328_GRF_MAC_CON1, in rk3328_set_rgmii_speed()
624 regmap_write(bsp_priv->grf, RK3328_GRF_MAC_CON1, in rk3328_set_rgmii_speed()
627 regmap_write(bsp_priv->grf, RK3328_GRF_MAC_CON1, in rk3328_set_rgmii_speed()
635 struct device *dev = &bsp_priv->pdev->dev; in rk3328_set_rmii_speed()
638 if (IS_ERR(bsp_priv->grf)) { in rk3328_set_rmii_speed()
639 dev_err(dev, "Missing rockchip,grf property\n"); in rk3328_set_rmii_speed()
643 reg = bsp_priv->integrated_phy ? RK3328_GRF_MAC_CON2 : in rk3328_set_rmii_speed()
647 regmap_write(bsp_priv->grf, reg, in rk3328_set_rmii_speed()
651 regmap_write(bsp_priv->grf, reg, in rk3328_set_rmii_speed()
660 regmap_write(priv->grf, RK3328_GRF_MACPHY_CON1, in rk3328_integrated_phy_powerup()
703 struct device *dev = &bsp_priv->pdev->dev; in rk3366_set_to_rgmii()
705 if (IS_ERR(bsp_priv->grf)) { in rk3366_set_to_rgmii()
706 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3366_set_to_rgmii()
710 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6, in rk3366_set_to_rgmii()
713 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON7, in rk3366_set_to_rgmii()
721 struct device *dev = &bsp_priv->pdev->dev; in rk3366_set_to_rmii()
723 if (IS_ERR(bsp_priv->grf)) { in rk3366_set_to_rmii()
724 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3366_set_to_rmii()
728 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6, in rk3366_set_to_rmii()
734 struct device *dev = &bsp_priv->pdev->dev; in rk3366_set_rgmii_speed()
736 if (IS_ERR(bsp_priv->grf)) { in rk3366_set_rgmii_speed()
737 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3366_set_rgmii_speed()
742 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6, in rk3366_set_rgmii_speed()
745 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6, in rk3366_set_rgmii_speed()
748 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6, in rk3366_set_rgmii_speed()
756 struct device *dev = &bsp_priv->pdev->dev; in rk3366_set_rmii_speed()
758 if (IS_ERR(bsp_priv->grf)) { in rk3366_set_rmii_speed()
759 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3366_set_rmii_speed()
764 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6, in rk3366_set_rmii_speed()
768 regmap_write(bsp_priv->grf, RK3366_GRF_SOC_CON6, in rk3366_set_rmii_speed()
814 struct device *dev = &bsp_priv->pdev->dev; in rk3368_set_to_rgmii()
816 if (IS_ERR(bsp_priv->grf)) { in rk3368_set_to_rgmii()
817 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3368_set_to_rgmii()
821 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, in rk3368_set_to_rgmii()
824 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON16, in rk3368_set_to_rgmii()
832 struct device *dev = &bsp_priv->pdev->dev; in rk3368_set_to_rmii()
834 if (IS_ERR(bsp_priv->grf)) { in rk3368_set_to_rmii()
835 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3368_set_to_rmii()
839 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, in rk3368_set_to_rmii()
845 struct device *dev = &bsp_priv->pdev->dev; in rk3368_set_rgmii_speed()
847 if (IS_ERR(bsp_priv->grf)) { in rk3368_set_rgmii_speed()
848 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3368_set_rgmii_speed()
853 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, in rk3368_set_rgmii_speed()
856 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, in rk3368_set_rgmii_speed()
859 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, in rk3368_set_rgmii_speed()
867 struct device *dev = &bsp_priv->pdev->dev; in rk3368_set_rmii_speed()
869 if (IS_ERR(bsp_priv->grf)) { in rk3368_set_rmii_speed()
870 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3368_set_rmii_speed()
875 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, in rk3368_set_rmii_speed()
879 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, in rk3368_set_rmii_speed()
925 struct device *dev = &bsp_priv->pdev->dev; in rk3399_set_to_rgmii()
927 if (IS_ERR(bsp_priv->grf)) { in rk3399_set_to_rgmii()
928 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3399_set_to_rgmii()
932 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5, in rk3399_set_to_rgmii()
935 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON6, in rk3399_set_to_rgmii()
943 struct device *dev = &bsp_priv->pdev->dev; in rk3399_set_to_rmii()
945 if (IS_ERR(bsp_priv->grf)) { in rk3399_set_to_rmii()
946 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3399_set_to_rmii()
950 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5, in rk3399_set_to_rmii()
956 struct device *dev = &bsp_priv->pdev->dev; in rk3399_set_rgmii_speed()
958 if (IS_ERR(bsp_priv->grf)) { in rk3399_set_rgmii_speed()
959 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3399_set_rgmii_speed()
964 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5, in rk3399_set_rgmii_speed()
967 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5, in rk3399_set_rgmii_speed()
970 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5, in rk3399_set_rgmii_speed()
978 struct device *dev = &bsp_priv->pdev->dev; in rk3399_set_rmii_speed()
980 if (IS_ERR(bsp_priv->grf)) { in rk3399_set_rmii_speed()
981 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3399_set_rmii_speed()
986 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5, in rk3399_set_rmii_speed()
990 regmap_write(bsp_priv->grf, RK3399_GRF_SOC_CON5, in rk3399_set_rmii_speed()
1029 struct device *dev = &bsp_priv->pdev->dev; in rk3568_set_to_rgmii()
1032 if (IS_ERR(bsp_priv->grf)) { in rk3568_set_to_rgmii()
1033 dev_err(dev, "Missing rockchip,grf property\n"); in rk3568_set_to_rgmii()
1037 con0 = (bsp_priv->id == 1) ? RK3568_GRF_GMAC1_CON0 : in rk3568_set_to_rgmii()
1039 con1 = (bsp_priv->id == 1) ? RK3568_GRF_GMAC1_CON1 : in rk3568_set_to_rgmii()
1042 regmap_write(bsp_priv->grf, con0, in rk3568_set_to_rgmii()
1046 regmap_write(bsp_priv->grf, con1, in rk3568_set_to_rgmii()
1054 struct device *dev = &bsp_priv->pdev->dev; in rk3568_set_to_rmii()
1057 if (IS_ERR(bsp_priv->grf)) { in rk3568_set_to_rmii()
1058 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rk3568_set_to_rmii()
1062 con1 = (bsp_priv->id == 1) ? RK3568_GRF_GMAC1_CON1 : in rk3568_set_to_rmii()
1064 regmap_write(bsp_priv->grf, con1, RK3568_GMAC_PHY_INTF_SEL_RMII); in rk3568_set_to_rmii()
1069 struct device *dev = &bsp_priv->pdev->dev; in rk3568_set_gmac_speed()
1088 ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); in rk3568_set_gmac_speed()
1151 struct device *dev = &bsp_priv->pdev->dev; in rk3588_set_to_rgmii()
1152 u32 offset_con, id = bsp_priv->id; in rk3588_set_to_rgmii()
1154 if (IS_ERR(bsp_priv->grf) || IS_ERR(bsp_priv->php_grf)) { in rk3588_set_to_rgmii()
1155 dev_err(dev, "Missing rockchip,grf or rockchip,php_grf property\n"); in rk3588_set_to_rgmii()
1159 offset_con = bsp_priv->id == 1 ? RK3588_GRF_GMAC_CON9 : in rk3588_set_to_rgmii()
1162 regmap_write(bsp_priv->php_grf, RK3588_GRF_GMAC_CON0, in rk3588_set_to_rgmii()
1165 regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, in rk3588_set_to_rgmii()
1168 regmap_write(bsp_priv->grf, RK3588_GRF_GMAC_CON7, in rk3588_set_to_rgmii()
1172 regmap_write(bsp_priv->grf, offset_con, in rk3588_set_to_rgmii()
1179 struct device *dev = &bsp_priv->pdev->dev; in rk3588_set_to_rmii()
1181 if (IS_ERR(bsp_priv->php_grf)) { in rk3588_set_to_rmii()
1186 regmap_write(bsp_priv->php_grf, RK3588_GRF_GMAC_CON0, in rk3588_set_to_rmii()
1187 RK3588_GMAC_PHY_INTF_SEL_RMII(bsp_priv->id)); in rk3588_set_to_rmii()
1189 regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, in rk3588_set_to_rmii()
1190 RK3588_GMAC_CLK_RMII_MODE(bsp_priv->id)); in rk3588_set_to_rmii()
1195 struct device *dev = &bsp_priv->pdev->dev; in rk3588_set_gmac_speed()
1196 unsigned int val = 0, id = bsp_priv->id; in rk3588_set_gmac_speed()
1200 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) in rk3588_set_gmac_speed()
1206 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) in rk3588_set_gmac_speed()
1212 if (bsp_priv->phy_iface != PHY_INTERFACE_MODE_RMII) in rk3588_set_gmac_speed()
1221 regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, val); in rk3588_set_gmac_speed()
1231 unsigned int val = input ? RK3588_GMAC_CLK_SELET_IO(bsp_priv->id) : in rk3588_set_clock_selection()
1232 RK3588_GMAC_CLK_SELET_CRU(bsp_priv->id); in rk3588_set_clock_selection()
1234 val |= enable ? RK3588_GMAC_CLK_RMII_NOGATE(bsp_priv->id) : in rk3588_set_clock_selection()
1235 RK3588_GMAC_CLK_RMII_GATE(bsp_priv->id); in rk3588_set_clock_selection()
1237 regmap_write(bsp_priv->php_grf, RK3588_GRF_CLK_CON1, val); in rk3588_set_clock_selection()
1268 struct device *dev = &bsp_priv->pdev->dev; in rv1108_set_to_rmii()
1270 if (IS_ERR(bsp_priv->grf)) { in rv1108_set_to_rmii()
1271 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rv1108_set_to_rmii()
1275 regmap_write(bsp_priv->grf, RV1108_GRF_GMAC_CON0, in rv1108_set_to_rmii()
1281 struct device *dev = &bsp_priv->pdev->dev; in rv1108_set_rmii_speed()
1283 if (IS_ERR(bsp_priv->grf)) { in rv1108_set_rmii_speed()
1284 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rv1108_set_rmii_speed()
1289 regmap_write(bsp_priv->grf, RV1108_GRF_GMAC_CON0, in rv1108_set_rmii_speed()
1293 regmap_write(bsp_priv->grf, RV1108_GRF_GMAC_CON0, in rv1108_set_rmii_speed()
1336 struct device *dev = &bsp_priv->pdev->dev; in rv1126_set_to_rgmii()
1338 if (IS_ERR(bsp_priv->grf)) { in rv1126_set_to_rgmii()
1339 dev_err(dev, "Missing rockchip,grf property\n"); in rv1126_set_to_rgmii()
1343 regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON0, in rv1126_set_to_rgmii()
1350 regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON1, in rv1126_set_to_rgmii()
1354 regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON2, in rv1126_set_to_rgmii()
1361 struct device *dev = &bsp_priv->pdev->dev; in rv1126_set_to_rmii()
1363 if (IS_ERR(bsp_priv->grf)) { in rv1126_set_to_rmii()
1364 dev_err(dev, "%s: Missing rockchip,grf property\n", __func__); in rv1126_set_to_rmii()
1368 regmap_write(bsp_priv->grf, RV1126_GRF_GMAC_CON0, in rv1126_set_to_rmii()
1374 struct device *dev = &bsp_priv->pdev->dev; in rv1126_set_rgmii_speed()
1393 ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); in rv1126_set_rgmii_speed()
1401 struct device *dev = &bsp_priv->pdev->dev; in rv1126_set_rmii_speed()
1417 ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); in rv1126_set_rmii_speed()
1444 if (priv->ops->integrated_phy_powerup) in rk_gmac_integrated_phy_powerup()
1445 priv->ops->integrated_phy_powerup(priv); in rk_gmac_integrated_phy_powerup()
1447 regmap_write(priv->grf, RK_GRF_MACPHY_CON0, RK_MACPHY_CFG_CLK_50M); in rk_gmac_integrated_phy_powerup()
1448 regmap_write(priv->grf, RK_GRF_MACPHY_CON0, RK_GMAC2PHY_RMII_MODE); in rk_gmac_integrated_phy_powerup()
1450 regmap_write(priv->grf, RK_GRF_MACPHY_CON2, RK_GRF_CON2_MACPHY_ID); in rk_gmac_integrated_phy_powerup()
1451 regmap_write(priv->grf, RK_GRF_MACPHY_CON3, RK_GRF_CON3_MACPHY_ID); in rk_gmac_integrated_phy_powerup()
1453 if (priv->phy_reset) { in rk_gmac_integrated_phy_powerup()
1454 /* PHY needs to be disabled before trying to reset it */ in rk_gmac_integrated_phy_powerup()
1455 regmap_write(priv->grf, RK_GRF_MACPHY_CON0, RK_MACPHY_DISABLE); in rk_gmac_integrated_phy_powerup()
1456 if (priv->phy_reset) in rk_gmac_integrated_phy_powerup()
1457 reset_control_assert(priv->phy_reset); in rk_gmac_integrated_phy_powerup()
1459 if (priv->phy_reset) in rk_gmac_integrated_phy_powerup()
1460 reset_control_deassert(priv->phy_reset); in rk_gmac_integrated_phy_powerup()
1462 regmap_write(priv->grf, RK_GRF_MACPHY_CON0, RK_MACPHY_ENABLE); in rk_gmac_integrated_phy_powerup()
1469 regmap_write(priv->grf, RK_GRF_MACPHY_CON0, RK_MACPHY_DISABLE); in rk_gmac_integrated_phy_powerdown()
1470 if (priv->phy_reset) in rk_gmac_integrated_phy_powerdown()
1471 reset_control_assert(priv->phy_reset); in rk_gmac_integrated_phy_powerdown()
1476 struct rk_priv_data *bsp_priv = plat->bsp_priv; in rk_gmac_clk_init()
1477 struct device *dev = &bsp_priv->pdev->dev; in rk_gmac_clk_init()
1480 bsp_priv->clk_enabled = false; in rk_gmac_clk_init()
1482 bsp_priv->mac_clk_rx = devm_clk_get(dev, "mac_clk_rx"); in rk_gmac_clk_init()
1483 if (IS_ERR(bsp_priv->mac_clk_rx)) in rk_gmac_clk_init()
1487 bsp_priv->mac_clk_tx = devm_clk_get(dev, "mac_clk_tx"); in rk_gmac_clk_init()
1488 if (IS_ERR(bsp_priv->mac_clk_tx)) in rk_gmac_clk_init()
1492 bsp_priv->aclk_mac = devm_clk_get(dev, "aclk_mac"); in rk_gmac_clk_init()
1493 if (IS_ERR(bsp_priv->aclk_mac)) in rk_gmac_clk_init()
1497 bsp_priv->pclk_mac = devm_clk_get(dev, "pclk_mac"); in rk_gmac_clk_init()
1498 if (IS_ERR(bsp_priv->pclk_mac)) in rk_gmac_clk_init()
1502 bsp_priv->clk_mac = devm_clk_get(dev, "stmmaceth"); in rk_gmac_clk_init()
1503 if (IS_ERR(bsp_priv->clk_mac)) in rk_gmac_clk_init()
1507 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) { in rk_gmac_clk_init()
1508 bsp_priv->clk_mac_ref = devm_clk_get(dev, "clk_mac_ref"); in rk_gmac_clk_init()
1509 if (IS_ERR(bsp_priv->clk_mac_ref)) in rk_gmac_clk_init()
1513 if (!bsp_priv->clock_input) { in rk_gmac_clk_init()
1514 bsp_priv->clk_mac_refout = in rk_gmac_clk_init()
1516 if (IS_ERR(bsp_priv->clk_mac_refout)) in rk_gmac_clk_init()
1522 bsp_priv->clk_mac_speed = devm_clk_get(dev, "clk_mac_speed"); in rk_gmac_clk_init()
1523 if (IS_ERR(bsp_priv->clk_mac_speed)) in rk_gmac_clk_init()
1526 if (bsp_priv->clock_input) { in rk_gmac_clk_init()
1527 dev_info(dev, "clock input from PHY\n"); in rk_gmac_clk_init()
1529 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) in rk_gmac_clk_init()
1530 clk_set_rate(bsp_priv->clk_mac, 50000000); in rk_gmac_clk_init()
1533 if (plat->phy_node && bsp_priv->integrated_phy) { in rk_gmac_clk_init()
1534 bsp_priv->clk_phy = of_clk_get(plat->phy_node, 0); in rk_gmac_clk_init()
1535 if (IS_ERR(bsp_priv->clk_phy)) { in rk_gmac_clk_init()
1536 ret = PTR_ERR(bsp_priv->clk_phy); in rk_gmac_clk_init()
1537 dev_err(dev, "Cannot get PHY clock: %d\n", ret); in rk_gmac_clk_init()
1538 return -EINVAL; in rk_gmac_clk_init()
1540 clk_set_rate(bsp_priv->clk_phy, 50000000); in rk_gmac_clk_init()
1548 int phy_iface = bsp_priv->phy_iface; in gmac_clk_enable()
1551 if (!bsp_priv->clk_enabled) { in gmac_clk_enable()
1553 if (!IS_ERR(bsp_priv->mac_clk_rx)) in gmac_clk_enable()
1555 bsp_priv->mac_clk_rx); in gmac_clk_enable()
1557 if (!IS_ERR(bsp_priv->clk_mac_ref)) in gmac_clk_enable()
1559 bsp_priv->clk_mac_ref); in gmac_clk_enable()
1561 if (!IS_ERR(bsp_priv->clk_mac_refout)) in gmac_clk_enable()
1563 bsp_priv->clk_mac_refout); in gmac_clk_enable()
1566 if (!IS_ERR(bsp_priv->clk_phy)) in gmac_clk_enable()
1567 clk_prepare_enable(bsp_priv->clk_phy); in gmac_clk_enable()
1569 if (!IS_ERR(bsp_priv->aclk_mac)) in gmac_clk_enable()
1570 clk_prepare_enable(bsp_priv->aclk_mac); in gmac_clk_enable()
1572 if (!IS_ERR(bsp_priv->pclk_mac)) in gmac_clk_enable()
1573 clk_prepare_enable(bsp_priv->pclk_mac); in gmac_clk_enable()
1575 if (!IS_ERR(bsp_priv->mac_clk_tx)) in gmac_clk_enable()
1576 clk_prepare_enable(bsp_priv->mac_clk_tx); in gmac_clk_enable()
1578 if (!IS_ERR(bsp_priv->clk_mac_speed)) in gmac_clk_enable()
1579 clk_prepare_enable(bsp_priv->clk_mac_speed); in gmac_clk_enable()
1581 if (bsp_priv->ops && bsp_priv->ops->set_clock_selection) in gmac_clk_enable()
1582 bsp_priv->ops->set_clock_selection(bsp_priv, in gmac_clk_enable()
1583 bsp_priv->clock_input, true); in gmac_clk_enable()
1586 * if (!IS_ERR(bsp_priv->clk_mac)) in gmac_clk_enable()
1587 * clk_prepare_enable(bsp_priv->clk_mac); in gmac_clk_enable()
1590 bsp_priv->clk_enabled = true; in gmac_clk_enable()
1593 if (bsp_priv->clk_enabled) { in gmac_clk_enable()
1595 clk_disable_unprepare(bsp_priv->mac_clk_rx); in gmac_clk_enable()
1597 clk_disable_unprepare(bsp_priv->clk_mac_ref); in gmac_clk_enable()
1599 clk_disable_unprepare(bsp_priv->clk_mac_refout); in gmac_clk_enable()
1602 clk_disable_unprepare(bsp_priv->clk_phy); in gmac_clk_enable()
1604 clk_disable_unprepare(bsp_priv->aclk_mac); in gmac_clk_enable()
1606 clk_disable_unprepare(bsp_priv->pclk_mac); in gmac_clk_enable()
1608 clk_disable_unprepare(bsp_priv->mac_clk_tx); in gmac_clk_enable()
1610 clk_disable_unprepare(bsp_priv->clk_mac_speed); in gmac_clk_enable()
1612 if (bsp_priv->ops && bsp_priv->ops->set_clock_selection) in gmac_clk_enable()
1613 bsp_priv->ops->set_clock_selection(bsp_priv, in gmac_clk_enable()
1614 bsp_priv->clock_input, false); in gmac_clk_enable()
1616 * if (!IS_ERR(bsp_priv->clk_mac)) in gmac_clk_enable()
1617 * clk_disable_unprepare(bsp_priv->clk_mac); in gmac_clk_enable()
1619 bsp_priv->clk_enabled = false; in gmac_clk_enable()
1628 struct regulator *ldo = bsp_priv->regulator; in phy_power_on()
1630 struct device *dev = &bsp_priv->pdev->dev; in phy_power_on()
1638 dev_err(dev, "fail to enable phy-supply\n"); in phy_power_on()
1642 dev_err(dev, "fail to disable phy-supply\n"); in phy_power_on()
1653 struct device *dev = &pdev->dev; in rk_gmac_setup()
1661 return ERR_PTR(-ENOMEM); in rk_gmac_setup()
1663 of_get_phy_mode(dev->of_node, &bsp_priv->phy_iface); in rk_gmac_setup()
1664 bsp_priv->ops = ops; in rk_gmac_setup()
1670 if (res && ops->regs_valid) { in rk_gmac_setup()
1673 while (ops->regs[i]) { in rk_gmac_setup()
1674 if (ops->regs[i] == res->start) { in rk_gmac_setup()
1675 bsp_priv->id = i; in rk_gmac_setup()
1682 bsp_priv->regulator = devm_regulator_get_optional(dev, "phy"); in rk_gmac_setup()
1683 if (IS_ERR(bsp_priv->regulator)) { in rk_gmac_setup()
1684 if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER) { in rk_gmac_setup()
1685 dev_err(dev, "phy regulator is not available yet, deferred probing\n"); in rk_gmac_setup()
1686 return ERR_PTR(-EPROBE_DEFER); in rk_gmac_setup()
1689 bsp_priv->regulator = NULL; in rk_gmac_setup()
1692 ret = of_property_read_string(dev->of_node, "clock_in_out", &strings); in rk_gmac_setup()
1695 bsp_priv->clock_input = true; in rk_gmac_setup()
1700 bsp_priv->clock_input = true; in rk_gmac_setup()
1702 bsp_priv->clock_input = false; in rk_gmac_setup()
1705 ret = of_property_read_u32(dev->of_node, "tx_delay", &value); in rk_gmac_setup()
1707 bsp_priv->tx_delay = 0x30; in rk_gmac_setup()
1710 bsp_priv->tx_delay); in rk_gmac_setup()
1713 bsp_priv->tx_delay = value; in rk_gmac_setup()
1716 ret = of_property_read_u32(dev->of_node, "rx_delay", &value); in rk_gmac_setup()
1718 bsp_priv->rx_delay = 0x10; in rk_gmac_setup()
1721 bsp_priv->rx_delay); in rk_gmac_setup()
1724 bsp_priv->rx_delay = value; in rk_gmac_setup()
1727 bsp_priv->grf = syscon_regmap_lookup_by_phandle(dev->of_node, in rk_gmac_setup()
1728 "rockchip,grf"); in rk_gmac_setup()
1729 bsp_priv->php_grf = syscon_regmap_lookup_by_phandle(dev->of_node, in rk_gmac_setup()
1730 "rockchip,php-grf"); in rk_gmac_setup()
1732 if (plat->phy_node) { in rk_gmac_setup()
1733 bsp_priv->integrated_phy = of_property_read_bool(plat->phy_node, in rk_gmac_setup()
1734 "phy-is-integrated"); in rk_gmac_setup()
1735 if (bsp_priv->integrated_phy) { in rk_gmac_setup()
1736 bsp_priv->phy_reset = of_reset_control_get(plat->phy_node, NULL); in rk_gmac_setup()
1737 if (IS_ERR(bsp_priv->phy_reset)) { in rk_gmac_setup()
1738 dev_err(&pdev->dev, "No PHY reset control found.\n"); in rk_gmac_setup()
1739 bsp_priv->phy_reset = NULL; in rk_gmac_setup()
1743 dev_info(dev, "integrated PHY? (%s).\n", in rk_gmac_setup()
1744 bsp_priv->integrated_phy ? "yes" : "no"); in rk_gmac_setup()
1746 bsp_priv->pdev = pdev; in rk_gmac_setup()
1753 switch (bsp_priv->phy_iface) { in rk_gmac_check_ops()
1758 if (!bsp_priv->ops->set_to_rgmii) in rk_gmac_check_ops()
1759 return -EINVAL; in rk_gmac_check_ops()
1762 if (!bsp_priv->ops->set_to_rmii) in rk_gmac_check_ops()
1763 return -EINVAL; in rk_gmac_check_ops()
1766 dev_err(&bsp_priv->pdev->dev, in rk_gmac_check_ops()
1767 "unsupported interface %d", bsp_priv->phy_iface); in rk_gmac_check_ops()
1775 struct device *dev = &bsp_priv->pdev->dev; in rk_gmac_powerup()
1786 switch (bsp_priv->phy_iface) { in rk_gmac_powerup()
1789 bsp_priv->ops->set_to_rgmii(bsp_priv, bsp_priv->tx_delay, in rk_gmac_powerup()
1790 bsp_priv->rx_delay); in rk_gmac_powerup()
1794 bsp_priv->ops->set_to_rgmii(bsp_priv, 0, 0); in rk_gmac_powerup()
1798 bsp_priv->ops->set_to_rgmii(bsp_priv, bsp_priv->tx_delay, 0); in rk_gmac_powerup()
1802 bsp_priv->ops->set_to_rgmii(bsp_priv, 0, bsp_priv->rx_delay); in rk_gmac_powerup()
1806 bsp_priv->ops->set_to_rmii(bsp_priv); in rk_gmac_powerup()
1820 if (bsp_priv->integrated_phy) in rk_gmac_powerup()
1828 if (gmac->integrated_phy) in rk_gmac_powerdown()
1831 pm_runtime_put_sync(&gmac->pdev->dev); in rk_gmac_powerdown()
1840 struct device *dev = &bsp_priv->pdev->dev; in rk_fix_speed()
1842 switch (bsp_priv->phy_iface) { in rk_fix_speed()
1847 if (bsp_priv->ops->set_rgmii_speed) in rk_fix_speed()
1848 bsp_priv->ops->set_rgmii_speed(bsp_priv, speed); in rk_fix_speed()
1851 if (bsp_priv->ops->set_rmii_speed) in rk_fix_speed()
1852 bsp_priv->ops->set_rmii_speed(bsp_priv, speed); in rk_fix_speed()
1855 dev_err(dev, "unsupported interface %d", bsp_priv->phy_iface); in rk_fix_speed()
1866 data = of_device_get_match_data(&pdev->dev); in rk_gmac_probe()
1868 dev_err(&pdev->dev, "no of match data provided\n"); in rk_gmac_probe()
1869 return -EINVAL; in rk_gmac_probe()
1883 if (!plat_dat->has_gmac4) in rk_gmac_probe()
1884 plat_dat->has_gmac = true; in rk_gmac_probe()
1885 plat_dat->fix_mac_speed = rk_fix_speed; in rk_gmac_probe()
1887 plat_dat->bsp_priv = rk_gmac_setup(pdev, plat_dat, data); in rk_gmac_probe()
1888 if (IS_ERR(plat_dat->bsp_priv)) { in rk_gmac_probe()
1889 ret = PTR_ERR(plat_dat->bsp_priv); in rk_gmac_probe()
1897 ret = rk_gmac_powerup(plat_dat->bsp_priv); in rk_gmac_probe()
1901 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); in rk_gmac_probe()
1908 rk_gmac_powerdown(plat_dat->bsp_priv); in rk_gmac_probe()
1917 struct rk_priv_data *bsp_priv = get_stmmac_bsp_priv(&pdev->dev); in rk_gmac_remove()
1918 int ret = stmmac_dvr_remove(&pdev->dev); in rk_gmac_remove()
1931 /* Keep the PHY up if we use Wake-on-Lan. */ in rk_gmac_suspend()
1934 bsp_priv->suspended = true; in rk_gmac_suspend()
1944 /* The PHY was up for Wake-on-Lan. */ in rk_gmac_resume()
1945 if (bsp_priv->suspended) { in rk_gmac_resume()
1947 bsp_priv->suspended = false; in rk_gmac_resume()
1957 { .compatible = "rockchip,px30-gmac", .data = &px30_ops },
1958 { .compatible = "rockchip,rk3128-gmac", .data = &rk3128_ops },
1959 { .compatible = "rockchip,rk3228-gmac", .data = &rk3228_ops },
1960 { .compatible = "rockchip,rk3288-gmac", .data = &rk3288_ops },
1961 { .compatible = "rockchip,rk3308-gmac", .data = &rk3308_ops },
1962 { .compatible = "rockchip,rk3328-gmac", .data = &rk3328_ops },
1963 { .compatible = "rockchip,rk3366-gmac", .data = &rk3366_ops },
1964 { .compatible = "rockchip,rk3368-gmac", .data = &rk3368_ops },
1965 { .compatible = "rockchip,rk3399-gmac", .data = &rk3399_ops },
1966 { .compatible = "rockchip,rk3568-gmac", .data = &rk3568_ops },
1967 { .compatible = "rockchip,rk3588-gmac", .data = &rk3588_ops },
1968 { .compatible = "rockchip,rv1108-gmac", .data = &rv1108_ops },
1969 { .compatible = "rockchip,rv1126-gmac", .data = &rv1126_ops },
1978 .name = "rk_gmac-dwmac",
1985 MODULE_AUTHOR("Chen-Zhi (Roger Chen) <roger.chen@rock-chips.com>");