xref: /netbsd-src/sys/dev/clk/clk_backend.h (revision ed41487b0c334eb1ee99e83b5fae0834624baa7a)
1*ed41487bSjmcneill /* $NetBSD: clk_backend.h,v 1.4 2018/04/28 15:20:33 jmcneill Exp $ */
2bd0f8235Sjmcneill 
3bd0f8235Sjmcneill /*-
4bd0f8235Sjmcneill  * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
5bd0f8235Sjmcneill  * All rights reserved.
6bd0f8235Sjmcneill  *
7bd0f8235Sjmcneill  * Redistribution and use in source and binary forms, with or without
8bd0f8235Sjmcneill  * modification, are permitted provided that the following conditions
9bd0f8235Sjmcneill  * are met:
10bd0f8235Sjmcneill  * 1. Redistributions of source code must retain the above copyright
11bd0f8235Sjmcneill  *    notice, this list of conditions and the following disclaimer.
12bd0f8235Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
13bd0f8235Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
14bd0f8235Sjmcneill  *    documentation and/or other materials provided with the distribution.
15bd0f8235Sjmcneill  *
16bd0f8235Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17bd0f8235Sjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18bd0f8235Sjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19bd0f8235Sjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20bd0f8235Sjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21bd0f8235Sjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22bd0f8235Sjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23bd0f8235Sjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24bd0f8235Sjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25bd0f8235Sjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26bd0f8235Sjmcneill  * SUCH DAMAGE.
27bd0f8235Sjmcneill  */
28bd0f8235Sjmcneill 
29bd0f8235Sjmcneill #ifndef _DEV_CLK_CLK_BACKEND_H
30bd0f8235Sjmcneill #define _DEV_CLK_CLK_BACKEND_H
31bd0f8235Sjmcneill 
32*ed41487bSjmcneill #include <sys/sysctl.h>
33*ed41487bSjmcneill 
34bd0f8235Sjmcneill #include <dev/clk/clk.h>
35bd0f8235Sjmcneill 
36e69bfca1Sjmcneill struct clk_domain {
37*ed41487bSjmcneill 	const char *name;
38*ed41487bSjmcneill 	const struct sysctlnode *node;
39e69bfca1Sjmcneill 	const struct clk_funcs *funcs;
40e69bfca1Sjmcneill 	void *priv;
41e69bfca1Sjmcneill };
42e69bfca1Sjmcneill 
43bd0f8235Sjmcneill struct clk {
44e69bfca1Sjmcneill 	struct clk_domain *domain;
45bd0f8235Sjmcneill         const char *name;
46bd0f8235Sjmcneill         u_int flags;
47bd0f8235Sjmcneill #define CLK_SET_RATE_PARENT     0x01
48bd0f8235Sjmcneill };
49bd0f8235Sjmcneill 
50bd0f8235Sjmcneill struct clk_funcs {
51bd0f8235Sjmcneill 	struct clk *(*get)(void *, const char *);
52bd0f8235Sjmcneill 	void (*put)(void *, struct clk *);
53bd0f8235Sjmcneill 
54bd0f8235Sjmcneill 	u_int (*get_rate)(void *, struct clk *);
55bd0f8235Sjmcneill 	int (*set_rate)(void *, struct clk *, u_int);
5670d99699Sbouyer 	u_int (*round_rate)(void *, struct clk *, u_int);
57bd0f8235Sjmcneill 	int (*enable)(void *, struct clk *);
58bd0f8235Sjmcneill 	int (*disable)(void *, struct clk *);
59bd0f8235Sjmcneill 	int (*set_parent)(void *, struct clk *, struct clk *);
60bd0f8235Sjmcneill 	struct clk *(*get_parent)(void *, struct clk *);
61bd0f8235Sjmcneill };
62bd0f8235Sjmcneill 
63*ed41487bSjmcneill int	clk_attach(struct clk *);
64*ed41487bSjmcneill 
65bd0f8235Sjmcneill #endif /* _DEV_CLK_CLK_BACKEND_H */
66