blob: cd62848bece3bf45682645bcb3a6cd9bc085a21c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stephen Warrena9622432016-06-17 09:44:00 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warrena9622432016-06-17 09:44:00 -06006 */
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 Glassb7ae2772017-05-18 20:09:40 -060014
15struct ofnode_phandle_args;
Stephen Warrena9622432016-06-17 09:44:00 -060016
17/**
18 * struct clk_ops - The functions that a clock driver must implement.
Sean Andersond7dddc42021-12-22 12:11:13 -050019 * @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 Prusov32c57382023-11-09 13:55:13 +030028 * @dump: Print clock information.
Sean Andersond7dddc42021-12-22 12:11:13 -050029 *
30 * The individual methods are described more fully below.
Stephen Warrena9622432016-06-17 09:44:00 -060031 */
32struct clk_ops {
Stephen Warrena9622432016-06-17 09:44:00 -060033 int (*of_xlate)(struct clk *clock,
Simon Glassb7ae2772017-05-18 20:09:40 -060034 struct ofnode_phandle_args *args);
Stephen Warrena9622432016-06-17 09:44:00 -060035 int (*request)(struct clk *clock);
Sean Anderson553935f2022-01-15 17:24:58 -050036 void (*rfree)(struct clk *clock);
Dario Binacchib7f85892020-12-30 00:06:31 +010037 ulong (*round_rate)(struct clk *clk, ulong rate);
Stephen Warrena9622432016-06-17 09:44:00 -060038 ulong (*get_rate)(struct clk *clk);
Stephen Warrena9622432016-06-17 09:44:00 -060039 ulong (*set_rate)(struct clk *clk, ulong rate);
Philipp Tomsichf8e02b22018-01-08 11:15:08 +010040 int (*set_parent)(struct clk *clk, struct clk *parent);
Stephen Warrena9622432016-06-17 09:44:00 -060041 int (*enable)(struct clk *clk);
Stephen Warrena9622432016-06-17 09:44:00 -060042 int (*disable)(struct clk *clk);
Igor Prusov32c57382023-11-09 13:55:13 +030043#if IS_ENABLED(CONFIG_CMD_CLK)
44 void (*dump)(struct udevice *dev);
45#endif
Stephen Warrena9622432016-06-17 09:44:00 -060046};
47
Sean Andersond7dddc42021-12-22 12:11:13 -050048#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 */
67int of_xlate(struct clk *clock, struct ofnode_phandle_args *args);
68
69/**
70 * request() - Request a translated clock.
Paul Barker747b8d22023-08-14 20:13:34 +010071 * @clock: The clock struct to request; this has been filled in by
Sean Andersond7dddc42021-12-22 12:11:13 -050072 * 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 */
82int request(struct clk *clock);
83
84/**
85 * rfree() - Free a previously requested clock.
86 * @clock: The clock to free.
87 *
Sean Anderson553935f2022-01-15 17:24:58 -050088 * Free any resources allocated in request().
Sean Andersond7dddc42021-12-22 12:11:13 -050089 */
Sean Anderson553935f2022-01-15 17:24:58 -050090void rfree(struct clk *clock);
Sean Andersond7dddc42021-12-22 12:11:13 -050091
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 */
99ulong 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 */
107ulong 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 */
116ulong 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 */
125int 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 */
133int 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 */
141int disable(struct clk *clk);
Igor Prusov32c57382023-11-09 13:55:13 +0300142
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 */
150void dump(struct udevice *dev);
Sean Andersond7dddc42021-12-22 12:11:13 -0500151#endif
152
Stephen Warrena9622432016-06-17 09:44:00 -0600153#endif