2022-02-23 14:45:42 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Xilinx ethernet phy reset driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Xilinx, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm/device_compat.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
|
|
|
struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev,
|
2022-04-15 12:09:52 +00:00
|
|
|
int phyaddr)
|
2022-02-23 14:45:42 +00:00
|
|
|
{
|
|
|
|
struct phy_device *phydev;
|
|
|
|
struct ofnode_phandle_args phandle_args;
|
|
|
|
struct gpio_desc gpio;
|
|
|
|
ofnode node;
|
|
|
|
u32 id, assert, deassert;
|
|
|
|
u16 vendor, device;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
|
|
|
|
&phandle_args))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!ofnode_valid(phandle_args.node))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
node = phandle_args.node;
|
|
|
|
|
|
|
|
ret = ofnode_read_eth_phy_id(node, &vendor, &device);
|
|
|
|
if (ret) {
|
2022-03-30 09:07:54 +00:00
|
|
|
debug("Failed to read eth PHY id, err: %d\n", ret);
|
2022-02-23 14:45:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-03-30 09:07:54 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_DM_ETH_PHY)) {
|
|
|
|
ret = gpio_request_by_name_nodev(node, "reset-gpios", 0, &gpio,
|
|
|
|
GPIOD_ACTIVE_LOW);
|
|
|
|
if (!ret) {
|
|
|
|
assert = ofnode_read_u32_default(node,
|
|
|
|
"reset-assert-us", 0);
|
|
|
|
deassert = ofnode_read_u32_default(node,
|
|
|
|
"reset-deassert-us",
|
|
|
|
0);
|
|
|
|
ret = dm_gpio_set_value(&gpio, 1);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev,
|
|
|
|
"Failed assert gpio, err: %d\n", ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-02-23 14:45:42 +00:00
|
|
|
|
2022-03-30 09:07:54 +00:00
|
|
|
udelay(assert);
|
2022-02-23 14:45:42 +00:00
|
|
|
|
2022-03-30 09:07:54 +00:00
|
|
|
ret = dm_gpio_set_value(&gpio, 0);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev,
|
|
|
|
"Failed deassert gpio, err: %d\n",
|
|
|
|
ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-02-23 14:45:42 +00:00
|
|
|
|
2022-03-30 09:07:54 +00:00
|
|
|
udelay(deassert);
|
|
|
|
}
|
2022-02-23 14:45:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
id = vendor << 16 | device;
|
2022-04-15 12:09:52 +00:00
|
|
|
phydev = phy_device_create(bus, phyaddr, id, false);
|
2022-02-23 14:45:42 +00:00
|
|
|
if (phydev)
|
|
|
|
phydev->node = node;
|
|
|
|
|
|
|
|
return phydev;
|
|
|
|
}
|