1 /* $NetBSD: mesongxbb_aoclkc.c,v 1.3 2021/01/27 03:10:18 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2019 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30
31 __KERNEL_RCSID(1, "$NetBSD: mesongxbb_aoclkc.c,v 1.3 2021/01/27 03:10:18 thorpej Exp $");
32
33 #include <sys/param.h>
34 #include <sys/bus.h>
35 #include <sys/device.h>
36 #include <sys/systm.h>
37
38 #include <dev/fdt/fdtvar.h>
39
40 #include <arm/amlogic/meson_clk.h>
41 #include <arm/amlogic/mesongxbb_aoclkc.h>
42
43 #define AO_RTI_GEN_CTNL_REG0 0x40
44
45 #define GATE_PARENT "mpeg-clk"
46
47 static int mesongxbb_aoclkc_match(device_t, cfdata_t, void *);
48 static void mesongxbb_aoclkc_attach(device_t, device_t, void *);
49
50 static const struct device_compatible_entry compat_data[] = {
51 { .compat = "amlogic,meson-gxbb-aoclkc" },
52 { .compat = "amlogic,meson-gxl-aoclkc" },
53 DEVICE_COMPAT_EOL
54 };
55
56 CFATTACH_DECL_NEW(mesongxbb_aoclkc, sizeof(struct meson_clk_softc),
57 mesongxbb_aoclkc_match, mesongxbb_aoclkc_attach, NULL, NULL);
58
59 static struct meson_clk_reset mesongxbb_aoclkc_resets[] = {
60 MESON_CLK_RESET(MESONGXBB_RESET_AO_REMOTE, AO_RTI_GEN_CTNL_REG0, 16),
61 MESON_CLK_RESET(MESONGXBB_RESET_AO_UART1, AO_RTI_GEN_CTNL_REG0, 17),
62 MESON_CLK_RESET(MESONGXBB_RESET_AO_I2C_MASTER, AO_RTI_GEN_CTNL_REG0, 18),
63 MESON_CLK_RESET(MESONGXBB_RESET_AO_I2C_SLAVE, AO_RTI_GEN_CTNL_REG0, 19),
64 MESON_CLK_RESET(MESONGXBB_RESET_AO_UART2, AO_RTI_GEN_CTNL_REG0, 22),
65 MESON_CLK_RESET(MESONGXBB_RESET_AO_IR_BLASTER, AO_RTI_GEN_CTNL_REG0, 23),
66 };
67
68 static struct meson_clk_clk mesongxbb_aoclkc_clks[] = {
69 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_REMOTE, "remote_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 0),
70 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_I2C_MASTER, "i2c_master_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 1),
71 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_I2C_SLAVE, "i2c_slave_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 2),
72 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_UART1, "uart1_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 3),
73 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_UART2, "uart2_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 5),
74 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_IR_BLASTER, "ir_blaster_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 6),
75 };
76
77 static int
mesongxbb_aoclkc_match(device_t parent,cfdata_t cf,void * aux)78 mesongxbb_aoclkc_match(device_t parent, cfdata_t cf, void *aux)
79 {
80 struct fdt_attach_args * const faa = aux;
81
82 return of_compatible_match(faa->faa_phandle, compat_data);
83 }
84
85 static void
mesongxbb_aoclkc_attach(device_t parent,device_t self,void * aux)86 mesongxbb_aoclkc_attach(device_t parent, device_t self, void *aux)
87 {
88 struct meson_clk_softc * const sc = device_private(self);
89 struct fdt_attach_args * const faa = aux;
90
91 sc->sc_dev = self;
92 sc->sc_phandle = faa->faa_phandle;
93 sc->sc_syscon = fdtbus_syscon_lookup(OF_parent(sc->sc_phandle));
94 if (sc->sc_syscon == NULL) {
95 aprint_error(": couldn't get syscon registers\n");
96 return;
97 }
98
99 sc->sc_resets = mesongxbb_aoclkc_resets;
100 sc->sc_nresets = __arraycount(mesongxbb_aoclkc_resets);
101
102 sc->sc_clks = mesongxbb_aoclkc_clks;
103 sc->sc_nclks = __arraycount(mesongxbb_aoclkc_clks);
104
105 meson_clk_attach(sc);
106
107 aprint_naive("\n");
108 aprint_normal(": Meson GX AO clock controller\n");
109
110 meson_clk_print(sc);
111 }
112