Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ |
| 4 | * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 7 | #include <clk.h> |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <dm/device.h> |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 11 | #include <dm/device_compat.h> |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 12 | #include <generic-phy.h> |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 13 | #include <asm-generic/gpio.h> |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 14 | |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 15 | struct nop_phy_priv { |
| 16 | struct clk_bulk bulk; |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 17 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 18 | struct gpio_desc reset_gpio; |
| 19 | #endif |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 20 | }; |
| 21 | |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 22 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 23 | static 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 | |
| 31 | return dm_gpio_set_value(&priv->reset_gpio, false); |
| 32 | } |
| 33 | #endif |
| 34 | |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 35 | static int nop_phy_init(struct phy *phy) |
| 36 | { |
| 37 | struct nop_phy_priv *priv = dev_get_priv(phy->dev); |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 38 | int ret = 0; |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 39 | |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 40 | if (CONFIG_IS_ENABLED(CLK)) { |
| 41 | ret = clk_enable_bulk(&priv->bulk); |
| 42 | if (ret) |
| 43 | return ret; |
| 44 | } |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 45 | |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 46 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 47 | ret = nop_phy_reset(phy); |
| 48 | if (ret) { |
| 49 | if (CONFIG_IS_ENABLED(CLK)) |
| 50 | clk_disable_bulk(&priv->bulk); |
| 51 | return ret; |
| 52 | } |
| 53 | #endif |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int nop_phy_probe(struct udevice *dev) |
| 58 | { |
| 59 | struct nop_phy_priv *priv = dev_get_priv(dev); |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 60 | int ret = 0; |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 61 | |
| 62 | if (CONFIG_IS_ENABLED(CLK)) { |
| 63 | ret = clk_get_bulk(dev, &priv->bulk); |
| 64 | if (ret < 0) { |
| 65 | dev_err(dev, "Failed to get clk: %d\n", ret); |
| 66 | return ret; |
| 67 | } |
| 68 | } |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 69 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 70 | ret = gpio_request_by_name(dev, "reset-gpios", 0, |
| 71 | &priv->reset_gpio, |
| 72 | GPIOD_IS_OUT); |
| 73 | #endif |
| 74 | if (ret != -ENOENT) |
| 75 | return ret; |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 80 | static const struct udevice_id nop_phy_ids[] = { |
| 81 | { .compatible = "nop-phy" }, |
Marek Vasut | 1220aa9 | 2021-03-31 11:21:07 +0200 | [diff] [blame] | 82 | { .compatible = "usb-nop-xceiv" }, |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 83 | { } |
| 84 | }; |
| 85 | |
| 86 | static struct phy_ops nop_phy_ops = { |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 87 | .init = nop_phy_init, |
Adam Ford | 3970c82 | 2022-01-29 07:27:47 -0600 | [diff] [blame] | 88 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 89 | .reset = nop_phy_reset, |
| 90 | #endif |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | U_BOOT_DRIVER(nop_phy) = { |
| 94 | .name = "nop_phy", |
| 95 | .id = UCLASS_PHY, |
| 96 | .of_match = nop_phy_ids, |
| 97 | .ops = &nop_phy_ops, |
Peng Fan | 62ee957 | 2020-10-15 18:05:58 +0800 | [diff] [blame] | 98 | .probe = nop_phy_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 99 | .priv_auto = sizeof(struct nop_phy_priv), |
Jean-Jacques Hiblot | 3b63db3 | 2017-07-24 15:18:15 +0200 | [diff] [blame] | 100 | }; |