blob: 650ecc7b44022a385bcbafe651db61cefe2899d0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming79ce05b2010-10-20 15:35:16 -05002/*
Shaohui Xie04643262015-10-26 19:47:54 +08003 * Copyright 2011-2015 Freescale Semiconductor, Inc.
Andy Fleming79ce05b2010-10-20 15:35:16 -05004 */
5
Masahiro Yamada75f82d02018-03-05 01:20:11 +09006#include <linux/libfdt.h>
7#include <linux/libfdt_env.h>
Andy Fleming79ce05b2010-10-20 15:35:16 -05008#include <fdt_support.h>
9
Timur Tabi7d6493a2012-08-14 06:47:23 +000010#include <fm_eth.h>
Shaohui Xie04643262015-10-26 19:47:54 +080011#ifdef CONFIG_FSL_LAYERSCAPE
12#include <asm/arch/fsl_serdes.h>
13#else
Timur Tabi7d6493a2012-08-14 06:47:23 +000014#include <asm/fsl_serdes.h>
Shaohui Xie04643262015-10-26 19:47:54 +080015#endif
Timur Tabi7d6493a2012-08-14 06:47:23 +000016
Andy Fleming79ce05b2010-10-20 15:35:16 -050017/*
18 * Given the following ...
19 *
20 * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
21 * compatible string and 'addr' physical address)
22 *
23 * 2) The name of an alias that points to the ethernet-phy node (usually inside
24 * a virtual MDIO node)
25 *
26 * ... update that Ethernet node's phy-handle property to point to the
27 * ethernet-phy node. This is how we link an Ethernet node to its PHY, so each
28 * PHY in a virtual MDIO node must have an alias.
Timur Tabi991d0e52012-05-04 12:21:28 +000029 *
30 * Returns 0 on success, or a negative FDT error code on error.
Andy Fleming79ce05b2010-10-20 15:35:16 -050031 */
Timur Tabi991d0e52012-05-04 12:21:28 +000032int fdt_set_phy_handle(void *fdt, char *compat, phys_addr_t addr,
Andy Fleming79ce05b2010-10-20 15:35:16 -050033 const char *alias)
34{
Timur Tabi991d0e52012-05-04 12:21:28 +000035 int offset;
36 unsigned int ph;
Andy Fleming79ce05b2010-10-20 15:35:16 -050037 const char *path;
38
39 /* Get a path to the node that 'alias' points to */
40 path = fdt_get_alias(fdt, alias);
Timur Tabi991d0e52012-05-04 12:21:28 +000041 if (!path)
42 return -FDT_ERR_BADPATH;
Andy Fleming79ce05b2010-10-20 15:35:16 -050043
Timur Tabi991d0e52012-05-04 12:21:28 +000044 /* Get the offset of that node */
45 offset = fdt_path_offset(fdt, path);
46 if (offset < 0)
47 return offset;
48
49 ph = fdt_create_phandle(fdt, offset);
50 if (!ph)
51 return -FDT_ERR_BADPHANDLE;
Andy Fleming79ce05b2010-10-20 15:35:16 -050052
Shaohui Xie368fa552015-11-10 19:20:16 +080053 ph = cpu_to_fdt32(ph);
54
Andy Fleming79ce05b2010-10-20 15:35:16 -050055 offset = fdt_node_offset_by_compat_reg(fdt, compat, addr);
Timur Tabi991d0e52012-05-04 12:21:28 +000056 if (offset < 0)
57 return offset;
58
59 return fdt_setprop(fdt, offset, "phy-handle", &ph, sizeof(ph));
Andy Fleming79ce05b2010-10-20 15:35:16 -050060}
Timur Tabi7d6493a2012-08-14 06:47:23 +000061
62/*
63 * Return the SerDes device enum for a given Fman port
64 *
65 * This function just maps the fm_port namespace to the srds_prtcl namespace.
66 */
67enum srds_prtcl serdes_device_from_fm_port(enum fm_port port)
68{
69 static const enum srds_prtcl srds_table[] = {
70 [FM1_DTSEC1] = SGMII_FM1_DTSEC1,
71 [FM1_DTSEC2] = SGMII_FM1_DTSEC2,
72 [FM1_DTSEC3] = SGMII_FM1_DTSEC3,
73 [FM1_DTSEC4] = SGMII_FM1_DTSEC4,
74 [FM1_DTSEC5] = SGMII_FM1_DTSEC5,
75 [FM1_10GEC1] = XAUI_FM1,
76 [FM2_DTSEC1] = SGMII_FM2_DTSEC1,
77 [FM2_DTSEC2] = SGMII_FM2_DTSEC2,
78 [FM2_DTSEC3] = SGMII_FM2_DTSEC3,
79 [FM2_DTSEC4] = SGMII_FM2_DTSEC4,
80 [FM2_DTSEC5] = SGMII_FM2_DTSEC5,
81 [FM2_10GEC1] = XAUI_FM2,
82 };
83
84 if ((port < FM1_DTSEC1) || (port > FM2_10GEC1))
85 return NONE;
86 else
87 return srds_table[port];
88}