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