mesong12_aoclkc.c revision 1.3 1 1.3 msaitoh /* $NetBSD: mesong12_aoclkc.c,v 1.3 2024/02/07 04:20:26 msaitoh Exp $ */
2 1.1 ryo
3 1.1 ryo /*
4 1.3 msaitoh * Copyright (c) 2021 Ryo Shimizu
5 1.1 ryo * All rights reserved.
6 1.1 ryo *
7 1.1 ryo * Redistribution and use in source and binary forms, with or without
8 1.1 ryo * modification, are permitted provided that the following conditions
9 1.1 ryo * are met:
10 1.1 ryo * 1. Redistributions of source code must retain the above copyright
11 1.1 ryo * notice, this list of conditions and the following disclaimer.
12 1.1 ryo * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ryo * notice, this list of conditions and the following disclaimer in the
14 1.1 ryo * documentation and/or other materials provided with the distribution.
15 1.1 ryo *
16 1.1 ryo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 1.1 ryo * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 ryo * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 ryo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.1 ryo * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1 ryo * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1 ryo * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 ryo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.1 ryo * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 1.1 ryo * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 ryo * POSSIBILITY OF SUCH DAMAGE.
27 1.1 ryo */
28 1.1 ryo
29 1.1 ryo #include <sys/cdefs.h>
30 1.3 msaitoh __KERNEL_RCSID(0, "$NetBSD: mesong12_aoclkc.c,v 1.3 2024/02/07 04:20:26 msaitoh Exp $");
31 1.1 ryo
32 1.1 ryo #include <sys/param.h>
33 1.1 ryo #include <sys/types.h>
34 1.1 ryo #include <sys/bus.h>
35 1.1 ryo #include <sys/device.h>
36 1.1 ryo
37 1.1 ryo #include <dev/fdt/fdtvar.h>
38 1.1 ryo
39 1.1 ryo #include <arm/amlogic/meson_clk.h>
40 1.1 ryo #include <arm/amlogic/mesong12_aoclkc.h>
41 1.1 ryo
42 1.1 ryo #define AO_SOFT_RESET_REG 0x40
43 1.1 ryo #define AO_DOMAIN_CLOCK_GATEING0_REG 0x4c
44 1.1 ryo #define AO_DOMAIN_CLOCK_GATEING1_REG 0x50
45 1.1 ryo
46 1.1 ryo #define GATE_PARENT "mpeg-clk"
47 1.1 ryo
48 1.1 ryo static int mesong12_aoclkc_match(device_t, cfdata_t, void *);
49 1.1 ryo static void mesong12_aoclkc_attach(device_t, device_t, void *);
50 1.1 ryo
51 1.2 thorpej static const struct device_compatible_entry compat_data[] = {
52 1.2 thorpej { .compat = "amlogic,meson-g12a-aoclkc" },
53 1.2 thorpej DEVICE_COMPAT_EOL
54 1.1 ryo };
55 1.1 ryo
56 1.1 ryo CFATTACH_DECL_NEW(mesong12_aoclkc, sizeof(struct meson_clk_softc),
57 1.1 ryo mesong12_aoclkc_match, mesong12_aoclkc_attach, NULL, NULL);
58 1.1 ryo
59 1.1 ryo static struct meson_clk_reset mesong12_aoclkc_resets[] = {
60 1.1 ryo MESON_CLK_RESET(MESONG12_RESET_AO_IR_IN, AO_SOFT_RESET_REG, 16),
61 1.1 ryo MESON_CLK_RESET(MESONG12_RESET_AO_UART, AO_SOFT_RESET_REG, 17),
62 1.1 ryo MESON_CLK_RESET(MESONG12_RESET_AO_I2C_M, AO_SOFT_RESET_REG, 18),
63 1.1 ryo MESON_CLK_RESET(MESONG12_RESET_AO_I2C_S, AO_SOFT_RESET_REG, 19),
64 1.1 ryo MESON_CLK_RESET(MESONG12_RESET_AO_SAR_ADC, AO_SOFT_RESET_REG, 20),
65 1.1 ryo MESON_CLK_RESET(MESONG12_RESET_AO_UART2, AO_SOFT_RESET_REG, 22),
66 1.1 ryo MESON_CLK_RESET(MESONG12_RESET_AO_IR_OUT, AO_SOFT_RESET_REG, 23),
67 1.1 ryo };
68 1.1 ryo
69 1.1 ryo static struct meson_clk_clk mesong12_aoclkc_clks[] = {
70 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_AHB, "ahb_ao",
71 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 0),
72 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_IR_IN,"ir_in_ao",
73 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 1),
74 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_I2C_M0, "i2c_m0_ao",
75 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 2),
76 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_I2C_S0, "i2c_s0_ao",
77 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 3),
78 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_UART, "uart_ao",
79 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 4),
80 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_PROD_I2C, "prod_i2c_ao",
81 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 5),
82 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_UART2, "uart2_ao",
83 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 6),
84 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_IR_OUT, "ir_out_ao",
85 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 7),
86 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_SAR_ADC, "sar_adc_ao",
87 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING0_REG, 8),
88 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_MAILBOX, "mailbox_ao",
89 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING1_REG, 0),
90 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_M3, "m3_ao",
91 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING1_REG, 1),
92 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_AHB_SRAM, "ahb_sram_ao",
93 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING1_REG, 2),
94 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_RTI, "rti_ao",
95 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING1_REG, 3),
96 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_M4_FCLK, "m4_fclk_ao",
97 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING1_REG, 4),
98 1.1 ryo MESON_CLK_GATE(MESONG12_CLOCK_AO_M4_HCLK, "m4_hclk_ao",
99 1.1 ryo GATE_PARENT, AO_DOMAIN_CLOCK_GATEING1_REG, 5),
100 1.1 ryo };
101 1.1 ryo
102 1.1 ryo static int
103 1.1 ryo mesong12_aoclkc_match(device_t parent, cfdata_t cf, void *aux)
104 1.1 ryo {
105 1.1 ryo struct fdt_attach_args * const faa = aux;
106 1.1 ryo
107 1.2 thorpej return of_compatible_match(faa->faa_phandle, compat_data);
108 1.1 ryo }
109 1.1 ryo
110 1.1 ryo static void
111 1.1 ryo mesong12_aoclkc_attach(device_t parent, device_t self, void *aux)
112 1.1 ryo {
113 1.1 ryo struct meson_clk_softc * const sc = device_private(self);
114 1.1 ryo struct fdt_attach_args * const faa = aux;
115 1.1 ryo
116 1.1 ryo sc->sc_dev = self;
117 1.1 ryo sc->sc_phandle = faa->faa_phandle;
118 1.1 ryo sc->sc_syscon = fdtbus_syscon_lookup(OF_parent(sc->sc_phandle));
119 1.1 ryo if (sc->sc_syscon == NULL) {
120 1.1 ryo aprint_error(": couldn't get syscon registers\n");
121 1.1 ryo return;
122 1.1 ryo }
123 1.1 ryo
124 1.1 ryo sc->sc_resets = mesong12_aoclkc_resets;
125 1.1 ryo sc->sc_nresets = __arraycount(mesong12_aoclkc_resets);
126 1.1 ryo
127 1.1 ryo sc->sc_clks = mesong12_aoclkc_clks;
128 1.1 ryo sc->sc_nclks = __arraycount(mesong12_aoclkc_clks);
129 1.1 ryo
130 1.1 ryo aprint_naive("\n");
131 1.1 ryo aprint_normal(": Meson G12A AO clock controller\n");
132 1.1 ryo
133 1.1 ryo meson_clk_attach(sc);
134 1.1 ryo meson_clk_print(sc);
135 1.1 ryo }
136