Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 2 | /* |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 3 | * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/ |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 4 | * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 7 | #include <clk.h> |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <dm/device.h> |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 10 | #include <dm/device_compat.h> |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 11 | #include <generic-phy.h> |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 12 | #include <asm-generic/gpio.h> |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 13 | |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 14 | struct nop_phy_priv { |
| 15 | struct clk_bulk bulk; |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 16 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 17 | struct gpio_desc reset_gpio; |
| 18 | #endif |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 19 | }; |
| 20 | |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 21 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 22 | static 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 Ford | 35b82a8 | 2022-02-19 17:08:43 -0600 | [diff] [blame] | 30 | return dm_gpio_set_value(&priv->reset_gpio, true); |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 31 | } |
| 32 | #endif |
| 33 | |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 34 | static int nop_phy_init(struct phy *phy) |
| 35 | { |
| 36 | struct nop_phy_priv *priv = dev_get_priv(phy->dev); |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 37 | int ret = 0; |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 38 | |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 39 | if (CONFIG_IS_ENABLED(CLK)) { |
| 40 | ret = clk_enable_bulk(&priv->bulk); |
| 41 | if (ret) |
| 42 | return ret; |
| 43 | } |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 44 | |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 45 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Adam Ford | 35b82a8 | 2022-02-19 17:08:43 -0600 | [diff] [blame] | 46 | /* Take phy out of reset */ |
Tim Harvey | b8a2b00 | 2022-02-28 14:53:21 -0800 | [diff] [blame] | 47 | 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 Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 54 | } |
| 55 | #endif |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int nop_phy_probe(struct udevice *dev) |
| 60 | { |
| 61 | struct nop_phy_priv *priv = dev_get_priv(dev); |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 62 | int ret = 0; |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 63 | |
| 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 Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 71 | #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 Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 82 | static const struct udevice_id nop_phy_ids[] = { |
| 83 | { .compatible = "nop-phy" }, |
Marek Vasut | a4a1cb4 | 2021-03-31 11:21:07 +0200 | [diff] [blame] | 84 | { .compatible = "usb-nop-xceiv" }, |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 85 | { } |
| 86 | }; |
| 87 | |
| 88 | static struct phy_ops nop_phy_ops = { |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 89 | .init = nop_phy_init, |
Adam Ford | a59a8cb | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 90 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 91 | .reset = nop_phy_reset, |
| 92 | #endif |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | U_BOOT_DRIVER(nop_phy) = { |
| 96 | .name = "nop_phy", |
| 97 | .id = UCLASS_PHY, |
| 98 | .of_match = nop_phy_ids, |
| 99 | .ops = &nop_phy_ops, |
Peng Fan | 259029f | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 100 | .probe = nop_phy_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 101 | .priv_auto = sizeof(struct nop_phy_priv), |
Jean-Jacques Hiblot | c2da3e3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 102 | }; |