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