blob: d4e04ad148612c867944bccdf34c4419930f482b [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,
Yang Xiwene89289c2023-12-16 02:28:52 +080041 SANDBOX_CLK_TEST_ID_I2C_ROOT,
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +020042 SANDBOX_CLK_TEST_ID_DEVM1,
43 SANDBOX_CLK_TEST_ID_DEVM2,
44 SANDBOX_CLK_TEST_ID_DEVM_NULL,
Stephen Warrena9622432016-06-17 09:44:00 -060045
46 SANDBOX_CLK_TEST_ID_COUNT,
47};
48
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +020049#define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1
50
Simon Glass96d57362021-03-15 17:25:22 +130051struct 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
58struct 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
Simon Glass9bb88fb2021-03-15 17:25:24 +130064/* Platform data for the sandbox fixed-rate clock driver */
65struct 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
Stephen Warrena9622432016-06-17 09:44:00 -060072/**
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 */
79ulong 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 */
87int sandbox_clk_query_enable(struct udevice *dev, int id);
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +020088/**
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 */
95int sandbox_clk_query_requested(struct udevice *dev, int id);
Stephen Warrena9622432016-06-17 09:44:00 -060096
97/**
98 * sandbox_clk_test_get - Ask the sandbox clock test device to request its
99 * clocks.
100 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100101 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600102 * @return: 0 if OK, or a negative error code.
103 */
104int sandbox_clk_test_get(struct udevice *dev);
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200105
106/**
107 * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its
108 * clocks using the managed API.
109 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100110 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200111 * @return: 0 if OK, or a negative error code.
112 */
113int sandbox_clk_test_devm_get(struct udevice *dev);
114
Stephen Warrena9622432016-06-17 09:44:00 -0600115/**
Neil Armstrong567a38b2018-04-03 11:44:19 +0200116 * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
117 * clocks with the bulk clk API.
118 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100119 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200120 * @return: 0 if OK, or a negative error code.
121 */
122int sandbox_clk_test_get_bulk(struct udevice *dev);
123/**
Stephen Warrena9622432016-06-17 09:44:00 -0600124 * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
125 * clock's rate.
126 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100127 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600128 * @id: The test device's clock ID to query.
129 * @return: The rate of the clock.
130 */
131ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
132/**
Dario Binacchib7f85892020-12-30 00:06:31 +0100133 * 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 */
140ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate);
141/**
Stephen Warrena9622432016-06-17 09:44:00 -0600142 * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
143 * clock's rate.
144 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100145 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600146 * @id: The test device's clock ID to configure.
147 * @return: The new rate of the clock.
148 */
149ulong 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 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100154 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600155 * @id: The test device's clock ID to configure.
156 * @return: 0 if OK, or a negative error code.
157 */
158int sandbox_clk_test_enable(struct udevice *dev, int id);
159/**
Neil Armstrong567a38b2018-04-03 11:44:19 +0200160 * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable
161 * all clocks in it's clock bulk struct.
162 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100163 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200164 * @return: 0 if OK, or a negative error code.
165 */
166int sandbox_clk_test_enable_bulk(struct udevice *dev);
167/**
Stephen Warrena9622432016-06-17 09:44:00 -0600168 * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a
169 * clock.
170 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100171 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600172 * @id: The test device's clock ID to configure.
173 * @return: 0 if OK, or a negative error code.
174 */
175int sandbox_clk_test_disable(struct udevice *dev, int id);
176/**
Neil Armstrong567a38b2018-04-03 11:44:19 +0200177 * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable
178 * all clocks in it's clock bulk struct.
179 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100180 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200181 * @return: 0 if OK, or a negative error code.
182 */
183int sandbox_clk_test_disable_bulk(struct udevice *dev);
184/**
Stephen Warrena9622432016-06-17 09:44:00 -0600185 * sandbox_clk_test_free - Ask the sandbox clock test device to free its
186 * clocks.
187 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100188 * @dev: The sandbox clock test (client) device.
Stephen Warrena9622432016-06-17 09:44:00 -0600189 * @return: 0 if OK, or a negative error code.
190 */
191int sandbox_clk_test_free(struct udevice *dev);
Neil Armstrong567a38b2018-04-03 11:44:19 +0200192/**
193 * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release
194 * all clocks in it's clock bulk struct.
195 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100196 * @dev: The sandbox clock test (client) device.
Neil Armstrong567a38b2018-04-03 11:44:19 +0200197 * @return: 0 if OK, or a negative error code.
198 */
199int sandbox_clk_test_release_bulk(struct udevice *dev);
Fabrice Gasnier11192712018-07-24 16:31:28 +0200200/**
201 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
202 * clocks are valid.
203 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100204 * @dev: The sandbox clock test (client) device.
Fabrice Gasnier11192712018-07-24 16:31:28 +0200205 * @return: 0 if OK, or a negative error code.
206 */
207int sandbox_clk_test_valid(struct udevice *dev);
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200208/**
209 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
210 * clocks are valid.
211 *
Dario Binacchi6a02d3f2021-02-14 15:17:43 +0100212 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblot98e84182019-10-22 14:00:05 +0200213 * @return: 0 if OK, or a negative error code.
214 */
215struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id);
Stephen Warrena9622432016-06-17 09:44:00 -0600216
217#endif