Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 2 | /* |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 3 | * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/ |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 4 | * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <generic-phy.h> |
| 9 | |
Patrice Chotard | 030dd07 | 2020-07-28 09:13:32 +0200 | [diff] [blame] | 10 | #define DRIVER_DATA 0x12345678 |
| 11 | |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 12 | struct sandbox_phy_priv { |
| 13 | bool initialized; |
| 14 | bool on; |
| 15 | bool broken; |
| 16 | }; |
| 17 | |
| 18 | static int sandbox_phy_power_on(struct phy *phy) |
| 19 | { |
| 20 | struct sandbox_phy_priv *priv = dev_get_priv(phy->dev); |
| 21 | |
| 22 | if (!priv->initialized) |
| 23 | return -EIO; |
| 24 | |
| 25 | if (priv->broken) |
| 26 | return -EIO; |
| 27 | |
| 28 | priv->on = true; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static int sandbox_phy_power_off(struct phy *phy) |
| 34 | { |
| 35 | struct sandbox_phy_priv *priv = dev_get_priv(phy->dev); |
| 36 | |
| 37 | if (!priv->initialized) |
| 38 | return -EIO; |
| 39 | |
| 40 | if (priv->broken) |
| 41 | return -EIO; |
| 42 | |
| 43 | /* |
| 44 | * for validation purpose, let's says that power off |
| 45 | * works only for PHY 0 |
| 46 | */ |
| 47 | if (phy->id) |
| 48 | return -EIO; |
| 49 | |
| 50 | priv->on = false; |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static int sandbox_phy_init(struct phy *phy) |
| 56 | { |
| 57 | struct sandbox_phy_priv *priv = dev_get_priv(phy->dev); |
| 58 | |
| 59 | priv->initialized = true; |
| 60 | priv->on = true; |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int sandbox_phy_exit(struct phy *phy) |
| 66 | { |
| 67 | struct sandbox_phy_priv *priv = dev_get_priv(phy->dev); |
| 68 | |
| 69 | priv->initialized = false; |
| 70 | priv->on = false; |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
Patrice Chotard | 030dd07 | 2020-07-28 09:13:32 +0200 | [diff] [blame] | 75 | static int sandbox_phy_bind(struct udevice *dev) |
| 76 | { |
| 77 | if (dev_get_driver_data(dev) != DRIVER_DATA) |
| 78 | return -ENODATA; |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 83 | static int sandbox_phy_probe(struct udevice *dev) |
| 84 | { |
| 85 | struct sandbox_phy_priv *priv = dev_get_priv(dev); |
| 86 | |
| 87 | priv->initialized = false; |
| 88 | priv->on = false; |
Simon Glass | cfe0c90 | 2017-05-18 20:09:48 -0600 | [diff] [blame] | 89 | priv->broken = dev_read_bool(dev, "broken"); |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static struct phy_ops sandbox_phy_ops = { |
| 95 | .power_on = sandbox_phy_power_on, |
| 96 | .power_off = sandbox_phy_power_off, |
| 97 | .init = sandbox_phy_init, |
| 98 | .exit = sandbox_phy_exit, |
| 99 | }; |
| 100 | |
| 101 | static const struct udevice_id sandbox_phy_ids[] = { |
Patrice Chotard | 030dd07 | 2020-07-28 09:13:32 +0200 | [diff] [blame] | 102 | { .compatible = "sandbox,phy_no_driver_data", |
| 103 | }, |
| 104 | |
| 105 | { .compatible = "sandbox,phy", |
| 106 | .data = DRIVER_DATA |
| 107 | }, |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 108 | { } |
| 109 | }; |
| 110 | |
| 111 | U_BOOT_DRIVER(phy_sandbox) = { |
| 112 | .name = "phy_sandbox", |
| 113 | .id = UCLASS_PHY, |
Patrice Chotard | 030dd07 | 2020-07-28 09:13:32 +0200 | [diff] [blame] | 114 | .bind = sandbox_phy_bind, |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 115 | .of_match = sandbox_phy_ids, |
| 116 | .ops = &sandbox_phy_ops, |
| 117 | .probe = sandbox_phy_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 118 | .priv_auto = sizeof(struct sandbox_phy_priv), |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 119 | }; |