mesongxbb_aoclkc.c revision 1.1 1 /* $NetBSD: mesongxbb_aoclkc.c,v 1.1 2019/02/25 19:30:17 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2019 Jared McNeill <jmcneill (at) 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.1 2019/02/25 19:30:17 jmcneill 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 char * const compatible[] = {
51 "amlogic,meson-gxbb-aoclkc",
52 NULL
53 };
54
55 CFATTACH_DECL_NEW(mesongxbb_aoclkc, sizeof(struct meson_clk_softc),
56 mesongxbb_aoclkc_match, mesongxbb_aoclkc_attach, NULL, NULL);
57
58 static struct meson_clk_reset mesongxbb_aoclkc_resets[] = {
59 MESON_CLK_RESET(MESONGXBB_RESET_AO_REMOTE, AO_RTI_GEN_CTNL_REG0, 16),
60 MESON_CLK_RESET(MESONGXBB_RESET_AO_UART1, AO_RTI_GEN_CTNL_REG0, 17),
61 MESON_CLK_RESET(MESONGXBB_RESET_AO_I2C_MASTER, AO_RTI_GEN_CTNL_REG0, 18),
62 MESON_CLK_RESET(MESONGXBB_RESET_AO_I2C_SLAVE, AO_RTI_GEN_CTNL_REG0, 19),
63 MESON_CLK_RESET(MESONGXBB_RESET_AO_UART2, AO_RTI_GEN_CTNL_REG0, 22),
64 MESON_CLK_RESET(MESONGXBB_RESET_AO_IR_BLASTER, AO_RTI_GEN_CTNL_REG0, 23),
65 };
66
67 static struct meson_clk_clk mesongxbb_aoclkc_clks[] = {
68 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_REMOTE, "remote_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 0),
69 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_I2C_MASTER, "i2c_master_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 1),
70 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_I2C_SLAVE, "i2c_slave_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 2),
71 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_UART1, "uart1_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 3),
72 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_UART2, "uart2_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 5),
73 MESON_CLK_GATE(MESONGXBB_CLOCK_AO_IR_BLASTER, "ir_blaster_ao", GATE_PARENT, AO_RTI_GEN_CTNL_REG0, 6),
74 };
75
76 static int
77 mesongxbb_aoclkc_match(device_t parent, cfdata_t cf, void *aux)
78 {
79 struct fdt_attach_args * const faa = aux;
80
81 return of_match_compatible(faa->faa_phandle, compatible);
82 }
83
84 static void
85 mesongxbb_aoclkc_attach(device_t parent, device_t self, void *aux)
86 {
87 struct meson_clk_softc * const sc = device_private(self);
88 struct fdt_attach_args * const faa = aux;
89
90 sc->sc_dev = self;
91 sc->sc_phandle = faa->faa_phandle;
92 sc->sc_syscon = fdtbus_syscon_lookup(OF_parent(sc->sc_phandle));
93 if (sc->sc_syscon == NULL) {
94 aprint_error(": couldn't get syscon registers\n");
95 return;
96 }
97
98 sc->sc_resets = mesongxbb_aoclkc_resets;
99 sc->sc_nresets = __arraycount(mesongxbb_aoclkc_resets);
100
101 sc->sc_clks = mesongxbb_aoclkc_clks;
102 sc->sc_nclks = __arraycount(mesongxbb_aoclkc_clks);
103
104 meson_clk_attach(sc);
105
106 aprint_naive("\n");
107 aprint_normal(": Meson GXBB AO clock controller\n");
108
109 meson_clk_print(sc);
110 }
111