sun8i_h3_ccu.c revision 1.1 1 1.1 jmcneill /* $NetBSD: sun8i_h3_ccu.c,v 1.1 2017/06/28 23:51:29 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * Copyright (c) 2017 Emmanuel Vadot <manu (at) freebsd.org>
6 1.1 jmcneill * All rights reserved.
7 1.1 jmcneill *
8 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
9 1.1 jmcneill * modification, are permitted provided that the following conditions
10 1.1 jmcneill * are met:
11 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
12 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
13 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
15 1.1 jmcneill * documentation and/or other materials provided with the distribution.
16 1.1 jmcneill *
17 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 jmcneill * SUCH DAMAGE.
28 1.1 jmcneill */
29 1.1 jmcneill
30 1.1 jmcneill #include <sys/cdefs.h>
31 1.1 jmcneill
32 1.1 jmcneill __KERNEL_RCSID(1, "$NetBSD: sun8i_h3_ccu.c,v 1.1 2017/06/28 23:51:29 jmcneill Exp $");
33 1.1 jmcneill
34 1.1 jmcneill #include <sys/param.h>
35 1.1 jmcneill #include <sys/bus.h>
36 1.1 jmcneill #include <sys/device.h>
37 1.1 jmcneill #include <sys/systm.h>
38 1.1 jmcneill
39 1.1 jmcneill #include <dev/fdt/fdtvar.h>
40 1.1 jmcneill
41 1.1 jmcneill #include <arm/sunxi/sunxi_ccu.h>
42 1.1 jmcneill #include <arm/sunxi/sun8i_h3_ccu.h>
43 1.1 jmcneill
44 1.1 jmcneill #define USBPHY_CFG_REG 0x0cc
45 1.1 jmcneill #define MBUS_RST_REG 0x0fc
46 1.1 jmcneill #define BUS_SOFT_RST_REG0 0x2c0
47 1.1 jmcneill #define BUS_SOFT_RST_REG1 0x2c4
48 1.1 jmcneill #define BUS_SOFT_RST_REG2 0x2c8
49 1.1 jmcneill #define BUS_SOFT_RST_REG3 0x2d0
50 1.1 jmcneill #define BUS_SOFT_RST_REG4 0x2d8
51 1.1 jmcneill
52 1.1 jmcneill #define APB2_CFG_REG 0x058
53 1.1 jmcneill #define BUS_CLK_GATING_REG3 0x06c
54 1.1 jmcneill
55 1.1 jmcneill static int sun8i_h3_ccu_match(device_t, cfdata_t, void *);
56 1.1 jmcneill static void sun8i_h3_ccu_attach(device_t, device_t, void *);
57 1.1 jmcneill
58 1.1 jmcneill static const char * const compatible[] = {
59 1.1 jmcneill "allwinner,sun8i-h3-ccu",
60 1.1 jmcneill NULL
61 1.1 jmcneill };
62 1.1 jmcneill
63 1.1 jmcneill CFATTACH_DECL_NEW(sunxi_h3_ccu, sizeof(struct sunxi_ccu_softc),
64 1.1 jmcneill sun8i_h3_ccu_match, sun8i_h3_ccu_attach, NULL, NULL);
65 1.1 jmcneill
66 1.1 jmcneill static struct sunxi_ccu_reset sun8i_h3_ccu_resets[] = {
67 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_USB_PHY0, USBPHY_CFG_REG, 0),
68 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_USB_PHY1, USBPHY_CFG_REG, 1),
69 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_USB_PHY2, USBPHY_CFG_REG, 2),
70 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_USB_PHY3, USBPHY_CFG_REG, 3),
71 1.1 jmcneill
72 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_MBUS, MBUS_RST_REG, 31),
73 1.1 jmcneill
74 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_CE, BUS_SOFT_RST_REG0, 5),
75 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_DMA, BUS_SOFT_RST_REG0, 6),
76 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_MMC0, BUS_SOFT_RST_REG0, 8),
77 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_MMC1, BUS_SOFT_RST_REG0, 9),
78 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_MMC2, BUS_SOFT_RST_REG0, 10),
79 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_NAND, BUS_SOFT_RST_REG0, 13),
80 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_DRAM, BUS_SOFT_RST_REG0, 14),
81 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_EMAC, BUS_SOFT_RST_REG0, 17),
82 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_TS, BUS_SOFT_RST_REG0, 18),
83 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_HSTIMER, BUS_SOFT_RST_REG0, 19),
84 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_SPI0, BUS_SOFT_RST_REG0, 20),
85 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_SPI1, BUS_SOFT_RST_REG0, 21),
86 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_OTG, BUS_SOFT_RST_REG0, 23),
87 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_EHCI0, BUS_SOFT_RST_REG0, 24),
88 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_EHCI1, BUS_SOFT_RST_REG0, 25),
89 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_EHCI2, BUS_SOFT_RST_REG0, 26),
90 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_EHCI3, BUS_SOFT_RST_REG0, 27),
91 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_OHCI0, BUS_SOFT_RST_REG0, 28),
92 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_OHCI1, BUS_SOFT_RST_REG0, 29),
93 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_OHCI2, BUS_SOFT_RST_REG0, 30),
94 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_OHCI3, BUS_SOFT_RST_REG0, 31),
95 1.1 jmcneill
96 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_VE, BUS_SOFT_RST_REG1, 0),
97 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_TCON0, BUS_SOFT_RST_REG1, 3),
98 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_TCON1, BUS_SOFT_RST_REG1, 4),
99 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_DEINTERLACE, BUS_SOFT_RST_REG1, 5),
100 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_CSI, BUS_SOFT_RST_REG1, 8),
101 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_TVE, BUS_SOFT_RST_REG1, 9),
102 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_HDMI0, BUS_SOFT_RST_REG1, 10),
103 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_HDMI1, BUS_SOFT_RST_REG1, 11),
104 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_DE, BUS_SOFT_RST_REG1, 12),
105 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_GPU, BUS_SOFT_RST_REG1, 20),
106 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_MSGBOX, BUS_SOFT_RST_REG1, 21),
107 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_SPINLOCK, BUS_SOFT_RST_REG1, 22),
108 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_DBG, BUS_SOFT_RST_REG1, 31),
109 1.1 jmcneill
110 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_EPHY, BUS_SOFT_RST_REG2, 2),
111 1.1 jmcneill
112 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_CODEC, BUS_SOFT_RST_REG3, 0),
113 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_SPDIF, BUS_SOFT_RST_REG3, 1),
114 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_THS, BUS_SOFT_RST_REG3, 8),
115 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_I2S0, BUS_SOFT_RST_REG3, 12),
116 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_I2S1, BUS_SOFT_RST_REG3, 13),
117 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_I2S2, BUS_SOFT_RST_REG3, 14),
118 1.1 jmcneill
119 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_I2C0, BUS_SOFT_RST_REG4, 0),
120 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_I2C1, BUS_SOFT_RST_REG4, 1),
121 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_I2C2, BUS_SOFT_RST_REG4, 2),
122 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_UART0, BUS_SOFT_RST_REG4, 16),
123 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_UART1, BUS_SOFT_RST_REG4, 17),
124 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_UART2, BUS_SOFT_RST_REG4, 18),
125 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_UART3, BUS_SOFT_RST_REG4, 19),
126 1.1 jmcneill SUNXI_CCU_RESET(H3_RST_BUS_SCR, BUS_SOFT_RST_REG4, 20),
127 1.1 jmcneill };
128 1.1 jmcneill
129 1.1 jmcneill static const char *apb2_parents[] = { "losc", "hosc", "pll_periph0" };
130 1.1 jmcneill
131 1.1 jmcneill static struct sunxi_ccu_clk sun8i_h3_ccu_clks[] = {
132 1.1 jmcneill SUNXI_CCU_NM(H3_CLK_APB2, "apb2", apb2_parents,
133 1.1 jmcneill APB2_CFG_REG, __BITS(17,16), __BITS(4,0), __BITS(25,24),
134 1.1 jmcneill SUNXI_CCU_NM_POWER_OF_TWO),
135 1.1 jmcneill
136 1.1 jmcneill SUNXI_CCU_GATE(H3_CLK_BUS_UART0, "bus-uart0", "apb2",
137 1.1 jmcneill BUS_CLK_GATING_REG3, 19),
138 1.1 jmcneill };
139 1.1 jmcneill
140 1.1 jmcneill static int
141 1.1 jmcneill sun8i_h3_ccu_match(device_t parent, cfdata_t cf, void *aux)
142 1.1 jmcneill {
143 1.1 jmcneill struct fdt_attach_args * const faa = aux;
144 1.1 jmcneill
145 1.1 jmcneill return of_match_compatible(faa->faa_phandle, compatible);
146 1.1 jmcneill }
147 1.1 jmcneill
148 1.1 jmcneill static void
149 1.1 jmcneill sun8i_h3_ccu_attach(device_t parent, device_t self, void *aux)
150 1.1 jmcneill {
151 1.1 jmcneill struct sunxi_ccu_softc * const sc = device_private(self);
152 1.1 jmcneill struct fdt_attach_args * const faa = aux;
153 1.1 jmcneill
154 1.1 jmcneill sc->sc_dev = self;
155 1.1 jmcneill sc->sc_phandle = faa->faa_phandle;
156 1.1 jmcneill sc->sc_bst = faa->faa_bst;
157 1.1 jmcneill
158 1.1 jmcneill sc->sc_resets = sun8i_h3_ccu_resets;
159 1.1 jmcneill sc->sc_nresets = __arraycount(sun8i_h3_ccu_resets);
160 1.1 jmcneill
161 1.1 jmcneill sc->sc_clks = sun8i_h3_ccu_clks;
162 1.1 jmcneill sc->sc_nclks = __arraycount(sun8i_h3_ccu_clks);
163 1.1 jmcneill
164 1.1 jmcneill if (sunxi_ccu_attach(sc) != 0)
165 1.1 jmcneill return;
166 1.1 jmcneill
167 1.1 jmcneill aprint_naive("\n");
168 1.1 jmcneill aprint_normal(": H3 CCU\n");
169 1.1 jmcneill
170 1.1 jmcneill sunxi_ccu_print(sc);
171 1.1 jmcneill }
172