blob: 4f40a1d6d44679c116acd391bf466e31bfbafa69 [file] [log] [blame]
Andy Fleming652f7c22008-08-31 16:33:28 -05001/*
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>
Andy Flemingfeede8b2008-12-05 20:10:22 -060017#include <net.h>
18#include <libfdt.h>
Andy Fleming652f7c22008-08-31 16:33:28 -050019#include <tsec.h>
20
21void 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}
Andy Flemingfeede8b2008-12-05 20:10:22 -060029
30void 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
Andy Flemingfeede8b2008-12-05 20:10:22 -060050 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
Andy Flemingfeede8b2008-12-05 20:10:22 -060066 /*
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
Andy Flemingfeede8b2008-12-05 20:10:22 -060085 if (priv->flags & TSEC_SGMII)
86 fdt_setprop_cell(fdt, phynode, "reg", priv->phyaddr);
87 }
88}