1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2016, NVIDIA CORPORATION.
4  */
5 
6 #ifndef __SANDBOX_CLK_H
7 #define __SANDBOX_CLK_H
8 
9 #include <common.h>
10 #include <clk.h>
11 #include <dt-structs.h>
12 #include <linux/clk-provider.h>
13 
14 struct udevice;
15 
16 /**
17  * enum sandbox_clk_id - Identity of clocks implemented by the sandbox clock
18  * provider.
19  *
20  * These IDs are within/relative-to the clock provider.
21  */
22 enum sandbox_clk_id {
23 	SANDBOX_CLK_ID_SPI,
24 	SANDBOX_CLK_ID_I2C,
25 	SANDBOX_CLK_ID_UART1,
26 	SANDBOX_CLK_ID_UART2,
27 	SANDBOX_CLK_ID_BUS,
28 
29 	SANDBOX_CLK_ID_COUNT,
30 };
31 
32 /**
33  * enum sandbox_clk_test_id - Identity of the clocks consumed by the sandbox
34  * clock test device.
35  *
36  * These are the IDs the clock consumer knows the clocks as.
37  */
38 enum sandbox_clk_test_id {
39 	SANDBOX_CLK_TEST_ID_FIXED,
40 	SANDBOX_CLK_TEST_ID_SPI,
41 	SANDBOX_CLK_TEST_ID_I2C,
42 	SANDBOX_CLK_TEST_ID_DEVM1,
43 	SANDBOX_CLK_TEST_ID_DEVM2,
44 	SANDBOX_CLK_TEST_ID_DEVM_NULL,
45 
46 	SANDBOX_CLK_TEST_ID_COUNT,
47 };
48 
49 #define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1
50 
51 struct sandbox_clk_priv {
52 	bool probed;
53 	ulong rate[SANDBOX_CLK_ID_COUNT];
54 	bool enabled[SANDBOX_CLK_ID_COUNT];
55 	bool requested[SANDBOX_CLK_ID_COUNT];
56 };
57 
58 struct sandbox_clk_test {
59 	struct clk clks[SANDBOX_CLK_TEST_NON_DEVM_COUNT];
60 	struct clk *clkps[SANDBOX_CLK_TEST_ID_COUNT];
61 	struct clk_bulk bulk;
62 };
63 
64 /* Platform data for the sandbox fixed-rate clock driver */
65 struct sandbox_clk_fixed_rate_plat {
66 #if CONFIG_IS_ENABLED(OF_PLATDATA)
67 	struct dtd_sandbox_fixed_clock dtplat;
68 #endif
69 	struct clk_fixed_rate fixed;
70 };
71 
72 /**
73  * sandbox_clk_query_rate - Query the current rate of a sandbox clock.
74  *
75  * @dev:	The sandbox clock provider device.
76  * @id:		The clock to query.
77  * @return:	The rate of the clock.
78  */
79 ulong sandbox_clk_query_rate(struct udevice *dev, int id);
80 /**
81  * sandbox_clk_query_enable - Query the enable state of a sandbox clock.
82  *
83  * @dev:	The sandbox clock provider device.
84  * @id:		The clock to query.
85  * @return:	The rate of the clock.
86  */
87 int sandbox_clk_query_enable(struct udevice *dev, int id);
88 /**
89  * sandbox_clk_query_requested - Query the requested state of a sandbox clock.
90  *
91  * @dev:	The sandbox clock provider device.
92  * @id:		The clock to query.
93  * @return:	The rate of the clock.
94  */
95 int sandbox_clk_query_requested(struct udevice *dev, int id);
96 
97 /**
98  * sandbox_clk_test_get - Ask the sandbox clock test device to request its
99  * clocks.
100  *
101  * @dev:	The sandbox clock test (client) device.
102  * @return:	0 if OK, or a negative error code.
103  */
104 int sandbox_clk_test_get(struct udevice *dev);
105 
106 /**
107  * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its
108  * clocks using the managed API.
109  *
110  * @dev:	The sandbox clock test (client) device.
111  * @return:	0 if OK, or a negative error code.
112  */
113 int sandbox_clk_test_devm_get(struct udevice *dev);
114 
115 /**
116  * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
117  * clocks with the bulk clk API.
118  *
119  * @dev:	The sandbox clock test (client) device.
120  * @return:	0 if OK, or a negative error code.
121  */
122 int sandbox_clk_test_get_bulk(struct udevice *dev);
123 /**
124  * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
125  * clock's rate.
126  *
127  * @dev:	The sandbox clock test (client) device.
128  * @id:		The test device's clock ID to query.
129  * @return:	The rate of the clock.
130  */
131 ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
132 /**
133  * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a
134  * clock's rate.
135  *
136  * @dev:	The sandbox clock test (client) device.
137  * @id:		The test device's clock ID to configure.
138  * @return:	The rounded rate of the clock.
139  */
140 ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate);
141 /**
142  * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
143  * clock's rate.
144  *
145  * @dev:	The sandbox clock test (client) device.
146  * @id:		The test device's clock ID to configure.
147  * @return:	The new rate of the clock.
148  */
149 ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate);
150 /**
151  * sandbox_clk_test_enable - Ask the sandbox clock test device to enable a
152  * clock.
153  *
154  * @dev:	The sandbox clock test (client) device.
155  * @id:		The test device's clock ID to configure.
156  * @return:	0 if OK, or a negative error code.
157  */
158 int sandbox_clk_test_enable(struct udevice *dev, int id);
159 /**
160  * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable
161  * all clocks in it's clock bulk struct.
162  *
163  * @dev:	The sandbox clock test (client) device.
164  * @return:	0 if OK, or a negative error code.
165  */
166 int sandbox_clk_test_enable_bulk(struct udevice *dev);
167 /**
168  * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a
169  * clock.
170  *
171  * @dev:	The sandbox clock test (client) device.
172  * @id:		The test device's clock ID to configure.
173  * @return:	0 if OK, or a negative error code.
174  */
175 int sandbox_clk_test_disable(struct udevice *dev, int id);
176 /**
177  * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable
178  * all clocks in it's clock bulk struct.
179  *
180  * @dev:	The sandbox clock test (client) device.
181  * @return:	0 if OK, or a negative error code.
182  */
183 int sandbox_clk_test_disable_bulk(struct udevice *dev);
184 /**
185  * sandbox_clk_test_free - Ask the sandbox clock test device to free its
186  * clocks.
187  *
188  * @dev:	The sandbox clock test (client) device.
189  * @return:	0 if OK, or a negative error code.
190  */
191 int sandbox_clk_test_free(struct udevice *dev);
192 /**
193  * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release
194  * all clocks in it's clock bulk struct.
195  *
196  * @dev:	The sandbox clock test (client) device.
197  * @return:	0 if OK, or a negative error code.
198  */
199 int sandbox_clk_test_release_bulk(struct udevice *dev);
200 /**
201  * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
202  * clocks are valid.
203  *
204  * @dev:	The sandbox clock test (client) device.
205  * @return:	0 if OK, or a negative error code.
206  */
207 int sandbox_clk_test_valid(struct udevice *dev);
208 /**
209  * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
210  * clocks are valid.
211  *
212  * @dev:	The sandbox clock test (client) device.
213  * @return:	0 if OK, or a negative error code.
214  */
215 struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id);
216 
217 #endif
218