xref: /openbsd/sys/dev/ofw/ofw_clock.h (revision ff51f909)
1 /*	$OpenBSD: ofw_clock.h,v 1.7 2022/02/04 22:24:09 kettenis Exp $	*/
2 /*
3  * Copyright (c) 2016 Mark Kettenis
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef _DEV_OFW_CLOCK_H_
19 #define _DEV_OFW_CLOCK_H_
20 
21 struct clock_device {
22 	int	cd_node;
23 	void	*cd_cookie;
24 	uint32_t (*cd_get_frequency)(void *, uint32_t *);
25 	int	(*cd_set_frequency)(void *, uint32_t *, uint32_t);
26 	int	(*cd_set_parent)(void *, uint32_t *, uint32_t *);
27 	void	(*cd_enable)(void *, uint32_t *, int);
28 
29 	LIST_ENTRY(clock_device) cd_list;
30 	uint32_t cd_phandle;
31 	uint32_t cd_cells;
32 };
33 
34 void	clock_register(struct clock_device *);
35 
36 uint32_t clock_get_frequency(int, const char *);
37 uint32_t clock_get_frequency_idx(int, int);
38 int	clock_set_frequency(int, const char *, uint32_t);
39 int	clock_set_frequency_idx(int, int idx, uint32_t);
40 void	clock_set_assigned(int);
41 void	clock_enable(int, const char *);
42 void	clock_enable_idx(int, int);
43 void	clock_disable(int, const char *);
44 void	clock_disable_idx(int, int);
45 
46 static inline void
clock_enable_all(int node)47 clock_enable_all(int node)
48 {
49 	clock_enable_idx(node, -1);
50 }
51 
52 static inline void
clock_disable_all(int node)53 clock_disable_all(int node)
54 {
55 	clock_disable_idx(node, -1);
56 }
57 
58 struct reset_device {
59 	int	rd_node;
60 	void	*rd_cookie;
61 	void	(*rd_reset)(void *, uint32_t *, int);
62 
63 	LIST_ENTRY(reset_device) rd_list;
64 	uint32_t rd_phandle;
65 	uint32_t rd_cells;
66 };
67 
68 void	reset_register(struct reset_device *);
69 
70 void	reset_assert(int, const char *);
71 void	reset_assert_idx(int, int);
72 void	reset_deassert(int, const char *);
73 void	reset_deassert_idx(int, int);
74 
75 static inline void
reset_assert_all(int node)76 reset_assert_all(int node)
77 {
78 	reset_assert_idx(node, -1);
79 }
80 
81 static inline void
reset_deassert_all(int node)82 reset_deassert_all(int node)
83 {
84 	reset_deassert_idx(node, -1);
85 }
86 
87 #endif /* _DEV_OFW_CLOCK_H_ */
88