xref: /rk3399_rockchip-uboot/board/freescale/common/sgmii_riser.c (revision 7e91558032a0c1932dd7f4f562f9c7cc55efc496)
1 /*
2  * Freescale SGMII Riser Card
3  *
4  * This driver supports the SGMII Riser card found on the
5  * "DS" style of development board from Freescale.
6  *
7  * This software may be used and distributed according to the
8  * terms of the GNU Public License, Version 2, incorporated
9  * herein by reference.
10  *
11  * Copyright 2008 Freescale Semiconductor, Inc.
12  *
13  */
14 
15 #include <config.h>
16 #include <common.h>
17 #include <net.h>
18 #include <libfdt.h>
19 #include <tsec.h>
20 
21 void fsl_sgmii_riser_init(struct tsec_info_struct *tsec_info, int num)
22 {
23 	int i;
24 
25 	for (i = 0; i < num; i++)
26 		if (tsec_info[i].flags & TSEC_SGMII)
27 			tsec_info[i].phyaddr += SGMII_RISER_PHY_OFFSET;
28 }
29 
30 void fsl_sgmii_riser_fdt_fixup(void *fdt)
31 {
32 	struct eth_device *dev;
33 	int node;
34 	int i = -1;
35 	int etsec_num = 0;
36 
37 	node = fdt_path_offset(fdt, "/aliases");
38 	if (node < 0)
39 		return;
40 
41 	while ((dev = eth_get_dev_by_index(++i)) != NULL) {
42 		struct tsec_private *priv;
43 		int enet_node;
44 		char enet[16];
45 		const u32 *phyh;
46 		int phynode;
47 		const char *model;
48 		const char *path;
49 
50 		printf("Updating PHY address for %s\n", dev->name);
51 		if (!strstr(dev->name, "eTSEC"))
52 			continue;
53 
54 		sprintf(enet, "ethernet%d", etsec_num++);
55 		path = fdt_getprop(fdt, node, enet, NULL);
56 		if (!path) {
57 			debug("No alias for %s\n", enet);
58 			continue;
59 		}
60 
61 		enet_node = fdt_path_offset(fdt, path);
62 		if (enet_node < 0)
63 			continue;
64 
65 		model = fdt_getprop(fdt, enet_node, "model", NULL);
66 
67 		printf("%s's model is %s\n", enet, model);
68 		/*
69 		 * We only want to do this to eTSECs.  On some platforms
70 		 * there are more than one type of gianfar-style ethernet
71 		 * controller, and as we are creating an implicit connection
72 		 * between ethernet nodes and eTSEC devices, it is best to
73 		 * make the connection use as much explicit information
74 		 * as exists.
75 		 */
76 		if (!strstr(model, "TSEC"))
77 			continue;
78 
79 		phyh = fdt_getprop(fdt, enet_node, "phy-handle", NULL);
80 		if (!phyh)
81 			continue;
82 
83 		phynode = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*phyh));
84 
85 		priv = dev->priv;
86 
87 		printf("Device flags are %x\n", priv->flags);
88 		if (priv->flags & TSEC_SGMII)
89 			fdt_setprop_cell(fdt, phynode, "reg", priv->phyaddr);
90 	}
91 }
92