aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/of_mdio.c
diff options
context:
space:
mode:
authorFlorian Fainelli <f.fainelli@gmail.com>2013-12-05 17:52:10 -0500
committerDavid S. Miller <davem@davemloft.net>2013-12-06 14:57:20 -0500
commit2e79cb303010d5d2b7810c11bc5d1f09a8500405 (patch)
treea9b60e33e1b7a90512fbf6eff3a663309827193c /drivers/of/of_mdio.c
parent9d2c881afd41c18a67fb04c4386bb6812898cbf3 (diff)
net: of_mdio: factor PHY registration from of_mdiobus_register
Since commit 779d835e ("net: of_mdio: scan mdiobus for PHYs without reg property") we have two foreach loops which do pretty much the same thing. Factor the PHY device registration in a function helper: of_mdiobus_register_phy() which takes care of the details and allows for future PHY specific extensions. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/of/of_mdio.c')
-rw-r--r--drivers/of/of_mdio.c109
1 files changed, 46 insertions, 63 deletions
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index d5a57a9e329c..82485d2dac89 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -22,6 +22,47 @@
22MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); 22MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
23MODULE_LICENSE("GPL"); 23MODULE_LICENSE("GPL");
24 24
25static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child,
26 u32 addr)
27{
28 struct phy_device *phy;
29 bool is_c45;
30 int rc;
31
32 is_c45 = of_device_is_compatible(child,
33 "ethernet-phy-ieee802.3-c45");
34
35 phy = get_phy_device(mdio, addr, is_c45);
36 if (!phy || IS_ERR(phy))
37 return 1;
38
39 if (mdio->irq) {
40 mdio->irq[addr] =
41 irq_of_parse_and_map(child, 0);
42 if (!mdio->irq[addr])
43 mdio->irq[addr] = PHY_POLL;
44 }
45
46 /* Associate the OF node with the device structure so it
47 * can be looked up later */
48 of_node_get(child);
49 phy->dev.of_node = child;
50
51 /* All data is now stored in the phy struct;
52 * register it */
53 rc = phy_device_register(phy);
54 if (rc) {
55 phy_device_free(phy);
56 of_node_put(child);
57 return 1;
58 }
59
60 dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
61 child->name, addr);
62
63 return 0;
64}
65
25/** 66/**
26 * of_mdiobus_register - Register mii_bus and create PHYs from the device tree 67 * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
27 * @mdio: pointer to mii_bus structure 68 * @mdio: pointer to mii_bus structure
@@ -32,11 +73,10 @@ MODULE_LICENSE("GPL");
32 */ 73 */
33int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) 74int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
34{ 75{
35 struct phy_device *phy;
36 struct device_node *child; 76 struct device_node *child;
37 const __be32 *paddr; 77 const __be32 *paddr;
38 u32 addr; 78 u32 addr;
39 bool is_c45, scanphys = false; 79 bool scanphys = false;
40 int rc, i, len; 80 int rc, i, len;
41 81
42 /* Mask out all PHYs from auto probing. Instead the PHYs listed in 82 /* Mask out all PHYs from auto probing. Instead the PHYs listed in
@@ -73,38 +113,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
73 continue; 113 continue;
74 } 114 }
75 115
76 if (mdio->irq) { 116 rc = of_mdiobus_register_phy(mdio, child, addr);
77 mdio->irq[addr] = irq_of_parse_and_map(child, 0); 117 if (rc)
78 if (!mdio->irq[addr])
79 mdio->irq[addr] = PHY_POLL;
80 }
81
82 is_c45 = of_device_is_compatible(child,
83 "ethernet-phy-ieee802.3-c45");
84 phy = get_phy_device(mdio, addr, is_c45);
85
86 if (!phy || IS_ERR(phy)) {
87 dev_err(&mdio->dev,
88 "cannot get PHY at address %i\n",
89 addr);
90 continue;
91 }
92
93 /* Associate the OF node with the device structure so it
94 * can be looked up later */
95 of_node_get(child);
96 phy->dev.of_node = child;
97
98 /* All data is now stored in the phy struct; register it */
99 rc = phy_device_register(phy);
100 if (rc) {
101 phy_device_free(phy);
102 of_node_put(child);
103 continue; 118 continue;
104 }
105
106 dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
107 child->name, addr);
108 } 119 }
109 120
110 if (!scanphys) 121 if (!scanphys)
@@ -117,9 +128,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
117 if (paddr) 128 if (paddr)
118 continue; 129 continue;
119 130
120 is_c45 = of_device_is_compatible(child,
121 "ethernet-phy-ieee802.3-c45");
122
123 for (addr = 0; addr < PHY_MAX_ADDR; addr++) { 131 for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
124 /* skip already registered PHYs */ 132 /* skip already registered PHYs */
125 if (mdio->phy_map[addr]) 133 if (mdio->phy_map[addr])
@@ -129,34 +137,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
129 dev_info(&mdio->dev, "scan phy %s at address %i\n", 137 dev_info(&mdio->dev, "scan phy %s at address %i\n",
130 child->name, addr); 138 child->name, addr);
131 139
132 phy = get_phy_device(mdio, addr, is_c45); 140 rc = of_mdiobus_register_phy(mdio, child, addr);
133 if (!phy || IS_ERR(phy)) 141 if (rc)
134 continue; 142 continue;
135
136 if (mdio->irq) {
137 mdio->irq[addr] =
138 irq_of_parse_and_map(child, 0);
139 if (!mdio->irq[addr])
140 mdio->irq[addr] = PHY_POLL;
141 }
142
143 /* Associate the OF node with the device structure so it
144 * can be looked up later */
145 of_node_get(child);
146 phy->dev.of_node = child;
147
148 /* All data is now stored in the phy struct;
149 * register it */
150 rc = phy_device_register(phy);
151 if (rc) {
152 phy_device_free(phy);
153 of_node_put(child);
154 continue;
155 }
156
157 dev_info(&mdio->dev, "registered phy %s at address %i\n",
158 child->name, addr);
159 break;
160 } 143 }
161 } 144 }
162 145