blob: 3228672fc4ae347b500d8660699b3654741fc442 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Hannes Schmelzerda494602017-03-23 15:11:43 +010015
16DECLARE_GLOBAL_DATA_PTR;
17
18int fixedphy_probe(struct phy_device *phydev)
19{
20 struct fixed_link *priv;
21 int ofnode = phydev->addr;
22 u32 val;
23
24 /* check for mandatory properties within fixed-link node */
25 val = fdt_getprop_u32_default_node(gd->fdt_blob,
26 ofnode, 0, "speed", 0);
27 if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000) {
28 printf("ERROR: no/invalid speed given in fixed-link node!");
29 return -EINVAL;
30 }
31
32 priv = malloc(sizeof(*priv));
33 if (!priv)
34 return -ENOMEM;
35 memset(priv, 0, sizeof(*priv));
36
37 phydev->priv = priv;
Hannes Schmelzerda494602017-03-23 15:11:43 +010038
39 priv->link_speed = val;
40 priv->duplex = fdtdec_get_bool(gd->fdt_blob, ofnode, "full-duplex");
41 priv->pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "pause");
42 priv->asym_pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "asym-pause");
43
44 /* fixed-link phy must not be reset by core phy code */
45 phydev->flags |= PHY_FLAG_BROKEN_RESET;
46
47 return 0;
48}
49
50int fixedphy_startup(struct phy_device *phydev)
51{
52 struct fixed_link *priv = phydev->priv;
53
54 phydev->asym_pause = priv->asym_pause;
55 phydev->pause = priv->pause;
56 phydev->duplex = priv->duplex;
57 phydev->speed = priv->link_speed;
58 phydev->link = 1;
59
60 return 0;
61}
62
63int fixedphy_shutdown(struct phy_device *phydev)
64{
65 return 0;
66}
67
68static struct phy_driver fixedphy_driver = {
69 .uid = PHY_FIXED_ID,
70 .mask = 0xffffffff,
71 .name = "Fixed PHY",
72 .features = PHY_GBIT_FEATURES | SUPPORTED_MII,
73 .probe = fixedphy_probe,
74 .startup = fixedphy_startup,
75 .shutdown = fixedphy_shutdown,
76};
77
78int phy_fixed_init(void)
79{
80 phy_register(&fixedphy_driver);
81 return 0;
82}