Lines Matching full:bus
2 /* MDIO Bus interface
74 if (mdiodev->bus->mdio_map[mdiodev->addr]) in mdiobus_register_device()
90 mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev; in mdiobus_register_device()
98 if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev) in mdiobus_unregister_device()
103 mdiodev->bus->mdio_map[mdiodev->addr] = NULL; in mdiobus_unregister_device()
109 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr) in mdiobus_get_phy() argument
111 struct mdio_device *mdiodev = bus->mdio_map[addr]; in mdiobus_get_phy()
123 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr) in mdiobus_is_registered_device() argument
125 return bus->mdio_map[addr]; in mdiobus_is_registered_device()
132 * If non-zero, then bus->priv is points to that memory.
134 * Description: called by a bus driver to allocate an mii_bus
139 struct mii_bus *bus; in mdiobus_alloc_size() local
140 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN); in mdiobus_alloc_size()
148 alloc_size = sizeof(*bus); in mdiobus_alloc_size()
150 bus = kzalloc(alloc_size, GFP_KERNEL); in mdiobus_alloc_size()
151 if (!bus) in mdiobus_alloc_size()
154 bus->state = MDIOBUS_ALLOCATED; in mdiobus_alloc_size()
156 bus->priv = (void *)bus + aligned_size; in mdiobus_alloc_size()
160 bus->irq[i] = PHY_POLL; in mdiobus_alloc_size()
161 u64_stats_init(&bus->stats[i].syncp); in mdiobus_alloc_size()
164 return bus; in mdiobus_alloc_size()
177 struct mii_bus *bus = to_mii_bus(d); in mdiobus_release() local
178 BUG_ON(bus->state != MDIOBUS_RELEASED && in mdiobus_release()
180 bus->state != MDIOBUS_ALLOCATED); in mdiobus_release()
181 kfree(bus); in mdiobus_release()
203 static u64 mdio_bus_get_global_stat(struct mii_bus *bus, unsigned int offset) in mdio_bus_get_global_stat() argument
209 val += mdio_bus_get_stat(&bus->stats[i], offset); in mdio_bus_get_global_stat()
218 struct mii_bus *bus = to_mii_bus(dev); in mdio_bus_stat_field_show() local
227 val = mdio_bus_get_global_stat(bus, sattr->field_offset); in mdio_bus_stat_field_show()
229 val = mdio_bus_get_stat(&bus->stats[sattr->addr], in mdio_bus_stat_field_show()
240 struct mii_bus *bus = mdiodev->bus; in mdio_bus_device_stat_field_show() local
249 val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset); in mdio_bus_device_stat_field_show()
401 * and this must be put_deviced'ed once the bus is finished with.
419 * and this must be put once the bus is finished with.
438 /* Walk the list of subnodes of a mdio bus and look for a node that
444 static void of_mdiobus_link_mdiodev(struct mii_bus *bus, in of_mdiobus_link_mdiodev() argument
450 if (dev->of_node || !bus->dev.of_node) in of_mdiobus_link_mdiodev()
453 for_each_available_child_of_node(bus->dev.of_node, child) { in of_mdiobus_link_mdiodev()
477 * @bus: MDIO bus to create the devices on
482 static int mdiobus_create_device(struct mii_bus *bus, in mdiobus_create_device() argument
488 mdiodev = mdio_device_create(bus, bi->mdio_addr); in mdiobus_create_device()
505 * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
506 * @bus: target mii_bus
507 * @owner: module containing bus accessor functions
509 * Description: Called by a bus driver to bring up all the PHYs
510 * on a given bus, and attach them to the bus. Drivers should use
518 int __mdiobus_register(struct mii_bus *bus, struct module *owner) in __mdiobus_register() argument
524 if (NULL == bus || NULL == bus->name || in __mdiobus_register()
525 NULL == bus->read || NULL == bus->write) in __mdiobus_register()
528 BUG_ON(bus->state != MDIOBUS_ALLOCATED && in __mdiobus_register()
529 bus->state != MDIOBUS_UNREGISTERED); in __mdiobus_register()
531 bus->owner = owner; in __mdiobus_register()
532 bus->dev.parent = bus->parent; in __mdiobus_register()
533 bus->dev.class = &mdio_bus_class; in __mdiobus_register()
534 bus->dev.groups = NULL; in __mdiobus_register()
535 dev_set_name(&bus->dev, "%s", bus->id); in __mdiobus_register()
537 err = device_register(&bus->dev); in __mdiobus_register()
539 pr_err("mii_bus %s failed to register\n", bus->id); in __mdiobus_register()
543 mutex_init(&bus->mdio_lock); in __mdiobus_register()
544 mutex_init(&bus->shared_lock); in __mdiobus_register()
546 /* de-assert bus level PHY GPIO reset */ in __mdiobus_register()
547 gpiod = devm_gpiod_get_optional(&bus->dev, "reset", GPIOD_OUT_LOW); in __mdiobus_register()
549 dev_err(&bus->dev, "mii_bus %s couldn't get reset GPIO\n", in __mdiobus_register()
550 bus->id); in __mdiobus_register()
551 device_del(&bus->dev); in __mdiobus_register()
554 bus->reset_gpiod = gpiod; in __mdiobus_register()
557 fsleep(bus->reset_delay_us); in __mdiobus_register()
559 if (bus->reset_post_delay_us > 0) in __mdiobus_register()
560 fsleep(bus->reset_post_delay_us); in __mdiobus_register()
563 if (bus->reset) { in __mdiobus_register()
564 err = bus->reset(bus); in __mdiobus_register()
570 if ((bus->phy_mask & (1 << i)) == 0) { in __mdiobus_register()
573 phydev = mdiobus_scan(bus, i); in __mdiobus_register()
581 mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device); in __mdiobus_register()
583 bus->state = MDIOBUS_REGISTERED; in __mdiobus_register()
584 pr_info("%s: probed\n", bus->name); in __mdiobus_register()
589 mdiodev = bus->mdio_map[i]; in __mdiobus_register()
598 if (bus->reset_gpiod) in __mdiobus_register()
599 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in __mdiobus_register()
601 device_del(&bus->dev); in __mdiobus_register()
606 void mdiobus_unregister(struct mii_bus *bus) in mdiobus_unregister() argument
611 BUG_ON(bus->state != MDIOBUS_REGISTERED); in mdiobus_unregister()
612 bus->state = MDIOBUS_UNREGISTERED; in mdiobus_unregister()
615 mdiodev = bus->mdio_map[i]; in mdiobus_unregister()
627 if (bus->reset_gpiod) in mdiobus_unregister()
628 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in mdiobus_unregister()
630 device_del(&bus->dev); in mdiobus_unregister()
636 * @bus: mii_bus to free
642 void mdiobus_free(struct mii_bus *bus) in mdiobus_free() argument
645 if (bus->state == MDIOBUS_ALLOCATED) { in mdiobus_free()
646 kfree(bus); in mdiobus_free()
650 BUG_ON(bus->state != MDIOBUS_UNREGISTERED); in mdiobus_free()
651 bus->state = MDIOBUS_RELEASED; in mdiobus_free()
653 put_device(&bus->dev); in mdiobus_free()
658 * mdiobus_scan - scan a bus for MDIO devices.
659 * @bus: mii_bus to scan
660 * @addr: address on bus to scan
662 * This function scans the MDIO bus, looking for devices which can be
669 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) in mdiobus_scan() argument
674 switch (bus->probe_capabilities) { in mdiobus_scan()
677 phydev = get_phy_device(bus, addr, false); in mdiobus_scan()
680 phydev = get_phy_device(bus, addr, true); in mdiobus_scan()
683 phydev = get_phy_device(bus, addr, false); in mdiobus_scan()
685 phydev = get_phy_device(bus, addr, true); in mdiobus_scan()
694 * in the bus node, and set the of_node pointer in this case. in mdiobus_scan()
696 of_mdiobus_link_mdiodev(bus, &phydev->mdio); in mdiobus_scan()
730 * @bus: the mii_bus struct
734 * Read a MDIO bus register. Caller must hold the mdio bus lock.
738 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in __mdiobus_read() argument
742 WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock)); in __mdiobus_read()
744 retval = bus->read(bus, addr, regnum); in __mdiobus_read()
746 trace_mdio_access(bus, 1, addr, regnum, retval, retval); in __mdiobus_read()
747 mdiobus_stats_acct(&bus->stats[addr], true, retval); in __mdiobus_read()
755 * @bus: the mii_bus struct
760 * Write a MDIO bus register. Caller must hold the mdio bus lock.
764 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in __mdiobus_write() argument
768 WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock)); in __mdiobus_write()
770 err = bus->write(bus, addr, regnum, val); in __mdiobus_write()
772 trace_mdio_access(bus, 0, addr, regnum, val, err); in __mdiobus_write()
773 mdiobus_stats_acct(&bus->stats[addr], false, err); in __mdiobus_write()
781 * @bus: the mii_bus struct
792 int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, in __mdiobus_modify_changed() argument
797 ret = __mdiobus_read(bus, addr, regnum); in __mdiobus_modify_changed()
805 ret = __mdiobus_write(bus, addr, regnum, new); in __mdiobus_modify_changed()
813 * @bus: the mii_bus struct
817 * In case of nested MDIO bus access avoid lockdep false positives by
821 * because the bus read/write functions may wait for an interrupt
824 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read_nested() argument
828 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_read_nested()
829 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read_nested()
830 mutex_unlock(&bus->mdio_lock); in mdiobus_read_nested()
838 * @bus: the mii_bus struct
843 * because the bus read/write functions may wait for an interrupt
846 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read() argument
850 mutex_lock(&bus->mdio_lock); in mdiobus_read()
851 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read()
852 mutex_unlock(&bus->mdio_lock); in mdiobus_read()
860 * @bus: the mii_bus struct
865 * In case of nested MDIO bus access avoid lockdep false positives by
869 * because the bus read/write functions may wait for an interrupt
872 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write_nested() argument
876 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_write_nested()
877 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write_nested()
878 mutex_unlock(&bus->mdio_lock); in mdiobus_write_nested()
886 * @bus: the mii_bus struct
892 * because the bus read/write functions may wait for an interrupt
895 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write() argument
899 mutex_lock(&bus->mdio_lock); in mdiobus_write()
900 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write()
901 mutex_unlock(&bus->mdio_lock); in mdiobus_write()
910 * @bus: the mii_bus struct
916 int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, u16 set) in mdiobus_modify() argument
920 mutex_lock(&bus->mdio_lock); in mdiobus_modify()
921 err = __mdiobus_modify_changed(bus, addr, regnum, mask, set); in mdiobus_modify()
922 mutex_unlock(&bus->mdio_lock); in mdiobus_modify()
1016 MODULE_DESCRIPTION("MDIO bus/device layer");