Lines Matching +full:- +full:refclk

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * emac-rockchip.c - Rockchip EMAC specific glue layer
32 struct clk *refclk; member
39 u32 speed_offset = emac->soc_data->grf_speed_offset; in emac_rockchip_set_mac_speed()
55 err = regmap_write(emac->grf, emac->soc_data->grf_offset, data); in emac_rockchip_set_mac_speed()
77 .compatible = "rockchip,rk3036-emac",
81 .compatible = "rockchip,rk3066-emac",
85 .compatible = "rockchip,rk3188-emac",
95 struct device *dev = &pdev->dev; in emac_rockchip_probe()
103 if (!pdev->dev.of_node) in emac_rockchip_probe()
104 return -ENODEV; in emac_rockchip_probe()
108 return -ENOMEM; in emac_rockchip_probe()
113 priv->emac.drv_name = DRV_NAME; in emac_rockchip_probe()
114 priv->emac.set_mac_speed = emac_rockchip_set_mac_speed; in emac_rockchip_probe()
116 err = of_get_phy_mode(dev->of_node, &interface); in emac_rockchip_probe()
123 err = -ENOTSUPP; in emac_rockchip_probe()
127 priv->grf = syscon_regmap_lookup_by_phandle(dev->of_node, in emac_rockchip_probe()
129 if (IS_ERR(priv->grf)) { in emac_rockchip_probe()
131 PTR_ERR(priv->grf)); in emac_rockchip_probe()
132 err = PTR_ERR(priv->grf); in emac_rockchip_probe()
136 match = of_match_node(emac_rockchip_dt_ids, dev->of_node); in emac_rockchip_probe()
137 priv->soc_data = match->data; in emac_rockchip_probe()
139 priv->emac.clk = devm_clk_get(dev, "hclk"); in emac_rockchip_probe()
140 if (IS_ERR(priv->emac.clk)) { in emac_rockchip_probe()
142 PTR_ERR(priv->emac.clk)); in emac_rockchip_probe()
143 err = PTR_ERR(priv->emac.clk); in emac_rockchip_probe()
147 priv->refclk = devm_clk_get(dev, "macref"); in emac_rockchip_probe()
148 if (IS_ERR(priv->refclk)) { in emac_rockchip_probe()
150 PTR_ERR(priv->refclk)); in emac_rockchip_probe()
151 err = PTR_ERR(priv->refclk); in emac_rockchip_probe()
155 err = clk_prepare_enable(priv->refclk); in emac_rockchip_probe()
162 priv->regulator = devm_regulator_get_optional(dev, "phy"); in emac_rockchip_probe()
163 if (IS_ERR(priv->regulator)) { in emac_rockchip_probe()
164 if (PTR_ERR(priv->regulator) == -EPROBE_DEFER) { in emac_rockchip_probe()
165 err = -EPROBE_DEFER; in emac_rockchip_probe()
169 priv->regulator = NULL; in emac_rockchip_probe()
172 if (priv->regulator) { in emac_rockchip_probe()
173 err = regulator_enable(priv->regulator); in emac_rockchip_probe()
175 dev_err(dev, "failed to enable phy-supply (%d)\n", err); in emac_rockchip_probe()
181 data = (1 << (priv->soc_data->grf_speed_offset + 16)) | in emac_rockchip_probe()
182 (1 << priv->soc_data->grf_speed_offset); in emac_rockchip_probe()
184 data |= (1 << (priv->soc_data->grf_mode_offset + 16)) | in emac_rockchip_probe()
185 (0 << priv->soc_data->grf_mode_offset); in emac_rockchip_probe()
187 err = regmap_write(priv->grf, priv->soc_data->grf_offset, data); in emac_rockchip_probe()
195 err = clk_set_rate(priv->refclk, 50000000); in emac_rockchip_probe()
202 if (priv->soc_data->need_div_macclk) { in emac_rockchip_probe()
203 priv->macclk = devm_clk_get(dev, "macclk"); in emac_rockchip_probe()
204 if (IS_ERR(priv->macclk)) { in emac_rockchip_probe()
206 PTR_ERR(priv->macclk)); in emac_rockchip_probe()
207 err = PTR_ERR(priv->macclk); in emac_rockchip_probe()
211 err = clk_prepare_enable(priv->macclk); in emac_rockchip_probe()
218 err = clk_set_rate(priv->macclk, 25000000); in emac_rockchip_probe()
235 if (priv->soc_data->need_div_macclk) in emac_rockchip_probe()
236 clk_disable_unprepare(priv->macclk); in emac_rockchip_probe()
238 if (priv->regulator) in emac_rockchip_probe()
239 regulator_disable(priv->regulator); in emac_rockchip_probe()
241 clk_disable_unprepare(priv->refclk); in emac_rockchip_probe()
255 clk_disable_unprepare(priv->refclk); in emac_rockchip_remove()
257 if (priv->regulator) in emac_rockchip_remove()
258 regulator_disable(priv->regulator); in emac_rockchip_remove()
260 if (priv->soc_data->need_div_macclk) in emac_rockchip_remove()
261 clk_disable_unprepare(priv->macclk); in emac_rockchip_remove()