Path: blob/main/sys/arm64/qoriq/clk/ls1028a_clkgen.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Alstom Group.4* Copyright (c) 2021 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 ls1028a_pltfrm_pll_divs[] = {461, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 047};4849static struct qoriq_clk_pll_def ls1028a_pltfrm_pll = {50.clkdef = {51.name = "ls1028a_platform_pll",52.id = QORIQ_CLK_ID(QORIQ_TYPE_PLATFORM_PLL, 0),53.flags = 054},55.offset = 0x60080,56.shift = 1,57.mask = 0xFE,58.dividers = ls1028a_pltfrm_pll_divs,59.flags = QORIQ_CLK_PLL_HAS_KILL_BIT60};6162static const uint8_t ls1028a_cga_pll_divs[] = {632, 3, 4, 064};6566static struct qoriq_clk_pll_def ls1028a_cga_pll1 = {67.clkdef = {68.name = "ls1028a_cga_pll1",69.id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 0),70.flags = 071},72.offset = 0x80,73.shift = 1,74.mask = 0xFE,75.dividers = ls1028a_cga_pll_divs,76.flags = QORIQ_CLK_PLL_HAS_KILL_BIT77};7879static struct qoriq_clk_pll_def ls1028a_cga_pll2 = {80.clkdef = {81.name = "ls1028a_cga_pll2",82.id = QORIQ_CLK_ID(QORIQ_TYPE_INTERNAL, 20),83.flags = 084},85.offset = 0xA0,86.shift = 1,87.mask = 0xFE,88.dividers = ls1028a_cga_pll_divs,89.flags = QORIQ_CLK_PLL_HAS_KILL_BIT90};9192static struct qoriq_clk_pll_def *ls1028a_cga_plls[] = {93&ls1028a_cga_pll1,94&ls1028a_cga_pll295};9697static const char *ls1028a_cmux0_parent_names[] = {98"ls1028a_cga_pll1",99"ls1028a_cga_pll1_div2",100"ls1028a_cga_pll1_div4",101NULL,102"ls1028a_cga_pll2",103"ls1028a_cga_pll2_div2",104"ls1028a_cga_pll2_div4"105};106107static struct clk_mux_def ls1028a_cmux0 = {108.clkdef = {109.name = "ls1028a_cmux0",110.id = QORIQ_CLK_ID(QORIQ_TYPE_CMUX, 0),111.parent_names = ls1028a_cmux0_parent_names,112.parent_cnt = nitems(ls1028a_cmux0_parent_names),113.flags = 0114},115.offset = 0x70000,116.shift = 27,117.width = 4,118.mux_flags = 0119};120121static struct clk_mux_def ls1028a_cmux1 = {122.clkdef = {123.name = "ls1028a_cmux1",124.id = QORIQ_CLK_ID(QORIQ_TYPE_CMUX, 1),125.parent_names = ls1028a_cmux0_parent_names,126.parent_cnt = nitems(ls1028a_cmux0_parent_names),127.flags = 0128},129.offset = 0x70020,130.shift = 27,131.width = 4,132.mux_flags = 0133};134135static struct clk_mux_def ls1028a_cmux2 = {136.clkdef = {137.name = "ls1028a_cmux2",138.id = QORIQ_CLK_ID(QORIQ_TYPE_CMUX, 2),139.parent_names = ls1028a_cmux0_parent_names,140.parent_cnt = nitems(ls1028a_cmux0_parent_names),141.flags = 0142},143.offset = 0x70040,144.shift = 27,145.width = 4,146.mux_flags = 0147};148149static struct clk_mux_def ls1028a_cmux3 = {150.clkdef = {151.name = "ls1028a_cmux3",152.id = QORIQ_CLK_ID(QORIQ_TYPE_CMUX, 3),153.parent_names = ls1028a_cmux0_parent_names,154.parent_cnt = nitems(ls1028a_cmux0_parent_names),155.flags = 0156},157.offset = 0x70060,158.shift = 27,159.width = 4,160.mux_flags = 0161};162163static const char *ls1028a_hwaccel1_parent_names[] = {164"ls1028a_platform_pll",165"ls1028a_cga_pll1",166"ls1028a_cga_pll1_div2",167"ls1028a_cga_pll1_div3",168"ls1028a_cga_pll1_div4",169NULL,170"ls1028a_cga_pll2_div2",171"ls1028a_cga_pll2_div3"172};173174static const char *ls1028a_hwaccel2_parent_names[] = {175"ls1028a_platform_pll",176"ls1028a_cga_pll2",177"ls1028a_cga_pll2_div2",178"ls1028a_cga_pll2_div3",179"ls1028a_cga_pll2_div4",180NULL,181"ls1028a_cga_pll1_div2",182"ls1028a_cga_pll1_div3"183};184185static struct clk_mux_def ls1028a_hwaccel1 = {186.clkdef = {187.name = "ls1028a_hwaccel1",188.id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 0),189.parent_names = ls1028a_hwaccel1_parent_names,190.parent_cnt = nitems(ls1028a_hwaccel1_parent_names),191.flags = 0192},193.offset = 0x10,194.shift = 27,195.width = 4,196.mux_flags = 0197};198199static struct clk_mux_def ls1028a_hwaccel2 = {200.clkdef = {201.name = "ls1028a_hwaccel2",202.id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 1),203.parent_names = ls1028a_hwaccel2_parent_names,204.parent_cnt = nitems(ls1028a_hwaccel2_parent_names),205.flags = 0206},207.offset = 0x30,208.shift = 27,209.width = 4,210.mux_flags = 0211};212213static struct clk_mux_def ls1028a_hwaccel3 = {214.clkdef = {215.name = "ls1028a_hwaccel3",216.id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 2),217.parent_names = ls1028a_hwaccel1_parent_names,218.parent_cnt = nitems(ls1028a_hwaccel1_parent_names),219.flags = 0220},221.offset = 0x50,222.shift = 27,223.width = 4,224.mux_flags = 0225};226227static struct clk_mux_def ls1028a_hwaccel4 = {228.clkdef = {229.name = "ls1028a_hwaccel4",230.id = QORIQ_CLK_ID(QORIQ_TYPE_HWACCEL, 3),231.parent_names = ls1028a_hwaccel2_parent_names,232.parent_cnt = nitems(ls1028a_hwaccel2_parent_names),233.flags = 0234},235.offset = 0x70,236.shift = 27,237.width = 4,238.mux_flags = 0239};240241static struct clk_mux_def *ls1028a_mux_nodes[] = {242&ls1028a_cmux0,243&ls1028a_cmux1,244&ls1028a_cmux2,245&ls1028a_cmux3,246&ls1028a_hwaccel1,247&ls1028a_hwaccel2,248&ls1028a_hwaccel3,249&ls1028a_hwaccel4250};251252static int ls1028a_clkgen_probe(device_t);253static int ls1028a_clkgen_attach(device_t);254255static device_method_t ls1028a_clkgen_methods[] = {256DEVMETHOD(device_probe, ls1028a_clkgen_probe),257DEVMETHOD(device_attach, ls1028a_clkgen_attach),258259DEVMETHOD_END260};261262DEFINE_CLASS_1(ls1028a_clkgen, ls1028a_clkgen_driver, ls1028a_clkgen_methods,263sizeof(struct qoriq_clkgen_softc), qoriq_clkgen_driver);264265EARLY_DRIVER_MODULE(ls1028a_clkgen, simplebus, ls1028a_clkgen_driver, 0, 0,266BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);267268static int269ls1028a_clkgen_probe(device_t dev)270{271272if (!ofw_bus_status_okay(dev))273return (ENXIO);274275if(!ofw_bus_is_compatible(dev, "fsl,ls1028a-clockgen"))276return (ENXIO);277278device_set_desc(dev, "LS1028A clockgen");279return (BUS_PROBE_DEFAULT);280}281282static int283ls1028a_clkgen_attach(device_t dev)284{285struct qoriq_clkgen_softc *sc;286287sc = device_get_softc(dev);288289sc->pltfrm_pll_def = &ls1028a_pltfrm_pll;290sc->cga_pll = ls1028a_cga_plls;291sc->cga_pll_num = nitems(ls1028a_cga_plls);292sc->mux = ls1028a_mux_nodes;293sc->mux_num = nitems(ls1028a_mux_nodes);294sc->flags = QORIQ_LITTLE_ENDIAN;295296return (qoriq_clkgen_attach(dev));297}298299300