Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __SANDBOX_CLK_H |
| 7 | #define __SANDBOX_CLK_H |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | cc7ffd3 | 2021-03-15 17:25:22 +1300 | [diff] [blame^] | 10 | #include <clk.h> |
| 11 | #include <dt-structs.h> |
| 12 | #include <linux/clk-provider.h> |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 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, |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 25 | SANDBOX_CLK_ID_UART1, |
| 26 | SANDBOX_CLK_ID_UART2, |
Sean Anderson | 4a3390f | 2020-06-24 06:41:12 -0400 | [diff] [blame] | 27 | SANDBOX_CLK_ID_BUS, |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 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, |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 42 | SANDBOX_CLK_TEST_ID_DEVM1, |
| 43 | SANDBOX_CLK_TEST_ID_DEVM2, |
| 44 | SANDBOX_CLK_TEST_ID_DEVM_NULL, |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 45 | |
| 46 | SANDBOX_CLK_TEST_ID_COUNT, |
| 47 | }; |
| 48 | |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 49 | #define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1 |
| 50 | |
Simon Glass | cc7ffd3 | 2021-03-15 17:25:22 +1300 | [diff] [blame^] | 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 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 64 | /** |
| 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 | */ |
| 71 | ulong 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 | */ |
| 79 | int sandbox_clk_query_enable(struct udevice *dev, int id); |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 80 | /** |
| 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 | */ |
| 87 | int sandbox_clk_query_requested(struct udevice *dev, int id); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * sandbox_clk_test_get - Ask the sandbox clock test device to request its |
| 91 | * clocks. |
| 92 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 93 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 94 | * @return: 0 if OK, or a negative error code. |
| 95 | */ |
| 96 | int sandbox_clk_test_get(struct udevice *dev); |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its |
| 100 | * clocks using the managed API. |
| 101 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 102 | * @dev: The sandbox clock test (client) device. |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 103 | * @return: 0 if OK, or a negative error code. |
| 104 | */ |
| 105 | int sandbox_clk_test_devm_get(struct udevice *dev); |
| 106 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 107 | /** |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 108 | * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its |
| 109 | * clocks with the bulk clk API. |
| 110 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 111 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 112 | * @return: 0 if OK, or a negative error code. |
| 113 | */ |
| 114 | int sandbox_clk_test_get_bulk(struct udevice *dev); |
| 115 | /** |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 116 | * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a |
| 117 | * clock's rate. |
| 118 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 119 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 120 | * @id: The test device's clock ID to query. |
| 121 | * @return: The rate of the clock. |
| 122 | */ |
| 123 | ulong sandbox_clk_test_get_rate(struct udevice *dev, int id); |
| 124 | /** |
Dario Binacchi | 2983ad5 | 2020-12-30 00:06:31 +0100 | [diff] [blame] | 125 | * 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 | */ |
| 132 | ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate); |
| 133 | /** |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 134 | * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a |
| 135 | * clock's rate. |
| 136 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 137 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 138 | * @id: The test device's clock ID to configure. |
| 139 | * @return: The new rate of the clock. |
| 140 | */ |
| 141 | ulong 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 Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 146 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 147 | * @id: The test device's clock ID to configure. |
| 148 | * @return: 0 if OK, or a negative error code. |
| 149 | */ |
| 150 | int sandbox_clk_test_enable(struct udevice *dev, int id); |
| 151 | /** |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 152 | * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable |
| 153 | * all clocks in it's clock bulk struct. |
| 154 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 155 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 156 | * @return: 0 if OK, or a negative error code. |
| 157 | */ |
| 158 | int sandbox_clk_test_enable_bulk(struct udevice *dev); |
| 159 | /** |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 160 | * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a |
| 161 | * clock. |
| 162 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 163 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 164 | * @id: The test device's clock ID to configure. |
| 165 | * @return: 0 if OK, or a negative error code. |
| 166 | */ |
| 167 | int sandbox_clk_test_disable(struct udevice *dev, int id); |
| 168 | /** |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 169 | * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable |
| 170 | * all clocks in it's clock bulk struct. |
| 171 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 172 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 173 | * @return: 0 if OK, or a negative error code. |
| 174 | */ |
| 175 | int sandbox_clk_test_disable_bulk(struct udevice *dev); |
| 176 | /** |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 177 | * sandbox_clk_test_free - Ask the sandbox clock test device to free its |
| 178 | * clocks. |
| 179 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 180 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 181 | * @return: 0 if OK, or a negative error code. |
| 182 | */ |
| 183 | int sandbox_clk_test_free(struct udevice *dev); |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 184 | /** |
| 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 Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 188 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 65388d0 | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 189 | * @return: 0 if OK, or a negative error code. |
| 190 | */ |
| 191 | int sandbox_clk_test_release_bulk(struct udevice *dev); |
Fabrice Gasnier | 1fe243a | 2018-07-24 16:31:28 +0200 | [diff] [blame] | 192 | /** |
| 193 | * sandbox_clk_test_valid - Ask the sandbox clock test device to check its |
| 194 | * clocks are valid. |
| 195 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 196 | * @dev: The sandbox clock test (client) device. |
Fabrice Gasnier | 1fe243a | 2018-07-24 16:31:28 +0200 | [diff] [blame] | 197 | * @return: 0 if OK, or a negative error code. |
| 198 | */ |
| 199 | int sandbox_clk_test_valid(struct udevice *dev); |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 200 | /** |
| 201 | * sandbox_clk_test_valid - Ask the sandbox clock test device to check its |
| 202 | * clocks are valid. |
| 203 | * |
Dario Binacchi | d67da44 | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 204 | * @dev: The sandbox clock test (client) device. |
Jean-Jacques Hiblot | dd2e0ce | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 205 | * @return: 0 if OK, or a negative error code. |
| 206 | */ |
| 207 | struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id); |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 208 | |
| 209 | #endif |