Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | a962243 | 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 | 96d5736 | 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 | a962243 | 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 | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 25 | SANDBOX_CLK_ID_UART1, |
| 26 | SANDBOX_CLK_ID_UART2, |
Sean Anderson | b786054 | 2020-06-24 06:41:12 -0400 | [diff] [blame] | 27 | SANDBOX_CLK_ID_BUS, |
Stephen Warren | a962243 | 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 | 98e8418 | 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 | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 45 | |
| 46 | SANDBOX_CLK_TEST_ID_COUNT, |
| 47 | }; |
| 48 | |
Jean-Jacques Hiblot | 98e8418 | 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 | 96d5736 | 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 | |
Simon Glass | 9bb88fb | 2021-03-15 17:25:24 +1300 | [diff] [blame] | 64 | /* Platform data for the sandbox fixed-rate clock driver */ |
| 65 | struct 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 Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 72 | /** |
| 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 | */ |
| 79 | ulong 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 | */ |
| 87 | int sandbox_clk_query_enable(struct udevice *dev, int id); |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 88 | /** |
| 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 | */ |
| 95 | int sandbox_clk_query_requested(struct udevice *dev, int id); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * sandbox_clk_test_get - Ask the sandbox clock test device to request its |
| 99 | * clocks. |
| 100 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 101 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 102 | * @return: 0 if OK, or a negative error code. |
| 103 | */ |
| 104 | int sandbox_clk_test_get(struct udevice *dev); |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its |
| 108 | * clocks using the managed API. |
| 109 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 110 | * @dev: The sandbox clock test (client) device. |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 111 | * @return: 0 if OK, or a negative error code. |
| 112 | */ |
| 113 | int sandbox_clk_test_devm_get(struct udevice *dev); |
| 114 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 115 | /** |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 116 | * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its |
| 117 | * clocks with the bulk clk API. |
| 118 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 119 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 120 | * @return: 0 if OK, or a negative error code. |
| 121 | */ |
| 122 | int sandbox_clk_test_get_bulk(struct udevice *dev); |
| 123 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 124 | * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a |
| 125 | * clock's rate. |
| 126 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 127 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 128 | * @id: The test device's clock ID to query. |
| 129 | * @return: The rate of the clock. |
| 130 | */ |
| 131 | ulong sandbox_clk_test_get_rate(struct udevice *dev, int id); |
| 132 | /** |
Dario Binacchi | b7f8589 | 2020-12-30 00:06:31 +0100 | [diff] [blame] | 133 | * 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 | */ |
| 140 | ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate); |
| 141 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 142 | * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a |
| 143 | * clock's rate. |
| 144 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 145 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 146 | * @id: The test device's clock ID to configure. |
| 147 | * @return: The new rate of the clock. |
| 148 | */ |
| 149 | ulong 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 Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 154 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 155 | * @id: The test device's clock ID to configure. |
| 156 | * @return: 0 if OK, or a negative error code. |
| 157 | */ |
| 158 | int sandbox_clk_test_enable(struct udevice *dev, int id); |
| 159 | /** |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 160 | * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable |
| 161 | * all clocks in it's clock bulk struct. |
| 162 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 163 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 164 | * @return: 0 if OK, or a negative error code. |
| 165 | */ |
| 166 | int sandbox_clk_test_enable_bulk(struct udevice *dev); |
| 167 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 168 | * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a |
| 169 | * clock. |
| 170 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 171 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 172 | * @id: The test device's clock ID to configure. |
| 173 | * @return: 0 if OK, or a negative error code. |
| 174 | */ |
| 175 | int sandbox_clk_test_disable(struct udevice *dev, int id); |
| 176 | /** |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 177 | * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable |
| 178 | * all clocks in it's clock bulk struct. |
| 179 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 180 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 181 | * @return: 0 if OK, or a negative error code. |
| 182 | */ |
| 183 | int sandbox_clk_test_disable_bulk(struct udevice *dev); |
| 184 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 185 | * sandbox_clk_test_free - Ask the sandbox clock test device to free its |
| 186 | * clocks. |
| 187 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 188 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 189 | * @return: 0 if OK, or a negative error code. |
| 190 | */ |
| 191 | int sandbox_clk_test_free(struct udevice *dev); |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 192 | /** |
| 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 Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 196 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 197 | * @return: 0 if OK, or a negative error code. |
| 198 | */ |
| 199 | int sandbox_clk_test_release_bulk(struct udevice *dev); |
Fabrice Gasnier | 1119271 | 2018-07-24 16:31:28 +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 | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 204 | * @dev: The sandbox clock test (client) device. |
Fabrice Gasnier | 1119271 | 2018-07-24 16:31:28 +0200 | [diff] [blame] | 205 | * @return: 0 if OK, or a negative error code. |
| 206 | */ |
| 207 | int sandbox_clk_test_valid(struct udevice *dev); |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 208 | /** |
| 209 | * sandbox_clk_test_valid - Ask the sandbox clock test device to check its |
| 210 | * clocks are valid. |
| 211 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 212 | * @dev: The sandbox clock test (client) device. |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 213 | * @return: 0 if OK, or a negative error code. |
| 214 | */ |
| 215 | struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 216 | |
| 217 | #endif |