xref: /openbmc/u-boot/board/freescale/common/fman.c (revision 8495faf5)
1 /*
2  * Copyright 2011 Freescale Semiconductor, Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22 
23 #include <common.h>
24 #include <libfdt.h>
25 #include <libfdt_env.h>
26 #include <fdt_support.h>
27 
28 #include <fm_eth.h>
29 #include <asm/fsl_serdes.h>
30 
31 /*
32  * Given the following ...
33  *
34  * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
35  * compatible string and 'addr' physical address)
36  *
37  * 2) The name of an alias that points to the ethernet-phy node (usually inside
38  * a virtual MDIO node)
39  *
40  * ... update that Ethernet node's phy-handle property to point to the
41  * ethernet-phy node.  This is how we link an Ethernet node to its PHY, so each
42  * PHY in a virtual MDIO node must have an alias.
43  *
44  * Returns 0 on success, or a negative FDT error code on error.
45  */
46 int fdt_set_phy_handle(void *fdt, char *compat, phys_addr_t addr,
47 			const char *alias)
48 {
49 	int offset;
50 	unsigned int ph;
51 	const char *path;
52 
53 	/* Get a path to the node that 'alias' points to */
54 	path = fdt_get_alias(fdt, alias);
55 	if (!path)
56 		return -FDT_ERR_BADPATH;
57 
58 	/* Get the offset of that node */
59 	offset = fdt_path_offset(fdt, path);
60 	if (offset < 0)
61 		return offset;
62 
63 	ph = fdt_create_phandle(fdt, offset);
64 	if (!ph)
65 		return -FDT_ERR_BADPHANDLE;
66 
67 	offset = fdt_node_offset_by_compat_reg(fdt, compat, addr);
68 	if (offset < 0)
69 		return offset;
70 
71 	return fdt_setprop(fdt, offset, "phy-handle", &ph, sizeof(ph));
72 }
73 
74 /*
75  * Return the SerDes device enum for a given Fman port
76  *
77  * This function just maps the fm_port namespace to the srds_prtcl namespace.
78  */
79 enum srds_prtcl serdes_device_from_fm_port(enum fm_port port)
80 {
81 	static const enum srds_prtcl srds_table[] = {
82 		[FM1_DTSEC1] = SGMII_FM1_DTSEC1,
83 		[FM1_DTSEC2] = SGMII_FM1_DTSEC2,
84 		[FM1_DTSEC3] = SGMII_FM1_DTSEC3,
85 		[FM1_DTSEC4] = SGMII_FM1_DTSEC4,
86 		[FM1_DTSEC5] = SGMII_FM1_DTSEC5,
87 		[FM1_10GEC1] = XAUI_FM1,
88 		[FM2_DTSEC1] = SGMII_FM2_DTSEC1,
89 		[FM2_DTSEC2] = SGMII_FM2_DTSEC2,
90 		[FM2_DTSEC3] = SGMII_FM2_DTSEC3,
91 		[FM2_DTSEC4] = SGMII_FM2_DTSEC4,
92 		[FM2_DTSEC5] = SGMII_FM2_DTSEC5,
93 		[FM2_10GEC1] = XAUI_FM2,
94 	};
95 
96 	if ((port < FM1_DTSEC1) || (port > FM2_10GEC1))
97 		return NONE;
98 	else
99 		return srds_table[port];
100 }
101