Lines Matching refs:bus

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
113 if (addr < 0 || addr >= ARRAY_SIZE(bus->mdio_map)) in mdiobus_get_phy()
116 mdiodev = bus->mdio_map[addr]; in mdiobus_get_phy()
128 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr) in mdiobus_is_registered_device() argument
130 return bus->mdio_map[addr]; in mdiobus_is_registered_device()
144 struct mii_bus *bus; in mdiobus_alloc_size() local
145 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN); in mdiobus_alloc_size()
153 alloc_size = sizeof(*bus); in mdiobus_alloc_size()
155 bus = kzalloc(alloc_size, GFP_KERNEL); in mdiobus_alloc_size()
156 if (!bus) in mdiobus_alloc_size()
159 bus->state = MDIOBUS_ALLOCATED; in mdiobus_alloc_size()
161 bus->priv = (void *)bus + aligned_size; in mdiobus_alloc_size()
165 bus->irq[i] = PHY_POLL; in mdiobus_alloc_size()
166 u64_stats_init(&bus->stats[i].syncp); in mdiobus_alloc_size()
169 return bus; in mdiobus_alloc_size()
182 struct mii_bus *bus = to_mii_bus(d); in mdiobus_release() local
184 WARN(bus->state != MDIOBUS_RELEASED && in mdiobus_release()
186 bus->state != MDIOBUS_ALLOCATED, in mdiobus_release()
188 bus->id); in mdiobus_release()
189 kfree(bus); in mdiobus_release()
211 static u64 mdio_bus_get_global_stat(struct mii_bus *bus, unsigned int offset) in mdio_bus_get_global_stat() argument
217 val += mdio_bus_get_stat(&bus->stats[i], offset); in mdio_bus_get_global_stat()
226 struct mii_bus *bus = to_mii_bus(dev); in mdio_bus_stat_field_show() local
235 val = mdio_bus_get_global_stat(bus, sattr->field_offset); in mdio_bus_stat_field_show()
237 val = mdio_bus_get_stat(&bus->stats[sattr->addr], in mdio_bus_stat_field_show()
248 struct mii_bus *bus = mdiodev->bus; in mdio_bus_device_stat_field_show() local
257 val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset); in mdio_bus_device_stat_field_show()
452 static void of_mdiobus_link_mdiodev(struct mii_bus *bus, in of_mdiobus_link_mdiodev() argument
458 if (dev->of_node || !bus->dev.of_node) in of_mdiobus_link_mdiodev()
461 for_each_available_child_of_node(bus->dev.of_node, child) { in of_mdiobus_link_mdiodev()
492 static int mdiobus_create_device(struct mii_bus *bus, in mdiobus_create_device() argument
498 mdiodev = mdio_device_create(bus, bi->mdio_addr); in mdiobus_create_device()
528 int __mdiobus_register(struct mii_bus *bus, struct module *owner) in __mdiobus_register() argument
534 if (NULL == bus || NULL == bus->name || in __mdiobus_register()
535 NULL == bus->read || NULL == bus->write) in __mdiobus_register()
538 if (bus->parent && bus->parent->of_node) in __mdiobus_register()
539 bus->parent->of_node->fwnode.flags |= in __mdiobus_register()
542 WARN(bus->state != MDIOBUS_ALLOCATED && in __mdiobus_register()
543 bus->state != MDIOBUS_UNREGISTERED, in __mdiobus_register()
544 "%s: not in ALLOCATED or UNREGISTERED state\n", bus->id); in __mdiobus_register()
546 bus->owner = owner; in __mdiobus_register()
547 bus->dev.parent = bus->parent; in __mdiobus_register()
548 bus->dev.class = &mdio_bus_class; in __mdiobus_register()
549 bus->dev.groups = NULL; in __mdiobus_register()
550 dev_set_name(&bus->dev, "%s", bus->id); in __mdiobus_register()
557 bus->state = MDIOBUS_UNREGISTERED; in __mdiobus_register()
559 err = device_register(&bus->dev); in __mdiobus_register()
561 pr_err("mii_bus %s failed to register\n", bus->id); in __mdiobus_register()
565 mutex_init(&bus->mdio_lock); in __mdiobus_register()
566 mutex_init(&bus->shared_lock); in __mdiobus_register()
569 gpiod = devm_gpiod_get_optional(&bus->dev, "reset", GPIOD_OUT_HIGH); in __mdiobus_register()
571 err = dev_err_probe(&bus->dev, PTR_ERR(gpiod), in __mdiobus_register()
573 bus->id); in __mdiobus_register()
574 device_del(&bus->dev); in __mdiobus_register()
577 bus->reset_gpiod = gpiod; in __mdiobus_register()
578 fsleep(bus->reset_delay_us); in __mdiobus_register()
580 if (bus->reset_post_delay_us > 0) in __mdiobus_register()
581 fsleep(bus->reset_post_delay_us); in __mdiobus_register()
584 if (bus->reset) { in __mdiobus_register()
585 err = bus->reset(bus); in __mdiobus_register()
591 if ((bus->phy_mask & BIT(i)) == 0) { in __mdiobus_register()
594 phydev = mdiobus_scan(bus, i); in __mdiobus_register()
602 mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device); in __mdiobus_register()
604 bus->state = MDIOBUS_REGISTERED; in __mdiobus_register()
605 dev_dbg(&bus->dev, "probed\n"); in __mdiobus_register()
610 mdiodev = bus->mdio_map[i]; in __mdiobus_register()
619 if (bus->reset_gpiod) in __mdiobus_register()
620 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in __mdiobus_register()
622 device_del(&bus->dev); in __mdiobus_register()
627 void mdiobus_unregister(struct mii_bus *bus) in mdiobus_unregister() argument
632 if (WARN_ON_ONCE(bus->state != MDIOBUS_REGISTERED)) in mdiobus_unregister()
634 bus->state = MDIOBUS_UNREGISTERED; in mdiobus_unregister()
637 mdiodev = bus->mdio_map[i]; in mdiobus_unregister()
649 if (bus->reset_gpiod) in mdiobus_unregister()
650 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in mdiobus_unregister()
652 device_del(&bus->dev); in mdiobus_unregister()
664 void mdiobus_free(struct mii_bus *bus) in mdiobus_free() argument
667 if (bus->state == MDIOBUS_ALLOCATED) { in mdiobus_free()
668 kfree(bus); in mdiobus_free()
672 WARN(bus->state != MDIOBUS_UNREGISTERED, in mdiobus_free()
673 "%s: not in UNREGISTERED state\n", bus->id); in mdiobus_free()
674 bus->state = MDIOBUS_RELEASED; in mdiobus_free()
676 put_device(&bus->dev); in mdiobus_free()
692 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) in mdiobus_scan() argument
697 switch (bus->probe_capabilities) { in mdiobus_scan()
700 phydev = get_phy_device(bus, addr, false); in mdiobus_scan()
703 phydev = get_phy_device(bus, addr, true); in mdiobus_scan()
706 phydev = get_phy_device(bus, addr, false); in mdiobus_scan()
708 phydev = get_phy_device(bus, addr, true); in mdiobus_scan()
719 of_mdiobus_link_mdiodev(bus, &phydev->mdio); in mdiobus_scan()
761 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in __mdiobus_read() argument
765 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_read()
767 retval = bus->read(bus, addr, regnum); in __mdiobus_read()
769 trace_mdio_access(bus, 1, addr, regnum, retval, retval); in __mdiobus_read()
770 mdiobus_stats_acct(&bus->stats[addr], true, retval); in __mdiobus_read()
787 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in __mdiobus_write() argument
791 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_write()
793 err = bus->write(bus, addr, regnum, val); in __mdiobus_write()
795 trace_mdio_access(bus, 0, addr, regnum, val, err); in __mdiobus_write()
796 mdiobus_stats_acct(&bus->stats[addr], false, err); in __mdiobus_write()
815 int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, in __mdiobus_modify_changed() argument
820 ret = __mdiobus_read(bus, addr, regnum); in __mdiobus_modify_changed()
828 ret = __mdiobus_write(bus, addr, regnum, new); in __mdiobus_modify_changed()
847 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read_nested() argument
851 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_read_nested()
852 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read_nested()
853 mutex_unlock(&bus->mdio_lock); in mdiobus_read_nested()
869 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read() argument
873 mutex_lock(&bus->mdio_lock); in mdiobus_read()
874 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read()
875 mutex_unlock(&bus->mdio_lock); in mdiobus_read()
895 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write_nested() argument
899 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_write_nested()
900 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write_nested()
901 mutex_unlock(&bus->mdio_lock); in mdiobus_write_nested()
918 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write() argument
922 mutex_lock(&bus->mdio_lock); in mdiobus_write()
923 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write()
924 mutex_unlock(&bus->mdio_lock); in mdiobus_write()
939 int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, u16 set) in mdiobus_modify() argument
943 mutex_lock(&bus->mdio_lock); in mdiobus_modify()
944 err = __mdiobus_modify_changed(bus, addr, regnum, mask, set); in mdiobus_modify()
945 mutex_unlock(&bus->mdio_lock); in mdiobus_modify()
960 int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, in mdiobus_modify_changed() argument
965 mutex_lock(&bus->mdio_lock); in mdiobus_modify_changed()
966 err = __mdiobus_modify_changed(bus, addr, regnum, mask, set); in mdiobus_modify_changed()
967 mutex_unlock(&bus->mdio_lock); in mdiobus_modify_changed()