Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <libfdt.h> |
| 9 | #include <libfdt_env.h> |
| 10 | #include <fdt_support.h> |
| 11 | |
Timur Tabi | 45b092d | 2012-08-14 06:47:23 +0000 | [diff] [blame] | 12 | #include <fm_eth.h> |
| 13 | #include <asm/fsl_serdes.h> |
| 14 | |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 15 | /* |
| 16 | * Given the following ... |
| 17 | * |
| 18 | * 1) A pointer to an Fman Ethernet node (as identified by the 'compat' |
| 19 | * compatible string and 'addr' physical address) |
| 20 | * |
| 21 | * 2) The name of an alias that points to the ethernet-phy node (usually inside |
| 22 | * a virtual MDIO node) |
| 23 | * |
| 24 | * ... update that Ethernet node's phy-handle property to point to the |
| 25 | * ethernet-phy node. This is how we link an Ethernet node to its PHY, so each |
| 26 | * PHY in a virtual MDIO node must have an alias. |
Timur Tabi | 1fc0d59 | 2012-05-04 12:21:28 +0000 | [diff] [blame] | 27 | * |
| 28 | * Returns 0 on success, or a negative FDT error code on error. |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 29 | */ |
Timur Tabi | 1fc0d59 | 2012-05-04 12:21:28 +0000 | [diff] [blame] | 30 | int fdt_set_phy_handle(void *fdt, char *compat, phys_addr_t addr, |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 31 | const char *alias) |
| 32 | { |
Timur Tabi | 1fc0d59 | 2012-05-04 12:21:28 +0000 | [diff] [blame] | 33 | int offset; |
| 34 | unsigned int ph; |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 35 | const char *path; |
| 36 | |
| 37 | /* Get a path to the node that 'alias' points to */ |
| 38 | path = fdt_get_alias(fdt, alias); |
Timur Tabi | 1fc0d59 | 2012-05-04 12:21:28 +0000 | [diff] [blame] | 39 | if (!path) |
| 40 | return -FDT_ERR_BADPATH; |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 41 | |
Timur Tabi | 1fc0d59 | 2012-05-04 12:21:28 +0000 | [diff] [blame] | 42 | /* Get the offset of that node */ |
| 43 | offset = fdt_path_offset(fdt, path); |
| 44 | if (offset < 0) |
| 45 | return offset; |
| 46 | |
| 47 | ph = fdt_create_phandle(fdt, offset); |
| 48 | if (!ph) |
| 49 | return -FDT_ERR_BADPHANDLE; |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 50 | |
| 51 | offset = fdt_node_offset_by_compat_reg(fdt, compat, addr); |
Timur Tabi | 1fc0d59 | 2012-05-04 12:21:28 +0000 | [diff] [blame] | 52 | if (offset < 0) |
| 53 | return offset; |
| 54 | |
| 55 | return fdt_setprop(fdt, offset, "phy-handle", &ph, sizeof(ph)); |
Andy Fleming | 2915609 | 2010-10-20 15:35:16 -0500 | [diff] [blame] | 56 | } |
Timur Tabi | 45b092d | 2012-08-14 06:47:23 +0000 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * Return the SerDes device enum for a given Fman port |
| 60 | * |
| 61 | * This function just maps the fm_port namespace to the srds_prtcl namespace. |
| 62 | */ |
| 63 | enum srds_prtcl serdes_device_from_fm_port(enum fm_port port) |
| 64 | { |
| 65 | static const enum srds_prtcl srds_table[] = { |
| 66 | [FM1_DTSEC1] = SGMII_FM1_DTSEC1, |
| 67 | [FM1_DTSEC2] = SGMII_FM1_DTSEC2, |
| 68 | [FM1_DTSEC3] = SGMII_FM1_DTSEC3, |
| 69 | [FM1_DTSEC4] = SGMII_FM1_DTSEC4, |
| 70 | [FM1_DTSEC5] = SGMII_FM1_DTSEC5, |
| 71 | [FM1_10GEC1] = XAUI_FM1, |
| 72 | [FM2_DTSEC1] = SGMII_FM2_DTSEC1, |
| 73 | [FM2_DTSEC2] = SGMII_FM2_DTSEC2, |
| 74 | [FM2_DTSEC3] = SGMII_FM2_DTSEC3, |
| 75 | [FM2_DTSEC4] = SGMII_FM2_DTSEC4, |
| 76 | [FM2_DTSEC5] = SGMII_FM2_DTSEC5, |
| 77 | [FM2_10GEC1] = XAUI_FM2, |
| 78 | }; |
| 79 | |
| 80 | if ((port < FM1_DTSEC1) || (port > FM2_10GEC1)) |
| 81 | return NONE; |
| 82 | else |
| 83 | return srds_table[port]; |
| 84 | } |