]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
3b63db37 | 2 | /* |
a94a4071 | 3 | * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/ |
3b63db37 | 4 | * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> |
3b63db37 JJH |
5 | */ |
6 | ||
62ee9576 | 7 | #include <clk.h> |
d678a59d | 8 | #include <common.h> |
3b63db37 JJH |
9 | #include <dm.h> |
10 | #include <dm/device.h> | |
62ee9576 | 11 | #include <dm/device_compat.h> |
3b63db37 | 12 | #include <generic-phy.h> |
3970c82a | 13 | #include <asm-generic/gpio.h> |
3b63db37 | 14 | |
62ee9576 PF |
15 | struct nop_phy_priv { |
16 | struct clk_bulk bulk; | |
3970c82a AF |
17 | #if CONFIG_IS_ENABLED(DM_GPIO) |
18 | struct gpio_desc reset_gpio; | |
19 | #endif | |
62ee9576 PF |
20 | }; |
21 | ||
3970c82a AF |
22 | #if CONFIG_IS_ENABLED(DM_GPIO) |
23 | static int nop_phy_reset(struct phy *phy) | |
24 | { | |
25 | struct nop_phy_priv *priv = dev_get_priv(phy->dev); | |
26 | ||
27 | /* Return if there is no gpio since it's optional */ | |
28 | if (!dm_gpio_is_valid(&priv->reset_gpio)) | |
29 | return 0; | |
30 | ||
f9852acd | 31 | return dm_gpio_set_value(&priv->reset_gpio, true); |
3970c82a AF |
32 | } |
33 | #endif | |
34 | ||
62ee9576 PF |
35 | static int nop_phy_init(struct phy *phy) |
36 | { | |
37 | struct nop_phy_priv *priv = dev_get_priv(phy->dev); | |
3970c82a | 38 | int ret = 0; |
62ee9576 | 39 | |
3970c82a AF |
40 | if (CONFIG_IS_ENABLED(CLK)) { |
41 | ret = clk_enable_bulk(&priv->bulk); | |
42 | if (ret) | |
43 | return ret; | |
44 | } | |
62ee9576 | 45 | |
3970c82a | 46 | #if CONFIG_IS_ENABLED(DM_GPIO) |
f9852acd | 47 | /* Take phy out of reset */ |
a41b88ec TH |
48 | if (dm_gpio_is_valid(&priv->reset_gpio)) { |
49 | ret = dm_gpio_set_value(&priv->reset_gpio, false); | |
50 | if (ret) { | |
51 | if (CONFIG_IS_ENABLED(CLK)) | |
52 | clk_disable_bulk(&priv->bulk); | |
53 | return ret; | |
54 | } | |
3970c82a AF |
55 | } |
56 | #endif | |
62ee9576 PF |
57 | return 0; |
58 | } | |
59 | ||
60 | static int nop_phy_probe(struct udevice *dev) | |
61 | { | |
62 | struct nop_phy_priv *priv = dev_get_priv(dev); | |
3970c82a | 63 | int ret = 0; |
62ee9576 PF |
64 | |
65 | if (CONFIG_IS_ENABLED(CLK)) { | |
66 | ret = clk_get_bulk(dev, &priv->bulk); | |
67 | if (ret < 0) { | |
68 | dev_err(dev, "Failed to get clk: %d\n", ret); | |
69 | return ret; | |
70 | } | |
71 | } | |
3970c82a AF |
72 | #if CONFIG_IS_ENABLED(DM_GPIO) |
73 | ret = gpio_request_by_name(dev, "reset-gpios", 0, | |
74 | &priv->reset_gpio, | |
75 | GPIOD_IS_OUT); | |
76 | #endif | |
77 | if (ret != -ENOENT) | |
78 | return ret; | |
62ee9576 PF |
79 | |
80 | return 0; | |
81 | } | |
82 | ||
3b63db37 JJH |
83 | static const struct udevice_id nop_phy_ids[] = { |
84 | { .compatible = "nop-phy" }, | |
1220aa9a | 85 | { .compatible = "usb-nop-xceiv" }, |
3b63db37 JJH |
86 | { } |
87 | }; | |
88 | ||
89 | static struct phy_ops nop_phy_ops = { | |
62ee9576 | 90 | .init = nop_phy_init, |
3970c82a AF |
91 | #if CONFIG_IS_ENABLED(DM_GPIO) |
92 | .reset = nop_phy_reset, | |
93 | #endif | |
3b63db37 JJH |
94 | }; |
95 | ||
96 | U_BOOT_DRIVER(nop_phy) = { | |
97 | .name = "nop_phy", | |
98 | .id = UCLASS_PHY, | |
99 | .of_match = nop_phy_ids, | |
100 | .ops = &nop_phy_ops, | |
62ee9576 | 101 | .probe = nop_phy_probe, |
41575d8e | 102 | .priv_auto = sizeof(struct nop_phy_priv), |
3b63db37 | 103 | }; |