Lines Matching +full:sun7i +full:- +full:a20 +full:- +full:gmac

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dwmac-sunxi.c - Allwinner sunxi DWMAC specific glue layer
5 * Copyright (C) 2013 Chen-Yu Tsai
7 * Chen-Yu Tsai <wens@csie.org>
32 struct sunxi_priv_data *gmac = priv; in sun7i_gmac_init() local
35 if (gmac->regulator) { in sun7i_gmac_init()
36 ret = regulator_enable(gmac->regulator); in sun7i_gmac_init()
41 /* Set GMAC interface port mode in sun7i_gmac_init()
43 * The GMAC TX clock lines are configured by setting the clock in sun7i_gmac_init()
44 * rate, which then uses the auto-reparenting feature of the in sun7i_gmac_init()
47 if (phy_interface_mode_is_rgmii(gmac->interface)) { in sun7i_gmac_init()
48 clk_set_rate(gmac->tx_clk, SUN7I_GMAC_GMII_RGMII_RATE); in sun7i_gmac_init()
49 clk_prepare_enable(gmac->tx_clk); in sun7i_gmac_init()
50 gmac->clk_enabled = 1; in sun7i_gmac_init()
52 clk_set_rate(gmac->tx_clk, SUN7I_GMAC_MII_RATE); in sun7i_gmac_init()
53 ret = clk_prepare(gmac->tx_clk); in sun7i_gmac_init()
54 if (ret && gmac->regulator) in sun7i_gmac_init()
55 regulator_disable(gmac->regulator); in sun7i_gmac_init()
63 struct sunxi_priv_data *gmac = priv; in sun7i_gmac_exit() local
65 if (gmac->clk_enabled) { in sun7i_gmac_exit()
66 clk_disable(gmac->tx_clk); in sun7i_gmac_exit()
67 gmac->clk_enabled = 0; in sun7i_gmac_exit()
69 clk_unprepare(gmac->tx_clk); in sun7i_gmac_exit()
71 if (gmac->regulator) in sun7i_gmac_exit()
72 regulator_disable(gmac->regulator); in sun7i_gmac_exit()
77 struct sunxi_priv_data *gmac = priv; in sun7i_fix_speed() local
80 if (gmac->interface != PHY_INTERFACE_MODE_GMII) in sun7i_fix_speed()
83 if (gmac->clk_enabled) { in sun7i_fix_speed()
84 clk_disable(gmac->tx_clk); in sun7i_fix_speed()
85 gmac->clk_enabled = 0; in sun7i_fix_speed()
87 clk_unprepare(gmac->tx_clk); in sun7i_fix_speed()
90 clk_set_rate(gmac->tx_clk, SUN7I_GMAC_GMII_RGMII_RATE); in sun7i_fix_speed()
91 clk_prepare_enable(gmac->tx_clk); in sun7i_fix_speed()
92 gmac->clk_enabled = 1; in sun7i_fix_speed()
94 clk_set_rate(gmac->tx_clk, SUN7I_GMAC_MII_RATE); in sun7i_fix_speed()
95 clk_prepare(gmac->tx_clk); in sun7i_fix_speed()
103 struct sunxi_priv_data *gmac; in sun7i_gmac_probe() local
104 struct device *dev = &pdev->dev; in sun7i_gmac_probe()
115 gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); in sun7i_gmac_probe()
116 if (!gmac) in sun7i_gmac_probe()
117 return -ENOMEM; in sun7i_gmac_probe()
119 ret = of_get_phy_mode(dev->of_node, &gmac->interface); in sun7i_gmac_probe()
120 if (ret && ret != -ENODEV) { in sun7i_gmac_probe()
121 dev_err(dev, "Can't get phy-mode\n"); in sun7i_gmac_probe()
125 gmac->tx_clk = devm_clk_get(dev, "allwinner_gmac_tx"); in sun7i_gmac_probe()
126 if (IS_ERR(gmac->tx_clk)) { in sun7i_gmac_probe()
128 return PTR_ERR(gmac->tx_clk); in sun7i_gmac_probe()
132 gmac->regulator = devm_regulator_get_optional(dev, "phy"); in sun7i_gmac_probe()
133 if (IS_ERR(gmac->regulator)) { in sun7i_gmac_probe()
134 if (PTR_ERR(gmac->regulator) == -EPROBE_DEFER) in sun7i_gmac_probe()
135 return -EPROBE_DEFER; in sun7i_gmac_probe()
137 gmac->regulator = NULL; in sun7i_gmac_probe()
142 plat_dat->tx_coe = 1; in sun7i_gmac_probe()
143 plat_dat->has_gmac = true; in sun7i_gmac_probe()
144 plat_dat->bsp_priv = gmac; in sun7i_gmac_probe()
145 plat_dat->init = sun7i_gmac_init; in sun7i_gmac_probe()
146 plat_dat->exit = sun7i_gmac_exit; in sun7i_gmac_probe()
147 plat_dat->fix_mac_speed = sun7i_fix_speed; in sun7i_gmac_probe()
148 plat_dat->tx_fifo_size = 4096; in sun7i_gmac_probe()
149 plat_dat->rx_fifo_size = 16384; in sun7i_gmac_probe()
151 ret = sun7i_gmac_init(pdev, plat_dat->bsp_priv); in sun7i_gmac_probe()
155 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); in sun7i_gmac_probe()
162 sun7i_gmac_exit(pdev, plat_dat->bsp_priv); in sun7i_gmac_probe()
168 { .compatible = "allwinner,sun7i-a20-gmac" },
177 .name = "sun7i-dwmac",
184 MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");