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