blob: 7054b440347ce677c48d14e0af5ddd52e71dc3d3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Heikki Krogerus723487a2015-05-13 15:26:52 +03002#include <linux/phy/phy.h>
3
4/**
5 * Helper that registers PHY for a ULPI device and adds a lookup for binding it
6 * and it's controller, which is always the parent.
7 */
8static inline struct phy
Axel Lin42ad8f62015-06-05 08:27:03 +08009*ulpi_phy_create(struct ulpi *ulpi, const struct phy_ops *ops)
Heikki Krogerus723487a2015-05-13 15:26:52 +030010{
11 struct phy *phy;
12 int ret;
13
14 phy = phy_create(&ulpi->dev, NULL, ops);
15 if (IS_ERR(phy))
16 return phy;
17
18 ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));
19 if (ret) {
20 phy_destroy(phy);
21 return ERR_PTR(ret);
22 }
23
24 return phy;
25}
26
27/* Remove a PHY that was created with ulpi_phy_create() and it's lookup. */
28static inline void ulpi_phy_destroy(struct ulpi *ulpi, struct phy *phy)
29{
30 phy_remove_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));
31 phy_destroy(phy);
32}