1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 * Copyright (c) 2016, NVIDIA CORPORATION.
11 /* See clk.h for background documentation. */
15 struct ofnode_phandle_args;
18 * struct clk_ops - The functions that a clock driver must implement.
19 * @of_xlate: Translate a client's device-tree (OF) clock specifier.
20 * @request: Request a translated clock.
21 * @rfree: Free a previously requested clock.
22 * @round_rate: Adjust a rate to the exact rate a clock can provide.
23 * @get_rate: Get current clock rate.
24 * @set_rate: Set current clock rate.
25 * @set_parent: Set current clock parent
26 * @enable: Enable a clock.
27 * @disable: Disable a clock.
29 * The individual methods are described more fully below.
32 int (*of_xlate)(struct clk *clock,
33 struct ofnode_phandle_args *args);
34 int (*request)(struct clk *clock);
35 void (*rfree)(struct clk *clock);
36 ulong (*round_rate)(struct clk *clk, ulong rate);
37 ulong (*get_rate)(struct clk *clk);
38 ulong (*set_rate)(struct clk *clk, ulong rate);
39 int (*set_parent)(struct clk *clk, struct clk *parent);
40 int (*enable)(struct clk *clk);
41 int (*disable)(struct clk *clk);
44 #if 0 /* For documentation only */
46 * of_xlate() - Translate a client's device-tree (OF) clock specifier.
47 * @clock: The clock struct to hold the translation result.
48 * @args: The clock specifier values from device tree.
50 * The clock core calls this function as the first step in implementing
51 * a client's clk_get_by_*() call.
53 * If this function pointer is set to NULL, the clock core will use a
54 * default implementation, which assumes #clock-cells = <1>, and that
55 * the DT cell contains a simple integer clock ID.
57 * At present, the clock API solely supports device-tree. If this
58 * changes, other xxx_xlate() functions may be added to support those
61 * Return: 0 if OK, or a negative error code.
63 int of_xlate(struct clk *clock, struct ofnode_phandle_args *args);
66 * request() - Request a translated clock.
67 * @clock: The clock struct to request; this has been fille in by
68 * a previoux xxx_xlate() function call, or by the caller
71 * The clock core calls this function as the second step in
72 * implementing a client's clk_get_by_*() call, following a successful
73 * xxx_xlate() call, or as the only step in implementing a client's
76 * Return: 0 if OK, or a negative error code.
78 int request(struct clk *clock);
81 * rfree() - Free a previously requested clock.
82 * @clock: The clock to free.
84 * Free any resources allocated in request().
86 void rfree(struct clk *clock);
89 * round_rate() - Adjust a rate to the exact rate a clock can provide.
90 * @clk: The clock to manipulate.
91 * @rate: Desidered clock rate in Hz.
93 * Return: rounded rate in Hz, or -ve error code.
95 ulong round_rate(struct clk *clk, ulong rate);
98 * get_rate() - Get current clock rate.
99 * @clk: The clock to query.
101 * Return: clock rate in Hz, or -ve error code
103 ulong get_rate(struct clk *clk);
106 * set_rate() - Set current clock rate.
107 * @clk: The clock to manipulate.
108 * @rate: New clock rate in Hz.
110 * Return: new rate, or -ve error code.
112 ulong set_rate(struct clk *clk, ulong rate);
115 * set_parent() - Set current clock parent
116 * @clk: The clock to manipulate.
117 * @parent: New clock parent.
119 * Return: zero on success, or -ve error code.
121 int set_parent(struct clk *clk, struct clk *parent);
124 * enable() - Enable a clock.
125 * @clk: The clock to manipulate.
127 * Return: zero on success, or -ve error code.
129 int enable(struct clk *clk);
132 * disable() - Disable a clock.
133 * @clk: The clock to manipulate.
135 * Return: zero on success, or -ve error code.
137 int disable(struct clk *clk);