xref: /freebsd/sys/dev/clk/allwinner/aw_ccung.h (revision be82b3a0bf72ed3b5f01ac9fcd8dcd3802e3c742)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2017,2018 Emmanuel Vadot <manu@freebsd.org>
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 
28 #ifndef __CCU_NG_H__
29 #define __CCU_NG_H__
30 
31 #include <dev/clk/allwinner/aw_clk.h>
32 #include <dev/clk/allwinner/aw_clk_m.h>
33 #include <dev/clk/allwinner/aw_clk_mipi.h>
34 #include <dev/clk/allwinner/aw_clk_nkmp.h>
35 #include <dev/clk/allwinner/aw_clk_nm.h>
36 #include <dev/clk/allwinner/aw_clk_nmm.h>
37 #include <dev/clk/allwinner/aw_clk_np.h>
38 #include <dev/clk/allwinner/aw_clk_prediv_mux.h>
39 #include <dev/clk/allwinner/aw_clk_frac.h>
40 #include <dev/clk/clk_mux.h>
41 #include <dev/clk/clk_div.h>
42 #include <dev/clk/clk_fixed.h>
43 
44 enum aw_ccung_clk_type {
45 	AW_CLK_UNDEFINED = 0,
46 	AW_CLK_MUX,
47 	AW_CLK_DIV,
48 	AW_CLK_FIXED,
49 	AW_CLK_NKMP,
50 	AW_CLK_NM,
51 	AW_CLK_PREDIV_MUX,
52 	AW_CLK_FRAC,
53 	AW_CLK_M,
54 	AW_CLK_MIPI,
55 	AW_CLK_NP,
56 	AW_CLK_NMM,
57 };
58 
59 struct aw_ccung_clk {
60 	enum aw_ccung_clk_type	type;
61 	union {
62 		struct clk_mux_def		*mux;
63 		struct clk_div_def		*div;
64 		struct clk_fixed_def		*fixed;
65 		struct aw_clk_nkmp_def		*nkmp;
66 		struct aw_clk_nm_def		*nm;
67 		struct aw_clk_prediv_mux_def	*prediv_mux;
68 		struct aw_clk_frac_def		*frac;
69 		struct aw_clk_m_def		*m;
70 		struct aw_clk_mipi_def		*mipi;
71 		struct aw_clk_np_def		*np;
72 		struct aw_clk_nmm_def		*nmm;
73 	} clk;
74 };
75 
76 struct aw_ccung_softc {
77 	device_t		dev;
78 	struct resource		*res;
79 	struct clkdom		*clkdom;
80 	struct mtx		mtx;
81 	struct aw_ccung_reset	*resets;
82 	int			nresets;
83 	struct aw_ccung_gate	*gates;
84 	int			ngates;
85 	struct aw_ccung_clk	*clks;
86 	int			nclks;
87 	struct aw_clk_init	*clk_init;
88 	int			n_clk_init;
89 };
90 
91 struct aw_ccung_reset {
92 	uint32_t	offset;
93 	uint32_t	shift;
94 };
95 
96 struct aw_ccung_gate {
97 	const char	*name;
98 	const char	*parent_name;
99 	uint32_t	id;
100 	uint32_t	offset;
101 	uint32_t	shift;
102 };
103 
104 DECLARE_CLASS(aw_ccung_driver);
105 
106 int aw_ccung_attach(device_t dev);
107 
108 #endif /* __CCU_NG_H__ */
109