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) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _CLK_UCLASS_H |
| 9 | #define _CLK_UCLASS_H |
| 10 | |
| 11 | /* See clk.h for background documentation. */ |
| 12 | |
| 13 | #include <clk.h> |
Simon Glass | b7ae277 | 2017-05-18 20:09:40 -0600 | [diff] [blame] | 14 | |
| 15 | struct ofnode_phandle_args; |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * struct clk_ops - The functions that a clock driver must implement. |
| 19 | */ |
| 20 | struct clk_ops { |
| 21 | /** |
| 22 | * of_xlate - Translate a client's device-tree (OF) clock specifier. |
| 23 | * |
| 24 | * The clock core calls this function as the first step in implementing |
| 25 | * a client's clk_get_by_*() call. |
| 26 | * |
| 27 | * If this function pointer is set to NULL, the clock core will use a |
| 28 | * default implementation, which assumes #clock-cells = <1>, and that |
| 29 | * the DT cell contains a simple integer clock ID. |
| 30 | * |
| 31 | * At present, the clock API solely supports device-tree. If this |
| 32 | * changes, other xxx_xlate() functions may be added to support those |
| 33 | * other mechanisms. |
| 34 | * |
| 35 | * @clock: The clock struct to hold the translation result. |
| 36 | * @args: The clock specifier values from device tree. |
| 37 | * @return 0 if OK, or a negative error code. |
| 38 | */ |
| 39 | int (*of_xlate)(struct clk *clock, |
Simon Glass | b7ae277 | 2017-05-18 20:09:40 -0600 | [diff] [blame] | 40 | struct ofnode_phandle_args *args); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 41 | /** |
| 42 | * request - Request a translated clock. |
| 43 | * |
| 44 | * The clock core calls this function as the second step in |
| 45 | * implementing a client's clk_get_by_*() call, following a successful |
| 46 | * xxx_xlate() call, or as the only step in implementing a client's |
| 47 | * clk_request() call. |
| 48 | * |
| 49 | * @clock: The clock struct to request; this has been fille in by |
| 50 | * a previoux xxx_xlate() function call, or by the caller |
| 51 | * of clk_request(). |
| 52 | * @return 0 if OK, or a negative error code. |
| 53 | */ |
| 54 | int (*request)(struct clk *clock); |
| 55 | /** |
Simon Glass | 2cdd3f4 | 2020-02-03 07:35:54 -0700 | [diff] [blame] | 56 | * rfree - Free a previously requested clock. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 57 | * |
| 58 | * This is the implementation of the client clk_free() API. |
| 59 | * |
| 60 | * @clock: The clock to free. |
| 61 | * @return 0 if OK, or a negative error code. |
| 62 | */ |
Simon Glass | 2cdd3f4 | 2020-02-03 07:35:54 -0700 | [diff] [blame] | 63 | int (*rfree)(struct clk *clock); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 64 | /** |
Dario Binacchi | b7f8589 | 2020-12-30 00:06:31 +0100 | [diff] [blame] | 65 | * round_rate() - Adjust a rate to the exact rate a clock can provide. |
| 66 | * |
| 67 | * @clk: The clock to manipulate. |
| 68 | * @rate: Desidered clock rate in Hz. |
| 69 | * @return rounded rate in Hz, or -ve error code. |
| 70 | */ |
| 71 | ulong (*round_rate)(struct clk *clk, ulong rate); |
| 72 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 73 | * get_rate() - Get current clock rate. |
| 74 | * |
| 75 | * @clk: The clock to query. |
| 76 | * @return clock rate in Hz, or -ve error code |
| 77 | */ |
| 78 | ulong (*get_rate)(struct clk *clk); |
| 79 | /** |
| 80 | * set_rate() - Set current clock rate. |
| 81 | * |
| 82 | * @clk: The clock to manipulate. |
| 83 | * @rate: New clock rate in Hz. |
| 84 | * @return new rate, or -ve error code. |
| 85 | */ |
| 86 | ulong (*set_rate)(struct clk *clk, ulong rate); |
| 87 | /** |
Philipp Tomsich | f8e02b2 | 2018-01-08 11:15:08 +0100 | [diff] [blame] | 88 | * set_parent() - Set current clock parent |
| 89 | * |
| 90 | * @clk: The clock to manipulate. |
| 91 | * @parent: New clock parent. |
| 92 | * @return zero on success, or -ve error code. |
| 93 | */ |
| 94 | int (*set_parent)(struct clk *clk, struct clk *parent); |
| 95 | /** |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 96 | * enable() - Enable a clock. |
| 97 | * |
| 98 | * @clk: The clock to manipulate. |
| 99 | * @return zero on success, or -ve error code. |
| 100 | */ |
| 101 | int (*enable)(struct clk *clk); |
| 102 | /** |
| 103 | * disable() - Disable a clock. |
| 104 | * |
| 105 | * @clk: The clock to manipulate. |
| 106 | * @return zero on success, or -ve error code. |
| 107 | */ |
| 108 | int (*disable)(struct clk *clk); |
| 109 | }; |
| 110 | |
| 111 | #endif |