of_parse_clkspec(9)
π 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, soindexis like, respectfully stepping aside. πnameβ the clock name to find and parse. and if name isNULL, 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
0upon successfully parsing the clock specifier. we love a clean zero. π- otherwise,
-ENOENTif name isNULL - or
-EINVALif name is non-NULLand 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:
struct clk_core(9)clk_pm_runtime_get_all(9)clk_pm_runtime_put_all(9)clk_core_get(9)clk_determine_rate_noop(9)clk_rate_exclusive_put(9)clk_rate_exclusive_get(9)clk_unprepare(9)clk_prepare(9)clk_disable(9)clk_gate_restore_context(9)clk_save_context(9)clk_restore_context(9)clk_enable(9)clk_is_enabled_when_prepared(9)clk_hw_init_rate_request(9)clk_hw_forward_rate_request(9)__clk_determine_rate(9)clk_hw_round_rate(9)clk_round_rate(9)__clk_notify(9)__clk_recalc_accuracies(9)clk_get_accuracy(9)__clk_recalc_rates(9)clk_get_rate(9)clk_hw_get_parent_index(9)__clk_speculate_rates(9)clk_set_rate(9)clk_set_rate_exclusive(9)clk_set_rate_range(9)clk_set_min_rate(9)clk_set_max_rate(9)clk_get_parent(9)clk_has_parent(9)clk_set_parent(9)clk_set_phase(9)clk_get_phase(9)clk_set_duty_cycle(9)clk_get_scaled_duty_cycle(9)clk_is_match(9)clk_debug_register(9)clk_debug_init(9)__clk_core_init(9)clk_core_link_consumer(9)clk_core_unlink_consumer(9)alloc_clk(9)free_clk(9)clk_hw_create_clk(9)clk_hw_get_clk(9)dev_or_parent_of_node(9)clk_register(9)clk_hw_register(9)clk_unregister(9)clk_hw_unregister(9)devm_clk_register(9)devm_clk_hw_register(9)devm_clk_hw_get_clk(9)clk_notifier_register(9)clk_notifier_unregister(9)struct of_clk_provider(9)of_clk_add_provider(9)of_clk_add_hw_provider(9)devm_of_clk_add_hw_provider(9)of_clk_del_provider(9)of_clk_get_from_provider(9)of_clk_get_by_name(9)of_clk_get_parent_count(9)of_clk_parent_fill(9)of_clk_detect_critical(9)of_clk_init(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms