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