blob: 358303108d8dc7531d55947377553efeee42a43b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming29156092010-10-20 15:35:16 -05002/*
Shaohui Xiee8297342015-10-26 19:47:54 +08003 * Copyright 2011-2015 Freescale Semiconductor, Inc.
Andy Fleming29156092010-10-20 15:35:16 -05004 */
5
6#include <common.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +09007#include <linux/libfdt.h>
8#include <linux/libfdt_env.h>
Andy Fleming29156092010-10-20 15:35:16 -05009#include <fdt_support.h>
10
Timur Tabi45b092d2012-08-14 06:47:23 +000011#include <fm_eth.h>
Shaohui Xiee8297342015-10-26 19:47:54 +080012#ifdef CONFIG_FSL_LAYERSCAPE
13#include <asm/arch/fsl_serdes.h>
14#else
Timur Tabi45b092d2012-08-14 06:47:23 +000015#include <asm/fsl_serdes.h>
Shaohui Xiee8297342015-10-26 19:47:54 +080016#endif
Timur Tabi45b092d2012-08-14 06:47:23 +000017
Andy Fleming29156092010-10-20 15:35:16 -050018/*
19 * Given the following ...
20 *
21 * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
22 * compatible string and 'addr' physical address)
23 *
24 * 2) The name of an alias that points to the ethernet-phy node (usually inside
25 * a virtual MDIO node)
26 *
27 * ... update that Ethernet node's phy-handle property to point to the
28 * ethernet-phy node. This is how we link an Ethernet node to its PHY, so each
29 * PHY in a virtual MDIO node must have an alias.
Timur Tabi1fc0d592012-05-04 12:21:28 +000030 *
31 * Returns 0 on success, or a negative FDT error code on error.
Andy Fleming29156092010-10-20 15:35:16 -050032 */
Timur Tabi1fc0d592012-05-04 12:21:28 +000033int fdt_set_phy_handle(void *fdt, char *compat, phys_addr_t addr,
Andy Fleming29156092010-10-20 15:35:16 -050034 const char *alias)
35{
Timur Tabi1fc0d592012-05-04 12:21:28 +000036 int offset;
37 unsigned int ph;
Andy Fleming29156092010-10-20 15:35:16 -050038 const char *path;
39
40 /* Get a path to the node that 'alias' points to */
41 path = fdt_get_alias(fdt, alias);
Timur Tabi1fc0d592012-05-04 12:21:28 +000042 if (!path)
43 return -FDT_ERR_BADPATH;
Andy Fleming29156092010-10-20 15:35:16 -050044
Timur Tabi1fc0d592012-05-04 12:21:28 +000045 /* Get the offset of that node */
46 offset = fdt_path_offset(fdt, path);
47 if (offset < 0)
48 return offset;
49
50 ph = fdt_create_phandle(fdt, offset);
51 if (!ph)
52 return -FDT_ERR_BADPHANDLE;
Andy Fleming29156092010-10-20 15:35:16 -050053
Shaohui Xie1aaf3f92015-11-10 19:20:16 +080054 ph = cpu_to_fdt32(ph);
55
Andy Fleming29156092010-10-20 15:35:16 -050056 offset = fdt_node_offset_by_compat_reg(fdt, compat, addr);
Timur Tabi1fc0d592012-05-04 12:21:28 +000057 if (offset < 0)
58 return offset;
59
60 return fdt_setprop(fdt, offset, "phy-handle", &ph, sizeof(ph));
Andy Fleming29156092010-10-20 15:35:16 -050061}
Timur Tabi45b092d2012-08-14 06:47:23 +000062
63/*
64 * Return the SerDes device enum for a given Fman port
65 *
66 * This function just maps the fm_port namespace to the srds_prtcl namespace.
67 */
68enum srds_prtcl serdes_device_from_fm_port(enum fm_port port)
69{
70 static const enum srds_prtcl srds_table[] = {
71 [FM1_DTSEC1] = SGMII_FM1_DTSEC1,
72 [FM1_DTSEC2] = SGMII_FM1_DTSEC2,
73 [FM1_DTSEC3] = SGMII_FM1_DTSEC3,
74 [FM1_DTSEC4] = SGMII_FM1_DTSEC4,
75 [FM1_DTSEC5] = SGMII_FM1_DTSEC5,
76 [FM1_10GEC1] = XAUI_FM1,
77 [FM2_DTSEC1] = SGMII_FM2_DTSEC1,
78 [FM2_DTSEC2] = SGMII_FM2_DTSEC2,
79 [FM2_DTSEC3] = SGMII_FM2_DTSEC3,
80 [FM2_DTSEC4] = SGMII_FM2_DTSEC4,
81 [FM2_DTSEC5] = SGMII_FM2_DTSEC5,
82 [FM2_10GEC1] = XAUI_FM2,
83 };
84
85 if ((port < FM1_DTSEC1) || (port > FM2_10GEC1))
86 return NONE;
87 else
88 return srds_table[port];
89}