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
179 WARN(bus->state != MDIOBUS_RELEASED && in mdiobus_release()
181 bus->state != MDIOBUS_ALLOCATED, in mdiobus_release()
183 bus->id); in mdiobus_release()
184 kfree(bus); in mdiobus_release()
206 static u64 mdio_bus_get_global_stat(struct mii_bus *bus, unsigned int offset) in mdio_bus_get_global_stat() argument
212 val += mdio_bus_get_stat(&bus->stats[i], offset); in mdio_bus_get_global_stat()
221 struct mii_bus *bus = to_mii_bus(dev); in mdio_bus_stat_field_show() local
230 val = mdio_bus_get_global_stat(bus, sattr->field_offset); in mdio_bus_stat_field_show()
232 val = mdio_bus_get_stat(&bus->stats[sattr->addr], in mdio_bus_stat_field_show()
243 struct mii_bus *bus = mdiodev->bus; in mdio_bus_device_stat_field_show() local
252 val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset); in mdio_bus_device_stat_field_show()
404 * and this must be put_deviced'ed once the bus is finished with.
422 * and this must be put once the bus is finished with.
441 /* Walk the list of subnodes of a mdio bus and look for a node that
447 static void of_mdiobus_link_mdiodev(struct mii_bus *bus, in of_mdiobus_link_mdiodev() argument
453 if (dev->of_node || !bus->dev.of_node) in of_mdiobus_link_mdiodev()
456 for_each_available_child_of_node(bus->dev.of_node, child) { in of_mdiobus_link_mdiodev()
482 * @bus: MDIO bus to create the devices on
487 static int mdiobus_create_device(struct mii_bus *bus, in mdiobus_create_device() argument
493 mdiodev = mdio_device_create(bus, bi->mdio_addr); in mdiobus_create_device()
510 * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
511 * @bus: target mii_bus
512 * @owner: module containing bus accessor functions
514 * Description: Called by a bus driver to bring up all the PHYs
515 * on a given bus, and attach them to the bus. Drivers should use
523 int __mdiobus_register(struct mii_bus *bus, struct module *owner) in __mdiobus_register() argument
529 if (NULL == bus || NULL == bus->name || in __mdiobus_register()
530 NULL == bus->read || NULL == bus->write) in __mdiobus_register()
533 if (bus->parent && bus->parent->of_node) in __mdiobus_register()
534 bus->parent->of_node->fwnode.flags |= in __mdiobus_register()
537 WARN(bus->state != MDIOBUS_ALLOCATED && in __mdiobus_register()
538 bus->state != MDIOBUS_UNREGISTERED, in __mdiobus_register()
539 "%s: not in ALLOCATED or UNREGISTERED state\n", bus->id); in __mdiobus_register()
541 bus->owner = owner; in __mdiobus_register()
542 bus->dev.parent = bus->parent; in __mdiobus_register()
543 bus->dev.class = &mdio_bus_class; in __mdiobus_register()
544 bus->dev.groups = NULL; in __mdiobus_register()
545 dev_set_name(&bus->dev, "%s", bus->id); in __mdiobus_register()
552 bus->state = MDIOBUS_UNREGISTERED; in __mdiobus_register()
554 err = device_register(&bus->dev); in __mdiobus_register()
556 pr_err("mii_bus %s failed to register\n", bus->id); in __mdiobus_register()
560 mutex_init(&bus->mdio_lock); in __mdiobus_register()
561 mutex_init(&bus->shared_lock); in __mdiobus_register()
563 /* assert bus level PHY GPIO reset */ in __mdiobus_register()
564 gpiod = devm_gpiod_get_optional(&bus->dev, "reset", GPIOD_OUT_HIGH); in __mdiobus_register()
566 err = dev_err_probe(&bus->dev, PTR_ERR(gpiod), in __mdiobus_register()
568 bus->id); in __mdiobus_register()
569 device_del(&bus->dev); in __mdiobus_register()
572 bus->reset_gpiod = gpiod; in __mdiobus_register()
573 fsleep(bus->reset_delay_us); in __mdiobus_register()
575 if (bus->reset_post_delay_us > 0) in __mdiobus_register()
576 fsleep(bus->reset_post_delay_us); in __mdiobus_register()
579 if (bus->reset) { in __mdiobus_register()
580 err = bus->reset(bus); in __mdiobus_register()
586 if ((bus->phy_mask & BIT(i)) == 0) { in __mdiobus_register()
589 phydev = mdiobus_scan(bus, i); in __mdiobus_register()
597 mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device); in __mdiobus_register()
599 bus->state = MDIOBUS_REGISTERED; in __mdiobus_register()
600 dev_dbg(&bus->dev, "probed\n"); in __mdiobus_register()
605 mdiodev = bus->mdio_map[i]; in __mdiobus_register()
614 if (bus->reset_gpiod) in __mdiobus_register()
615 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in __mdiobus_register()
617 device_del(&bus->dev); in __mdiobus_register()
622 void mdiobus_unregister(struct mii_bus *bus) in mdiobus_unregister() argument
627 if (WARN_ON_ONCE(bus->state != MDIOBUS_REGISTERED)) in mdiobus_unregister()
629 bus->state = MDIOBUS_UNREGISTERED; in mdiobus_unregister()
632 mdiodev = bus->mdio_map[i]; in mdiobus_unregister()
644 if (bus->reset_gpiod) in mdiobus_unregister()
645 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in mdiobus_unregister()
647 device_del(&bus->dev); in mdiobus_unregister()
653 * @bus: mii_bus to free
659 void mdiobus_free(struct mii_bus *bus) in mdiobus_free() argument
662 if (bus->state == MDIOBUS_ALLOCATED) { in mdiobus_free()
663 kfree(bus); in mdiobus_free()
667 WARN(bus->state != MDIOBUS_UNREGISTERED, in mdiobus_free()
668 "%s: not in UNREGISTERED state\n", bus->id); in mdiobus_free()
669 bus->state = MDIOBUS_RELEASED; in mdiobus_free()
671 put_device(&bus->dev); in mdiobus_free()
676 * mdiobus_scan - scan a bus for MDIO devices.
677 * @bus: mii_bus to scan
678 * @addr: address on bus to scan
680 * This function scans the MDIO bus, looking for devices which can be
687 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) in mdiobus_scan() argument
692 switch (bus->probe_capabilities) { in mdiobus_scan()
695 phydev = get_phy_device(bus, addr, false); in mdiobus_scan()
698 phydev = get_phy_device(bus, addr, true); in mdiobus_scan()
701 phydev = get_phy_device(bus, addr, false); in mdiobus_scan()
703 phydev = get_phy_device(bus, addr, true); in mdiobus_scan()
712 * in the bus node, and set the of_node pointer in this case. in mdiobus_scan()
714 of_mdiobus_link_mdiodev(bus, &phydev->mdio); in mdiobus_scan()
748 * @bus: the mii_bus struct
752 * Read a MDIO bus register. Caller must hold the mdio bus lock.
756 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in __mdiobus_read() argument
760 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_read()
762 retval = bus->read(bus, addr, regnum); in __mdiobus_read()
764 trace_mdio_access(bus, 1, addr, regnum, retval, retval); in __mdiobus_read()
765 mdiobus_stats_acct(&bus->stats[addr], true, retval); in __mdiobus_read()
773 * @bus: the mii_bus struct
778 * Write a MDIO bus register. Caller must hold the mdio bus lock.
782 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in __mdiobus_write() argument
786 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_write()
788 err = bus->write(bus, addr, regnum, val); in __mdiobus_write()
790 trace_mdio_access(bus, 0, addr, regnum, val, err); in __mdiobus_write()
791 mdiobus_stats_acct(&bus->stats[addr], false, err); in __mdiobus_write()
799 * @bus: the mii_bus struct
810 int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, in __mdiobus_modify_changed() argument
815 ret = __mdiobus_read(bus, addr, regnum); in __mdiobus_modify_changed()
823 ret = __mdiobus_write(bus, addr, regnum, new); in __mdiobus_modify_changed()
831 * @bus: the mii_bus struct
835 * In case of nested MDIO bus access avoid lockdep false positives by
839 * because the bus read/write functions may wait for an interrupt
842 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read_nested() argument
846 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_read_nested()
847 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read_nested()
848 mutex_unlock(&bus->mdio_lock); in mdiobus_read_nested()
856 * @bus: the mii_bus struct
861 * because the bus read/write functions may wait for an interrupt
864 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read() argument
868 mutex_lock(&bus->mdio_lock); in mdiobus_read()
869 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read()
870 mutex_unlock(&bus->mdio_lock); in mdiobus_read()
878 * @bus: the mii_bus struct
883 * In case of nested MDIO bus access avoid lockdep false positives by
887 * because the bus read/write functions may wait for an interrupt
890 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write_nested() argument
894 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_write_nested()
895 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write_nested()
896 mutex_unlock(&bus->mdio_lock); in mdiobus_write_nested()
904 * @bus: the mii_bus struct
910 * because the bus read/write functions may wait for an interrupt
913 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write() argument
917 mutex_lock(&bus->mdio_lock); in mdiobus_write()
918 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write()
919 mutex_unlock(&bus->mdio_lock); in mdiobus_write()
928 * @bus: the mii_bus struct
934 int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, u16 set) in mdiobus_modify() argument
938 mutex_lock(&bus->mdio_lock); in mdiobus_modify()
939 err = __mdiobus_modify_changed(bus, addr, regnum, mask, set); in mdiobus_modify()
940 mutex_unlock(&bus->mdio_lock); in mdiobus_modify()
949 * @bus: the mii_bus struct
955 int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, in mdiobus_modify_changed() argument
960 mutex_lock(&bus->mdio_lock); in mdiobus_modify_changed()
961 err = __mdiobus_modify_changed(bus, addr, regnum, mask, set); in mdiobus_modify_changed()
962 mutex_unlock(&bus->mdio_lock); in mdiobus_modify_changed()
1061 MODULE_DESCRIPTION("MDIO bus/device layer");