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 | |
Simon Glass | 96d5736 | 2021-03-15 17:25:22 +1300 | [diff] [blame] | 9 | #include <clk.h> |
| 10 | #include <dt-structs.h> |
| 11 | #include <linux/clk-provider.h> |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 12 | |
| 13 | struct 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 | */ |
| 21 | enum sandbox_clk_id { |
| 22 | SANDBOX_CLK_ID_SPI, |
| 23 | SANDBOX_CLK_ID_I2C, |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 24 | SANDBOX_CLK_ID_UART1, |
| 25 | SANDBOX_CLK_ID_UART2, |
Sean Anderson | b786054 | 2020-06-24 06:41:12 -0400 | [diff] [blame] | 26 | SANDBOX_CLK_ID_BUS, |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 27 | |
| 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 | */ |
| 37 | enum sandbox_clk_test_id { |
| 38 | SANDBOX_CLK_TEST_ID_FIXED, |
| 39 | SANDBOX_CLK_TEST_ID_SPI, |
| 40 | SANDBOX_CLK_TEST_ID_I2C, |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 41 | SANDBOX_CLK_TEST_ID_DEVM1, |
| 42 | SANDBOX_CLK_TEST_ID_DEVM2, |
| 43 | SANDBOX_CLK_TEST_ID_DEVM_NULL, |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 44 | |
| 45 | SANDBOX_CLK_TEST_ID_COUNT, |
| 46 | }; |
| 47 | |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 48 | #define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1 |
| 49 | |
Simon Glass | 96d5736 | 2021-03-15 17:25:22 +1300 | [diff] [blame] | 50 | struct sandbox_clk_priv { |
| 51 | bool probed; |
| 52 | ulong rate[SANDBOX_CLK_ID_COUNT]; |
| 53 | bool enabled[SANDBOX_CLK_ID_COUNT]; |
| 54 | bool requested[SANDBOX_CLK_ID_COUNT]; |
| 55 | }; |
| 56 | |
| 57 | struct sandbox_clk_test { |
| 58 | struct clk clks[SANDBOX_CLK_TEST_NON_DEVM_COUNT]; |
| 59 | struct clk *clkps[SANDBOX_CLK_TEST_ID_COUNT]; |
| 60 | struct clk_bulk bulk; |
| 61 | }; |
| 62 | |
Simon Glass | 9bb88fb | 2021-03-15 17:25:24 +1300 | [diff] [blame] | 63 | /* Platform data for the sandbox fixed-rate clock driver */ |
| 64 | struct sandbox_clk_fixed_rate_plat { |
| 65 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 66 | struct dtd_sandbox_fixed_clock dtplat; |
| 67 | #endif |
| 68 | struct clk_fixed_rate fixed; |
| 69 | }; |
| 70 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 71 | /** |
| 72 | * sandbox_clk_query_rate - Query the current rate of a sandbox clock. |
| 73 | * |
| 74 | * @dev: The sandbox clock provider device. |
| 75 | * @id: The clock to query. |
| 76 | * @return: The rate of the clock. |
| 77 | */ |
| 78 | ulong sandbox_clk_query_rate(struct udevice *dev, int id); |
| 79 | /** |
| 80 | * sandbox_clk_query_enable - Query the enable state of a sandbox clock. |
| 81 | * |
| 82 | * @dev: The sandbox clock provider device. |
| 83 | * @id: The clock to query. |
| 84 | * @return: The rate of the clock. |
| 85 | */ |
| 86 | int sandbox_clk_query_enable(struct udevice *dev, int id); |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 87 | /** |
| 88 | * sandbox_clk_query_requested - Query the requested state of a sandbox clock. |
| 89 | * |
| 90 | * @dev: The sandbox clock provider device. |
| 91 | * @id: The clock to query. |
| 92 | * @return: The rate of the clock. |
| 93 | */ |
| 94 | int sandbox_clk_query_requested(struct udevice *dev, int id); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * sandbox_clk_test_get - Ask the sandbox clock test device to request its |
| 98 | * clocks. |
| 99 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 100 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 101 | * @return: 0 if OK, or a negative error code. |
| 102 | */ |
| 103 | int sandbox_clk_test_get(struct udevice *dev); |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its |
| 107 | * clocks using the managed API. |
| 108 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 109 | * @dev: The sandbox clock test (client) device. |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 110 | * @return: 0 if OK, or a negative error code. |
| 111 | */ |
| 112 | int sandbox_clk_test_devm_get(struct udevice *dev); |
| 113 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 114 | /** |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 115 | * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its |
| 116 | * clocks with the bulk clk API. |
| 117 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 118 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 119 | * @return: 0 if OK, or a negative error code. |
| 120 | */ |
| 121 | int sandbox_clk_test_get_bulk(struct udevice *dev); |
| 122 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 123 | * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a |
| 124 | * clock's rate. |
| 125 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 126 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 127 | * @id: The test device's clock ID to query. |
| 128 | * @return: The rate of the clock. |
| 129 | */ |
| 130 | ulong sandbox_clk_test_get_rate(struct udevice *dev, int id); |
| 131 | /** |
Dario Binacchi | b7f8589 | 2020-12-30 00:06:31 +0100 | [diff] [blame] | 132 | * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a |
| 133 | * clock's rate. |
| 134 | * |
| 135 | * @dev: The sandbox clock test (client) device. |
| 136 | * @id: The test device's clock ID to configure. |
| 137 | * @return: The rounded rate of the clock. |
| 138 | */ |
| 139 | ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate); |
| 140 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 141 | * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a |
| 142 | * clock's rate. |
| 143 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 144 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 145 | * @id: The test device's clock ID to configure. |
| 146 | * @return: The new rate of the clock. |
| 147 | */ |
| 148 | ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate); |
| 149 | /** |
| 150 | * sandbox_clk_test_enable - Ask the sandbox clock test device to enable a |
| 151 | * clock. |
| 152 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 153 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 154 | * @id: The test device's clock ID to configure. |
| 155 | * @return: 0 if OK, or a negative error code. |
| 156 | */ |
| 157 | int sandbox_clk_test_enable(struct udevice *dev, int id); |
| 158 | /** |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 159 | * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable |
| 160 | * all clocks in it's clock bulk struct. |
| 161 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 162 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 163 | * @return: 0 if OK, or a negative error code. |
| 164 | */ |
| 165 | int sandbox_clk_test_enable_bulk(struct udevice *dev); |
| 166 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 167 | * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a |
| 168 | * clock. |
| 169 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 170 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 171 | * @id: The test device's clock ID to configure. |
| 172 | * @return: 0 if OK, or a negative error code. |
| 173 | */ |
| 174 | int sandbox_clk_test_disable(struct udevice *dev, int id); |
| 175 | /** |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 176 | * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable |
| 177 | * all clocks in it's clock bulk struct. |
| 178 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 179 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 180 | * @return: 0 if OK, or a negative error code. |
| 181 | */ |
| 182 | int sandbox_clk_test_disable_bulk(struct udevice *dev); |
| 183 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 184 | * sandbox_clk_test_free - Ask the sandbox clock test device to free its |
| 185 | * clocks. |
| 186 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 187 | * @dev: The sandbox clock test (client) device. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 188 | * @return: 0 if OK, or a negative error code. |
| 189 | */ |
| 190 | int sandbox_clk_test_free(struct udevice *dev); |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 191 | /** |
| 192 | * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release |
| 193 | * all clocks in it's clock bulk struct. |
| 194 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 195 | * @dev: The sandbox clock test (client) device. |
Neil Armstrong | 567a38b | 2018-04-03 11:44:19 +0200 | [diff] [blame] | 196 | * @return: 0 if OK, or a negative error code. |
| 197 | */ |
| 198 | int sandbox_clk_test_release_bulk(struct udevice *dev); |
Fabrice Gasnier | 1119271 | 2018-07-24 16:31:28 +0200 | [diff] [blame] | 199 | /** |
| 200 | * sandbox_clk_test_valid - Ask the sandbox clock test device to check its |
| 201 | * clocks are valid. |
| 202 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 203 | * @dev: The sandbox clock test (client) device. |
Fabrice Gasnier | 1119271 | 2018-07-24 16:31:28 +0200 | [diff] [blame] | 204 | * @return: 0 if OK, or a negative error code. |
| 205 | */ |
| 206 | int sandbox_clk_test_valid(struct udevice *dev); |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 207 | /** |
| 208 | * sandbox_clk_test_valid - Ask the sandbox clock test device to check its |
| 209 | * clocks are valid. |
| 210 | * |
Dario Binacchi | 6a02d3f | 2021-02-14 15:17:43 +0100 | [diff] [blame] | 211 | * @dev: The sandbox clock test (client) device. |
Jean-Jacques Hiblot | 98e8418 | 2019-10-22 14:00:05 +0200 | [diff] [blame] | 212 | * @return: 0 if OK, or a negative error code. |
| 213 | */ |
| 214 | 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] | 215 | |
| 216 | #endif |