blob: a56ed25498529c337afeded7b422ebe95c6a2bbd [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stephen Warren135aa952016-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 Warren135aa952016-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 Glassa4e0ef52017-05-18 20:09:40 -060014
15struct ofnode_phandle_args;
Stephen Warren135aa952016-06-17 09:44:00 -060016
17/**
18 * struct clk_ops - The functions that a clock driver must implement.
Sean Andersona0abea82021-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.
28 *
29 * The individual methods are described more fully below.
Stephen Warren135aa952016-06-17 09:44:00 -060030 */
31struct clk_ops {
Stephen Warren135aa952016-06-17 09:44:00 -060032 int (*of_xlate)(struct clk *clock,
Simon Glassa4e0ef52017-05-18 20:09:40 -060033 struct ofnode_phandle_args *args);
Stephen Warren135aa952016-06-17 09:44:00 -060034 int (*request)(struct clk *clock);
Sean Anderson276d4462022-01-15 17:24:58 -050035 void (*rfree)(struct clk *clock);
Dario Binacchi2983ad52020-12-30 00:06:31 +010036 ulong (*round_rate)(struct clk *clk, ulong rate);
Stephen Warren135aa952016-06-17 09:44:00 -060037 ulong (*get_rate)(struct clk *clk);
Stephen Warren135aa952016-06-17 09:44:00 -060038 ulong (*set_rate)(struct clk *clk, ulong rate);
Philipp Tomsichf7d10462018-01-08 11:15:08 +010039 int (*set_parent)(struct clk *clk, struct clk *parent);
Stephen Warren135aa952016-06-17 09:44:00 -060040 int (*enable)(struct clk *clk);
Stephen Warren135aa952016-06-17 09:44:00 -060041 int (*disable)(struct clk *clk);
Caleb Connollyd3888992023-10-02 16:56:21 +010042 void (*dump_clks)(struct udevice *dev);
Caleb Connolly0d743022023-10-20 17:58:00 +010043 void (*debug_clks)(struct udevice *dev, int argc, char *const argv[]);
Stephen Warren135aa952016-06-17 09:44:00 -060044};
45
Sean Andersona0abea82021-12-22 12:11:13 -050046#if 0 /* For documentation only */
47/**
48 * of_xlate() - Translate a client's device-tree (OF) clock specifier.
49 * @clock: The clock struct to hold the translation result.
50 * @args: The clock specifier values from device tree.
51 *
52 * The clock core calls this function as the first step in implementing
53 * a client's clk_get_by_*() call.
54 *
55 * If this function pointer is set to NULL, the clock core will use a
56 * default implementation, which assumes #clock-cells = <1>, and that
57 * the DT cell contains a simple integer clock ID.
58 *
59 * At present, the clock API solely supports device-tree. If this
60 * changes, other xxx_xlate() functions may be added to support those
61 * other mechanisms.
62 *
63 * Return: 0 if OK, or a negative error code.
64 */
65int of_xlate(struct clk *clock, struct ofnode_phandle_args *args);
66
67/**
68 * request() - Request a translated clock.
Paul Barker52029b72023-08-14 20:13:34 +010069 * @clock: The clock struct to request; this has been filled in by
Sean Andersona0abea82021-12-22 12:11:13 -050070 * a previoux xxx_xlate() function call, or by the caller
71 * of clk_request().
72 *
73 * The clock core calls this function as the second step in
74 * implementing a client's clk_get_by_*() call, following a successful
75 * xxx_xlate() call, or as the only step in implementing a client's
76 * clk_request() call.
77 *
78 * Return: 0 if OK, or a negative error code.
79 */
80int request(struct clk *clock);
81
82/**
83 * rfree() - Free a previously requested clock.
84 * @clock: The clock to free.
85 *
Sean Anderson276d4462022-01-15 17:24:58 -050086 * Free any resources allocated in request().
Sean Andersona0abea82021-12-22 12:11:13 -050087 */
Sean Anderson276d4462022-01-15 17:24:58 -050088void rfree(struct clk *clock);
Sean Andersona0abea82021-12-22 12:11:13 -050089
90/**
91 * round_rate() - Adjust a rate to the exact rate a clock can provide.
92 * @clk: The clock to manipulate.
93 * @rate: Desidered clock rate in Hz.
94 *
95 * Return: rounded rate in Hz, or -ve error code.
96 */
97ulong round_rate(struct clk *clk, ulong rate);
98
99/**
100 * get_rate() - Get current clock rate.
101 * @clk: The clock to query.
102 *
103 * Return: clock rate in Hz, or -ve error code
104 */
105ulong get_rate(struct clk *clk);
106
107/**
108 * set_rate() - Set current clock rate.
109 * @clk: The clock to manipulate.
110 * @rate: New clock rate in Hz.
111 *
112 * Return: new rate, or -ve error code.
113 */
114ulong set_rate(struct clk *clk, ulong rate);
115
116/**
117 * set_parent() - Set current clock parent
118 * @clk: The clock to manipulate.
119 * @parent: New clock parent.
120 *
121 * Return: zero on success, or -ve error code.
122 */
123int set_parent(struct clk *clk, struct clk *parent);
124
125/**
126 * enable() - Enable a clock.
127 * @clk: The clock to manipulate.
128 *
129 * Return: zero on success, or -ve error code.
130 */
131int enable(struct clk *clk);
132
133/**
134 * disable() - Disable a clock.
135 * @clk: The clock to manipulate.
136 *
137 * Return: zero on success, or -ve error code.
138 */
139int disable(struct clk *clk);
140#endif
141
Stephen Warren135aa952016-06-17 09:44:00 -0600142#endif