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 		if (!strstr(dev->name, "eTSEC"))
51 			continue;
52 
53 		sprintf(enet, "ethernet%d", etsec_num++);
54 		path = fdt_getprop(fdt, node, enet, NULL);
55 		if (!path) {
56 			debug("No alias for %s\n", enet);
57 			continue;
58 		}
59 
60 		enet_node = fdt_path_offset(fdt, path);
61 		if (enet_node < 0)
62 			continue;
63 
64 		model = fdt_getprop(fdt, enet_node, "model", NULL);
65 
66 		/*
67 		 * We only want to do this to eTSECs.  On some platforms
68 		 * there are more than one type of gianfar-style ethernet
69 		 * controller, and as we are creating an implicit connection
70 		 * between ethernet nodes and eTSEC devices, it is best to
71 		 * make the connection use as much explicit information
72 		 * as exists.
73 		 */
74 		if (!strstr(model, "TSEC"))
75 			continue;
76 
77 		phyh = fdt_getprop(fdt, enet_node, "phy-handle", NULL);
78 		if (!phyh)
79 			continue;
80 
81 		phynode = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*phyh));
82 
83 		priv = dev->priv;
84 
85 		if (priv->flags & TSEC_SGMII)
86 			fdt_setprop_cell(fdt, phynode, "reg", priv->phyaddr);
87 	}
88 }
89