xref: /openbmc/u-boot/drivers/net/phy/fixed.c (revision f77d4410)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Fixed-Link phy
4  *
5  * Copyright 2017 Bernecker & Rainer Industrieelektronik GmbH
6  */
7 
8 #include <config.h>
9 #include <common.h>
10 #include <phy.h>
11 #include <dm.h>
12 #include <fdt_support.h>
13 
14 DECLARE_GLOBAL_DATA_PTR;
15 
16 int fixedphy_probe(struct phy_device *phydev)
17 {
18 	struct fixed_link *priv;
19 	int ofnode = phydev->addr;
20 	u32 val;
21 
22 	/* check for mandatory properties within fixed-link node */
23 	val = fdt_getprop_u32_default_node(gd->fdt_blob,
24 					   ofnode, 0, "speed", 0);
25 	if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000) {
26 		printf("ERROR: no/invalid speed given in fixed-link node!");
27 		return -EINVAL;
28 	}
29 
30 	priv = malloc(sizeof(*priv));
31 	if (!priv)
32 		return -ENOMEM;
33 	memset(priv, 0, sizeof(*priv));
34 
35 	phydev->priv = priv;
36 
37 	priv->link_speed = val;
38 	priv->duplex = fdtdec_get_bool(gd->fdt_blob, ofnode, "full-duplex");
39 	priv->pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "pause");
40 	priv->asym_pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "asym-pause");
41 
42 	/* fixed-link phy must not be reset by core phy code */
43 	phydev->flags |= PHY_FLAG_BROKEN_RESET;
44 
45 	return 0;
46 }
47 
48 int fixedphy_startup(struct phy_device *phydev)
49 {
50 	struct fixed_link *priv = phydev->priv;
51 
52 	phydev->asym_pause = priv->asym_pause;
53 	phydev->pause = priv->pause;
54 	phydev->duplex = priv->duplex;
55 	phydev->speed = priv->link_speed;
56 	phydev->link = 1;
57 
58 	return 0;
59 }
60 
61 int fixedphy_shutdown(struct phy_device *phydev)
62 {
63 	return 0;
64 }
65 
66 static struct phy_driver fixedphy_driver = {
67 	.uid		= PHY_FIXED_ID,
68 	.mask		= 0xffffffff,
69 	.name		= "Fixed PHY",
70 	.features	= PHY_GBIT_FEATURES | SUPPORTED_MII,
71 	.probe		= fixedphy_probe,
72 	.startup	= fixedphy_startup,
73 	.shutdown	= fixedphy_shutdown,
74 };
75 
76 int phy_fixed_init(void)
77 {
78 	phy_register(&fixedphy_driver);
79 	return 0;
80 }
81