xref: /openbmc/u-boot/include/clk-uclass.h (revision 010ad8c3)
1 /*
2  * Copyright (c) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  * Copyright (c) 2016, NVIDIA CORPORATION.
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 #ifndef _CLK_UCLASS_H
10 #define _CLK_UCLASS_H
11 
12 /* See clk.h for background documentation. */
13 
14 #include <clk.h>
15 
16 struct ofnode_phandle_args;
17 
18 /**
19  * struct clk_ops - The functions that a clock driver must implement.
20  */
21 struct clk_ops {
22 	/**
23 	 * of_xlate - Translate a client's device-tree (OF) clock specifier.
24 	 *
25 	 * The clock core calls this function as the first step in implementing
26 	 * a client's clk_get_by_*() call.
27 	 *
28 	 * If this function pointer is set to NULL, the clock core will use a
29 	 * default implementation, which assumes #clock-cells = <1>, and that
30 	 * the DT cell contains a simple integer clock ID.
31 	 *
32 	 * At present, the clock API solely supports device-tree. If this
33 	 * changes, other xxx_xlate() functions may be added to support those
34 	 * other mechanisms.
35 	 *
36 	 * @clock:	The clock struct to hold the translation result.
37 	 * @args:	The clock specifier values from device tree.
38 	 * @return 0 if OK, or a negative error code.
39 	 */
40 	int (*of_xlate)(struct clk *clock,
41 			struct ofnode_phandle_args *args);
42 	/**
43 	 * request - Request a translated clock.
44 	 *
45 	 * The clock core calls this function as the second step in
46 	 * implementing a client's clk_get_by_*() call, following a successful
47 	 * xxx_xlate() call, or as the only step in implementing a client's
48 	 * clk_request() call.
49 	 *
50 	 * @clock:	The clock struct to request; this has been fille in by
51 	 *		a previoux xxx_xlate() function call, or by the caller
52 	 *		of clk_request().
53 	 * @return 0 if OK, or a negative error code.
54 	 */
55 	int (*request)(struct clk *clock);
56 	/**
57 	 * free - Free a previously requested clock.
58 	 *
59 	 * This is the implementation of the client clk_free() API.
60 	 *
61 	 * @clock:	The clock to free.
62 	 * @return 0 if OK, or a negative error code.
63 	 */
64 	int (*free)(struct clk *clock);
65 	/**
66 	 * get_rate() - Get current clock rate.
67 	 *
68 	 * @clk:	The clock to query.
69 	 * @return clock rate in Hz, or -ve error code
70 	 */
71 	ulong (*get_rate)(struct clk *clk);
72 	/**
73 	 * set_rate() - Set current clock rate.
74 	 *
75 	 * @clk:	The clock to manipulate.
76 	 * @rate:	New clock rate in Hz.
77 	 * @return new rate, or -ve error code.
78 	 */
79 	ulong (*set_rate)(struct clk *clk, ulong rate);
80 	/**
81 	 * enable() - Enable a clock.
82 	 *
83 	 * @clk:	The clock to manipulate.
84 	 * @return zero on success, or -ve error code.
85 	 */
86 	int (*enable)(struct clk *clk);
87 	/**
88 	 * disable() - Disable a clock.
89 	 *
90 	 * @clk:	The clock to manipulate.
91 	 * @return zero on success, or -ve error code.
92 	 */
93 	int (*disable)(struct clk *clk);
94 };
95 
96 #endif
97