blob: e2ee6e92068e9c8031297a350a629104575a3d4f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +02002/*
3 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +02005 */
6
Peng Fan259029f2020-10-15 18:05:58 +08007#include <clk.h>
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +02008#include <common.h>
9#include <dm.h>
10#include <dm/device.h>
Peng Fan259029f2020-10-15 18:05:58 +080011#include <dm/device_compat.h>
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020012#include <generic-phy.h>
Adam Forda59a8cb2022-01-29 07:27:47 -060013#include <asm-generic/gpio.h>
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020014
Peng Fan259029f2020-10-15 18:05:58 +080015struct nop_phy_priv {
16 struct clk_bulk bulk;
Adam Forda59a8cb2022-01-29 07:27:47 -060017#if CONFIG_IS_ENABLED(DM_GPIO)
18 struct gpio_desc reset_gpio;
19#endif
Peng Fan259029f2020-10-15 18:05:58 +080020};
21
Adam Forda59a8cb2022-01-29 07:27:47 -060022#if CONFIG_IS_ENABLED(DM_GPIO)
23static 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
Adam Ford35b82a82022-02-19 17:08:43 -060031 return dm_gpio_set_value(&priv->reset_gpio, true);
Adam Forda59a8cb2022-01-29 07:27:47 -060032}
33#endif
34
Peng Fan259029f2020-10-15 18:05:58 +080035static int nop_phy_init(struct phy *phy)
36{
37 struct nop_phy_priv *priv = dev_get_priv(phy->dev);
Adam Forda59a8cb2022-01-29 07:27:47 -060038 int ret = 0;
Peng Fan259029f2020-10-15 18:05:58 +080039
Adam Forda59a8cb2022-01-29 07:27:47 -060040 if (CONFIG_IS_ENABLED(CLK)) {
41 ret = clk_enable_bulk(&priv->bulk);
42 if (ret)
43 return ret;
44 }
Peng Fan259029f2020-10-15 18:05:58 +080045
Adam Forda59a8cb2022-01-29 07:27:47 -060046#if CONFIG_IS_ENABLED(DM_GPIO)
Adam Ford35b82a82022-02-19 17:08:43 -060047 /* Take phy out of reset */
48 ret = dm_gpio_set_value(&priv->reset_gpio, false);
Adam Forda59a8cb2022-01-29 07:27:47 -060049 if (ret) {
50 if (CONFIG_IS_ENABLED(CLK))
51 clk_disable_bulk(&priv->bulk);
52 return ret;
53 }
54#endif
Peng Fan259029f2020-10-15 18:05:58 +080055 return 0;
56}
57
58static int nop_phy_probe(struct udevice *dev)
59{
60 struct nop_phy_priv *priv = dev_get_priv(dev);
Adam Forda59a8cb2022-01-29 07:27:47 -060061 int ret = 0;
Peng Fan259029f2020-10-15 18:05:58 +080062
63 if (CONFIG_IS_ENABLED(CLK)) {
64 ret = clk_get_bulk(dev, &priv->bulk);
65 if (ret < 0) {
66 dev_err(dev, "Failed to get clk: %d\n", ret);
67 return ret;
68 }
69 }
Adam Forda59a8cb2022-01-29 07:27:47 -060070#if CONFIG_IS_ENABLED(DM_GPIO)
71 ret = gpio_request_by_name(dev, "reset-gpios", 0,
72 &priv->reset_gpio,
73 GPIOD_IS_OUT);
74#endif
75 if (ret != -ENOENT)
76 return ret;
Peng Fan259029f2020-10-15 18:05:58 +080077
78 return 0;
79}
80
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020081static const struct udevice_id nop_phy_ids[] = {
82 { .compatible = "nop-phy" },
Marek Vasuta4a1cb42021-03-31 11:21:07 +020083 { .compatible = "usb-nop-xceiv" },
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020084 { }
85};
86
87static struct phy_ops nop_phy_ops = {
Peng Fan259029f2020-10-15 18:05:58 +080088 .init = nop_phy_init,
Adam Forda59a8cb2022-01-29 07:27:47 -060089#if CONFIG_IS_ENABLED(DM_GPIO)
90 .reset = nop_phy_reset,
91#endif
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020092};
93
94U_BOOT_DRIVER(nop_phy) = {
95 .name = "nop_phy",
96 .id = UCLASS_PHY,
97 .of_match = nop_phy_ids,
98 .ops = &nop_phy_ops,
Peng Fan259029f2020-10-15 18:05:58 +080099 .probe = nop_phy_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700100 .priv_auto = sizeof(struct nop_phy_priv),
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +0200101};