Lines Matching +full:dwmac +full:- +full:3
1 // SPDX-License-Identifier: GPL-2.0
3 * dwmac-imx.c - DWMAC Specific Glue layer for NXP imx8
33 #define MX93_GPR_ENET_QOS_INTF_MODE_MASK GENMASK(3, 0)
34 #define MX93_GPR_ENET_QOS_INTF_MASK GENMASK(3, 1)
70 struct imx_priv_data *dwmac = plat_dat->bsp_priv; in imx8mp_set_intf_mode() local
73 switch (plat_dat->mac_interface) { in imx8mp_set_intf_mode()
79 val |= (dwmac->rmii_refclk_ext ? 0 : GPR_ENET_QOS_CLK_TX_CLK_SEL); in imx8mp_set_intf_mode()
89 pr_debug("imx dwmac doesn't support %d interface\n", in imx8mp_set_intf_mode()
90 plat_dat->mac_interface); in imx8mp_set_intf_mode()
91 return -EINVAL; in imx8mp_set_intf_mode()
95 return regmap_update_bits(dwmac->intf_regmap, dwmac->intf_reg_off, in imx8mp_set_intf_mode()
110 struct imx_priv_data *dwmac = plat_dat->bsp_priv; in imx93_set_intf_mode() local
113 switch (plat_dat->mac_interface) { in imx93_set_intf_mode()
127 dev_dbg(dwmac->dev, "imx dwmac doesn't support %d interface\n", in imx93_set_intf_mode()
128 plat_dat->mac_interface); in imx93_set_intf_mode()
129 return -EINVAL; in imx93_set_intf_mode()
133 return regmap_update_bits(dwmac->intf_regmap, dwmac->intf_reg_off, in imx93_set_intf_mode()
139 struct imx_priv_data *dwmac = priv; in imx_dwmac_clks_config() local
143 ret = clk_prepare_enable(dwmac->clk_mem); in imx_dwmac_clks_config()
145 dev_err(dwmac->dev, "mem clock enable failed\n"); in imx_dwmac_clks_config()
149 ret = clk_prepare_enable(dwmac->clk_tx); in imx_dwmac_clks_config()
151 dev_err(dwmac->dev, "tx clock enable failed\n"); in imx_dwmac_clks_config()
152 clk_disable_unprepare(dwmac->clk_mem); in imx_dwmac_clks_config()
156 clk_disable_unprepare(dwmac->clk_tx); in imx_dwmac_clks_config()
157 clk_disable_unprepare(dwmac->clk_mem); in imx_dwmac_clks_config()
166 struct imx_priv_data *dwmac = priv; in imx_dwmac_init() local
169 plat_dat = dwmac->plat_dat; in imx_dwmac_init()
171 if (dwmac->ops->set_intf_mode) { in imx_dwmac_init()
172 ret = dwmac->ops->set_intf_mode(plat_dat); in imx_dwmac_init()
188 struct imx_priv_data *dwmac = priv; in imx_dwmac_fix_speed() local
192 plat_dat = dwmac->plat_dat; in imx_dwmac_fix_speed()
194 if (dwmac->ops->mac_rgmii_txclk_auto_adj || in imx_dwmac_fix_speed()
195 (plat_dat->mac_interface == PHY_INTERFACE_MODE_RMII) || in imx_dwmac_fix_speed()
196 (plat_dat->mac_interface == PHY_INTERFACE_MODE_MII)) in imx_dwmac_fix_speed()
210 dev_err(dwmac->dev, "invalid speed %u\n", speed); in imx_dwmac_fix_speed()
214 err = clk_set_rate(dwmac->clk_tx, rate); in imx_dwmac_fix_speed()
216 dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate); in imx_dwmac_fix_speed()
221 struct imx_priv_data *dwmac = priv; in imx93_dwmac_fix_speed() local
227 if (!dwmac || mode != MLO_AN_FIXED) in imx93_dwmac_fix_speed()
230 if (regmap_read(dwmac->intf_regmap, dwmac->intf_reg_off, &iface)) in imx93_dwmac_fix_speed()
237 old_ctrl = readl(dwmac->base_addr + MAC_CTRL_REG); in imx93_dwmac_fix_speed()
239 regmap_update_bits(dwmac->intf_regmap, dwmac->intf_reg_off, in imx93_dwmac_fix_speed()
241 writel(ctrl, dwmac->base_addr + MAC_CTRL_REG); in imx93_dwmac_fix_speed()
244 readl(dwmac->base_addr + MAC_CTRL_REG); in imx93_dwmac_fix_speed()
248 regmap_update_bits(dwmac->intf_regmap, dwmac->intf_reg_off, in imx93_dwmac_fix_speed()
251 writel(old_ctrl, dwmac->base_addr + MAC_CTRL_REG); in imx93_dwmac_fix_speed()
263 if (plat_dat->mac_interface == PHY_INTERFACE_MODE_RMII) { in imx_dwmac_mx93_reset()
274 imx_dwmac_parse_dt(struct imx_priv_data *dwmac, struct device *dev) in imx_dwmac_parse_dt() argument
276 struct device_node *np = dev->of_node; in imx_dwmac_parse_dt()
279 dwmac->rmii_refclk_ext = of_property_read_bool(np, "snps,rmii_refclk_ext"); in imx_dwmac_parse_dt()
281 dwmac->clk_tx = devm_clk_get(dev, "tx"); in imx_dwmac_parse_dt()
282 if (IS_ERR(dwmac->clk_tx)) { in imx_dwmac_parse_dt()
284 return PTR_ERR(dwmac->clk_tx); in imx_dwmac_parse_dt()
287 dwmac->clk_mem = NULL; in imx_dwmac_parse_dt()
291 dwmac->clk_mem = devm_clk_get(dev, "mem"); in imx_dwmac_parse_dt()
292 if (IS_ERR(dwmac->clk_mem)) { in imx_dwmac_parse_dt()
294 return PTR_ERR(dwmac->clk_mem); in imx_dwmac_parse_dt()
304 dwmac->intf_regmap = syscon_regmap_lookup_by_phandle(np, "intf_mode"); in imx_dwmac_parse_dt()
305 if (IS_ERR(dwmac->intf_regmap)) in imx_dwmac_parse_dt()
306 return PTR_ERR(dwmac->intf_regmap); in imx_dwmac_parse_dt()
308 err = of_property_read_u32_index(np, "intf_mode", 1, &dwmac->intf_reg_off); in imx_dwmac_parse_dt()
322 struct imx_priv_data *dwmac; in imx_dwmac_probe() local
330 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); in imx_dwmac_probe()
331 if (!dwmac) in imx_dwmac_probe()
332 return -ENOMEM; in imx_dwmac_probe()
338 data = of_device_get_match_data(&pdev->dev); in imx_dwmac_probe()
340 dev_err(&pdev->dev, "failed to get match data\n"); in imx_dwmac_probe()
341 return -EINVAL; in imx_dwmac_probe()
344 dwmac->ops = data; in imx_dwmac_probe()
345 dwmac->dev = &pdev->dev; in imx_dwmac_probe()
347 ret = imx_dwmac_parse_dt(dwmac, &pdev->dev); in imx_dwmac_probe()
349 dev_err(&pdev->dev, "failed to parse OF data\n"); in imx_dwmac_probe()
353 if (data->flags & STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY) in imx_dwmac_probe()
354 plat_dat->flags |= STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY; in imx_dwmac_probe()
357 for (int i = 1; i < plat_dat->tx_queues_to_use; i++) in imx_dwmac_probe()
358 plat_dat->tx_queues_cfg[i].tbs_en = 1; in imx_dwmac_probe()
360 plat_dat->host_dma_width = dwmac->ops->addr_width; in imx_dwmac_probe()
361 plat_dat->init = imx_dwmac_init; in imx_dwmac_probe()
362 plat_dat->exit = imx_dwmac_exit; in imx_dwmac_probe()
363 plat_dat->clks_config = imx_dwmac_clks_config; in imx_dwmac_probe()
364 plat_dat->fix_mac_speed = imx_dwmac_fix_speed; in imx_dwmac_probe()
365 plat_dat->bsp_priv = dwmac; in imx_dwmac_probe()
366 dwmac->plat_dat = plat_dat; in imx_dwmac_probe()
367 dwmac->base_addr = stmmac_res.addr; in imx_dwmac_probe()
369 ret = imx_dwmac_clks_config(dwmac, true); in imx_dwmac_probe()
373 ret = imx_dwmac_init(pdev, dwmac); in imx_dwmac_probe()
377 if (dwmac->ops->fix_mac_speed) in imx_dwmac_probe()
378 plat_dat->fix_mac_speed = dwmac->ops->fix_mac_speed; in imx_dwmac_probe()
379 dwmac->plat_dat->fix_soc_reset = dwmac->ops->fix_soc_reset; in imx_dwmac_probe()
381 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); in imx_dwmac_probe()
388 imx_dwmac_exit(pdev, plat_dat->bsp_priv); in imx_dwmac_probe()
390 imx_dwmac_clks_config(dwmac, false); in imx_dwmac_probe()
416 { .compatible = "nxp,imx8mp-dwmac-eqos", .data = &imx8mp_dwmac_data },
417 { .compatible = "nxp,imx8dxl-dwmac-eqos", .data = &imx8dxl_dwmac_data },
418 { .compatible = "nxp,imx93-dwmac-eqos", .data = &imx93_dwmac_data },
427 .name = "imx-dwmac",
435 MODULE_DESCRIPTION("NXP imx8 DWMAC Specific Glue layer");