blob: 2b7dbca8f75511af5c67f5f58ab478e96f9d1e06 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Stephen Warrena9622432016-06-17 09:44:00 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warrena9622432016-06-17 09:44:00 -06004 */
5
6#ifndef __SANDBOX_CLK_H
7#define __SANDBOX_CLK_H
8
Simon Glass96d57362021-03-15 17:25:22 +13009#include <clk.h>
10#include <dt-structs.h>
11#include <linux/clk-provider.h>
Stephen Warrena9622432016-06-17 09:44:00 -060012
13struct udevice;
14
15/**
16 * enum sandbox_clk_id - Identity of clocks implemented by the sandbox clock
17 * provider.
18 *
19 * These IDs are within/relative-to the clock provider.
20 */
21enum sandbox_clk_id {
22 SANDBOX_CLK_ID_SPI,
23 SANDBOX_CLK_ID_I2C,
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +020024 SANDBOX_CLK_ID_UART1,
25 SANDBOX_CLK_ID_UART2,
Sean Andersonb7860542020-06-24 06:41:12 -040026 SANDBOX_CLK_ID_BUS,
Stephen Warrena9622432016-06-17 09:44:00 -060027
28 SANDBOX_CLK_ID_COUNT,
29};
30
31/**
32 * enum sandbox_clk_test_id - Identity of the clocks consumed by the sandbox
33 * clock test device.
34 *
35 * These are the IDs the clock consumer knows the clocks as.
36 */
37enum sandbox_clk_test_id {
38 SANDBOX_CLK_TEST_ID_FIXED,
39 SANDBOX_CLK_TEST_ID_SPI,
40 SANDBOX_CLK_TEST_ID_I2C,
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +020041 SANDBOX_CLK_TEST_ID_DEVM1,
42 SANDBOX_CLK_TEST_ID_DEVM2,
43 SANDBOX_CLK_TEST_ID_DEVM_NULL,
Stephen Warrena9622432016-06-17 09:44:00 -060044
45 SANDBOX_CLK_TEST_ID_COUNT,
46};
47
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +020048#define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1
49
Simon Glass96d57362021-03-15 17:25:22 +130050struct sandbox_clk_priv {
51 bool probed;
52 ulong rate[SANDBOX_CLK_ID_COUNT];
53 bool enabled[SANDBOX_CLK_ID_COUNT];
54 bool requested[SANDBOX_CLK_ID_COUNT];
55};
56
57struct sandbox_clk_test {
58 struct clk clks[SANDBOX_CLK_TEST_NON_DEVM_COUNT];
59 struct clk *clkps[SANDBOX_CLK_TEST_ID_COUNT];
60 struct clk_bulk bulk;
61};
62
Simon Glass9bb88fb2021-03-15 17:25:24 +130063/* Platform data for the sandbox fixed-rate clock driver */
64struct sandbox_clk_fixed_rate_plat {
65#if CONFIG_IS_ENABLED(OF_PLATDATA)
66 struct dtd_sandbox_fixed_clock dtplat;
67#endif
68 struct clk_fixed_rate fixed;
69};
70
Stephen Warrena9622432016-06-17 09:44:00 -060071/**
72 * sandbox_clk_query_rate - Query the current rate of a sandbox clock.
73 *
74 * @dev: The sandbox clock provider device.
75 * @id: The clock to query.
76 * @return: The rate of the clock.
77 */
78ulong sandbox_clk_query_rate(struct udevice *dev, int id);
79/**
80 * sandbox_clk_query_enable - Query the enable state of a sandbox clock.
81 *
82 * @dev: The sandbox clock provider device.
83 * @id: The clock to query.
84 * @return: The rate of the clock.
85 */
86int sandbox_clk_query_enable(struct udevice *dev, int id);
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +020087/**
88 * sandbox_clk_query_requested - Query the requested state of a sandbox clock.
89 *
90 * @dev: The sandbox clock provider device.
91 * @id: The clock to query.
92 * @return: The rate of the clock.
93 */
94int sandbox_clk_query_requested(struct udevice *dev, int id);
Stephen Warrena9622432016-06-17 09:44:00 -060095
96/**
97 * sandbox_clk_test_get - Ask the sandbox clock test device to request its
98 * clocks.
99 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100100 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600101 * @return: 0 if OK, or a negative error code.
102 */
103int sandbox_clk_test_get(struct udevice *dev);
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200104
105/**
106 * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its
107 * clocks using the managed API.
108 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100109 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200110 * @return: 0 if OK, or a negative error code.
111 */
112int sandbox_clk_test_devm_get(struct udevice *dev);
113
Stephen Warrena9622432016-06-17 09:44:00 -0600114/**
Neil Armstrong567a38b2018-04-03 11:44:19 +0200115 * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
116 * clocks with the bulk clk API.
117 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100118 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200119 * @return: 0 if OK, or a negative error code.
120 */
121int sandbox_clk_test_get_bulk(struct udevice *dev);
122/**
Stephen Warrena9622432016-06-17 09:44:00 -0600123 * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
124 * clock's rate.
125 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100126 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600127 * @id: The test device's clock ID to query.
128 * @return: The rate of the clock.
129 */
130ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
131/**
Dario Binacchib7f85892020-12-30 00:06:31 +0100132 * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a
133 * clock's rate.
134 *
135 * @dev: The sandbox clock test (client) device.
136 * @id: The test device's clock ID to configure.
137 * @return: The rounded rate of the clock.
138 */
139ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate);
140/**
Stephen Warrena9622432016-06-17 09:44:00 -0600141 * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
142 * clock's rate.
143 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100144 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600145 * @id: The test device's clock ID to configure.
146 * @return: The new rate of the clock.
147 */
148ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate);
149/**
150 * sandbox_clk_test_enable - Ask the sandbox clock test device to enable a
151 * clock.
152 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100153 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600154 * @id: The test device's clock ID to configure.
155 * @return: 0 if OK, or a negative error code.
156 */
157int sandbox_clk_test_enable(struct udevice *dev, int id);
158/**
Neil Armstrong567a38b2018-04-03 11:44:19 +0200159 * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable
160 * all clocks in it's clock bulk struct.
161 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100162 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200163 * @return: 0 if OK, or a negative error code.
164 */
165int sandbox_clk_test_enable_bulk(struct udevice *dev);
166/**
Stephen Warrena9622432016-06-17 09:44:00 -0600167 * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a
168 * clock.
169 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100170 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600171 * @id: The test device's clock ID to configure.
172 * @return: 0 if OK, or a negative error code.
173 */
174int sandbox_clk_test_disable(struct udevice *dev, int id);
175/**
Neil Armstrong567a38b2018-04-03 11:44:19 +0200176 * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable
177 * all clocks in it's clock bulk struct.
178 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100179 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200180 * @return: 0 if OK, or a negative error code.
181 */
182int sandbox_clk_test_disable_bulk(struct udevice *dev);
183/**
Stephen Warrena9622432016-06-17 09:44:00 -0600184 * sandbox_clk_test_free - Ask the sandbox clock test device to free its
185 * clocks.
186 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100187 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600188 * @return: 0 if OK, or a negative error code.
189 */
190int sandbox_clk_test_free(struct udevice *dev);
Neil Armstrong567a38b2018-04-03 11:44:19 +0200191/**
192 * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release
193 * all clocks in it's clock bulk struct.
194 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100195 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200196 * @return: 0 if OK, or a negative error code.
197 */
198int sandbox_clk_test_release_bulk(struct udevice *dev);
Fabrice Gasnier11192712018-07-24 16:31:28 +0200199/**
200 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
201 * clocks are valid.
202 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100203 * @dev: The sandbox clock test (client) device.
Fabrice Gasnier11192712018-07-24 16:31:28 +0200204 * @return: 0 if OK, or a negative error code.
205 */
206int sandbox_clk_test_valid(struct udevice *dev);
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200207/**
208 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
209 * clocks are valid.
210 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100211 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200212 * @return: 0 if OK, or a negative error code.
213 */
214struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id);
Stephen Warrena9622432016-06-17 09:44:00 -0600215
216#endif