H A D | dwmac-rk.c | 38 void (*set_to_rgmii)(struct rk_priv_data *bsp_priv, 40 void (*set_to_rmii)(struct rk_priv_data *bsp_priv); 41 void (*set_rgmii_speed)(struct rk_priv_data *bsp_priv, int speed); 42 void (*set_rmii_speed)(struct rk_priv_data *bsp_priv, int speed); 103 static void rk3288_set_to_rgmii(struct rk_priv_data *bsp_priv, rk3288_set_to_rgmii() argument 106 struct device *dev = &bsp_priv->pdev->dev; rk3288_set_to_rgmii() 108 if (IS_ERR(bsp_priv->grf)) { rk3288_set_to_rgmii() 113 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, rk3288_set_to_rgmii() 116 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON3, rk3288_set_to_rgmii() 123 static void rk3288_set_to_rmii(struct rk_priv_data *bsp_priv) rk3288_set_to_rmii() argument 125 struct device *dev = &bsp_priv->pdev->dev; rk3288_set_to_rmii() 127 if (IS_ERR(bsp_priv->grf)) { rk3288_set_to_rmii() 132 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, rk3288_set_to_rmii() 136 static void rk3288_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) rk3288_set_rgmii_speed() argument 138 struct device *dev = &bsp_priv->pdev->dev; rk3288_set_rgmii_speed() 140 if (IS_ERR(bsp_priv->grf)) { rk3288_set_rgmii_speed() 146 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, rk3288_set_rgmii_speed() 149 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, rk3288_set_rgmii_speed() 152 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, rk3288_set_rgmii_speed() 158 static void rk3288_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) rk3288_set_rmii_speed() argument 160 struct device *dev = &bsp_priv->pdev->dev; rk3288_set_rmii_speed() 162 if (IS_ERR(bsp_priv->grf)) { rk3288_set_rmii_speed() 168 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, rk3288_set_rmii_speed() 172 regmap_write(bsp_priv->grf, RK3288_GRF_SOC_CON1, rk3288_set_rmii_speed() 215 static void rk3368_set_to_rgmii(struct rk_priv_data *bsp_priv, rk3368_set_to_rgmii() argument 218 struct device *dev = &bsp_priv->pdev->dev; rk3368_set_to_rgmii() 220 if (IS_ERR(bsp_priv->grf)) { rk3368_set_to_rgmii() 225 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, rk3368_set_to_rgmii() 228 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON16, rk3368_set_to_rgmii() 235 static void rk3368_set_to_rmii(struct rk_priv_data *bsp_priv) rk3368_set_to_rmii() argument 237 struct device *dev = &bsp_priv->pdev->dev; rk3368_set_to_rmii() 239 if (IS_ERR(bsp_priv->grf)) { rk3368_set_to_rmii() 244 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, rk3368_set_to_rmii() 248 static void rk3368_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) rk3368_set_rgmii_speed() argument 250 struct device *dev = &bsp_priv->pdev->dev; rk3368_set_rgmii_speed() 252 if (IS_ERR(bsp_priv->grf)) { rk3368_set_rgmii_speed() 258 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, rk3368_set_rgmii_speed() 261 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, rk3368_set_rgmii_speed() 264 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, rk3368_set_rgmii_speed() 270 static void rk3368_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) rk3368_set_rmii_speed() argument 272 struct device *dev = &bsp_priv->pdev->dev; rk3368_set_rmii_speed() 274 if (IS_ERR(bsp_priv->grf)) { rk3368_set_rmii_speed() 280 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, rk3368_set_rmii_speed() 284 regmap_write(bsp_priv->grf, RK3368_GRF_SOC_CON15, rk3368_set_rmii_speed() 299 static int gmac_clk_init(struct rk_priv_data *bsp_priv) gmac_clk_init() argument 301 struct device *dev = &bsp_priv->pdev->dev; gmac_clk_init() 303 bsp_priv->clk_enabled = false; gmac_clk_init() 305 bsp_priv->mac_clk_rx = devm_clk_get(dev, "mac_clk_rx"); gmac_clk_init() 306 if (IS_ERR(bsp_priv->mac_clk_rx)) gmac_clk_init() 310 bsp_priv->mac_clk_tx = devm_clk_get(dev, "mac_clk_tx"); gmac_clk_init() 311 if (IS_ERR(bsp_priv->mac_clk_tx)) gmac_clk_init() 315 bsp_priv->aclk_mac = devm_clk_get(dev, "aclk_mac"); gmac_clk_init() 316 if (IS_ERR(bsp_priv->aclk_mac)) gmac_clk_init() 320 bsp_priv->pclk_mac = devm_clk_get(dev, "pclk_mac"); gmac_clk_init() 321 if (IS_ERR(bsp_priv->pclk_mac)) gmac_clk_init() 325 bsp_priv->clk_mac = devm_clk_get(dev, "stmmaceth"); gmac_clk_init() 326 if (IS_ERR(bsp_priv->clk_mac)) gmac_clk_init() 330 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) { gmac_clk_init() 331 bsp_priv->clk_mac_ref = devm_clk_get(dev, "clk_mac_ref"); gmac_clk_init() 332 if (IS_ERR(bsp_priv->clk_mac_ref)) gmac_clk_init() 336 if (!bsp_priv->clock_input) { gmac_clk_init() 337 bsp_priv->clk_mac_refout = gmac_clk_init() 339 if (IS_ERR(bsp_priv->clk_mac_refout)) gmac_clk_init() 345 if (bsp_priv->clock_input) { gmac_clk_init() 348 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) gmac_clk_init() 349 clk_set_rate(bsp_priv->clk_mac, 50000000); gmac_clk_init() 355 static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable) gmac_clk_enable() argument 357 int phy_iface = bsp_priv->phy_iface; gmac_clk_enable() 360 if (!bsp_priv->clk_enabled) { gmac_clk_enable() 362 if (!IS_ERR(bsp_priv->mac_clk_rx)) gmac_clk_enable() 364 bsp_priv->mac_clk_rx); gmac_clk_enable() 366 if (!IS_ERR(bsp_priv->clk_mac_ref)) gmac_clk_enable() 368 bsp_priv->clk_mac_ref); gmac_clk_enable() 370 if (!IS_ERR(bsp_priv->clk_mac_refout)) gmac_clk_enable() 372 bsp_priv->clk_mac_refout); gmac_clk_enable() 375 if (!IS_ERR(bsp_priv->aclk_mac)) gmac_clk_enable() 376 clk_prepare_enable(bsp_priv->aclk_mac); gmac_clk_enable() 378 if (!IS_ERR(bsp_priv->pclk_mac)) gmac_clk_enable() 379 clk_prepare_enable(bsp_priv->pclk_mac); gmac_clk_enable() 381 if (!IS_ERR(bsp_priv->mac_clk_tx)) gmac_clk_enable() 382 clk_prepare_enable(bsp_priv->mac_clk_tx); gmac_clk_enable() 385 * if (!IS_ERR(bsp_priv->clk_mac)) gmac_clk_enable() 386 * clk_prepare_enable(bsp_priv->clk_mac); gmac_clk_enable() 389 bsp_priv->clk_enabled = true; gmac_clk_enable() 392 if (bsp_priv->clk_enabled) { gmac_clk_enable() 394 if (!IS_ERR(bsp_priv->mac_clk_rx)) gmac_clk_enable() 396 bsp_priv->mac_clk_rx); gmac_clk_enable() 398 if (!IS_ERR(bsp_priv->clk_mac_ref)) gmac_clk_enable() 400 bsp_priv->clk_mac_ref); gmac_clk_enable() 402 if (!IS_ERR(bsp_priv->clk_mac_refout)) gmac_clk_enable() 404 bsp_priv->clk_mac_refout); gmac_clk_enable() 407 if (!IS_ERR(bsp_priv->aclk_mac)) gmac_clk_enable() 408 clk_disable_unprepare(bsp_priv->aclk_mac); gmac_clk_enable() 410 if (!IS_ERR(bsp_priv->pclk_mac)) gmac_clk_enable() 411 clk_disable_unprepare(bsp_priv->pclk_mac); gmac_clk_enable() 413 if (!IS_ERR(bsp_priv->mac_clk_tx)) gmac_clk_enable() 414 clk_disable_unprepare(bsp_priv->mac_clk_tx); gmac_clk_enable() 416 * if (!IS_ERR(bsp_priv->clk_mac)) gmac_clk_enable() 417 * clk_disable_unprepare(bsp_priv->clk_mac); gmac_clk_enable() 419 bsp_priv->clk_enabled = false; gmac_clk_enable() 426 static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable) phy_power_on() argument 428 struct regulator *ldo = bsp_priv->regulator; phy_power_on() 430 struct device *dev = &bsp_priv->pdev->dev; phy_power_on() 453 struct rk_priv_data *bsp_priv; rk_gmac_setup() local 459 bsp_priv = devm_kzalloc(dev, sizeof(*bsp_priv), GFP_KERNEL); rk_gmac_setup() 460 if (!bsp_priv) rk_gmac_setup() 463 bsp_priv->phy_iface = of_get_phy_mode(dev->of_node); rk_gmac_setup() 464 bsp_priv->ops = ops; rk_gmac_setup() 466 bsp_priv->regulator = devm_regulator_get_optional(dev, "phy"); rk_gmac_setup() 467 if (IS_ERR(bsp_priv->regulator)) { rk_gmac_setup() 468 if (PTR_ERR(bsp_priv->regulator) == -EPROBE_DEFER) { rk_gmac_setup() 473 bsp_priv->regulator = NULL; rk_gmac_setup() 479 bsp_priv->clock_input = true; rk_gmac_setup() 484 bsp_priv->clock_input = true; rk_gmac_setup() 486 bsp_priv->clock_input = false; rk_gmac_setup() 491 bsp_priv->tx_delay = 0x30; rk_gmac_setup() 494 bsp_priv->tx_delay); rk_gmac_setup() 497 bsp_priv->tx_delay = value; rk_gmac_setup() 502 bsp_priv->rx_delay = 0x10; rk_gmac_setup() 505 bsp_priv->rx_delay); rk_gmac_setup() 508 bsp_priv->rx_delay = value; rk_gmac_setup() 511 bsp_priv->grf = syscon_regmap_lookup_by_phandle(dev->of_node, rk_gmac_setup() 513 bsp_priv->pdev = pdev; rk_gmac_setup() 516 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RGMII) { rk_gmac_setup() 518 bsp_priv->ops->set_to_rgmii(bsp_priv, bsp_priv->tx_delay, rk_gmac_setup() 519 bsp_priv->rx_delay); rk_gmac_setup() 520 } else if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) { rk_gmac_setup() 522 bsp_priv->ops->set_to_rmii(bsp_priv); rk_gmac_setup() 527 gmac_clk_init(bsp_priv); rk_gmac_setup() 529 return bsp_priv; rk_gmac_setup() 534 struct rk_priv_data *bsp_priv = priv; rk_gmac_init() local 537 ret = phy_power_on(bsp_priv, true); rk_gmac_init() 541 ret = gmac_clk_enable(bsp_priv, true); rk_gmac_init() 558 struct rk_priv_data *bsp_priv = priv; rk_fix_speed() local 559 struct device *dev = &bsp_priv->pdev->dev; rk_fix_speed() 561 if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RGMII) rk_fix_speed() 562 bsp_priv->ops->set_rgmii_speed(bsp_priv, speed); rk_fix_speed() 563 else if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_RMII) rk_fix_speed() 564 bsp_priv->ops->set_rmii_speed(bsp_priv, speed); rk_fix_speed() 566 dev_err(dev, "unsupported interface %d", bsp_priv->phy_iface); rk_fix_speed() 595 plat_dat->bsp_priv = rk_gmac_setup(pdev, data); rk_gmac_probe() 596 if (IS_ERR(plat_dat->bsp_priv)) rk_gmac_probe() 597 return PTR_ERR(plat_dat->bsp_priv); rk_gmac_probe() 599 ret = rk_gmac_init(pdev, plat_dat->bsp_priv); rk_gmac_probe()
|