Lines Matching full:bus

2 /* MDIO Bus interface
83 if (mdiodev->bus->mdio_map[mdiodev->addr]) in mdiobus_register_device()
99 mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev; in mdiobus_register_device()
107 if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev) in mdiobus_unregister_device()
110 mdiodev->bus->mdio_map[mdiodev->addr] = NULL; in mdiobus_unregister_device()
116 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr) in mdiobus_get_phy() argument
118 struct mdio_device *mdiodev = bus->mdio_map[addr]; in mdiobus_get_phy()
130 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr) in mdiobus_is_registered_device() argument
132 return bus->mdio_map[addr]; in mdiobus_is_registered_device()
139 * If non-zero, then bus->priv is points to that memory.
141 * Description: called by a bus driver to allocate an mii_bus
146 struct mii_bus *bus; in mdiobus_alloc_size() local
147 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN); in mdiobus_alloc_size()
155 alloc_size = sizeof(*bus); in mdiobus_alloc_size()
157 bus = kzalloc(alloc_size, GFP_KERNEL); in mdiobus_alloc_size()
158 if (!bus) in mdiobus_alloc_size()
161 bus->state = MDIOBUS_ALLOCATED; in mdiobus_alloc_size()
163 bus->priv = (void *)bus + aligned_size; in mdiobus_alloc_size()
167 bus->irq[i] = PHY_POLL; in mdiobus_alloc_size()
169 return bus; in mdiobus_alloc_size()
204 struct mii_bus **ptr, *bus; in devm_mdiobus_alloc_size() local
211 bus = mdiobus_alloc_size(sizeof_priv); in devm_mdiobus_alloc_size()
212 if (bus) { in devm_mdiobus_alloc_size()
213 *ptr = bus; in devm_mdiobus_alloc_size()
219 return bus; in devm_mdiobus_alloc_size()
226 * @bus: the mii_bus associated with the device
230 void devm_mdiobus_free(struct device *dev, struct mii_bus *bus) in devm_mdiobus_free() argument
235 devm_mdiobus_match, bus); in devm_mdiobus_free()
249 struct mii_bus *bus = to_mii_bus(d); in mdiobus_release() local
250 BUG_ON(bus->state != MDIOBUS_RELEASED && in mdiobus_release()
252 bus->state != MDIOBUS_ALLOCATED); in mdiobus_release()
253 kfree(bus); in mdiobus_release()
268 * and this must be put once the bus is finished with.
287 /* Walk the list of subnodes of a mdio bus and look for a node that
293 static void of_mdiobus_link_mdiodev(struct mii_bus *bus, in of_mdiobus_link_mdiodev() argument
299 if (dev->of_node || !bus->dev.of_node) in of_mdiobus_link_mdiodev()
302 for_each_available_child_of_node(bus->dev.of_node, child) { in of_mdiobus_link_mdiodev()
326 * @bus: MDIO bus to create the devices on
331 static int mdiobus_create_device(struct mii_bus *bus, in mdiobus_create_device() argument
337 mdiodev = mdio_device_create(bus, bi->mdio_addr); in mdiobus_create_device()
354 * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
355 * @bus: target mii_bus
356 * @owner: module containing bus accessor functions
358 * Description: Called by a bus driver to bring up all the PHYs
359 * on a given bus, and attach them to the bus. Drivers should use
367 int __mdiobus_register(struct mii_bus *bus, struct module *owner) in __mdiobus_register() argument
373 if (NULL == bus || NULL == bus->name || in __mdiobus_register()
374 NULL == bus->read || NULL == bus->write) in __mdiobus_register()
377 BUG_ON(bus->state != MDIOBUS_ALLOCATED && in __mdiobus_register()
378 bus->state != MDIOBUS_UNREGISTERED); in __mdiobus_register()
380 bus->owner = owner; in __mdiobus_register()
381 bus->dev.parent = bus->parent; in __mdiobus_register()
382 bus->dev.class = &mdio_bus_class; in __mdiobus_register()
383 bus->dev.groups = NULL; in __mdiobus_register()
384 dev_set_name(&bus->dev, "%s", bus->id); in __mdiobus_register()
386 err = device_register(&bus->dev); in __mdiobus_register()
388 pr_err("mii_bus %s failed to register\n", bus->id); in __mdiobus_register()
392 mutex_init(&bus->mdio_lock); in __mdiobus_register()
394 /* de-assert bus level PHY GPIO reset */ in __mdiobus_register()
395 gpiod = devm_gpiod_get_optional(&bus->dev, "reset", GPIOD_OUT_LOW); in __mdiobus_register()
397 dev_err(&bus->dev, "mii_bus %s couldn't get reset GPIO\n", in __mdiobus_register()
398 bus->id); in __mdiobus_register()
399 device_del(&bus->dev); in __mdiobus_register()
402 bus->reset_gpiod = gpiod; in __mdiobus_register()
405 udelay(bus->reset_delay_us); in __mdiobus_register()
409 if (bus->reset) in __mdiobus_register()
410 bus->reset(bus); in __mdiobus_register()
413 if ((bus->phy_mask & (1 << i)) == 0) { in __mdiobus_register()
416 phydev = mdiobus_scan(bus, i); in __mdiobus_register()
424 mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device); in __mdiobus_register()
426 bus->state = MDIOBUS_REGISTERED; in __mdiobus_register()
427 pr_info("%s: probed\n", bus->name); in __mdiobus_register()
432 mdiodev = bus->mdio_map[i]; in __mdiobus_register()
441 if (bus->reset_gpiod) in __mdiobus_register()
442 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in __mdiobus_register()
444 device_del(&bus->dev); in __mdiobus_register()
449 void mdiobus_unregister(struct mii_bus *bus) in mdiobus_unregister() argument
454 BUG_ON(bus->state != MDIOBUS_REGISTERED); in mdiobus_unregister()
455 bus->state = MDIOBUS_UNREGISTERED; in mdiobus_unregister()
458 mdiodev = bus->mdio_map[i]; in mdiobus_unregister()
470 if (bus->reset_gpiod) in mdiobus_unregister()
471 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in mdiobus_unregister()
473 device_del(&bus->dev); in mdiobus_unregister()
479 * @bus: mii_bus to free
485 void mdiobus_free(struct mii_bus *bus) in mdiobus_free() argument
488 if (bus->state == MDIOBUS_ALLOCATED) { in mdiobus_free()
489 kfree(bus); in mdiobus_free()
493 BUG_ON(bus->state != MDIOBUS_UNREGISTERED); in mdiobus_free()
494 bus->state = MDIOBUS_RELEASED; in mdiobus_free()
496 put_device(&bus->dev); in mdiobus_free()
501 * mdiobus_scan - scan a bus for MDIO devices.
502 * @bus: mii_bus to scan
503 * @addr: address on bus to scan
505 * This function scans the MDIO bus, looking for devices which can be
512 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) in mdiobus_scan() argument
517 phydev = get_phy_device(bus, addr, false); in mdiobus_scan()
523 * in the bus node, and set the of_node pointer in this case. in mdiobus_scan()
525 of_mdiobus_link_mdiodev(bus, &phydev->mdio); in mdiobus_scan()
539 * @bus: the mii_bus struct
543 * Read a MDIO bus register. Caller must hold the mdio bus lock.
547 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in __mdiobus_read() argument
551 WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock)); in __mdiobus_read()
553 retval = bus->read(bus, addr, regnum); in __mdiobus_read()
555 trace_mdio_access(bus, 1, addr, regnum, retval, retval); in __mdiobus_read()
563 * @bus: the mii_bus struct
568 * Write a MDIO bus register. Caller must hold the mdio bus lock.
572 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in __mdiobus_write() argument
576 WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock)); in __mdiobus_write()
578 err = bus->write(bus, addr, regnum, val); in __mdiobus_write()
580 trace_mdio_access(bus, 0, addr, regnum, val, err); in __mdiobus_write()
588 * @bus: the mii_bus struct
592 * In case of nested MDIO bus access avoid lockdep false positives by
596 * because the bus read/write functions may wait for an interrupt
599 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read_nested() argument
605 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_read_nested()
606 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read_nested()
607 mutex_unlock(&bus->mdio_lock); in mdiobus_read_nested()
615 * @bus: the mii_bus struct
620 * because the bus read/write functions may wait for an interrupt
623 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read() argument
629 mutex_lock(&bus->mdio_lock); in mdiobus_read()
630 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read()
631 mutex_unlock(&bus->mdio_lock); in mdiobus_read()
639 * @bus: the mii_bus struct
644 * In case of nested MDIO bus access avoid lockdep false positives by
648 * because the bus read/write functions may wait for an interrupt
651 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write_nested() argument
657 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_write_nested()
658 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write_nested()
659 mutex_unlock(&bus->mdio_lock); in mdiobus_write_nested()
667 * @bus: the mii_bus struct
673 * because the bus read/write functions may wait for an interrupt
676 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write() argument
682 mutex_lock(&bus->mdio_lock); in mdiobus_write()
683 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write()
684 mutex_unlock(&bus->mdio_lock); in mdiobus_write()
759 MODULE_DESCRIPTION("MDIO bus/device layer");