_of_phy_get(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’œ _of_phy_get (9) β€” from the Kernel API Manual, bestie

okay so picture this: you're deep in the kernel, you've got a device_node, and you need the actual phy that goes with it. that's literally what this function is for. it's giving "matchmaker, but for device tree nodes and phys" πŸ’…


✨ SYNOPSIS ✨

struct phy * _of_phy_get (struct device_node *np , int index );

like. look at her. returns a struct phy *, takes two args, no drama. iconic tbh πŸŽ€


🌸 ARGUMENTS 🌸

  • np β€” the device_node you're trying to get the phy for. this is your starting point, your main character, your whole reason for being here 🫢
  • index β€” which phy you want, by index. bc sometimes there's more than one, and you gotta be specific, yk? πŸ™ˆ

πŸ”₯ DESCRIPTION πŸ”₯

so here's the tea β˜• β€” _of_phy_get returns the phy that's associated with the given phandle value, and it does it after getting a refcount to it. refcount = it's officially yours, don't forget to put it back later, ngl 😭

but it can also go two other ways, and you should lowkey be ready for both:

  • it returns -ENODEV if there is no such phy at all. like... she's just not there. not found. πŸ’€
  • it returns -EPROBE_DEFER if there is a phandle to the phy, but the device isn't loaded yet. so she exists, she's just not ready yet β€” pls come back later, k? ✨

and how does it actually find the phy instance? bestie, this is the good part. it uses the of_xlate call back function that was provided when the phy_provider got registered. that's the whole trick. that's the vibe. that's the mechanism 🧚

fr fr: -EPROBE_DEFER is not an error, it's an invitation to try again. don't panic. 🌈

πŸ¦‹ SEE ALSO πŸ¦‹

literally the whole friend group, ok. all of these are in the kernel file ./drivers/phy/phy-core.c and they're all linked up:

phy_create_lookup(9), phy_remove_lookup(9), phy_init(9), phy_exit(9), phy_power_on(9), phy_power_off(9), phy_calibrate(9), phy_notify_connect(9), phy_notify_disconnect(9), phy_notify_state(9), phy_configure(9), phy_validate(9), of_phy_get(9), of_phy_put(9), phy_put(9), devm_phy_put(9), of_phy_simple_xlate(9), phy_get(9), devm_phy_get(9), devm_phy_optional_get(9), devm_of_phy_get(9), devm_of_phy_optional_get(9), devm_of_phy_get_by_index(9), phy_create(9), devm_phy_create(9), phy_destroy(9), devm_phy_destroy(9), __of_phy_provider_register(9), __devm_of_phy_provider_register(9), of_phy_provider_unregister(9), devm_of_phy_provider_unregister(9), phy_release(9)


and that's the page!! mwah πŸ’‹ okay so the source for all this is ./drivers/phy, dated October 2026, and yes the section is 9, and yes I remembered. periodt. πŸ‘‘πŸ’–

πŸ“¦ where this page comes from