sun50i_a64_r_ccu.c revision 1.1 1 1.1 jmcneill /* $NetBSD: sun50i_a64_r_ccu.c,v 1.1 2018/05/05 09:54:53 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2017-2018 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.1 jmcneill
31 1.1 jmcneill __KERNEL_RCSID(1, "$NetBSD: sun50i_a64_r_ccu.c,v 1.1 2018/05/05 09:54:53 jmcneill Exp $");
32 1.1 jmcneill
33 1.1 jmcneill #include <sys/param.h>
34 1.1 jmcneill #include <sys/bus.h>
35 1.1 jmcneill #include <sys/device.h>
36 1.1 jmcneill #include <sys/systm.h>
37 1.1 jmcneill
38 1.1 jmcneill #include <dev/fdt/fdtvar.h>
39 1.1 jmcneill
40 1.1 jmcneill #include <arm/sunxi/sunxi_ccu.h>
41 1.1 jmcneill #include <arm/sunxi/sun50i_a64_r_ccu.h>
42 1.1 jmcneill
43 1.1 jmcneill #define AR100_CFG_REG 0x00
44 1.1 jmcneill #define APB0_CFG_REG 0x0c
45 1.1 jmcneill #define APB0_GATE_REG 0x28
46 1.1 jmcneill #define IR_CFG_REG 0x54
47 1.1 jmcneill #define APB0_RESET_REG 0xb0
48 1.1 jmcneill
49 1.1 jmcneill static int sun50i_a64_r_ccu_match(device_t, cfdata_t, void *);
50 1.1 jmcneill static void sun50i_a64_r_ccu_attach(device_t, device_t, void *);
51 1.1 jmcneill
52 1.1 jmcneill static const char * const compatible[] = {
53 1.1 jmcneill "allwinner,sun50i-a64-r-ccu",
54 1.1 jmcneill NULL
55 1.1 jmcneill };
56 1.1 jmcneill
57 1.1 jmcneill CFATTACH_DECL_NEW(sunxi_a64_r_ccu, sizeof(struct sunxi_ccu_softc),
58 1.1 jmcneill sun50i_a64_r_ccu_match, sun50i_a64_r_ccu_attach, NULL, NULL);
59 1.1 jmcneill
60 1.1 jmcneill static struct sunxi_ccu_reset sun50i_a64_r_ccu_resets[] = {
61 1.1 jmcneill SUNXI_CCU_RESET(A64_R_RST_APB0_IR, APB0_RESET_REG, 1),
62 1.1 jmcneill SUNXI_CCU_RESET(A64_R_RST_APB0_TIMER, APB0_RESET_REG, 2),
63 1.1 jmcneill SUNXI_CCU_RESET(A64_R_RST_APB0_RSB, APB0_RESET_REG, 3),
64 1.1 jmcneill SUNXI_CCU_RESET(A64_R_RST_APB0_UART, APB0_RESET_REG, 4),
65 1.1 jmcneill SUNXI_CCU_RESET(A64_R_RST_APB0_I2C, APB0_RESET_REG, 6),
66 1.1 jmcneill };
67 1.1 jmcneill
68 1.1 jmcneill static const char *ar100_parents[] = { "losc", "hosc", "pll_periph0", "losc" };
69 1.1 jmcneill static const char *apb0_parents[] = { "ahb0" };
70 1.1 jmcneill static const char *mod_parents[] = { "losc", "hosc" };
71 1.1 jmcneill
72 1.1 jmcneill static struct sunxi_ccu_clk sun50i_a64_r_ccu_clks[] = {
73 1.1 jmcneill SUNXI_CCU_PREDIV(A64_R_CLK_AR100, "ar100", ar100_parents,
74 1.1 jmcneill AR100_CFG_REG, /* reg */
75 1.1 jmcneill __BITS(12,8), /* prediv */
76 1.1 jmcneill __BIT(2), /* prediv_sel */
77 1.1 jmcneill __BITS(5,4), /* div */
78 1.1 jmcneill __BITS(17,16), /* sel */
79 1.1 jmcneill SUNXI_CCU_PREDIV_POWER_OF_TWO),
80 1.1 jmcneill
81 1.1 jmcneill SUNXI_CCU_FIXED_FACTOR(A64_R_CLK_AHB0, "ahb0", "ar100", 1, 1),
82 1.1 jmcneill
83 1.1 jmcneill SUNXI_CCU_DIV(A64_R_CLK_APB0, "apb0", apb0_parents,
84 1.1 jmcneill APB0_CFG_REG, /* reg */
85 1.1 jmcneill __BITS(1,0), /* div */
86 1.1 jmcneill 0, /* sel */
87 1.1 jmcneill SUNXI_CCU_DIV_POWER_OF_TWO),
88 1.1 jmcneill
89 1.1 jmcneill SUNXI_CCU_GATE(A64_R_CLK_APB0_PIO, "apb0-pio", "apb0",
90 1.1 jmcneill APB0_GATE_REG, 0),
91 1.1 jmcneill SUNXI_CCU_GATE(A64_R_CLK_APB0_IR, "apb0-ir", "apb0",
92 1.1 jmcneill APB0_GATE_REG, 1),
93 1.1 jmcneill SUNXI_CCU_GATE(A64_R_CLK_APB0_TIMER, "apb0-timer", "apb0",
94 1.1 jmcneill APB0_GATE_REG, 2),
95 1.1 jmcneill SUNXI_CCU_GATE(A64_R_CLK_APB0_RSB, "apb0-rsb", "apb0",
96 1.1 jmcneill APB0_GATE_REG, 3),
97 1.1 jmcneill SUNXI_CCU_GATE(A64_R_CLK_APB0_UART, "apb0-uart", "apb0",
98 1.1 jmcneill APB0_GATE_REG, 4),
99 1.1 jmcneill SUNXI_CCU_GATE(A64_R_CLK_APB0_I2C, "apb0-i2c", "apb0",
100 1.1 jmcneill APB0_GATE_REG, 6),
101 1.1 jmcneill SUNXI_CCU_GATE(A64_R_CLK_APB0_TWD, "apb0-twd", "apb0",
102 1.1 jmcneill APB0_GATE_REG, 7),
103 1.1 jmcneill SUNXI_CCU_NM(A64_R_CLK_IR, "ir", mod_parents,
104 1.1 jmcneill IR_CFG_REG, /* reg */
105 1.1 jmcneill __BITS(3,0), /* n */
106 1.1 jmcneill __BITS(17,16), /* m */
107 1.1 jmcneill __BITS(25,24), /* sel */
108 1.1 jmcneill __BIT(31), /* enable */
109 1.1 jmcneill 0)
110 1.1 jmcneill };
111 1.1 jmcneill
112 1.1 jmcneill static int
113 1.1 jmcneill sun50i_a64_r_ccu_match(device_t parent, cfdata_t cf, void *aux)
114 1.1 jmcneill {
115 1.1 jmcneill struct fdt_attach_args * const faa = aux;
116 1.1 jmcneill
117 1.1 jmcneill return of_match_compatible(faa->faa_phandle, compatible);
118 1.1 jmcneill }
119 1.1 jmcneill
120 1.1 jmcneill static void
121 1.1 jmcneill sun50i_a64_r_ccu_attach(device_t parent, device_t self, void *aux)
122 1.1 jmcneill {
123 1.1 jmcneill struct sunxi_ccu_softc * const sc = device_private(self);
124 1.1 jmcneill struct fdt_attach_args * const faa = aux;
125 1.1 jmcneill
126 1.1 jmcneill sc->sc_dev = self;
127 1.1 jmcneill sc->sc_phandle = faa->faa_phandle;
128 1.1 jmcneill sc->sc_bst = faa->faa_bst;
129 1.1 jmcneill
130 1.1 jmcneill sc->sc_resets = sun50i_a64_r_ccu_resets;
131 1.1 jmcneill sc->sc_nresets = __arraycount(sun50i_a64_r_ccu_resets);
132 1.1 jmcneill
133 1.1 jmcneill sc->sc_clks = sun50i_a64_r_ccu_clks;
134 1.1 jmcneill sc->sc_nclks = __arraycount(sun50i_a64_r_ccu_clks);
135 1.1 jmcneill
136 1.1 jmcneill if (sunxi_ccu_attach(sc) != 0)
137 1.1 jmcneill return;
138 1.1 jmcneill
139 1.1 jmcneill aprint_naive("\n");
140 1.1 jmcneill aprint_normal(": A64 PRCM CCU\n");
141 1.1 jmcneill
142 1.1 jmcneill sunxi_ccu_print(sc);
143 1.1 jmcneill }
144