Lines Matching full:bus
2 /* MDIO Bus interface
73 if (mdiodev->bus->mdio_map[mdiodev->addr]) in mdiobus_register_device()
89 mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev; in mdiobus_register_device()
97 if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev) in mdiobus_unregister_device()
102 mdiodev->bus->mdio_map[mdiodev->addr] = NULL; in mdiobus_unregister_device()
108 static struct mdio_device *mdiobus_find_device(struct mii_bus *bus, int addr) in mdiobus_find_device() argument
110 bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map); in mdiobus_find_device()
115 return bus->mdio_map[addr]; in mdiobus_find_device()
118 struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr) in mdiobus_get_phy() argument
122 mdiodev = mdiobus_find_device(bus, addr); in mdiobus_get_phy()
133 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr) in mdiobus_is_registered_device() argument
135 return mdiobus_find_device(bus, addr) != NULL; in mdiobus_is_registered_device()
142 * If non-zero, then bus->priv is points to that memory.
144 * Description: called by a bus driver to allocate an mii_bus
149 struct mii_bus *bus; in mdiobus_alloc_size() local
150 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN); in mdiobus_alloc_size()
158 alloc_size = sizeof(*bus); in mdiobus_alloc_size()
160 bus = kzalloc(alloc_size, GFP_KERNEL); in mdiobus_alloc_size()
161 if (!bus) in mdiobus_alloc_size()
164 bus->state = MDIOBUS_ALLOCATED; in mdiobus_alloc_size()
166 bus->priv = (void *)bus + aligned_size; in mdiobus_alloc_size()
170 bus->irq[i] = PHY_POLL; in mdiobus_alloc_size()
171 u64_stats_init(&bus->stats[i].syncp); in mdiobus_alloc_size()
174 return bus; in mdiobus_alloc_size()
187 struct mii_bus *bus = to_mii_bus(d); in mdiobus_release() local
189 WARN(bus->state != MDIOBUS_RELEASED && in mdiobus_release()
191 bus->state != MDIOBUS_ALLOCATED, in mdiobus_release()
193 bus->id); in mdiobus_release()
195 if (bus->state == MDIOBUS_RELEASED) in mdiobus_release()
198 kfree(bus); in mdiobus_release()
220 static u64 mdio_bus_get_global_stat(struct mii_bus *bus, unsigned int offset) in mdio_bus_get_global_stat() argument
226 val += mdio_bus_get_stat(&bus->stats[i], offset); in mdio_bus_get_global_stat()
235 struct mii_bus *bus = to_mii_bus(dev); in mdio_bus_stat_field_show() local
244 val = mdio_bus_get_global_stat(bus, sattr->field_offset); in mdio_bus_stat_field_show()
246 val = mdio_bus_get_stat(&bus->stats[sattr->addr], in mdio_bus_stat_field_show()
257 struct mii_bus *bus = mdiodev->bus; in mdio_bus_device_stat_field_show() local
266 val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset); in mdio_bus_device_stat_field_show()
418 * and this must be put_deviced'ed once the bus is finished with.
436 * and this must be put once the bus is finished with.
455 /* Walk the list of subnodes of a mdio bus and look for a node that
504 static void of_mdiobus_link_mdiodev(struct mii_bus *bus, in of_mdiobus_link_mdiodev() argument
509 if (dev->of_node || !bus->dev.of_node) in of_mdiobus_link_mdiodev()
512 of_mdiobus_find_phy(dev, mdiodev, bus->dev.of_node); in of_mdiobus_link_mdiodev()
524 * @bus: MDIO bus to create the devices on
529 static int mdiobus_create_device(struct mii_bus *bus, in mdiobus_create_device() argument
535 mdiodev = mdio_device_create(bus, bi->mdio_addr); in mdiobus_create_device()
551 static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45) in mdiobus_scan() argument
556 phydev = get_phy_device(bus, addr, c45); in mdiobus_scan()
561 * in the bus node, and set the of_node pointer in this case. in mdiobus_scan()
563 of_mdiobus_link_mdiodev(bus, &phydev->mdio); in mdiobus_scan()
575 * mdiobus_scan_c22 - scan one address on a bus for C22 MDIO devices.
576 * @bus: mii_bus to scan
577 * @addr: address on bus to scan
579 * This function scans one address on the MDIO bus, looking for
586 struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr) in mdiobus_scan_c22() argument
588 return mdiobus_scan(bus, addr, false); in mdiobus_scan_c22()
593 * mdiobus_scan_c45 - scan one address on a bus for C45 MDIO devices.
594 * @bus: mii_bus to scan
595 * @addr: address on bus to scan
597 * This function scans one address on the MDIO bus, looking for
604 static struct phy_device *mdiobus_scan_c45(struct mii_bus *bus, int addr) in mdiobus_scan_c45() argument
606 return mdiobus_scan(bus, addr, true); in mdiobus_scan_c45()
609 static int mdiobus_scan_bus_c22(struct mii_bus *bus) in mdiobus_scan_bus_c22() argument
614 if ((bus->phy_mask & BIT(i)) == 0) { in mdiobus_scan_bus_c22()
617 phydev = mdiobus_scan_c22(bus, i); in mdiobus_scan_bus_c22()
625 static int mdiobus_scan_bus_c45(struct mii_bus *bus) in mdiobus_scan_bus_c45() argument
630 if ((bus->phy_mask & BIT(i)) == 0) { in mdiobus_scan_bus_c45()
634 if (bus->mdio_map[i]) in mdiobus_scan_bus_c45()
637 phydev = mdiobus_scan_c45(bus, i); in mdiobus_scan_bus_c45()
646 * transaction on the bus, like accepting a read themselves, and
652 static bool mdiobus_prevent_c45_scan(struct mii_bus *bus) in mdiobus_prevent_c45_scan() argument
660 phydev = mdiobus_get_phy(bus, i); in mdiobus_prevent_c45_scan()
672 * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
673 * @bus: target mii_bus
674 * @owner: module containing bus accessor functions
676 * Description: Called by a bus driver to bring up all the PHYs
677 * on a given bus, and attach them to the bus. Drivers should use
685 int __mdiobus_register(struct mii_bus *bus, struct module *owner) in __mdiobus_register() argument
692 if (!bus || !bus->name) in __mdiobus_register()
696 if (!!bus->read != !!bus->write || !!bus->read_c45 != !!bus->write_c45) in __mdiobus_register()
700 if (!bus->read && !bus->read_c45) in __mdiobus_register()
703 if (bus->parent && bus->parent->of_node) in __mdiobus_register()
704 bus->parent->of_node->fwnode.flags |= in __mdiobus_register()
707 WARN(bus->state != MDIOBUS_ALLOCATED && in __mdiobus_register()
708 bus->state != MDIOBUS_UNREGISTERED, in __mdiobus_register()
709 "%s: not in ALLOCATED or UNREGISTERED state\n", bus->id); in __mdiobus_register()
711 bus->owner = owner; in __mdiobus_register()
712 bus->dev.parent = bus->parent; in __mdiobus_register()
713 bus->dev.class = &mdio_bus_class; in __mdiobus_register()
714 bus->dev.groups = NULL; in __mdiobus_register()
715 dev_set_name(&bus->dev, "%s", bus->id); in __mdiobus_register()
717 /* If the bus state is allocated, we're registering a fresh bus in __mdiobus_register()
719 * to the fwnode. This will be dropped when the bus is released. in __mdiobus_register()
720 * If the bus was set to unregistered, it means that the bus was in __mdiobus_register()
723 if (bus->state == MDIOBUS_ALLOCATED) in __mdiobus_register()
724 fwnode_handle_get(dev_fwnode(&bus->dev)); in __mdiobus_register()
731 bus->state = MDIOBUS_UNREGISTERED; in __mdiobus_register()
733 err = device_register(&bus->dev); in __mdiobus_register()
735 pr_err("mii_bus %s failed to register\n", bus->id); in __mdiobus_register()
739 mutex_init(&bus->mdio_lock); in __mdiobus_register()
740 mutex_init(&bus->shared_lock); in __mdiobus_register()
742 /* assert bus level PHY GPIO reset */ in __mdiobus_register()
743 gpiod = devm_gpiod_get_optional(&bus->dev, "reset", GPIOD_OUT_HIGH); in __mdiobus_register()
745 err = dev_err_probe(&bus->dev, PTR_ERR(gpiod), in __mdiobus_register()
747 bus->id); in __mdiobus_register()
748 device_del(&bus->dev); in __mdiobus_register()
751 bus->reset_gpiod = gpiod; in __mdiobus_register()
752 fsleep(bus->reset_delay_us); in __mdiobus_register()
754 if (bus->reset_post_delay_us > 0) in __mdiobus_register()
755 fsleep(bus->reset_post_delay_us); in __mdiobus_register()
758 if (bus->reset) { in __mdiobus_register()
759 err = bus->reset(bus); in __mdiobus_register()
764 if (bus->read) { in __mdiobus_register()
765 err = mdiobus_scan_bus_c22(bus); in __mdiobus_register()
770 prevent_c45_scan = mdiobus_prevent_c45_scan(bus); in __mdiobus_register()
772 if (!prevent_c45_scan && bus->read_c45) { in __mdiobus_register()
773 err = mdiobus_scan_bus_c45(bus); in __mdiobus_register()
778 mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device); in __mdiobus_register()
780 bus->state = MDIOBUS_REGISTERED; in __mdiobus_register()
781 dev_dbg(&bus->dev, "probed\n"); in __mdiobus_register()
786 mdiodev = bus->mdio_map[i]; in __mdiobus_register()
795 if (bus->reset_gpiod) in __mdiobus_register()
796 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in __mdiobus_register()
798 device_del(&bus->dev); in __mdiobus_register()
803 void mdiobus_unregister(struct mii_bus *bus) in mdiobus_unregister() argument
808 if (WARN_ON_ONCE(bus->state != MDIOBUS_REGISTERED)) in mdiobus_unregister()
810 bus->state = MDIOBUS_UNREGISTERED; in mdiobus_unregister()
813 mdiodev = bus->mdio_map[i]; in mdiobus_unregister()
825 if (bus->reset_gpiod) in mdiobus_unregister()
826 gpiod_set_value_cansleep(bus->reset_gpiod, 1); in mdiobus_unregister()
828 device_del(&bus->dev); in mdiobus_unregister()
834 * @bus: mii_bus to free
840 void mdiobus_free(struct mii_bus *bus) in mdiobus_free() argument
843 if (bus->state == MDIOBUS_ALLOCATED) { in mdiobus_free()
844 kfree(bus); in mdiobus_free()
848 WARN(bus->state != MDIOBUS_UNREGISTERED, in mdiobus_free()
849 "%s: not in UNREGISTERED state\n", bus->id); in mdiobus_free()
850 bus->state = MDIOBUS_RELEASED; in mdiobus_free()
852 put_device(&bus->dev); in mdiobus_free()
878 * @bus: the mii_bus struct
882 * Read a MDIO bus register. Caller must hold the mdio bus lock.
886 int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in __mdiobus_read() argument
890 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_read()
892 if (bus->read) in __mdiobus_read()
893 retval = bus->read(bus, addr, regnum); in __mdiobus_read()
897 trace_mdio_access(bus, 1, addr, regnum, retval, retval); in __mdiobus_read()
898 mdiobus_stats_acct(&bus->stats[addr], true, retval); in __mdiobus_read()
906 * @bus: the mii_bus struct
911 * Write a MDIO bus register. Caller must hold the mdio bus lock.
915 int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in __mdiobus_write() argument
919 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_write()
921 if (bus->write) in __mdiobus_write()
922 err = bus->write(bus, addr, regnum, val); in __mdiobus_write()
926 trace_mdio_access(bus, 0, addr, regnum, val, err); in __mdiobus_write()
927 mdiobus_stats_acct(&bus->stats[addr], false, err); in __mdiobus_write()
935 * @bus: the mii_bus struct
946 int __mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, in __mdiobus_modify_changed() argument
951 ret = __mdiobus_read(bus, addr, regnum); in __mdiobus_modify_changed()
959 ret = __mdiobus_write(bus, addr, regnum, new); in __mdiobus_modify_changed()
967 * @bus: the mii_bus struct
972 * Read a MDIO bus register. Caller must hold the mdio bus lock.
976 int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum) in __mdiobus_c45_read() argument
980 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_c45_read()
982 if (bus->read_c45) in __mdiobus_c45_read()
983 retval = bus->read_c45(bus, addr, devad, regnum); in __mdiobus_c45_read()
987 trace_mdio_access(bus, 1, addr, regnum, retval, retval); in __mdiobus_c45_read()
988 mdiobus_stats_acct(&bus->stats[addr], true, retval); in __mdiobus_c45_read()
996 * @bus: the mii_bus struct
1002 * Write a MDIO bus register. Caller must hold the mdio bus lock.
1006 int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum, in __mdiobus_c45_write() argument
1011 lockdep_assert_held_once(&bus->mdio_lock); in __mdiobus_c45_write()
1013 if (bus->write_c45) in __mdiobus_c45_write()
1014 err = bus->write_c45(bus, addr, devad, regnum, val); in __mdiobus_c45_write()
1018 trace_mdio_access(bus, 0, addr, regnum, val, err); in __mdiobus_c45_write()
1019 mdiobus_stats_acct(&bus->stats[addr], false, err); in __mdiobus_c45_write()
1027 * @bus: the mii_bus struct
1039 static int __mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, in __mdiobus_c45_modify_changed() argument
1045 ret = __mdiobus_c45_read(bus, addr, devad, regnum); in __mdiobus_c45_modify_changed()
1053 ret = __mdiobus_c45_write(bus, addr, devad, regnum, new); in __mdiobus_c45_modify_changed()
1060 * @bus: the mii_bus struct
1064 * In case of nested MDIO bus access avoid lockdep false positives by
1068 * because the bus read/write functions may wait for an interrupt
1071 int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read_nested() argument
1075 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_read_nested()
1076 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read_nested()
1077 mutex_unlock(&bus->mdio_lock); in mdiobus_read_nested()
1085 * @bus: the mii_bus struct
1090 * because the bus read/write functions may wait for an interrupt
1093 int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum) in mdiobus_read() argument
1097 mutex_lock(&bus->mdio_lock); in mdiobus_read()
1098 retval = __mdiobus_read(bus, addr, regnum); in mdiobus_read()
1099 mutex_unlock(&bus->mdio_lock); in mdiobus_read()
1107 * @bus: the mii_bus struct
1113 * because the bus read/write functions may wait for an interrupt
1116 int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum) in mdiobus_c45_read() argument
1120 mutex_lock(&bus->mdio_lock); in mdiobus_c45_read()
1121 retval = __mdiobus_c45_read(bus, addr, devad, regnum); in mdiobus_c45_read()
1122 mutex_unlock(&bus->mdio_lock); in mdiobus_c45_read()
1130 * @bus: the mii_bus struct
1135 * In case of nested MDIO bus access avoid lockdep false positives by
1139 * because the bus read/write functions may wait for an interrupt
1142 int mdiobus_c45_read_nested(struct mii_bus *bus, int addr, int devad, in mdiobus_c45_read_nested() argument
1147 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_c45_read_nested()
1148 retval = __mdiobus_c45_read(bus, addr, devad, regnum); in mdiobus_c45_read_nested()
1149 mutex_unlock(&bus->mdio_lock); in mdiobus_c45_read_nested()
1157 * @bus: the mii_bus struct
1162 * In case of nested MDIO bus access avoid lockdep false positives by
1166 * because the bus read/write functions may wait for an interrupt
1169 int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write_nested() argument
1173 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_write_nested()
1174 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write_nested()
1175 mutex_unlock(&bus->mdio_lock); in mdiobus_write_nested()
1183 * @bus: the mii_bus struct
1189 * because the bus read/write functions may wait for an interrupt
1192 int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val) in mdiobus_write() argument
1196 mutex_lock(&bus->mdio_lock); in mdiobus_write()
1197 err = __mdiobus_write(bus, addr, regnum, val); in mdiobus_write()
1198 mutex_unlock(&bus->mdio_lock); in mdiobus_write()
1206 * @bus: the mii_bus struct
1213 * because the bus read/write functions may wait for an interrupt
1216 int mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum, in mdiobus_c45_write() argument
1221 mutex_lock(&bus->mdio_lock); in mdiobus_c45_write()
1222 err = __mdiobus_c45_write(bus, addr, devad, regnum, val); in mdiobus_c45_write()
1223 mutex_unlock(&bus->mdio_lock); in mdiobus_c45_write()
1231 * @bus: the mii_bus struct
1237 * In case of nested MDIO bus access avoid lockdep false positives by
1241 * because the bus read/write functions may wait for an interrupt
1244 int mdiobus_c45_write_nested(struct mii_bus *bus, int addr, int devad, in mdiobus_c45_write_nested() argument
1249 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); in mdiobus_c45_write_nested()
1250 err = __mdiobus_c45_write(bus, addr, devad, regnum, val); in mdiobus_c45_write_nested()
1251 mutex_unlock(&bus->mdio_lock); in mdiobus_c45_write_nested()
1260 * @bus: the mii_bus struct
1266 int __mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, in __mdiobus_modify() argument
1271 err = __mdiobus_modify_changed(bus, addr, regnum, mask, set); in __mdiobus_modify()
1280 * @bus: the mii_bus struct
1286 int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask, u16 set) in mdiobus_modify() argument
1290 mutex_lock(&bus->mdio_lock); in mdiobus_modify()
1291 err = __mdiobus_modify(bus, addr, regnum, mask, set); in mdiobus_modify()
1292 mutex_unlock(&bus->mdio_lock); in mdiobus_modify()
1301 * @bus: the mii_bus struct
1308 int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnum, in mdiobus_c45_modify() argument
1313 mutex_lock(&bus->mdio_lock); in mdiobus_c45_modify()
1314 err = __mdiobus_c45_modify_changed(bus, addr, devad, regnum, in mdiobus_c45_modify()
1316 mutex_unlock(&bus->mdio_lock); in mdiobus_c45_modify()
1325 * @bus: the mii_bus struct
1331 int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, in mdiobus_modify_changed() argument
1336 mutex_lock(&bus->mdio_lock); in mdiobus_modify_changed()
1337 err = __mdiobus_modify_changed(bus, addr, regnum, mask, set); in mdiobus_modify_changed()
1338 mutex_unlock(&bus->mdio_lock); in mdiobus_modify_changed()
1347 * @bus: the mii_bus struct
1354 int mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, int devad, in mdiobus_c45_modify_changed() argument
1359 mutex_lock(&bus->mdio_lock); in mdiobus_c45_modify_changed()
1360 err = __mdiobus_c45_modify_changed(bus, addr, devad, regnum, mask, set); in mdiobus_c45_modify_changed()
1361 mutex_unlock(&bus->mdio_lock); in mdiobus_c45_modify_changed()
1460 MODULE_DESCRIPTION("MDIO bus/device layer");