Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Fixed-Link phy |
| 4 | * |
| 5 | * Copyright 2017 Bernecker & Rainer Industrieelektronik GmbH |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <config.h> |
| 9 | #include <common.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 11 | #include <phy.h> |
| 12 | #include <dm.h> |
| 13 | #include <fdt_support.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Bin Meng | 7d2129b | 2021-03-14 20:14:53 +0800 | [diff] [blame] | 18 | static int fixedphy_probe(struct phy_device *phydev) |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 19 | { |
Vladimir Oltean | 6ca194a | 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 | |
Bin Meng | 7d2129b | 2021-03-14 20:14:53 +0800 | [diff] [blame] | 26 | static int fixedphy_config(struct phy_device *phydev) |
Vladimir Oltean | 6ca194a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 27 | { |
| 28 | ofnode node = phy_get_ofnode(phydev); |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 29 | struct fixed_link *priv; |
Bin Meng | 1346267 | 2021-03-14 20:14:55 +0800 | [diff] [blame] | 30 | bool old_binding = false; |
| 31 | u32 old_val[5]; |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 32 | u32 val; |
| 33 | |
Vladimir Oltean | 6ca194a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 34 | if (!ofnode_valid(node)) |
| 35 | return -EINVAL; |
| 36 | |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 37 | /* check for mandatory properties within fixed-link node */ |
Vladimir Oltean | 6ca194a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 38 | val = ofnode_read_u32_default(node, "speed", 0); |
Bin Meng | 1346267 | 2021-03-14 20:14:55 +0800 | [diff] [blame] | 39 | |
| 40 | if (!val) { |
| 41 | /* try old binding */ |
| 42 | old_binding = true; |
| 43 | if (ofnode_read_u32_array(node, "fixed-link", old_val, |
| 44 | ARRAY_SIZE(old_val))) { |
| 45 | printf("ERROR: no/invalid <fixed-link> property!\n"); |
| 46 | return -ENOENT; |
| 47 | } |
| 48 | val = old_val[2]; |
| 49 | } |
| 50 | |
Vladimir Oltean | 312e15b | 2021-01-25 14:23:51 +0200 | [diff] [blame] | 51 | if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 && |
| 52 | val != SPEED_2500 && val != SPEED_10000) { |
Bin Meng | fbe5aea | 2021-03-14 20:14:54 +0800 | [diff] [blame] | 53 | printf("ERROR: no/invalid speed given in fixed-link node!\n"); |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 54 | return -EINVAL; |
| 55 | } |
| 56 | |
| 57 | priv = malloc(sizeof(*priv)); |
| 58 | if (!priv) |
| 59 | return -ENOMEM; |
| 60 | memset(priv, 0, sizeof(*priv)); |
| 61 | |
| 62 | phydev->priv = priv; |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 63 | |
| 64 | priv->link_speed = val; |
Bin Meng | 1346267 | 2021-03-14 20:14:55 +0800 | [diff] [blame] | 65 | if (!old_binding) { |
| 66 | priv->duplex = ofnode_read_bool(node, "full-duplex"); |
| 67 | priv->pause = ofnode_read_bool(node, "pause"); |
| 68 | priv->asym_pause = ofnode_read_bool(node, "asym-pause"); |
| 69 | } else { |
| 70 | priv->duplex = old_val[1]; |
| 71 | priv->pause = old_val[3]; |
| 72 | priv->asym_pause = old_val[4]; |
| 73 | } |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
Bin Meng | 7d2129b | 2021-03-14 20:14:53 +0800 | [diff] [blame] | 78 | static int fixedphy_startup(struct phy_device *phydev) |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 79 | { |
| 80 | struct fixed_link *priv = phydev->priv; |
| 81 | |
| 82 | phydev->asym_pause = priv->asym_pause; |
| 83 | phydev->pause = priv->pause; |
| 84 | phydev->duplex = priv->duplex; |
| 85 | phydev->speed = priv->link_speed; |
| 86 | phydev->link = 1; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Bin Meng | 7d2129b | 2021-03-14 20:14:53 +0800 | [diff] [blame] | 91 | static int fixedphy_shutdown(struct phy_device *phydev) |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 92 | { |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static struct phy_driver fixedphy_driver = { |
| 97 | .uid = PHY_FIXED_ID, |
| 98 | .mask = 0xffffffff, |
| 99 | .name = "Fixed PHY", |
| 100 | .features = PHY_GBIT_FEATURES | SUPPORTED_MII, |
| 101 | .probe = fixedphy_probe, |
Vladimir Oltean | 6ca194a | 2021-03-14 20:14:48 +0800 | [diff] [blame] | 102 | .config = fixedphy_config, |
Hannes Schmelzer | da49460 | 2017-03-23 15:11:43 +0100 | [diff] [blame] | 103 | .startup = fixedphy_startup, |
| 104 | .shutdown = fixedphy_shutdown, |
| 105 | }; |
| 106 | |
| 107 | int phy_fixed_init(void) |
| 108 | { |
| 109 | phy_register(&fixedphy_driver); |
| 110 | return 0; |
| 111 | } |