RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
clk.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2022, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2022-11-26 GuEe-GUI first version
9 */
10
11#ifndef __CLK_H__
12#define __CLK_H__
13
14#include <rthw.h>
15
16#include <ref.h>
17#include <drivers/ofw.h>
18
19#define RT_CLK_NODE_OBJ_NAME "CLKNP"
20
21struct rt_clk_ops;
22struct rt_reset_control_node;
23
25{
26 /*
27 * Defined as the array like this if if the CLK have multi out clocks:
28 *
29 * struct XYZ_single_clk
30 * {
31 * struct rt_clk_node parent;
32 * ...
33 * };
34 *
35 * struct XYZ_multi_clk
36 * {
37 * struct rt_clk_node parent[N];
38 * ...
39 * };
40 * We assume the 'N' is the max value of element in 'clock-indices' if OFW.
41 */
43
46
47 const char *name;
48 const struct rt_clk_ops *ops;
49
51 struct rt_ref ref;
52
56
58
59 void *priv;
60
61 struct rt_clk *clk;
63};
64
72
73struct rt_clk
74{
76
77 const char *dev_id;
78 const char *con_id;
79
83
84 void *fw_node;
85 void *priv;
86};
87
89{
91 struct rt_clk *clks[];
92};
93
95{
96 rt_err_t (*init)(struct rt_clk *, void *fw_data);
97 rt_err_t (*finit)(struct rt_clk *);
98 /* API */
99 rt_err_t (*prepare)(struct rt_clk *);
100 void (*unprepare)(struct rt_clk *);
102 rt_err_t (*enable)(struct rt_clk *);
103 void (*disable)(struct rt_clk *);
105 rt_err_t (*set_rate)(struct rt_clk *, rt_ubase_t rate, rt_ubase_t parent_rate);
106 rt_err_t (*set_parent)(struct rt_clk *, struct rt_clk *parent);
107 rt_err_t (*set_phase)(struct rt_clk *, int degrees);
109 rt_base_t (*round_rate)(struct rt_clk *, rt_ubase_t drate, rt_ubase_t *prate);
110};
111
112struct rt_clk_notifier;
113
114#define RT_CLK_MSG_PRE_RATE_CHANGE RT_BIT(0)
115#define RT_CLK_MSG_POST_RATE_CHANGE RT_BIT(1)
116#define RT_CLK_MSG_ABORT_RATE_CHANGE RT_BIT(2)
117
119 rt_ubase_t msg, rt_ubase_t old_rate, rt_ubase_t new_rate);
120
129
132
135
136rt_err_t rt_clk_set_parent(struct rt_clk *clk, struct rt_clk *clk_parent);
137
140
142void rt_clk_disable(struct rt_clk *clk);
143
146
149
151void rt_clk_array_disable(struct rt_clk_array *clk_arr);
152
155
161
162rt_err_t rt_clk_set_phase(struct rt_clk *clk, int degrees);
164
166
167struct rt_clk *rt_clk_get_parent(struct rt_clk *clk);
168
170struct rt_clk *rt_clk_get_by_index(struct rt_device *dev, int index);
171struct rt_clk *rt_clk_get_by_name(struct rt_device *dev, const char *name);
172void rt_clk_array_put(struct rt_clk_array *clk_arr);
173void rt_clk_put(struct rt_clk *clk);
174
175#ifdef RT_USING_OFW
176struct rt_clk_array *rt_ofw_get_clk_array(struct rt_ofw_node *np);
177struct rt_clk *rt_ofw_get_clk(struct rt_ofw_node *np, int index);
178struct rt_clk *rt_ofw_get_clk_by_name(struct rt_ofw_node *np, const char *name);
179rt_ssize_t rt_ofw_count_of_clk(struct rt_ofw_node *clk_ofw_np);
180#else
181rt_inline struct rt_clk *rt_ofw_get_clk(struct rt_ofw_node *np, int index)
182{
183 return RT_NULL;
184}
185rt_inline struct rt_clk *rt_ofw_get_clk_by_name(struct rt_ofw_node *np, const char *name)
186{
187 return RT_NULL;
188}
189rt_inline rt_ssize_t rt_ofw_count_of_clk(struct rt_ofw_node *clk_ofw_np)
190{
191 return 0;
192}
193#endif /* RT_USING_OFW */
194
195#endif /* __CLK_H__ */
rt_inline struct rt_clk * rt_ofw_get_clk_by_name(struct rt_ofw_node *np, const char *name)
定义 clk.h:185
rt_err_t rt_clk_array_enable(struct rt_clk_array *clk_arr)
rt_err_t rt_clk_unprepare(struct rt_clk *clk)
void rt_clk_disable(struct rt_clk *clk)
void rt_clk_disable_unprepare(struct rt_clk *clk)
rt_err_t rt_clk_array_prepare_enable(struct rt_clk_array *clk_arr)
struct rt_clk * rt_clk_get_by_name(struct rt_device *dev, const char *name)
rt_err_t rt_clk_set_rate(struct rt_clk *clk, rt_ubase_t rate)
rt_err_t rt_clk_set_phase(struct rt_clk *clk, int degrees)
rt_err_t rt_clk_notifier_register(struct rt_clk *clk, struct rt_clk_notifier *notifier)
rt_err_t rt_clk_set_parent(struct rt_clk *clk, struct rt_clk *clk_parent)
struct rt_clk * rt_clk_get_by_index(struct rt_device *dev, int index)
struct rt_clk_array * rt_clk_get_array(struct rt_device *dev)
void rt_clk_put(struct rt_clk *clk)
void rt_clk_array_put(struct rt_clk_array *clk_arr)
rt_err_t rt_clk_register(struct rt_clk_node *clk_np, struct rt_clk_node *parent_np)
rt_err_t rt_clk_unregister(struct rt_clk_node *clk_np)
rt_err_t rt_clk_notifier_unregister(struct rt_clk *clk, struct rt_clk_notifier *notifier)
void rt_clk_array_disable(struct rt_clk_array *clk_arr)
rt_inline rt_ssize_t rt_ofw_count_of_clk(struct rt_ofw_node *clk_ofw_np)
定义 clk.h:189
rt_ubase_t rt_clk_get_rate(struct rt_clk *clk)
void rt_clk_array_disable_unprepare(struct rt_clk_array *clk_arr)
rt_err_t rt_clk_prepare(struct rt_clk *clk)
rt_inline struct rt_clk * rt_ofw_get_clk(struct rt_ofw_node *np, int index)
定义 clk.h:181
rt_err_t rt_clk_set_max_rate(struct rt_clk *clk, rt_ubase_t rate)
rt_err_t rt_clk_array_unprepare(struct rt_clk_array *clk_arr)
rt_err_t rt_clk_array_prepare(struct rt_clk_array *clk_arr)
rt_err_t(* rt_clk_notifier_callback)(struct rt_clk_notifier *notifier, rt_ubase_t msg, rt_ubase_t old_rate, rt_ubase_t new_rate)
定义 clk.h:118
rt_base_t rt_clk_round_rate(struct rt_clk *clk, rt_ubase_t rate)
rt_err_t rt_clk_enable(struct rt_clk *clk)
struct rt_clk * rt_clk_get_parent(struct rt_clk *clk)
rt_err_t rt_clk_set_rate_range(struct rt_clk *clk, rt_ubase_t min, rt_ubase_t max)
rt_err_t rt_clk_prepare_enable(struct rt_clk *clk)
rt_err_t rt_clk_set_min_rate(struct rt_clk *clk, rt_ubase_t rate)
rt_base_t rt_clk_get_phase(struct rt_clk *clk)
rt_base_t rt_ssize_t
rt_int32_t rt_base_t
int rt_bool_t
rt_base_t rt_err_t
rt_ubase_t rt_size_t
struct rt_list_node rt_list_t
rt_uint32_t rt_ubase_t
#define RT_NULL
rt_size_t count
定义 clk.h:90
struct rt_clk * clks[]
定义 clk.h:91
rt_ubase_t fixed_rate
定义 clk.h:69
struct rt_clk_node clk
定义 clk.h:67
rt_ubase_t fixed_accuracy
定义 clk.h:70
struct rt_clk * clk
定义 clk.h:61
const struct rt_clk_ops * ops
定义 clk.h:48
rt_list_t list
定义 clk.h:44
rt_ubase_t max_rate
定义 clk.h:55
struct rt_ref ref
定义 clk.h:51
rt_size_t multi_clk
定义 clk.h:62
struct rt_object rt_parent
定义 clk.h:42
rt_size_t notifier_count
定义 clk.h:57
const char * name
定义 clk.h:47
struct rt_clk_node * parent
定义 clk.h:50
rt_ubase_t min_rate
定义 clk.h:54
void * priv
定义 clk.h:59
rt_ubase_t rate
定义 clk.h:53
rt_list_t children_nodes
定义 clk.h:45
rt_list_t list
定义 clk.h:123
rt_clk_notifier_callback callback
定义 clk.h:126
struct rt_clk * clk
定义 clk.h:125
rt_err_t(* finit)(struct rt_clk *)
定义 clk.h:97
rt_err_t(* enable)(struct rt_clk *)
定义 clk.h:102
rt_err_t(* set_parent)(struct rt_clk *, struct rt_clk *parent)
定义 clk.h:106
rt_err_t(* set_phase)(struct rt_clk *, int degrees)
定义 clk.h:107
rt_err_t(* prepare)(struct rt_clk *)
定义 clk.h:99
rt_bool_t(* is_prepared)(struct rt_clk *)
定义 clk.h:101
rt_base_t(* round_rate)(struct rt_clk *, rt_ubase_t drate, rt_ubase_t *prate)
定义 clk.h:109
rt_base_t(* get_phase)(struct rt_clk *)
定义 clk.h:108
rt_err_t(* init)(struct rt_clk *, void *fw_data)
定义 clk.h:96
void(* disable)(struct rt_clk *)
定义 clk.h:103
void(* unprepare)(struct rt_clk *)
定义 clk.h:100
rt_err_t(* set_rate)(struct rt_clk *, rt_ubase_t rate, rt_ubase_t parent_rate)
定义 clk.h:105
rt_bool_t(* is_enabled)(struct rt_clk *)
定义 clk.h:104
void * priv
定义 clk.h:85
int enable_count
定义 clk.h:82
struct rt_clk_node * clk_np
定义 clk.h:75
const char * dev_id
定义 clk.h:77
void * fw_node
定义 clk.h:84
int prepare_count
定义 clk.h:81
rt_ubase_t rate
定义 clk.h:80
const char * con_id
定义 clk.h:78