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