Commit e5c7d1f669806289e121b9ac3535e8f6de594b8e

Authored by Baruch Siach
Committed by Rob Herring
1 parent d022bbc712

of/mdio: fix fixed link bus name

Since 9e6c643b (phy/fixed: use an unique MDIO bus name) the name of the fixed
PHY bus is "fixed-0". Teach of_phy_connect_fixed_link() the new name.

Tested on a P1020RDB PowerPC system.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Acked-by: Florian Fainelli <florian@openwrt.org>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

drivers/of/of_mdio.c
1 /* 1 /*
2 * OF helpers for the MDIO (Ethernet PHY) API 2 * OF helpers for the MDIO (Ethernet PHY) API
3 * 3 *
4 * Copyright (c) 2009 Secret Lab Technologies, Ltd. 4 * Copyright (c) 2009 Secret Lab Technologies, Ltd.
5 * 5 *
6 * This file is released under the GPLv2 6 * This file is released under the GPLv2
7 * 7 *
8 * This file provides helper functions for extracting PHY device information 8 * This file provides helper functions for extracting PHY device information
9 * out of the OpenFirmware device tree and using it to populate an mii_bus. 9 * out of the OpenFirmware device tree and using it to populate an mii_bus.
10 */ 10 */
11 11
12 #include <linux/kernel.h> 12 #include <linux/kernel.h>
13 #include <linux/device.h> 13 #include <linux/device.h>
14 #include <linux/netdevice.h> 14 #include <linux/netdevice.h>
15 #include <linux/err.h> 15 #include <linux/err.h>
16 #include <linux/phy.h> 16 #include <linux/phy.h>
17 #include <linux/of.h> 17 #include <linux/of.h>
18 #include <linux/of_irq.h> 18 #include <linux/of_irq.h>
19 #include <linux/of_mdio.h> 19 #include <linux/of_mdio.h>
20 #include <linux/module.h> 20 #include <linux/module.h>
21 21
22 MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); 22 MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
23 MODULE_LICENSE("GPL"); 23 MODULE_LICENSE("GPL");
24 24
25 /** 25 /**
26 * of_mdiobus_register - Register mii_bus and create PHYs from the device tree 26 * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
27 * @mdio: pointer to mii_bus structure 27 * @mdio: pointer to mii_bus structure
28 * @np: pointer to device_node of MDIO bus. 28 * @np: pointer to device_node of MDIO bus.
29 * 29 *
30 * This function registers the mii_bus structure and registers a phy_device 30 * This function registers the mii_bus structure and registers a phy_device
31 * for each child node of @np. 31 * for each child node of @np.
32 */ 32 */
33 int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) 33 int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
34 { 34 {
35 struct phy_device *phy; 35 struct phy_device *phy;
36 struct device_node *child; 36 struct device_node *child;
37 int rc, i; 37 int rc, i;
38 38
39 /* Mask out all PHYs from auto probing. Instead the PHYs listed in 39 /* Mask out all PHYs from auto probing. Instead the PHYs listed in
40 * the device tree are populated after the bus has been registered */ 40 * the device tree are populated after the bus has been registered */
41 mdio->phy_mask = ~0; 41 mdio->phy_mask = ~0;
42 42
43 /* Clear all the IRQ properties */ 43 /* Clear all the IRQ properties */
44 if (mdio->irq) 44 if (mdio->irq)
45 for (i=0; i<PHY_MAX_ADDR; i++) 45 for (i=0; i<PHY_MAX_ADDR; i++)
46 mdio->irq[i] = PHY_POLL; 46 mdio->irq[i] = PHY_POLL;
47 47
48 /* Register the MDIO bus */ 48 /* Register the MDIO bus */
49 rc = mdiobus_register(mdio); 49 rc = mdiobus_register(mdio);
50 if (rc) 50 if (rc)
51 return rc; 51 return rc;
52 52
53 /* Loop over the child nodes and register a phy_device for each one */ 53 /* Loop over the child nodes and register a phy_device for each one */
54 for_each_child_of_node(np, child) { 54 for_each_child_of_node(np, child) {
55 const __be32 *paddr; 55 const __be32 *paddr;
56 u32 addr; 56 u32 addr;
57 int len; 57 int len;
58 58
59 /* A PHY must have a reg property in the range [0-31] */ 59 /* A PHY must have a reg property in the range [0-31] */
60 paddr = of_get_property(child, "reg", &len); 60 paddr = of_get_property(child, "reg", &len);
61 if (!paddr || len < sizeof(*paddr)) { 61 if (!paddr || len < sizeof(*paddr)) {
62 dev_err(&mdio->dev, "%s has invalid PHY address\n", 62 dev_err(&mdio->dev, "%s has invalid PHY address\n",
63 child->full_name); 63 child->full_name);
64 continue; 64 continue;
65 } 65 }
66 66
67 addr = be32_to_cpup(paddr); 67 addr = be32_to_cpup(paddr);
68 if (addr >= 32) { 68 if (addr >= 32) {
69 dev_err(&mdio->dev, "%s PHY address %i is too large\n", 69 dev_err(&mdio->dev, "%s PHY address %i is too large\n",
70 child->full_name, addr); 70 child->full_name, addr);
71 continue; 71 continue;
72 } 72 }
73 73
74 if (mdio->irq) { 74 if (mdio->irq) {
75 mdio->irq[addr] = irq_of_parse_and_map(child, 0); 75 mdio->irq[addr] = irq_of_parse_and_map(child, 0);
76 if (!mdio->irq[addr]) 76 if (!mdio->irq[addr])
77 mdio->irq[addr] = PHY_POLL; 77 mdio->irq[addr] = PHY_POLL;
78 } 78 }
79 79
80 phy = get_phy_device(mdio, addr); 80 phy = get_phy_device(mdio, addr);
81 if (!phy || IS_ERR(phy)) { 81 if (!phy || IS_ERR(phy)) {
82 dev_err(&mdio->dev, "error probing PHY at address %i\n", 82 dev_err(&mdio->dev, "error probing PHY at address %i\n",
83 addr); 83 addr);
84 continue; 84 continue;
85 } 85 }
86 86
87 /* Associate the OF node with the device structure so it 87 /* Associate the OF node with the device structure so it
88 * can be looked up later */ 88 * can be looked up later */
89 of_node_get(child); 89 of_node_get(child);
90 phy->dev.of_node = child; 90 phy->dev.of_node = child;
91 91
92 /* All data is now stored in the phy struct; register it */ 92 /* All data is now stored in the phy struct; register it */
93 rc = phy_device_register(phy); 93 rc = phy_device_register(phy);
94 if (rc) { 94 if (rc) {
95 phy_device_free(phy); 95 phy_device_free(phy);
96 of_node_put(child); 96 of_node_put(child);
97 continue; 97 continue;
98 } 98 }
99 99
100 dev_dbg(&mdio->dev, "registered phy %s at address %i\n", 100 dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
101 child->name, addr); 101 child->name, addr);
102 } 102 }
103 103
104 return 0; 104 return 0;
105 } 105 }
106 EXPORT_SYMBOL(of_mdiobus_register); 106 EXPORT_SYMBOL(of_mdiobus_register);
107 107
108 /* Helper function for of_phy_find_device */ 108 /* Helper function for of_phy_find_device */
109 static int of_phy_match(struct device *dev, void *phy_np) 109 static int of_phy_match(struct device *dev, void *phy_np)
110 { 110 {
111 return dev->of_node == phy_np; 111 return dev->of_node == phy_np;
112 } 112 }
113 113
114 /** 114 /**
115 * of_phy_find_device - Give a PHY node, find the phy_device 115 * of_phy_find_device - Give a PHY node, find the phy_device
116 * @phy_np: Pointer to the phy's device tree node 116 * @phy_np: Pointer to the phy's device tree node
117 * 117 *
118 * Returns a pointer to the phy_device. 118 * Returns a pointer to the phy_device.
119 */ 119 */
120 struct phy_device *of_phy_find_device(struct device_node *phy_np) 120 struct phy_device *of_phy_find_device(struct device_node *phy_np)
121 { 121 {
122 struct device *d; 122 struct device *d;
123 if (!phy_np) 123 if (!phy_np)
124 return NULL; 124 return NULL;
125 125
126 d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match); 126 d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
127 return d ? to_phy_device(d) : NULL; 127 return d ? to_phy_device(d) : NULL;
128 } 128 }
129 EXPORT_SYMBOL(of_phy_find_device); 129 EXPORT_SYMBOL(of_phy_find_device);
130 130
131 /** 131 /**
132 * of_phy_connect - Connect to the phy described in the device tree 132 * of_phy_connect - Connect to the phy described in the device tree
133 * @dev: pointer to net_device claiming the phy 133 * @dev: pointer to net_device claiming the phy
134 * @phy_np: Pointer to device tree node for the PHY 134 * @phy_np: Pointer to device tree node for the PHY
135 * @hndlr: Link state callback for the network device 135 * @hndlr: Link state callback for the network device
136 * @iface: PHY data interface type 136 * @iface: PHY data interface type
137 * 137 *
138 * Returns a pointer to the phy_device if successful. NULL otherwise 138 * Returns a pointer to the phy_device if successful. NULL otherwise
139 */ 139 */
140 struct phy_device *of_phy_connect(struct net_device *dev, 140 struct phy_device *of_phy_connect(struct net_device *dev,
141 struct device_node *phy_np, 141 struct device_node *phy_np,
142 void (*hndlr)(struct net_device *), u32 flags, 142 void (*hndlr)(struct net_device *), u32 flags,
143 phy_interface_t iface) 143 phy_interface_t iface)
144 { 144 {
145 struct phy_device *phy = of_phy_find_device(phy_np); 145 struct phy_device *phy = of_phy_find_device(phy_np);
146 146
147 if (!phy) 147 if (!phy)
148 return NULL; 148 return NULL;
149 149
150 return phy_connect_direct(dev, phy, hndlr, flags, iface) ? NULL : phy; 150 return phy_connect_direct(dev, phy, hndlr, flags, iface) ? NULL : phy;
151 } 151 }
152 EXPORT_SYMBOL(of_phy_connect); 152 EXPORT_SYMBOL(of_phy_connect);
153 153
154 /** 154 /**
155 * of_phy_connect_fixed_link - Parse fixed-link property and return a dummy phy 155 * of_phy_connect_fixed_link - Parse fixed-link property and return a dummy phy
156 * @dev: pointer to net_device claiming the phy 156 * @dev: pointer to net_device claiming the phy
157 * @hndlr: Link state callback for the network device 157 * @hndlr: Link state callback for the network device
158 * @iface: PHY data interface type 158 * @iface: PHY data interface type
159 * 159 *
160 * This function is a temporary stop-gap and will be removed soon. It is 160 * This function is a temporary stop-gap and will be removed soon. It is
161 * only to support the fs_enet, ucc_geth and gianfar Ethernet drivers. Do 161 * only to support the fs_enet, ucc_geth and gianfar Ethernet drivers. Do
162 * not call this function from new drivers. 162 * not call this function from new drivers.
163 */ 163 */
164 struct phy_device *of_phy_connect_fixed_link(struct net_device *dev, 164 struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
165 void (*hndlr)(struct net_device *), 165 void (*hndlr)(struct net_device *),
166 phy_interface_t iface) 166 phy_interface_t iface)
167 { 167 {
168 struct device_node *net_np; 168 struct device_node *net_np;
169 char bus_id[MII_BUS_ID_SIZE + 3]; 169 char bus_id[MII_BUS_ID_SIZE + 3];
170 struct phy_device *phy; 170 struct phy_device *phy;
171 const __be32 *phy_id; 171 const __be32 *phy_id;
172 int sz; 172 int sz;
173 173
174 if (!dev->dev.parent) 174 if (!dev->dev.parent)
175 return NULL; 175 return NULL;
176 176
177 net_np = dev->dev.parent->of_node; 177 net_np = dev->dev.parent->of_node;
178 if (!net_np) 178 if (!net_np)
179 return NULL; 179 return NULL;
180 180
181 phy_id = of_get_property(net_np, "fixed-link", &sz); 181 phy_id = of_get_property(net_np, "fixed-link", &sz);
182 if (!phy_id || sz < sizeof(*phy_id)) 182 if (!phy_id || sz < sizeof(*phy_id))
183 return NULL; 183 return NULL;
184 184
185 sprintf(bus_id, PHY_ID_FMT, "0", be32_to_cpu(phy_id[0])); 185 sprintf(bus_id, PHY_ID_FMT, "fixed-0", be32_to_cpu(phy_id[0]));
186 186
187 phy = phy_connect(dev, bus_id, hndlr, 0, iface); 187 phy = phy_connect(dev, bus_id, hndlr, 0, iface);
188 return IS_ERR(phy) ? NULL : phy; 188 return IS_ERR(phy) ? NULL : phy;
189 } 189 }
190 EXPORT_SYMBOL(of_phy_connect_fixed_link); 190 EXPORT_SYMBOL(of_phy_connect_fixed_link);
191 191