blob: 4dfdee60dccb23f454353453122c6b34dd1e4cd8 [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>
Marek Vasut01792852023-05-31 00:51:26 +020010#include <dm/device-internal.h>
11#include <dm/lists.h>
Michal Simek488eec52022-02-23 15:45:42 +010012#include <phy.h>
13#include <linux/delay.h>
14#include <asm/gpio.h>
15
16struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev,
Tom Rini6a25a7e2022-04-15 08:09:52 -040017 int phyaddr)
Michal Simek488eec52022-02-23 15:45:42 +010018{
19 struct phy_device *phydev;
20 struct ofnode_phandle_args phandle_args;
Marek Vasut01792852023-05-31 00:51:26 +020021 const char *node_name;
22 struct udevice *pdev;
Michal Simek488eec52022-02-23 15:45:42 +010023 u16 vendor, device;
Marek Vasutcf54eeb2024-03-18 15:57:01 +010024 ofnode node;
25 u32 id;
Michal Simek488eec52022-02-23 15:45:42 +010026 int ret;
27
28 if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
29 &phandle_args))
30 return NULL;
31
32 if (!ofnode_valid(phandle_args.node))
33 return NULL;
34
35 node = phandle_args.node;
36
37 ret = ofnode_read_eth_phy_id(node, &vendor, &device);
38 if (ret) {
T Karthik Reddy13f3fe32022-03-30 11:07:54 +020039 debug("Failed to read eth PHY id, err: %d\n", ret);
Michal Simek488eec52022-02-23 15:45:42 +010040 return NULL;
41 }
42
Marek Vasutcf54eeb2024-03-18 15:57:01 +010043 ret = phy_gpio_reset(dev);
44 if (ret)
45 return NULL;
Michal Simek488eec52022-02-23 15:45:42 +010046
Marek Vasut51a4b6f2024-01-28 02:19:40 +010047 if (phyaddr == -1)
48 phyaddr = ofnode_read_u32_default(phandle_args.node, "reg", -1);
49
Michal Simek488eec52022-02-23 15:45:42 +010050 id = vendor << 16 | device;
Tom Rini6a25a7e2022-04-15 08:09:52 -040051 phydev = phy_device_create(bus, phyaddr, id, false);
Michal Simek488eec52022-02-23 15:45:42 +010052 if (phydev)
53 phydev->node = node;
54
Marek Vasut01792852023-05-31 00:51:26 +020055 if (IS_ENABLED(CONFIG_DM_ETH_PHY) && ofnode_valid(node)) {
56 node_name = ofnode_get_name(node);
57 ret = device_bind_driver_to_node(dev, "eth_phy_generic_drv",
58 node_name, node,
59 &pdev);
60 if (ret)
61 return NULL;
62
63 ret = device_probe(pdev);
64 if (ret)
65 return NULL;
66 }
67
Michal Simek488eec52022-02-23 15:45:42 +010068 return phydev;
69}