Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 1 | // 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 Vasut | 0179285 | 2023-05-31 00:51:26 +0200 | [diff] [blame] | 10 | #include <dm/device-internal.h> |
| 11 | #include <dm/lists.h> |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 12 | #include <phy.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <asm/gpio.h> |
| 15 | |
| 16 | struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, |
Tom Rini | 6a25a7e | 2022-04-15 08:09:52 -0400 | [diff] [blame] | 17 | int phyaddr) |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 18 | { |
| 19 | struct phy_device *phydev; |
| 20 | struct ofnode_phandle_args phandle_args; |
Marek Vasut | 0179285 | 2023-05-31 00:51:26 +0200 | [diff] [blame] | 21 | const char *node_name; |
| 22 | struct udevice *pdev; |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 23 | u16 vendor, device; |
Marek Vasut | cf54eeb | 2024-03-18 15:57:01 +0100 | [diff] [blame] | 24 | ofnode node; |
| 25 | u32 id; |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 26 | 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 Reddy | 13f3fe3 | 2022-03-30 11:07:54 +0200 | [diff] [blame] | 39 | debug("Failed to read eth PHY id, err: %d\n", ret); |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 40 | return NULL; |
| 41 | } |
| 42 | |
Marek Vasut | cf54eeb | 2024-03-18 15:57:01 +0100 | [diff] [blame] | 43 | ret = phy_gpio_reset(dev); |
| 44 | if (ret) |
| 45 | return NULL; |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 46 | |
Marek Vasut | 51a4b6f | 2024-01-28 02:19:40 +0100 | [diff] [blame] | 47 | if (phyaddr == -1) |
| 48 | phyaddr = ofnode_read_u32_default(phandle_args.node, "reg", -1); |
| 49 | |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 50 | id = vendor << 16 | device; |
Tom Rini | 6a25a7e | 2022-04-15 08:09:52 -0400 | [diff] [blame] | 51 | phydev = phy_device_create(bus, phyaddr, id, false); |
Michal Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 52 | if (phydev) |
| 53 | phydev->node = node; |
| 54 | |
Marek Vasut | 0179285 | 2023-05-31 00:51:26 +0200 | [diff] [blame] | 55 | 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 Simek | 488eec5 | 2022-02-23 15:45:42 +0100 | [diff] [blame] | 68 | return phydev; |
| 69 | } |