blob: aeacb91bc13875c2e874d205c8b2ab4742a3cb18 [file] [log] [blame]
Andy Fleming3d19fad2008-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 Flemingacaccae2008-12-05 20:10:22 -060017#include <net.h>
18#include <libfdt.h>
Andy Fleming3d19fad2008-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 Flemingacaccae2008-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
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}