Path: blob/main/sys/arm64/qoriq/clk/ls1046a_clkgen.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2020 Alstom Group.4* Copyright (c) 2020 Semihalf.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/bus.h>30#include <sys/kernel.h>31#include <sys/module.h>32#include <sys/mutex.h>33#include <sys/rman.h>34#include <machine/bus.h>3536#include <dev/fdt/simplebus.h>3738#include <dev/ofw/ofw_bus.h>39#include <dev/ofw/ofw_bus_subr.h>4041#include <dev/clk/clk_fixed.h>4243#include <arm64/qoriq/clk/qoriq_clkgen.h>4445static uint8_t ls1046a_pltfrm_pll_divs[] = {462, 4, 047};4849static struct qoriq_clk_pll_def ls1046a_pltfrm_pll = {50.clkdef = {51.name = "ls1046a_platform_pll",52.id = QORIQ_CLK_ID(QORIQ_TYPE_PLATFORM_PLL, 0),53.flags = 054},55.offset = 0xC00,56.shift = 1,57.mask = 0x7E,58.dividers = ls1046a_pltfrm_pll_divs,59.flags = 060};6162static const uint8_t ls1046a_cga1_pll_divs[] = {632, 3, 4, 064};6566static struct qoriq_clk_pll_def ls1046a_cga1_pll = {67.clkdef = {68.name = "ls1046a_cga_pll1",69.id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 0),70.flags = 071},72.offset = 0x800,73.shift = 1,74.mask = 0x1FE,75.dividers = ls1046a_cga1_pll_divs,76.flags = QORIQ_CLK_PLL_HAS_KILL_BIT77};7879static struct qoriq_clk_pll_def ls1046a_cga2_pll = {80.clkdef = {81.name = "ls1046a_cga_pll2",82.id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 20),83.flags = 084},85.offset = 0x820,86.shift = 1,87.mask = 0x1FE,88.dividers = ls1046a_cga1_pll_divs,89.flags = QORIQ_CLK_PLL_HAS_KILL_BIT90};9192static struct qoriq_clk_pll_def *ls1046a_cga_plls[] = {93&ls1046a_cga1_pll,94&ls1046a_cga2_pll95};9697static const char *ls1046a_cmux0_parent_names[] = {98"ls1046a_cga_pll1",99NULL,100"ls1046a_cga_pll1_div2",101NULL,102"ls1046a_cga_pll2",103NULL,104"ls1046a_cga_pll2_div2"105};106107static struct clk_mux_def ls1046a_cmux0 = {108.clkdef = {109.name = "ls1046a_cmux0",110.id = QORIQ_CLK_ID(QORIQ_TYPE_CMUX, 0),111.parent_names = ls1046a_cmux0_parent_names,112.parent_cnt = nitems(ls1046a_cmux0_parent_names),113.flags = 0114},115.offset = 0,116.shift = 27,117.width = 4,118.mux_flags = 0119};120121static const char *ls1046a_hwaccel1_parent_names[] = {122NULL,123NULL,124"ls1046a_cga_pll1_div2",125"ls1046a_cga_pll1_div3",126"ls1046a_cga_pll1_div4",127"ls1046a_platform_pll",128"ls1046a_cga_pll2_div2",129"ls1046a_cga_pll2_div3"130};131132static const char *ls1046a_hwaccel2_parent_names[] = {133NULL,134"ls1046a_cga_pll2",135"ls1046a_cga_pll2_div2",136"ls1046a_cga_pll2_div3",137NULL,138NULL,139"ls1046a_cga_pll1_div2"140};141142static struct clk_mux_def ls1046a_hwaccel1 = {143.clkdef = {144.name = "ls1046a_hwaccel1",145.id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 0),146.parent_names = ls1046a_hwaccel1_parent_names,147.parent_cnt = nitems(ls1046a_hwaccel1_parent_names),148.flags = 0149},150.offset = 0x10,151.shift = 27,152.width = 4,153.mux_flags = 0154};155156static struct clk_mux_def ls1046a_hwaccel2 = {157.clkdef = {158.name = "ls1046a_hwaccel2",159.id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 1),160.parent_names = ls1046a_hwaccel2_parent_names,161.parent_cnt = nitems(ls1046a_hwaccel2_parent_names),162.flags = 0163},164.offset = 0x30,165.shift = 27,166.width = 4,167.mux_flags = 0168};169170static struct clk_mux_def *ls1046a_mux_nodes[] = {171&ls1046a_cmux0,172&ls1046a_hwaccel1,173&ls1046a_hwaccel2174};175176const char *ls1046a_fman_srcs[] = {177"ls1046a_hwaccel1"178};179180static int ls1046a_clkgen_probe(device_t);181static int ls1046a_clkgen_attach(device_t);182183static device_method_t ls1046a_clkgen_methods[] = {184DEVMETHOD(device_probe, ls1046a_clkgen_probe),185DEVMETHOD(device_attach, ls1046a_clkgen_attach),186187DEVMETHOD_END188};189190DEFINE_CLASS_1(ls1046a_clkgen, ls1046a_clkgen_driver, ls1046a_clkgen_methods,191sizeof(struct qoriq_clkgen_softc), qoriq_clkgen_driver);192193EARLY_DRIVER_MODULE(ls1046a_clkgen, simplebus, ls1046a_clkgen_driver, 0, 0,194BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);195196static int197ls1046a_fman_init(device_t dev)198{199struct qoriq_clkgen_softc *sc;200struct clk_fixed_def def;201int error;202203sc = device_get_softc(dev);204205def.clkdef.name = "ls1046a_fman",206def.clkdef.id = QORIQ_CLK_ID(QORIQ_TYPE_FMAN, 0),207def.clkdef.parent_names = ls1046a_fman_srcs;208def.clkdef.parent_cnt = nitems(ls1046a_fman_srcs);209def.clkdef.flags = 0;210def.freq = 0;211def.mult = 1;212def.div = 1;213def.fixed_flags = 0;214215error = clknode_fixed_register(sc->clkdom, &def);216return (error);217}218219static int220ls1046a_clkgen_probe(device_t dev)221{222223if (!ofw_bus_status_okay(dev))224return (ENXIO);225226if(!ofw_bus_is_compatible(dev, "fsl,ls1046a-clockgen"))227return (ENXIO);228229device_set_desc(dev, "LS1046A clockgen");230return (BUS_PROBE_DEFAULT);231}232233static int234ls1046a_clkgen_attach(device_t dev)235{236struct qoriq_clkgen_softc *sc;237238sc = device_get_softc(dev);239240sc->pltfrm_pll_def = &ls1046a_pltfrm_pll;241sc->cga_pll = ls1046a_cga_plls;242sc->cga_pll_num = nitems(ls1046a_cga_plls);243sc->mux = ls1046a_mux_nodes;244sc->mux_num = nitems(ls1046a_mux_nodes);245sc->init_func = ls1046a_fman_init;246sc->flags = 0;247248return (qoriq_clkgen_attach(dev));249}250251252