of_parse_clkspec(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… of_parse_clkspec β€” Kernel API Manual ✨

okay so bestie, we're in the Kernel API Manual today and the function we're stanning is of_parse_clkspec(9). it's giving device-tree clock detective energy and honestly? iconic. πŸŽ€


πŸ¦‹ NAME

of_parse_clkspec β€” literally parses a DT clock specifier for a given device node. that's the whole vibe. no cap. πŸ’–


✨ SYNOPSIS

int of_parse_clkspec (const struct device_node *np , int index , const
char *name , struct of_phandle_args *out_args );

yes she takes four args, we'll get into each one, don't panic. 🫢


🌸 ARGUMENTS

  • np β€” the device node you're parsing the clock specifier from. this is your main character node. πŸ‘‘
  • index β€” the index of the phandle to parse the clock out of. important: if index < 0, then name is the one that gets used, so index is like, respectfully stepping aside. πŸ™ˆ
  • name β€” the clock name to find and parse. and if name is NULL, then the index is used instead. it's a whole either/or situation, iykyk. πŸ’«
  • out_args β€” the result of parsing the clock specifier lives here. this is where the good stuff goes. πŸ“

πŸ’œ DESCRIPTION

so what she actually does: she parses a device node's "clocks" and "clock-names" properties to find the phandle and cells for the index or name that you want. then the resulting clock specifier gets placed into out_args, or β€” and this is the part where we all go 😭 β€” an errno is returned when there's a parsing error.

and bestie, listen: the index argument is ignored if name is non-NULL. like fully ignored. don't come for her, she told you upfront. πŸ’…


🌈 EXAMPLE

okay this is the part where it gets good, look at these nodes:

phandle1: clock-controller1 { #clock-cells = <2>; }

phandle2: clock-controller2 { #clock-cells = <1>; }

clock-consumer3 { clocks = <phandle1 1 2 phandle2 3>; clock-names =
"name1", "name2"; }

so to get a device_node for clock-controller2 node you may call this function a few different ways:

of_parse_clkspec(clock-consumer3, -1, "name2", args);
of_parse_clkspec(clock-consumer3, 1, NULL, args);
of_parse_clkspec(clock-consumer3, 1, "name2", args);

three separate paths, same destination. slay. πŸ”₯


⭐ RETURN

  • 0 upon successfully parsing the clock specifier. we love a clean zero. πŸŽ€
  • otherwise, -ENOENT if name is NULL
  • or -EINVAL if name is non-NULL and it can't be found in the "clock-names" property of np. rude but fair. πŸ’€
fr fr memorize those two error codes, they will absolutely come up in your debugging era.

🧚 SEE ALSO

okay this list is long long, so buckle up bestie, we're going through the whole clk cinematic universe. starting with the kernel file:

Kernel file ./drivers/clk/clk.c

and the whole cast, in order:

like I said. the whole universe. πŸŒ€ go read them, I believe in you.


that's the whole page bestie, go parse some clock specifiers ✨

cute lil sign-off: this one came from ./drivers/clk, dated October 2026, and it's filed under of_parse_clkspec(9). mwah. πŸ’‹πŸ«Ά

πŸ“¦ where this page comes from