Lines Matching +full:dwmac +full:- +full:4

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dwmac-sti.c - STMicroelectronics DWMAC Specific Glue layer
5 * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
44 * ------------------------------------------------
47 * ------------------------------------------------
49 *| | clk-125/txclk | txclk |
50 * ------------------------------------------------
52 *| | clk-125/txclk | clkgen |
54 * ------------------------------------------------
56 *| | |clkgen/phyclk-in |
57 * ------------------------------------------------
60 *-------------------------------
62 *-------------------------------
64 *-------------------------------
66 *-------------------------------
68 *-------------------------------
70 *-------------------------------
79 *-----------------------
81 *-----------------------
83 *-----------------------
86 *-----------------------
89 *-----------------------
92 *-----------------------
105 * 3 bits [4:2]
106 * 000-GMII/MII
107 * 001-RGMII
108 * 010-SGMII
109 * 100-RMII
111 #define MII_PHY_SEL_MASK GENMASK(4, 2)
112 #define ETH_PHY_SEL_RMII BIT(4)
123 u32 ctrl_reg; /* GMAC glue-logic control register */
162 struct sti_dwmac *dwmac = priv; in stih4xx_fix_retime_src() local
163 u32 src = dwmac->tx_retime_src; in stih4xx_fix_retime_src()
164 u32 reg = dwmac->ctrl_reg; in stih4xx_fix_retime_src()
167 if (dwmac->interface == PHY_INTERFACE_MODE_MII) { in stih4xx_fix_retime_src()
169 } else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) { in stih4xx_fix_retime_src()
170 if (dwmac->ext_phyclk) { in stih4xx_fix_retime_src()
176 } else if (IS_PHY_IF_MODE_RGMII(dwmac->interface)) { in stih4xx_fix_retime_src()
191 clk_set_rate(dwmac->clk, freq); in stih4xx_fix_retime_src()
193 regmap_update_bits(dwmac->regmap, reg, STIH4XX_RETIME_SRC_MASK, in stih4xx_fix_retime_src()
199 struct sti_dwmac *dwmac = priv; in stid127_fix_retime_src() local
200 u32 reg = dwmac->ctrl_reg; in stid127_fix_retime_src()
204 if (dwmac->interface == PHY_INTERFACE_MODE_MII) { in stid127_fix_retime_src()
206 } else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) { in stid127_fix_retime_src()
207 if (!dwmac->ext_phyclk) { in stid127_fix_retime_src()
211 } else if (IS_PHY_IF_MODE_RGMII(dwmac->interface)) { in stid127_fix_retime_src()
222 clk_set_rate(dwmac->clk, freq); in stid127_fix_retime_src()
224 regmap_update_bits(dwmac->regmap, reg, STID127_RETIME_SRC_MASK, val); in stid127_fix_retime_src()
227 static int sti_dwmac_set_mode(struct sti_dwmac *dwmac) in sti_dwmac_set_mode() argument
229 struct regmap *regmap = dwmac->regmap; in sti_dwmac_set_mode()
230 int iface = dwmac->interface; in sti_dwmac_set_mode()
231 u32 reg = dwmac->ctrl_reg; in sti_dwmac_set_mode()
234 if (dwmac->gmac_en) in sti_dwmac_set_mode()
242 dwmac->fix_retime_src(dwmac, dwmac->speed); in sti_dwmac_set_mode()
247 static int sti_dwmac_parse_data(struct sti_dwmac *dwmac, in sti_dwmac_parse_data() argument
251 struct device *dev = &pdev->dev; in sti_dwmac_parse_data()
252 struct device_node *np = dev->of_node; in sti_dwmac_parse_data()
257 dwmac->clk_sel_reg = -ENXIO; in sti_dwmac_parse_data()
258 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sti-clkconf"); in sti_dwmac_parse_data()
260 dwmac->clk_sel_reg = res->start; in sti_dwmac_parse_data()
266 err = of_property_read_u32_index(np, "st,syscon", 1, &dwmac->ctrl_reg); in sti_dwmac_parse_data()
272 err = of_get_phy_mode(np, &dwmac->interface); in sti_dwmac_parse_data()
273 if (err && err != -ENODEV) { in sti_dwmac_parse_data()
274 dev_err(dev, "Can't get phy-mode\n"); in sti_dwmac_parse_data()
278 dwmac->regmap = regmap; in sti_dwmac_parse_data()
279 dwmac->gmac_en = of_property_read_bool(np, "st,gmac_en"); in sti_dwmac_parse_data()
280 dwmac->ext_phyclk = of_property_read_bool(np, "st,ext-phyclk"); in sti_dwmac_parse_data()
281 dwmac->tx_retime_src = TX_RETIME_SRC_NA; in sti_dwmac_parse_data()
282 dwmac->speed = SPEED_100; in sti_dwmac_parse_data()
284 if (IS_PHY_IF_MODE_GBIT(dwmac->interface)) { in sti_dwmac_parse_data()
287 dwmac->tx_retime_src = TX_RETIME_SRC_CLKGEN; in sti_dwmac_parse_data()
289 err = of_property_read_string(np, "st,tx-retime-src", &rs); in sti_dwmac_parse_data()
294 dwmac->tx_retime_src = TX_RETIME_SRC_CLK_125; in sti_dwmac_parse_data()
296 dwmac->tx_retime_src = TX_RETIME_SRC_TXCLK; in sti_dwmac_parse_data()
298 dwmac->speed = SPEED_1000; in sti_dwmac_parse_data()
301 dwmac->clk = devm_clk_get(dev, "sti-ethclk"); in sti_dwmac_parse_data()
302 if (IS_ERR(dwmac->clk)) { in sti_dwmac_parse_data()
304 dwmac->clk = NULL; in sti_dwmac_parse_data()
315 struct sti_dwmac *dwmac; in sti_dwmac_probe() local
318 data = of_device_get_match_data(&pdev->dev); in sti_dwmac_probe()
320 dev_err(&pdev->dev, "No OF match data provided\n"); in sti_dwmac_probe()
321 return -EINVAL; in sti_dwmac_probe()
332 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); in sti_dwmac_probe()
333 if (!dwmac) { in sti_dwmac_probe()
334 ret = -ENOMEM; in sti_dwmac_probe()
338 ret = sti_dwmac_parse_data(dwmac, pdev); in sti_dwmac_probe()
340 dev_err(&pdev->dev, "Unable to parse OF data\n"); in sti_dwmac_probe()
344 dwmac->fix_retime_src = data->fix_retime_src; in sti_dwmac_probe()
346 plat_dat->bsp_priv = dwmac; in sti_dwmac_probe()
347 plat_dat->fix_mac_speed = data->fix_retime_src; in sti_dwmac_probe()
349 ret = clk_prepare_enable(dwmac->clk); in sti_dwmac_probe()
353 ret = sti_dwmac_set_mode(dwmac); in sti_dwmac_probe()
357 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); in sti_dwmac_probe()
364 clk_disable_unprepare(dwmac->clk); in sti_dwmac_probe()
373 struct sti_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev); in sti_dwmac_remove() local
374 int ret = stmmac_dvr_remove(&pdev->dev); in sti_dwmac_remove()
376 clk_disable_unprepare(dwmac->clk); in sti_dwmac_remove()
384 struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev); in sti_dwmac_suspend() local
387 clk_disable_unprepare(dwmac->clk); in sti_dwmac_suspend()
394 struct sti_dwmac *dwmac = get_stmmac_bsp_priv(dev); in sti_dwmac_resume() local
396 clk_prepare_enable(dwmac->clk); in sti_dwmac_resume()
397 sti_dwmac_set_mode(dwmac); in sti_dwmac_resume()
415 { .compatible = "st,stih415-dwmac", .data = &stih4xx_dwmac_data},
416 { .compatible = "st,stih416-dwmac", .data = &stih4xx_dwmac_data},
417 { .compatible = "st,stid127-dwmac", .data = &stid127_dwmac_data},
418 { .compatible = "st,stih407-dwmac", .data = &stih4xx_dwmac_data},
427 .name = "sti-dwmac",
435 MODULE_DESCRIPTION("STMicroelectronics DWMAC Specific Glue layer");