blob: c53e3216d0fd6182c48191a48834a6900af6f7ee [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/*
Nishanth Menoneaa39c62023-11-01 15:56:03 -05003 * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +02004 * 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 */
Tim Harveyb8a2b002022-02-28 14:53:21 -080048 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 }
Adam Forda59a8cb2022-01-29 07:27:47 -060055 }
56#endif
Peng Fan259029f2020-10-15 18:05:58 +080057 return 0;
58}
59
60static int nop_phy_probe(struct udevice *dev)
61{
62 struct nop_phy_priv *priv = dev_get_priv(dev);
Adam Forda59a8cb2022-01-29 07:27:47 -060063 int ret = 0;
Peng Fan259029f2020-10-15 18:05:58 +080064
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 }
Adam Forda59a8cb2022-01-29 07:27:47 -060072#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;
Peng Fan259029f2020-10-15 18:05:58 +080079
80 return 0;
81}
82
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020083static const struct udevice_id nop_phy_ids[] = {
84 { .compatible = "nop-phy" },
Marek Vasuta4a1cb42021-03-31 11:21:07 +020085 { .compatible = "usb-nop-xceiv" },
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020086 { }
87};
88
89static struct phy_ops nop_phy_ops = {
Peng Fan259029f2020-10-15 18:05:58 +080090 .init = nop_phy_init,
Adam Forda59a8cb2022-01-29 07:27:47 -060091#if CONFIG_IS_ENABLED(DM_GPIO)
92 .reset = nop_phy_reset,
93#endif
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020094};
95
96U_BOOT_DRIVER(nop_phy) = {
97 .name = "nop_phy",
98 .id = UCLASS_PHY,
99 .of_match = nop_phy_ids,
100 .ops = &nop_phy_ops,
Peng Fan259029f2020-10-15 18:05:58 +0800101 .probe = nop_phy_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700102 .priv_auto = sizeof(struct nop_phy_priv),
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +0200103};