xref: /f-stack/freebsd/arm/allwinner/clkng/aw_ccung.h (revision 22ce4aff)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2017,2018 Emmanuel Vadot <[email protected]>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef __CCU_NG_H__
31 #define __CCU_NG_H__
32 
33 #include <arm/allwinner/clkng/aw_clk.h>
34 #include <arm/allwinner/clkng/aw_clk_m.h>
35 #include <arm/allwinner/clkng/aw_clk_mipi.h>
36 #include <arm/allwinner/clkng/aw_clk_nkmp.h>
37 #include <arm/allwinner/clkng/aw_clk_nm.h>
38 #include <arm/allwinner/clkng/aw_clk_nmm.h>
39 #include <arm/allwinner/clkng/aw_clk_np.h>
40 #include <arm/allwinner/clkng/aw_clk_prediv_mux.h>
41 #include <arm/allwinner/clkng/aw_clk_frac.h>
42 #include <dev/extres/clk/clk_mux.h>
43 #include <dev/extres/clk/clk_div.h>
44 #include <dev/extres/clk/clk_fixed.h>
45 
46 enum aw_ccung_clk_type {
47 	AW_CLK_UNDEFINED = 0,
48 	AW_CLK_MUX,
49 	AW_CLK_DIV,
50 	AW_CLK_FIXED,
51 	AW_CLK_NKMP,
52 	AW_CLK_NM,
53 	AW_CLK_PREDIV_MUX,
54 	AW_CLK_FRAC,
55 	AW_CLK_M,
56 	AW_CLK_MIPI,
57 	AW_CLK_NP,
58 	AW_CLK_NMM,
59 };
60 
61 struct aw_ccung_clk {
62 	enum aw_ccung_clk_type	type;
63 	union {
64 		struct clk_mux_def		*mux;
65 		struct clk_div_def		*div;
66 		struct clk_fixed_def		*fixed;
67 		struct aw_clk_nkmp_def		*nkmp;
68 		struct aw_clk_nm_def		*nm;
69 		struct aw_clk_prediv_mux_def	*prediv_mux;
70 		struct aw_clk_frac_def		*frac;
71 		struct aw_clk_m_def		*m;
72 		struct aw_clk_mipi_def		*mipi;
73 		struct aw_clk_np_def		*np;
74 		struct aw_clk_nmm_def		*nmm;
75 	} clk;
76 };
77 
78 struct aw_ccung_softc {
79 	device_t		dev;
80 	struct resource		*res;
81 	struct clkdom		*clkdom;
82 	struct mtx		mtx;
83 	struct aw_ccung_reset	*resets;
84 	int			nresets;
85 	struct aw_ccung_gate	*gates;
86 	int			ngates;
87 	struct aw_ccung_clk	*clks;
88 	int			nclks;
89 	struct aw_clk_init	*clk_init;
90 	int			n_clk_init;
91 };
92 
93 struct aw_ccung_reset {
94 	uint32_t	offset;
95 	uint32_t	shift;
96 };
97 
98 struct aw_ccung_gate {
99 	const char	*name;
100 	const char	*parent_name;
101 	uint32_t	id;
102 	uint32_t	offset;
103 	uint32_t	shift;
104 };
105 
106 DECLARE_CLASS(aw_ccung_driver);
107 
108 int aw_ccung_attach(device_t dev);
109 
110 #endif /* __CCU_NG_H__ */
111