Lines Matching full:gmac
2 * Qualcomm Atheros IPQ806x GMAC glue layer
115 static int get_clk_div_sgmii(struct ipq806x_gmac *gmac, unsigned int speed) in get_clk_div_sgmii() argument
117 struct device *dev = &gmac->pdev->dev; in get_clk_div_sgmii()
141 static int get_clk_div_rgmii(struct ipq806x_gmac *gmac, unsigned int speed) in get_clk_div_rgmii() argument
143 struct device *dev = &gmac->pdev->dev; in get_clk_div_rgmii()
167 static int ipq806x_gmac_set_speed(struct ipq806x_gmac *gmac, unsigned int speed) in ipq806x_gmac_set_speed() argument
172 switch (gmac->phy_mode) { in ipq806x_gmac_set_speed()
177 div = get_clk_div_rgmii(gmac, speed); in ipq806x_gmac_set_speed()
178 clk_bits = NSS_COMMON_CLK_GATE_RGMII_RX_EN(gmac->id) | in ipq806x_gmac_set_speed()
179 NSS_COMMON_CLK_GATE_RGMII_TX_EN(gmac->id); in ipq806x_gmac_set_speed()
183 div = get_clk_div_sgmii(gmac, speed); in ipq806x_gmac_set_speed()
184 clk_bits = NSS_COMMON_CLK_GATE_GMII_RX_EN(gmac->id) | in ipq806x_gmac_set_speed()
185 NSS_COMMON_CLK_GATE_GMII_TX_EN(gmac->id); in ipq806x_gmac_set_speed()
189 dev_err(&gmac->pdev->dev, "Unsupported PHY mode: \"%s\"\n", in ipq806x_gmac_set_speed()
190 phy_modes(gmac->phy_mode)); in ipq806x_gmac_set_speed()
195 regmap_read(gmac->nss_common, NSS_COMMON_CLK_GATE, &val); in ipq806x_gmac_set_speed()
197 regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val); in ipq806x_gmac_set_speed()
200 regmap_read(gmac->nss_common, NSS_COMMON_CLK_DIV0, &val); in ipq806x_gmac_set_speed()
202 << NSS_COMMON_CLK_DIV_OFFSET(gmac->id)); in ipq806x_gmac_set_speed()
203 val |= div << NSS_COMMON_CLK_DIV_OFFSET(gmac->id); in ipq806x_gmac_set_speed()
204 regmap_write(gmac->nss_common, NSS_COMMON_CLK_DIV0, val); in ipq806x_gmac_set_speed()
207 regmap_read(gmac->nss_common, NSS_COMMON_CLK_GATE, &val); in ipq806x_gmac_set_speed()
209 regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val); in ipq806x_gmac_set_speed()
214 static int ipq806x_gmac_of_parse(struct ipq806x_gmac *gmac) in ipq806x_gmac_of_parse() argument
216 struct device *dev = &gmac->pdev->dev; in ipq806x_gmac_of_parse()
219 ret = of_get_phy_mode(dev->of_node, &gmac->phy_mode); in ipq806x_gmac_of_parse()
225 if (of_property_read_u32(dev->of_node, "qcom,id", &gmac->id) < 0) { in ipq806x_gmac_of_parse()
234 if (gmac->id > 3) { in ipq806x_gmac_of_parse()
235 dev_err(dev, "invalid gmac id\n"); in ipq806x_gmac_of_parse()
239 gmac->core_clk = devm_clk_get(dev, "stmmaceth"); in ipq806x_gmac_of_parse()
240 if (IS_ERR(gmac->core_clk)) { in ipq806x_gmac_of_parse()
242 return PTR_ERR(gmac->core_clk); in ipq806x_gmac_of_parse()
244 clk_set_rate(gmac->core_clk, 266000000); in ipq806x_gmac_of_parse()
247 gmac->nss_common = syscon_regmap_lookup_by_phandle(dev->of_node, in ipq806x_gmac_of_parse()
249 if (IS_ERR(gmac->nss_common)) { in ipq806x_gmac_of_parse()
251 return PTR_ERR(gmac->nss_common); in ipq806x_gmac_of_parse()
255 gmac->qsgmii_csr = syscon_regmap_lookup_by_phandle(dev->of_node, in ipq806x_gmac_of_parse()
257 if (IS_ERR(gmac->qsgmii_csr)) in ipq806x_gmac_of_parse()
260 return PTR_ERR_OR_ZERO(gmac->qsgmii_csr); in ipq806x_gmac_of_parse()
265 struct ipq806x_gmac *gmac = priv; in ipq806x_gmac_fix_mac_speed() local
267 ipq806x_gmac_set_speed(gmac, speed); in ipq806x_gmac_fix_mac_speed()
271 ipq806x_gmac_configure_qsgmii_pcs_speed(struct ipq806x_gmac *gmac) in ipq806x_gmac_configure_qsgmii_pcs_speed() argument
273 struct platform_device *pdev = gmac->pdev; in ipq806x_gmac_configure_qsgmii_pcs_speed()
310 regmap_update_bits(gmac->qsgmii_csr, QSGMII_PCS_ALL_CH_CTL, in ipq806x_gmac_configure_qsgmii_pcs_speed()
312 QSGMII_PCS_CH_SPEED_SHIFT(gmac->id), in ipq806x_gmac_configure_qsgmii_pcs_speed()
314 QSGMII_PCS_CH_SPEED_SHIFT(gmac->id)); in ipq806x_gmac_configure_qsgmii_pcs_speed()
329 ipq806x_gmac_configure_qsgmii_params(struct ipq806x_gmac *gmac) in ipq806x_gmac_configure_qsgmii_params() argument
331 struct platform_device *pdev = gmac->pdev; in ipq806x_gmac_configure_qsgmii_params()
336 switch (gmac->id) { in ipq806x_gmac_configure_qsgmii_params()
356 default: /* gmac 0 can't be set in SGMII mode */ in ipq806x_gmac_configure_qsgmii_params()
357 dev_err(dev, "gmac id %d can't be in SGMII mode", gmac->id); in ipq806x_gmac_configure_qsgmii_params()
361 /* Common params across all gmac id */ in ipq806x_gmac_configure_qsgmii_params()
371 regmap_write(gmac->qsgmii_csr, QSGMII_PHY_SGMII_CTL(gmac->id), in ipq806x_gmac_configure_qsgmii_params()
382 struct ipq806x_gmac *gmac; in ipq806x_gmac_probe() local
394 gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); in ipq806x_gmac_probe()
395 if (!gmac) in ipq806x_gmac_probe()
398 gmac->pdev = pdev; in ipq806x_gmac_probe()
400 err = ipq806x_gmac_of_parse(gmac); in ipq806x_gmac_probe()
406 regmap_write(gmac->qsgmii_csr, QSGMII_PCS_CAL_LCKDT_CTL, in ipq806x_gmac_probe()
414 switch (gmac->phy_mode) { in ipq806x_gmac_probe()
427 regmap_write(gmac->nss_common, NSS_COMMON_GMAC_CTL(gmac->id), val); in ipq806x_gmac_probe()
430 regmap_read(gmac->nss_common, NSS_COMMON_CLK_SRC_CTRL, &val); in ipq806x_gmac_probe()
431 val &= ~(1 << NSS_COMMON_CLK_SRC_CTRL_OFFSET(gmac->id)); in ipq806x_gmac_probe()
432 switch (gmac->phy_mode) { in ipq806x_gmac_probe()
437 val |= NSS_COMMON_CLK_SRC_CTRL_RGMII(gmac->id) << in ipq806x_gmac_probe()
438 NSS_COMMON_CLK_SRC_CTRL_OFFSET(gmac->id); in ipq806x_gmac_probe()
441 val |= NSS_COMMON_CLK_SRC_CTRL_SGMII(gmac->id) << in ipq806x_gmac_probe()
442 NSS_COMMON_CLK_SRC_CTRL_OFFSET(gmac->id); in ipq806x_gmac_probe()
447 regmap_write(gmac->nss_common, NSS_COMMON_CLK_SRC_CTRL, val); in ipq806x_gmac_probe()
450 regmap_read(gmac->nss_common, NSS_COMMON_CLK_GATE, &val); in ipq806x_gmac_probe()
451 val |= NSS_COMMON_CLK_GATE_PTP_EN(gmac->id); in ipq806x_gmac_probe()
452 switch (gmac->phy_mode) { in ipq806x_gmac_probe()
457 val |= NSS_COMMON_CLK_GATE_RGMII_RX_EN(gmac->id) | in ipq806x_gmac_probe()
458 NSS_COMMON_CLK_GATE_RGMII_TX_EN(gmac->id); in ipq806x_gmac_probe()
461 val |= NSS_COMMON_CLK_GATE_GMII_RX_EN(gmac->id) | in ipq806x_gmac_probe()
462 NSS_COMMON_CLK_GATE_GMII_TX_EN(gmac->id); in ipq806x_gmac_probe()
467 regmap_write(gmac->nss_common, NSS_COMMON_CLK_GATE, val); in ipq806x_gmac_probe()
469 if (gmac->phy_mode == PHY_INTERFACE_MODE_SGMII) { in ipq806x_gmac_probe()
470 err = ipq806x_gmac_configure_qsgmii_params(gmac); in ipq806x_gmac_probe()
474 err = ipq806x_gmac_configure_qsgmii_pcs_speed(gmac); in ipq806x_gmac_probe()
480 plat_dat->bsp_priv = gmac; in ipq806x_gmac_probe()
490 phy_modes(gmac->phy_mode)); in ipq806x_gmac_probe()
495 { .compatible = "qcom,ipq806x-gmac" },
504 .name = "ipq806x-gmac-dwmac",