]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/extres/clk/clk.h
Merge OpenSSL 1.1.1a.
[FreeBSD/FreeBSD.git] / sys / dev / extres / clk / clk.h
1 /*-
2  * Copyright 2016 Michal Meloun <mmel@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _DEV_EXTRES_CLK_H_
30 #define _DEV_EXTRES_CLK_H_
31 #include "opt_platform.h"
32
33 #include <sys/kobj.h>
34 #ifdef FDT
35 #include <dev/ofw/ofw_bus.h>
36 #endif
37 #include "clknode_if.h"
38
39 #define CLKNODE_IDX_NONE        -1              /* Not-selected index */
40
41 /* clknode flags. */
42 #define CLK_NODE_STATIC_STRINGS 0x00000001      /* Static name strings */
43 #define CLK_NODE_GLITCH_FREE    0x00000002      /* Freq can change w/o stop */
44 #define CLK_NODE_CANNOT_STOP    0x00000004      /* Clock cannot be disabled */
45
46 /* Flags passed to clk_set_freq() and clknode_set_freq(). */
47 #define CLK_SET_ROUND(x)        ((x) & (CLK_SET_ROUND_UP | CLK_SET_ROUND_DOWN))
48 #define CLK_SET_ROUND_EXACT     0
49 #define CLK_SET_ROUND_UP        0x00000001
50 #define CLK_SET_ROUND_DOWN      0x00000002
51 #define CLK_SET_ROUND_ANY       (CLK_SET_ROUND_UP | CLK_SET_ROUND_DOWN)
52
53 #define CLK_SET_USER_MASK       0x0000FFFF
54 #define CLK_SET_DRYRUN          0x00010000
55
56 typedef struct clk *clk_t;
57
58 /* Initialization parameters for clocknode creation. */
59 struct clknode_init_def {
60         const char      *name;
61         intptr_t        id;
62         const char      **parent_names;
63         int             parent_cnt;
64         int             flags;
65 };
66
67 /*
68  * Shorthands for constructing method tables.
69  */
70 #define CLKNODEMETHOD           KOBJMETHOD
71 #define CLKNODEMETHOD_END       KOBJMETHOD_END
72 #define clknode_method_t        kobj_method_t
73 #define clknode_class_t         kobj_class_t
74 DECLARE_CLASS(clknode_class);
75
76 /*
77  *  Clock domain functions.
78  */
79 struct clkdom *clkdom_create(device_t dev);
80 int clkdom_finit(struct clkdom *clkdom);
81 void clkdom_dump(struct clkdom * clkdom);
82 void clkdom_unlock(struct clkdom *clkdom);
83 void clkdom_xlock(struct clkdom *clkdom);
84
85 /*
86  * Clock providers interface.
87  */
88 struct clkdom *clkdom_get_by_dev(const device_t dev);
89
90 struct clknode *clknode_create(struct clkdom *clkdom,
91     clknode_class_t clknode_class, const struct clknode_init_def *def);
92 struct clknode *clknode_register(struct clkdom *cldom, struct clknode *clk);
93 #ifdef FDT
94 typedef int clknode_ofw_mapper_func(struct clkdom *clkdom, uint32_t ncells,
95     phandle_t *cells, struct clknode **clk);
96 void clkdom_set_ofw_mapper(struct clkdom *clkdom, clknode_ofw_mapper_func *cmp);
97 #endif
98
99 void clknode_init_parent_idx(struct clknode *clknode, int idx);
100 int clknode_set_parent_by_idx(struct clknode *clk, int idx);
101 int clknode_set_parent_by_name(struct clknode *clk, const char *name);
102 const char *clknode_get_name(struct clknode *clk);
103 const char **clknode_get_parent_names(struct clknode *clk);
104 int clknode_get_parents_num(struct clknode *clk);
105 int clknode_get_parent_idx(struct clknode *clk);
106 struct clknode *clknode_get_parent(struct clknode *clk);
107 int clknode_get_flags(struct clknode *clk);
108 void *clknode_get_softc(struct clknode *clk);
109 device_t clknode_get_device(struct clknode *clk);
110 struct clknode *clknode_find_by_name(const char *name);
111 struct clknode *clknode_find_by_id(struct clkdom *clkdom, intptr_t id);
112 int clknode_get_freq(struct clknode *clknode, uint64_t *freq);
113 int clknode_set_freq(struct clknode *clknode, uint64_t freq, int flags,
114     int enablecnt);
115 int clknode_enable(struct clknode *clknode);
116 int clknode_disable(struct clknode *clknode);
117 int clknode_stop(struct clknode *clknode, int depth);
118
119 /*
120  * Clock consumers interface.
121  */
122 int clk_get_by_name(device_t dev, const char *name, clk_t *clk);
123 int clk_get_by_id(device_t dev, struct clkdom *clkdom, intptr_t id, clk_t *clk);
124 int clk_release(clk_t clk);
125 int clk_get_freq(clk_t clk, uint64_t *freq);
126 int clk_set_freq(clk_t clk, uint64_t freq, int flags);
127 int clk_test_freq(clk_t clk, uint64_t freq, int flags);
128 int clk_enable(clk_t clk);
129 int clk_disable(clk_t clk);
130 int clk_stop(clk_t clk);
131 int clk_get_parent(clk_t clk, clk_t *parent);
132 int clk_set_parent_by_clk(clk_t clk, clk_t parent);
133 const char *clk_get_name(clk_t clk);
134
135 #ifdef FDT
136 int clk_set_assigned(device_t dev, phandle_t node);
137 int clk_get_by_ofw_index(device_t dev, phandle_t node, int idx, clk_t *clk);
138 int clk_get_by_ofw_index_prop(device_t dev, phandle_t cnode, const char *prop, int idx, clk_t *clk);
139 int clk_get_by_ofw_name(device_t dev, phandle_t node, const char *name,
140      clk_t *clk);
141 int clk_parse_ofw_out_names(device_t dev, phandle_t node,
142     const char ***out_names, uint32_t **indices);
143 int clk_parse_ofw_clk_name(device_t dev, phandle_t node, const char **name);
144 #endif
145
146 #endif /* _DEV_EXTRES_CLK_H_ */