blob: 6972b9e743add0f2f3e2c1b7e1459b9344016b13 [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,
Jean-Jacques Hiblotdd2e0ce2019-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 Warren135aa952016-06-17 09:44:00 -060045
46 SANDBOX_CLK_TEST_ID_COUNT,
47};
48
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +020049#define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1
50
Simon Glasscc7ffd32021-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
Stephen Warren135aa952016-06-17 09:44:00 -060064/**
65 * sandbox_clk_query_rate - Query the current rate of a sandbox clock.
66 *
67 * @dev: The sandbox clock provider device.
68 * @id: The clock to query.
69 * @return: The rate of the clock.
70 */
71ulong sandbox_clk_query_rate(struct udevice *dev, int id);
72/**
73 * sandbox_clk_query_enable - Query the enable state 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 */
79int sandbox_clk_query_enable(struct udevice *dev, int id);
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +020080/**
81 * sandbox_clk_query_requested - Query the requested 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_requested(struct udevice *dev, int id);
Stephen Warren135aa952016-06-17 09:44:00 -060088
89/**
90 * sandbox_clk_test_get - Ask the sandbox clock test device to request its
91 * clocks.
92 *
Dario Binacchid67da442021-02-14 15:17:43 +010093 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -060094 * @return: 0 if OK, or a negative error code.
95 */
96int sandbox_clk_test_get(struct udevice *dev);
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +020097
98/**
99 * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its
100 * clocks using the managed API.
101 *
Dario Binacchid67da442021-02-14 15:17:43 +0100102 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +0200103 * @return: 0 if OK, or a negative error code.
104 */
105int sandbox_clk_test_devm_get(struct udevice *dev);
106
Stephen Warren135aa952016-06-17 09:44:00 -0600107/**
Neil Armstrong65388d02018-04-03 11:44:19 +0200108 * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its
109 * clocks with the bulk clk API.
110 *
Dario Binacchid67da442021-02-14 15:17:43 +0100111 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200112 * @return: 0 if OK, or a negative error code.
113 */
114int sandbox_clk_test_get_bulk(struct udevice *dev);
115/**
Stephen Warren135aa952016-06-17 09:44:00 -0600116 * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a
117 * clock's rate.
118 *
Dario Binacchid67da442021-02-14 15:17:43 +0100119 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600120 * @id: The test device's clock ID to query.
121 * @return: The rate of the clock.
122 */
123ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
124/**
Dario Binacchi2983ad52020-12-30 00:06:31 +0100125 * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a
126 * clock's rate.
127 *
128 * @dev: The sandbox clock test (client) device.
129 * @id: The test device's clock ID to configure.
130 * @return: The rounded rate of the clock.
131 */
132ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate);
133/**
Stephen Warren135aa952016-06-17 09:44:00 -0600134 * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
135 * clock's rate.
136 *
Dario Binacchid67da442021-02-14 15:17:43 +0100137 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600138 * @id: The test device's clock ID to configure.
139 * @return: The new rate of the clock.
140 */
141ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate);
142/**
143 * sandbox_clk_test_enable - Ask the sandbox clock test device to enable a
144 * clock.
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: 0 if OK, or a negative error code.
149 */
150int sandbox_clk_test_enable(struct udevice *dev, int id);
151/**
Neil Armstrong65388d02018-04-03 11:44:19 +0200152 * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable
153 * all clocks in it's clock bulk struct.
154 *
Dario Binacchid67da442021-02-14 15:17:43 +0100155 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200156 * @return: 0 if OK, or a negative error code.
157 */
158int sandbox_clk_test_enable_bulk(struct udevice *dev);
159/**
Stephen Warren135aa952016-06-17 09:44:00 -0600160 * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a
161 * clock.
162 *
Dario Binacchid67da442021-02-14 15:17:43 +0100163 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600164 * @id: The test device's clock ID to configure.
165 * @return: 0 if OK, or a negative error code.
166 */
167int sandbox_clk_test_disable(struct udevice *dev, int id);
168/**
Neil Armstrong65388d02018-04-03 11:44:19 +0200169 * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable
170 * all clocks in it's clock bulk struct.
171 *
Dario Binacchid67da442021-02-14 15:17:43 +0100172 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200173 * @return: 0 if OK, or a negative error code.
174 */
175int sandbox_clk_test_disable_bulk(struct udevice *dev);
176/**
Stephen Warren135aa952016-06-17 09:44:00 -0600177 * sandbox_clk_test_free - Ask the sandbox clock test device to free its
178 * clocks.
179 *
Dario Binacchid67da442021-02-14 15:17:43 +0100180 * @dev: The sandbox clock test (client) device.
Stephen Warren135aa952016-06-17 09:44:00 -0600181 * @return: 0 if OK, or a negative error code.
182 */
183int sandbox_clk_test_free(struct udevice *dev);
Neil Armstrong65388d02018-04-03 11:44:19 +0200184/**
185 * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release
186 * all clocks in it's clock bulk struct.
187 *
Dario Binacchid67da442021-02-14 15:17:43 +0100188 * @dev: The sandbox clock test (client) device.
Neil Armstrong65388d02018-04-03 11:44:19 +0200189 * @return: 0 if OK, or a negative error code.
190 */
191int sandbox_clk_test_release_bulk(struct udevice *dev);
Fabrice Gasnier1fe243a2018-07-24 16:31:28 +0200192/**
193 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
194 * clocks are valid.
195 *
Dario Binacchid67da442021-02-14 15:17:43 +0100196 * @dev: The sandbox clock test (client) device.
Fabrice Gasnier1fe243a2018-07-24 16:31:28 +0200197 * @return: 0 if OK, or a negative error code.
198 */
199int sandbox_clk_test_valid(struct udevice *dev);
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +0200200/**
201 * sandbox_clk_test_valid - Ask the sandbox clock test device to check its
202 * clocks are valid.
203 *
Dario Binacchid67da442021-02-14 15:17:43 +0100204 * @dev: The sandbox clock test (client) device.
Jean-Jacques Hiblotdd2e0ce2019-10-22 14:00:05 +0200205 * @return: 0 if OK, or a negative error code.
206 */
207struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id);
Stephen Warren135aa952016-06-17 09:44:00 -0600208
209#endif