2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-07-24 13:18:15 +00:00
|
|
|
/*
|
2023-11-01 20:56:03 +00:00
|
|
|
* Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
|
2017-07-24 13:18:15 +00:00
|
|
|
* Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
|
|
|
|
*/
|
|
|
|
|
2020-10-15 10:05:58 +00:00
|
|
|
#include <clk.h>
|
2017-07-24 13:18:15 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <dm/device.h>
|
2020-10-15 10:05:58 +00:00
|
|
|
#include <dm/device_compat.h>
|
2017-07-24 13:18:15 +00:00
|
|
|
#include <generic-phy.h>
|
2022-01-29 13:27:47 +00:00
|
|
|
#include <asm-generic/gpio.h>
|
2017-07-24 13:18:15 +00:00
|
|
|
|
2020-10-15 10:05:58 +00:00
|
|
|
struct nop_phy_priv {
|
|
|
|
struct clk_bulk bulk;
|
2022-01-29 13:27:47 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
|
|
|
struct gpio_desc reset_gpio;
|
|
|
|
#endif
|
2020-10-15 10:05:58 +00:00
|
|
|
};
|
|
|
|
|
2022-01-29 13:27:47 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
|
|
|
static int nop_phy_reset(struct phy *phy)
|
|
|
|
{
|
|
|
|
struct nop_phy_priv *priv = dev_get_priv(phy->dev);
|
|
|
|
|
|
|
|
/* Return if there is no gpio since it's optional */
|
|
|
|
if (!dm_gpio_is_valid(&priv->reset_gpio))
|
|
|
|
return 0;
|
|
|
|
|
2022-02-19 23:08:43 +00:00
|
|
|
return dm_gpio_set_value(&priv->reset_gpio, true);
|
2022-01-29 13:27:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-10-15 10:05:58 +00:00
|
|
|
static int nop_phy_init(struct phy *phy)
|
|
|
|
{
|
|
|
|
struct nop_phy_priv *priv = dev_get_priv(phy->dev);
|
2022-01-29 13:27:47 +00:00
|
|
|
int ret = 0;
|
2020-10-15 10:05:58 +00:00
|
|
|
|
2022-01-29 13:27:47 +00:00
|
|
|
if (CONFIG_IS_ENABLED(CLK)) {
|
|
|
|
ret = clk_enable_bulk(&priv->bulk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-15 10:05:58 +00:00
|
|
|
|
2022-01-29 13:27:47 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
2022-02-19 23:08:43 +00:00
|
|
|
/* Take phy out of reset */
|
2022-02-28 22:53:21 +00:00
|
|
|
if (dm_gpio_is_valid(&priv->reset_gpio)) {
|
|
|
|
ret = dm_gpio_set_value(&priv->reset_gpio, false);
|
|
|
|
if (ret) {
|
|
|
|
if (CONFIG_IS_ENABLED(CLK))
|
|
|
|
clk_disable_bulk(&priv->bulk);
|
|
|
|
return ret;
|
|
|
|
}
|
2022-01-29 13:27:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-10-15 10:05:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nop_phy_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct nop_phy_priv *priv = dev_get_priv(dev);
|
2022-01-29 13:27:47 +00:00
|
|
|
int ret = 0;
|
2020-10-15 10:05:58 +00:00
|
|
|
|
|
|
|
if (CONFIG_IS_ENABLED(CLK)) {
|
|
|
|
ret = clk_get_bulk(dev, &priv->bulk);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "Failed to get clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2022-01-29 13:27:47 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
|
|
|
ret = gpio_request_by_name(dev, "reset-gpios", 0,
|
|
|
|
&priv->reset_gpio,
|
|
|
|
GPIOD_IS_OUT);
|
|
|
|
#endif
|
|
|
|
if (ret != -ENOENT)
|
|
|
|
return ret;
|
2020-10-15 10:05:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-24 13:18:15 +00:00
|
|
|
static const struct udevice_id nop_phy_ids[] = {
|
|
|
|
{ .compatible = "nop-phy" },
|
2021-03-31 09:21:07 +00:00
|
|
|
{ .compatible = "usb-nop-xceiv" },
|
2017-07-24 13:18:15 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct phy_ops nop_phy_ops = {
|
2020-10-15 10:05:58 +00:00
|
|
|
.init = nop_phy_init,
|
2022-01-29 13:27:47 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
|
|
|
.reset = nop_phy_reset,
|
|
|
|
#endif
|
2017-07-24 13:18:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(nop_phy) = {
|
|
|
|
.name = "nop_phy",
|
|
|
|
.id = UCLASS_PHY,
|
|
|
|
.of_match = nop_phy_ids,
|
|
|
|
.ops = &nop_phy_ops,
|
2020-10-15 10:05:58 +00:00
|
|
|
.probe = nop_phy_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct nop_phy_priv),
|
2017-07-24 13:18:15 +00:00
|
|
|
};
|