]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/phy/phy-uclass.c
d8b8d58e44f30d8f1cbc4423f7542f343a5c6ff2
2 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
3 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <generic-phy.h>
12 DECLARE_GLOBAL_DATA_PTR
;
14 static inline struct phy_ops
*phy_dev_ops(struct udevice
*dev
)
16 return (struct phy_ops
*)dev
->driver
->ops
;
19 static int generic_phy_xlate_offs_flags(struct phy
*phy
,
20 struct ofnode_phandle_args
*args
)
22 debug("%s(phy=%p)\n", __func__
, phy
);
24 if (args
->args_count
> 1) {
25 debug("Invaild args_count: %d\n", args
->args_count
);
30 phy
->id
= args
->args
[0];
37 int generic_phy_get_by_index(struct udevice
*dev
, int index
,
40 struct ofnode_phandle_args args
;
43 struct udevice
*phydev
;
45 debug("%s(dev=%p, index=%d, phy=%p)\n", __func__
, dev
, index
, phy
);
48 ret
= dev_read_phandle_with_args(dev
, "phys", "#phy-cells", 0, index
,
51 debug("%s: dev_read_phandle_with_args failed: err=%d\n",
56 ret
= uclass_get_device_by_ofnode(UCLASS_PHY
, args
.node
, &phydev
);
58 debug("%s: uclass_get_device_by_ofnode failed: err=%d\n",
65 ops
= phy_dev_ops(phydev
);
68 ret
= ops
->of_xlate(phy
, &args
);
70 ret
= generic_phy_xlate_offs_flags(phy
, &args
);
72 debug("of_xlate() failed: %d\n", ret
);
82 int generic_phy_get_by_name(struct udevice
*dev
, const char *phy_name
,
87 debug("%s(dev=%p, name=%s, phy=%p)\n", __func__
, dev
, phy_name
, phy
);
89 index
= dev_read_stringlist_search(dev
, "phy-names", phy_name
);
91 debug("dev_read_stringlist_search() failed: %d\n", index
);
95 return generic_phy_get_by_index(dev
, index
, phy
);
98 int generic_phy_init(struct phy
*phy
)
100 struct phy_ops
const *ops
= phy_dev_ops(phy
->dev
);
102 return ops
->init
? ops
->init(phy
) : 0;
105 int generic_phy_reset(struct phy
*phy
)
107 struct phy_ops
const *ops
= phy_dev_ops(phy
->dev
);
109 return ops
->reset
? ops
->reset(phy
) : 0;
112 int generic_phy_exit(struct phy
*phy
)
114 struct phy_ops
const *ops
= phy_dev_ops(phy
->dev
);
116 return ops
->exit
? ops
->exit(phy
) : 0;
119 int generic_phy_power_on(struct phy
*phy
)
121 struct phy_ops
const *ops
= phy_dev_ops(phy
->dev
);
123 return ops
->power_on
? ops
->power_on(phy
) : 0;
126 int generic_phy_power_off(struct phy
*phy
)
128 struct phy_ops
const *ops
= phy_dev_ops(phy
->dev
);
130 return ops
->power_off
? ops
->power_off(phy
) : 0;
133 UCLASS_DRIVER(phy
) = {