blob: 286171cba76a26bc3092f5b2c490b4a3ad6ab77c [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 <dm.h>
9#include <dm/device.h>
Peng Fan259029f2020-10-15 18:05:58 +080010#include <dm/device_compat.h>
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020011#include <generic-phy.h>
Adam Forda59a8cb2022-01-29 07:27:47 -060012#include <asm-generic/gpio.h>
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020013
Peng Fan259029f2020-10-15 18:05:58 +080014struct nop_phy_priv {
15 struct clk_bulk bulk;
Adam Forda59a8cb2022-01-29 07:27:47 -060016#if CONFIG_IS_ENABLED(DM_GPIO)
17 struct gpio_desc reset_gpio;
18#endif
Peng Fan259029f2020-10-15 18:05:58 +080019};
20
Adam Forda59a8cb2022-01-29 07:27:47 -060021#if CONFIG_IS_ENABLED(DM_GPIO)
22static int nop_phy_reset(struct phy *phy)
23{
24 struct nop_phy_priv *priv = dev_get_priv(phy->dev);
25
26 /* Return if there is no gpio since it's optional */
27 if (!dm_gpio_is_valid(&priv->reset_gpio))
28 return 0;
29
Adam Ford35b82a82022-02-19 17:08:43 -060030 return dm_gpio_set_value(&priv->reset_gpio, true);
Adam Forda59a8cb2022-01-29 07:27:47 -060031}
32#endif
33
Peng Fan259029f2020-10-15 18:05:58 +080034static int nop_phy_init(struct phy *phy)
35{
36 struct nop_phy_priv *priv = dev_get_priv(phy->dev);
Adam Forda59a8cb2022-01-29 07:27:47 -060037 int ret = 0;
Peng Fan259029f2020-10-15 18:05:58 +080038
Adam Forda59a8cb2022-01-29 07:27:47 -060039 if (CONFIG_IS_ENABLED(CLK)) {
40 ret = clk_enable_bulk(&priv->bulk);
41 if (ret)
42 return ret;
43 }
Peng Fan259029f2020-10-15 18:05:58 +080044
Adam Forda59a8cb2022-01-29 07:27:47 -060045#if CONFIG_IS_ENABLED(DM_GPIO)
Adam Ford35b82a82022-02-19 17:08:43 -060046 /* Take phy out of reset */
Tim Harveyb8a2b002022-02-28 14:53:21 -080047 if (dm_gpio_is_valid(&priv->reset_gpio)) {
48 ret = dm_gpio_set_value(&priv->reset_gpio, false);
49 if (ret) {
50 if (CONFIG_IS_ENABLED(CLK))
51 clk_disable_bulk(&priv->bulk);
52 return ret;
53 }
Adam Forda59a8cb2022-01-29 07:27:47 -060054 }
55#endif
Peng Fan259029f2020-10-15 18:05:58 +080056 return 0;
57}
58
59static int nop_phy_probe(struct udevice *dev)
60{
61 struct nop_phy_priv *priv = dev_get_priv(dev);
Adam Forda59a8cb2022-01-29 07:27:47 -060062 int ret = 0;
Peng Fan259029f2020-10-15 18:05:58 +080063
64 if (CONFIG_IS_ENABLED(CLK)) {
65 ret = clk_get_bulk(dev, &priv->bulk);
66 if (ret < 0) {
67 dev_err(dev, "Failed to get clk: %d\n", ret);
68 return ret;
69 }
70 }
Adam Forda59a8cb2022-01-29 07:27:47 -060071#if CONFIG_IS_ENABLED(DM_GPIO)
72 ret = gpio_request_by_name(dev, "reset-gpios", 0,
73 &priv->reset_gpio,
74 GPIOD_IS_OUT);
75#endif
76 if (ret != -ENOENT)
77 return ret;
Peng Fan259029f2020-10-15 18:05:58 +080078
79 return 0;
80}
81
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020082static const struct udevice_id nop_phy_ids[] = {
83 { .compatible = "nop-phy" },
Marek Vasuta4a1cb42021-03-31 11:21:07 +020084 { .compatible = "usb-nop-xceiv" },
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020085 { }
86};
87
88static struct phy_ops nop_phy_ops = {
Peng Fan259029f2020-10-15 18:05:58 +080089 .init = nop_phy_init,
Adam Forda59a8cb2022-01-29 07:27:47 -060090#if CONFIG_IS_ENABLED(DM_GPIO)
91 .reset = nop_phy_reset,
92#endif
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +020093};
94
95U_BOOT_DRIVER(nop_phy) = {
96 .name = "nop_phy",
97 .id = UCLASS_PHY,
98 .of_match = nop_phy_ids,
99 .ops = &nop_phy_ops,
Peng Fan259029f2020-10-15 18:05:58 +0800100 .probe = nop_phy_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700101 .priv_auto = sizeof(struct nop_phy_priv),
Jean-Jacques Hiblotc2da3e32017-07-24 15:18:15 +0200102};