Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Fixed-Link phy |
| 4 | * |
| 5 | * Copyright 2017 Bernecker & Rainer Industrieelektronik GmbH |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <config.h> |
| 9 | #include <common.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 11 | #include <phy.h> |
| 12 | #include <dm.h> |
| 13 | #include <fdt_support.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | int fixedphy_probe(struct phy_device *phydev) |
| 19 | { |
Vladimir Oltean | f27bc8a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 20 | /* fixed-link phy must not be reset by core phy code */ |
| 21 | phydev->flags |= PHY_FLAG_BROKEN_RESET; |
| 22 | |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | int fixedphy_config(struct phy_device *phydev) |
| 27 | { |
| 28 | ofnode node = phy_get_ofnode(phydev); |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 29 | struct fixed_link *priv; |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 30 | u32 val; |
| 31 | |
Vladimir Oltean | f27bc8a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 32 | if (!ofnode_valid(node)) |
| 33 | return -EINVAL; |
| 34 | |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 35 | /* check for mandatory properties within fixed-link node */ |
Vladimir Oltean | f27bc8a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 36 | val = ofnode_read_u32_default(node, "speed", 0); |
Vladimir Oltean | 56a5588 | 2021-01-25 14:23:51 +0200 | [diff] [blame] | 37 | if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 && |
| 38 | val != SPEED_2500 && val != SPEED_10000) { |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 39 | printf("ERROR: no/invalid speed given in fixed-link node!"); |
| 40 | return -EINVAL; |
| 41 | } |
| 42 | |
| 43 | priv = malloc(sizeof(*priv)); |
| 44 | if (!priv) |
| 45 | return -ENOMEM; |
| 46 | memset(priv, 0, sizeof(*priv)); |
| 47 | |
| 48 | phydev->priv = priv; |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 49 | |
| 50 | priv->link_speed = val; |
Vladimir Oltean | f27bc8a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 51 | priv->duplex = ofnode_read_bool(node, "full-duplex"); |
| 52 | priv->pause = ofnode_read_bool(node, "pause"); |
| 53 | priv->asym_pause = ofnode_read_bool(node, "asym-pause"); |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | int fixedphy_startup(struct phy_device *phydev) |
| 59 | { |
| 60 | struct fixed_link *priv = phydev->priv; |
| 61 | |
| 62 | phydev->asym_pause = priv->asym_pause; |
| 63 | phydev->pause = priv->pause; |
| 64 | phydev->duplex = priv->duplex; |
| 65 | phydev->speed = priv->link_speed; |
| 66 | phydev->link = 1; |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int fixedphy_shutdown(struct phy_device *phydev) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static struct phy_driver fixedphy_driver = { |
| 77 | .uid = PHY_FIXED_ID, |
| 78 | .mask = 0xffffffff, |
| 79 | .name = "Fixed PHY", |
| 80 | .features = PHY_GBIT_FEATURES | SUPPORTED_MII, |
| 81 | .probe = fixedphy_probe, |
Vladimir Oltean | f27bc8a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 82 | .config = fixedphy_config, |
Hannes Schmelzer | db40c1a | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 83 | .startup = fixedphy_startup, |
| 84 | .shutdown = fixedphy_shutdown, |
| 85 | }; |
| 86 | |
| 87 | int phy_fixed_init(void) |
| 88 | { |
| 89 | phy_register(&fixedphy_driver); |
| 90 | return 0; |
| 91 | } |