blob: 1daf2e7ac79ad252f178a3de9d9287b975b43861 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Stephen Warren135aa952016-06-17 09:44:00 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren135aa952016-06-17 09:44:00 -06004 */
5
6#ifndef __SANDBOX_CLK_H
7#define __SANDBOX_CLK_H
8
9#include <common.h>
Simon Glasscc7ffd32021-03-15 17:25:22 +130010#include <clk.h>
11#include <dt-structs.h>
12#include <linux/clk-provider.h>
Stephen Warren135aa952016-06-17 09:44:00 -060013
14struct 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 */
22enum sandbox_clk_id {
23 SANDBOX_CLK_ID_SPI,
24 SANDBOX_CLK_ID_I2C,
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +020025 SANDBOX_CLK_ID_UART1,
26 SANDBOX_CLK_ID_UART2,
Sean Anderson4a3390f2020-06-24 06:41:12 -040027 SANDBOX_CLK_ID_BUS,
Stephen Warren135aa952016-06-17 09:44:00 -060028
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 */
38enum sandbox_clk_test_id {
39 SANDBOX_CLK_TEST_ID_FIXED,
40 SANDBOX_CLK_TEST_ID_SPI,
41 SANDBOX_CLK_TEST_ID_I2C,
Yang Xiwend3061822023-12-16 02:28:52 +080042 SANDBOX_CLK_TEST_ID_I2C_ROOT,
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +020043 SANDBOX_CLK_TEST_ID_DEVM1,
44 SANDBOX_CLK_TEST_ID_DEVM2,
45 SANDBOX_CLK_TEST_ID_DEVM_NULL,
Stephen Warren135aa952016-06-17 09:44:00 -060046
47 SANDBOX_CLK_TEST_ID_COUNT,
48};
49
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +020050#define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1
51
Simon Glasscc7ffd32021-03-15 17:25:22 +130052struct sandbox_clk_priv {
53 bool probed;
54 ulong rate[SANDBOX_CLK_ID_COUNT];
55 bool enabled[SANDBOX_CLK_ID_COUNT];
56 bool requested[SANDBOX_CLK_ID_COUNT];
57};
58
59struct sandbox_clk_test {
60 struct clk clks[SANDBOX_CLK_TEST_NON_DEVM_COUNT];
61 struct clk *clkps[SANDBOX_CLK_TEST_ID_COUNT];
62 struct clk_bulk bulk;
63};
64
Simon Glass88139862021-03-15 17:25:24 +130065/* Platform data for the sandbox fixed-rate clock driver */
66struct sandbox_clk_fixed_rate_plat {
67#if CONFIG_IS_ENABLED(OF_PLATDATA)
68 struct dtd_sandbox_fixed_clock dtplat;
69#endif
70 struct clk_fixed_rate fixed;
71};
72
Stephen Warren135aa952016-06-17 09:44:00 -060073/**
74 * sandbox_clk_query_rate - Query the current rate of a sandbox clock.
75 *
76 * @dev: The sandbox clock provider device.
77 * @id: The clock to query.
78 * @return: The rate of the clock.
79 */
80ulong sandbox_clk_query_rate(struct udevice *dev, int id);
81/**
82 * sandbox_clk_query_enable - Query the enable state of a sandbox clock.
83 *
84 * @dev: The sandbox clock provider device.
85 * @id: The clock to query.
86 * @return: The rate of the clock.
87 */
88int sandbox_clk_query_enable(struct udevice *dev, int id);
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +020089/**
90 * sandbox_clk_query_requested - Query the requested state of a sandbox clock.
91 *
92 * @dev: The sandbox clock provider device.
93 * @id: The clock to query.
94 * @return: The rate of the clock.
95 */
96int sandbox_clk_query_requested(struct udevice *dev, int id);
Stephen Warren135aa952016-06-17 09:44:00 -060097
98/**
99 * sandbox_clk_test_get - Ask the sandbox clock test device to request its
100 * clocks.
101 *
Dario Binacchid67da442021-02-14 15:17:43 +0100102 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600103 * @return: 0 if OK, or a negative error code.
104 */
105int sandbox_clk_test_get(struct udevice *dev);
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +0200106
107/**
108 * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its
109 * clocks using the managed API.
110 *
Dario Binacchid67da442021-02-14 15:17:43 +0100111 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +0200112 * @return: 0 if OK, or a negative error code.
113 */
114int sandbox_clk_test_devm_get(struct udevice *dev);
115
Stephen Warren135aa952016-06-17 09:44:00 -0600116/**
Neil Armstrong65388d02018-04-03 11:44:19 +0200117 * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
118 * clocks with the bulk clk API.
119 *
Dario Binacchid67da442021-02-14 15:17:43 +0100120 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200121 * @return: 0 if OK, or a negative error code.
122 */
123int sandbox_clk_test_get_bulk(struct udevice *dev);
124/**
Stephen Warren135aa952016-06-17 09:44:00 -0600125 * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
126 * clock's rate.
127 *
Dario Binacchid67da442021-02-14 15:17:43 +0100128 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600129 * @id: The test device's clock ID to query.
130 * @return: The rate of the clock.
131 */
132ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
133/**
Dario Binacchi2983ad52020-12-30 00:06:31 +0100134 * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a
135 * clock's rate.
136 *
137 * @dev: The sandbox clock test (client) device.
138 * @id: The test device's clock ID to configure.
139 * @return: The rounded rate of the clock.
140 */
141ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate);
142/**
Stephen Warren135aa952016-06-17 09:44:00 -0600143 * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
144 * clock's rate.
145 *
Dario Binacchid67da442021-02-14 15:17:43 +0100146 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600147 * @id: The test device's clock ID to configure.
148 * @return: The new rate of the clock.
149 */
150ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate);
151/**
152 * sandbox_clk_test_enable - Ask the sandbox clock test device to enable a
153 * clock.
154 *
Dario Binacchid67da442021-02-14 15:17:43 +0100155 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600156 * @id: The test device's clock ID to configure.
157 * @return: 0 if OK, or a negative error code.
158 */
159int sandbox_clk_test_enable(struct udevice *dev, int id);
160/**
Neil Armstrong65388d02018-04-03 11:44:19 +0200161 * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable
162 * all clocks in it's clock bulk struct.
163 *
Dario Binacchid67da442021-02-14 15:17:43 +0100164 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200165 * @return: 0 if OK, or a negative error code.
166 */
167int sandbox_clk_test_enable_bulk(struct udevice *dev);
168/**
Stephen Warren135aa952016-06-17 09:44:00 -0600169 * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a
170 * clock.
171 *
Dario Binacchid67da442021-02-14 15:17:43 +0100172 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600173 * @id: The test device's clock ID to configure.
174 * @return: 0 if OK, or a negative error code.
175 */
176int sandbox_clk_test_disable(struct udevice *dev, int id);
177/**
Neil Armstrong65388d02018-04-03 11:44:19 +0200178 * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable
179 * all clocks in it's clock bulk struct.
180 *
Dario Binacchid67da442021-02-14 15:17:43 +0100181 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200182 * @return: 0 if OK, or a negative error code.
183 */
184int sandbox_clk_test_disable_bulk(struct udevice *dev);
185/**
Stephen Warren135aa952016-06-17 09:44:00 -0600186 * sandbox_clk_test_free - Ask the sandbox clock test device to free its
187 * clocks.
188 *
Dario Binacchid67da442021-02-14 15:17:43 +0100189 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600190 * @return: 0 if OK, or a negative error code.
191 */
192int sandbox_clk_test_free(struct udevice *dev);
Neil Armstrong65388d02018-04-03 11:44:19 +0200193/**
194 * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release
195 * all clocks in it's clock bulk struct.
196 *
Dario Binacchid67da442021-02-14 15:17:43 +0100197 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200198 * @return: 0 if OK, or a negative error code.
199 */
200int sandbox_clk_test_release_bulk(struct udevice *dev);
Fabrice Gasnier1fe243a2018-07-24 16:31:28 +0200201/**
202 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
203 * clocks are valid.
204 *
Dario Binacchid67da442021-02-14 15:17:43 +0100205 * @dev: The sandbox clock test (client) device.
Fabrice Gasnier1fe243a2018-07-24 16:31:28 +0200206 * @return: 0 if OK, or a negative error code.
207 */
208int sandbox_clk_test_valid(struct udevice *dev);
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +0200209/**
210 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
211 * clocks are valid.
212 *
Dario Binacchid67da442021-02-14 15:17:43 +0100213 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +0200214 * @return: 0 if OK, or a negative error code.
215 */
216struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id);
Stephen Warren135aa952016-06-17 09:44:00 -0600217
218#endif