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. |
Sean Anderson | d7dddc4 | 2021-12-22 12:11:13 -0500 | [diff] [blame] | 19 | * @of_xlate: Translate a client's device-tree (OF) clock specifier. |
| 20 | * @request: Request a translated clock. |
| 21 | * @rfree: Free a previously requested clock. |
| 22 | * @round_rate: Adjust a rate to the exact rate a clock can provide. |
| 23 | * @get_rate: Get current clock rate. |
| 24 | * @set_rate: Set current clock rate. |
| 25 | * @set_parent: Set current clock parent |
| 26 | * @enable: Enable a clock. |
| 27 | * @disable: Disable a clock. |
Igor Prusov | 32c5738 | 2023-11-09 13:55:13 +0300 | [diff] [blame] | 28 | * @dump: Print clock information. |
Sean Anderson | d7dddc4 | 2021-12-22 12:11:13 -0500 | [diff] [blame] | 29 | * |
| 30 | * The individual methods are described more fully below. |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 31 | */ |
| 32 | struct clk_ops { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 33 | int (*of_xlate)(struct clk *clock, |
Simon Glass | b7ae277 | 2017-05-18 20:09:40 -0600 | [diff] [blame] | 34 | struct ofnode_phandle_args *args); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 35 | int (*request)(struct clk *clock); |
Sean Anderson | 553935f | 2022-01-15 17:24:58 -0500 | [diff] [blame] | 36 | void (*rfree)(struct clk *clock); |
Dario Binacchi | b7f8589 | 2020-12-30 00:06:31 +0100 | [diff] [blame] | 37 | ulong (*round_rate)(struct clk *clk, ulong rate); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 38 | ulong (*get_rate)(struct clk *clk); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 39 | ulong (*set_rate)(struct clk *clk, ulong rate); |
Philipp Tomsich | f8e02b2 | 2018-01-08 11:15:08 +0100 | [diff] [blame] | 40 | int (*set_parent)(struct clk *clk, struct clk *parent); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 41 | int (*enable)(struct clk *clk); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 42 | int (*disable)(struct clk *clk); |
Igor Prusov | 32c5738 | 2023-11-09 13:55:13 +0300 | [diff] [blame] | 43 | #if IS_ENABLED(CONFIG_CMD_CLK) |
| 44 | void (*dump)(struct udevice *dev); |
| 45 | #endif |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 46 | }; |
| 47 | |
Sean Anderson | d7dddc4 | 2021-12-22 12:11:13 -0500 | [diff] [blame] | 48 | #if 0 /* For documentation only */ |
| 49 | /** |
| 50 | * of_xlate() - Translate a client's device-tree (OF) clock specifier. |
| 51 | * @clock: The clock struct to hold the translation result. |
| 52 | * @args: The clock specifier values from device tree. |
| 53 | * |
| 54 | * The clock core calls this function as the first step in implementing |
| 55 | * a client's clk_get_by_*() call. |
| 56 | * |
| 57 | * If this function pointer is set to NULL, the clock core will use a |
| 58 | * default implementation, which assumes #clock-cells = <1>, and that |
| 59 | * the DT cell contains a simple integer clock ID. |
| 60 | * |
| 61 | * At present, the clock API solely supports device-tree. If this |
| 62 | * changes, other xxx_xlate() functions may be added to support those |
| 63 | * other mechanisms. |
| 64 | * |
| 65 | * Return: 0 if OK, or a negative error code. |
| 66 | */ |
| 67 | int of_xlate(struct clk *clock, struct ofnode_phandle_args *args); |
| 68 | |
| 69 | /** |
| 70 | * request() - Request a translated clock. |
Paul Barker | 747b8d2 | 2023-08-14 20:13:34 +0100 | [diff] [blame] | 71 | * @clock: The clock struct to request; this has been filled in by |
Sean Anderson | d7dddc4 | 2021-12-22 12:11:13 -0500 | [diff] [blame] | 72 | * a previoux xxx_xlate() function call, or by the caller |
| 73 | * of clk_request(). |
| 74 | * |
| 75 | * The clock core calls this function as the second step in |
| 76 | * implementing a client's clk_get_by_*() call, following a successful |
| 77 | * xxx_xlate() call, or as the only step in implementing a client's |
| 78 | * clk_request() call. |
| 79 | * |
| 80 | * Return: 0 if OK, or a negative error code. |
| 81 | */ |
| 82 | int request(struct clk *clock); |
| 83 | |
| 84 | /** |
| 85 | * rfree() - Free a previously requested clock. |
| 86 | * @clock: The clock to free. |
| 87 | * |
Sean Anderson | 553935f | 2022-01-15 17:24:58 -0500 | [diff] [blame] | 88 | * Free any resources allocated in request(). |
Sean Anderson | d7dddc4 | 2021-12-22 12:11:13 -0500 | [diff] [blame] | 89 | */ |
Sean Anderson | 553935f | 2022-01-15 17:24:58 -0500 | [diff] [blame] | 90 | void rfree(struct clk *clock); |
Sean Anderson | d7dddc4 | 2021-12-22 12:11:13 -0500 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * round_rate() - Adjust a rate to the exact rate a clock can provide. |
| 94 | * @clk: The clock to manipulate. |
| 95 | * @rate: Desidered clock rate in Hz. |
| 96 | * |
| 97 | * Return: rounded rate in Hz, or -ve error code. |
| 98 | */ |
| 99 | ulong round_rate(struct clk *clk, ulong rate); |
| 100 | |
| 101 | /** |
| 102 | * get_rate() - Get current clock rate. |
| 103 | * @clk: The clock to query. |
| 104 | * |
| 105 | * Return: clock rate in Hz, or -ve error code |
| 106 | */ |
| 107 | ulong get_rate(struct clk *clk); |
| 108 | |
| 109 | /** |
| 110 | * set_rate() - Set current clock rate. |
| 111 | * @clk: The clock to manipulate. |
| 112 | * @rate: New clock rate in Hz. |
| 113 | * |
| 114 | * Return: new rate, or -ve error code. |
| 115 | */ |
| 116 | ulong set_rate(struct clk *clk, ulong rate); |
| 117 | |
| 118 | /** |
| 119 | * set_parent() - Set current clock parent |
| 120 | * @clk: The clock to manipulate. |
| 121 | * @parent: New clock parent. |
| 122 | * |
| 123 | * Return: zero on success, or -ve error code. |
| 124 | */ |
| 125 | int set_parent(struct clk *clk, struct clk *parent); |
| 126 | |
| 127 | /** |
| 128 | * enable() - Enable a clock. |
| 129 | * @clk: The clock to manipulate. |
| 130 | * |
| 131 | * Return: zero on success, or -ve error code. |
| 132 | */ |
| 133 | int enable(struct clk *clk); |
| 134 | |
| 135 | /** |
| 136 | * disable() - Disable a clock. |
| 137 | * @clk: The clock to manipulate. |
| 138 | * |
| 139 | * Return: zero on success, or -ve error code. |
| 140 | */ |
| 141 | int disable(struct clk *clk); |
Igor Prusov | 32c5738 | 2023-11-09 13:55:13 +0300 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * dump() - Print clock information. |
| 145 | * @dev: The clock device to dump. |
| 146 | * |
| 147 | * If present, this function is called by "clk dump" command for each |
| 148 | * bound device. |
| 149 | */ |
| 150 | void dump(struct udevice *dev); |
Sean Anderson | d7dddc4 | 2021-12-22 12:11:13 -0500 | [diff] [blame] | 151 | #endif |
| 152 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 153 | #endif |