blob: 84ff5c6275b523900d838d58f7aaa6b6bd6896e9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +02002/*
3 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +02005 */
6
7#include <common.h>
8#include <dm.h>
9#include <generic-phy.h>
10
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020011struct sandbox_phy_priv {
12 bool initialized;
13 bool on;
14 bool broken;
15};
16
17static int sandbox_phy_power_on(struct phy *phy)
18{
19 struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
20
21 if (!priv->initialized)
22 return -EIO;
23
24 if (priv->broken)
25 return -EIO;
26
27 priv->on = true;
28
29 return 0;
30}
31
32static int sandbox_phy_power_off(struct phy *phy)
33{
34 struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
35
36 if (!priv->initialized)
37 return -EIO;
38
39 if (priv->broken)
40 return -EIO;
41
42 /*
43 * for validation purpose, let's says that power off
44 * works only for PHY 0
45 */
46 if (phy->id)
47 return -EIO;
48
49 priv->on = false;
50
51 return 0;
52}
53
54static int sandbox_phy_init(struct phy *phy)
55{
56 struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
57
58 priv->initialized = true;
59 priv->on = true;
60
61 return 0;
62}
63
64static int sandbox_phy_exit(struct phy *phy)
65{
66 struct sandbox_phy_priv *priv = dev_get_priv(phy->dev);
67
68 priv->initialized = false;
69 priv->on = false;
70
71 return 0;
72}
73
74static int sandbox_phy_probe(struct udevice *dev)
75{
76 struct sandbox_phy_priv *priv = dev_get_priv(dev);
77
78 priv->initialized = false;
79 priv->on = false;
Simon Glass5204e9b2017-05-18 20:09:48 -060080 priv->broken = dev_read_bool(dev, "broken");
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020081
82 return 0;
83}
84
85static struct phy_ops sandbox_phy_ops = {
86 .power_on = sandbox_phy_power_on,
87 .power_off = sandbox_phy_power_off,
88 .init = sandbox_phy_init,
89 .exit = sandbox_phy_exit,
90};
91
92static const struct udevice_id sandbox_phy_ids[] = {
93 { .compatible = "sandbox,phy" },
94 { }
95};
96
97U_BOOT_DRIVER(phy_sandbox) = {
98 .name = "phy_sandbox",
99 .id = UCLASS_PHY,
100 .of_match = sandbox_phy_ids,
101 .ops = &sandbox_phy_ops,
102 .probe = sandbox_phy_probe,
103 .priv_auto_alloc_size = sizeof(struct sandbox_phy_priv),
104};