MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_phy_device_create

Function rt_phy_device_create

components/drivers/phy/phy.c:276–313  ·  view source on GitHub ↗

* @brief create a phy device * * Creates a new PHY device based on the given bus, address, PHY ID, and whether Clause 45 is supported. * * @param bus the pointer to the bus * @param addr PHY device address * @param phy_id PHY device id * @param is_c45 if suport Clause 45 * * @return if create success return the phy device pointer,else return RT_NULL */

Source from the content-addressed store, hash-verified

274 * @return if create success return the phy device pointer,else return RT_NULL
275 */
276struct rt_phy_device *rt_phy_device_create(struct mii_bus *bus, int addr,
277 rt_uint32_t phy_id, rt_bool_t is_c45)
278{
279 struct rt_phy_device *dev = rt_malloc(sizeof(struct rt_phy_device));
280
281 if (!dev)
282 {
283 LOG_E("Failed to allocate PHY device for %s:%d\n",
284 bus ? bus->name : "(null bus)", addr);
285 return RT_NULL;
286 }
287
288 memset(dev, 0, sizeof(*dev));
289
290 dev->duplex = -1;
291 dev->link = 0;
292 dev->interface = RT_PHY_INTERFACE_MODE_NA;
293#ifdef RT_USING_OFW
294 dev->node = RT_NULL;
295#endif
296 dev->autoneg = RT_TRUE;
297
298 dev->addr = addr;
299 dev->phy_id = phy_id;
300 dev->is_c45 = is_c45;
301 dev->bus = bus;
302
303 if(rt_phy_device_register(dev))
304 {
305 LOG_D("register phy device filed")
306 }
307
308 if (addr >= 0 && addr < RT_PHY_MAX && phy_id != RT_PHY_FIXED_ID &&
309 phy_id != RT_PHY_NCSI_ID)
310 bus->phymap[addr] = dev;
311
312 return dev;
313}
314
315/**
316 * @brief get phy id

Callers 2

create_phy_by_maskFunction · 0.85
rt_ofw_create_phyFunction · 0.85

Calls 2

rt_mallocFunction · 0.85
rt_phy_device_registerFunction · 0.85

Tested by

no test coverage detected