2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2020 Alstom Group.
5 * Copyright (c) 2020 Semihalf.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, 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
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/mutex.h>
38 #include <machine/bus.h>
40 #include <dev/fdt/simplebus.h>
42 #include <dev/ofw/ofw_bus.h>
43 #include <dev/ofw/ofw_bus_subr.h>
45 #include <dev/extres/clk/clk_fixed.h>
47 #include <arm64/qoriq/clk/qoriq_clkgen.h>
49 static uint8_t ls1046a_pltfrm_pll_divs[] = {
53 static struct qoriq_clk_pll_def ls1046a_pltfrm_pll = {
55 .name = "ls1046a_platform_pll",
56 .id = QORIQ_CLK_ID(QORIQ_TYPE_PLATFORM_PLL, 0),
62 .dividers = ls1046a_pltfrm_pll_divs,
66 static const uint8_t ls1046a_cga1_pll_divs[] = {
70 static struct qoriq_clk_pll_def ls1046a_cga1_pll = {
72 .name = "ls1046a_cga_pll1",
73 .id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 0),
79 .dividers = ls1046a_cga1_pll_divs,
80 .flags = QORIQ_CLK_PLL_HAS_KILL_BIT
83 static struct qoriq_clk_pll_def ls1046a_cga2_pll = {
85 .name = "ls1046a_cga_pll2",
86 .id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 20),
92 .dividers = ls1046a_cga1_pll_divs,
93 .flags = QORIQ_CLK_PLL_HAS_KILL_BIT
96 static struct qoriq_clk_pll_def *ls1046a_cga_plls[] = {
101 static const char *ls1046a_cmux0_parent_names[] = {
104 "ls1046a_cga_pll1_div2",
108 "ls1046a_cga_pll2_div2"
111 static struct clk_mux_def ls1046a_cmux0 = {
113 .name = "ls1046a_cmux0",
114 .id = QORIQ_CLK_ID(QORIQ_TYPE_CMUX, 0),
115 .parent_names = ls1046a_cmux0_parent_names,
116 .parent_cnt = nitems(ls1046a_cmux0_parent_names),
125 static const char *ls1046a_hwaccel1_parent_names[] = {
128 "ls1046a_cga_pll1_div2",
129 "ls1046a_cga_pll1_div3",
130 "ls1046a_cga_pll1_div4",
131 "ls1046a_platform_pll",
132 "ls1046a_cga_pll2_div2",
133 "ls1046a_cga_pll2_div3"
136 static const char *ls1046a_hwaccel2_parent_names[] = {
139 "ls1046a_cga_pll2_div2",
140 "ls1046a_cga_pll2_div3",
143 "ls1046a_cga_pll1_div2"
146 static struct clk_mux_def ls1046a_hwaccel1 = {
148 .name = "ls1046a_hwaccel1",
149 .id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 0),
150 .parent_names = ls1046a_hwaccel1_parent_names,
151 .parent_cnt = nitems(ls1046a_hwaccel1_parent_names),
160 static struct clk_mux_def ls1046a_hwaccel2 = {
162 .name = "ls1046a_hwaccel2",
163 .id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 1),
164 .parent_names = ls1046a_hwaccel2_parent_names,
165 .parent_cnt = nitems(ls1046a_hwaccel2_parent_names),
174 static struct clk_mux_def *ls1046a_mux_nodes[] = {
180 const char *ls1046a_fman_srcs[] = {
184 static int ls1046a_clkgen_probe(device_t);
185 static int ls1046a_clkgen_attach(device_t);
187 static device_method_t ls1046a_clkgen_methods[] = {
188 DEVMETHOD(device_probe, ls1046a_clkgen_probe),
189 DEVMETHOD(device_attach, ls1046a_clkgen_attach),
194 DEFINE_CLASS_1(ls1046a_clkgen, ls1046a_clkgen_driver, ls1046a_clkgen_methods,
195 sizeof(struct qoriq_clkgen_softc), qoriq_clkgen_driver);
197 static devclass_t ls1046a_clkgen_devclass;
199 EARLY_DRIVER_MODULE(ls1046a_clkgen, simplebus, ls1046a_clkgen_driver,
200 ls1046a_clkgen_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
203 ls1046a_fman_init(device_t dev)
205 struct qoriq_clkgen_softc *sc;
206 struct clk_fixed_def def;
209 sc = device_get_softc(dev);
211 def.clkdef.name = "ls1046a_fman",
212 def.clkdef.id = QORIQ_CLK_ID(QORIQ_TYPE_FMAN, 0),
213 def.clkdef.parent_names = ls1046a_fman_srcs;
214 def.clkdef.parent_cnt = nitems(ls1046a_fman_srcs);
215 def.clkdef.flags = 0;
221 error = clknode_fixed_register(sc->clkdom, &def);
226 ls1046a_clkgen_probe(device_t dev)
229 if (!ofw_bus_status_okay(dev))
232 if(!ofw_bus_is_compatible(dev, "fsl,ls1046a-clockgen"))
235 device_set_desc(dev, "LS1046A clockgen");
236 return (BUS_PROBE_DEFAULT);
240 ls1046a_clkgen_attach(device_t dev)
242 struct qoriq_clkgen_softc *sc;
244 sc = device_get_softc(dev);
246 sc->pltfrm_pll_def = &ls1046a_pltfrm_pll;
247 sc->cga_pll = ls1046a_cga_plls;
248 sc->cga_pll_num = nitems(ls1046a_cga_plls);
249 sc->mux = ls1046a_mux_nodes;
250 sc->mux_num = nitems(ls1046a_mux_nodes);
251 sc->init_func = ls1046a_fman_init;
254 return (qoriq_clkgen_attach(dev));