blob: 5617ac3ad62f681081b8acd82b17e72493b1d126 [file] [log] [blame]
Michal Simek488eec52022-02-23 15:45:42 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Xilinx ethernet phy reset driver
4 *
5 * Copyright (C) 2022 Xilinx, Inc.
6 */
7
8#include <common.h>
9#include <dm/device_compat.h>
10#include <phy.h>
11#include <linux/delay.h>
12#include <asm/gpio.h>
13
14struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev,
15 phy_interface_t interface)
16{
17 struct phy_device *phydev;
18 struct ofnode_phandle_args phandle_args;
19 struct gpio_desc gpio;
20 ofnode node;
21 u32 id, assert, deassert;
22 u16 vendor, device;
23 int ret;
24
25 if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
26 &phandle_args))
27 return NULL;
28
29 if (!ofnode_valid(phandle_args.node))
30 return NULL;
31
32 node = phandle_args.node;
33
34 ret = ofnode_read_eth_phy_id(node, &vendor, &device);
35 if (ret) {
36 dev_err(dev, "Failed to read eth PHY id, err: %d\n", ret);
37 return NULL;
38 }
39
40 ret = gpio_request_by_name_nodev(node, "reset-gpios", 0, &gpio,
41 GPIOD_ACTIVE_LOW);
42 if (!ret) {
43 assert = ofnode_read_u32_default(node, "reset-assert-us", 0);
44 deassert = ofnode_read_u32_default(node,
45 "reset-deassert-us", 0);
46 ret = dm_gpio_set_value(&gpio, 1);
47 if (ret) {
48 dev_err(dev, "Failed assert gpio, err: %d\n", ret);
49 return NULL;
50 }
51
52 udelay(assert);
53
54 ret = dm_gpio_set_value(&gpio, 0);
55 if (ret) {
56 dev_err(dev, "Failed deassert gpio, err: %d\n", ret);
57 return NULL;
58 }
59
60 udelay(deassert);
61 }
62
63 id = vendor << 16 | device;
64 phydev = phy_device_create(bus, 0, id, false, interface);
65 if (phydev)
66 phydev->node = node;
67
68 return phydev;
69}