Path: blob/main/sys/arm/mv/clk/a37x0_nb_periph_clk_driver.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 Semihalf.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include <sys/param.h>28#include <sys/bus.h>29#include <sys/kernel.h>30#include <sys/module.h>31#include <sys/mutex.h>32#include <sys/rman.h>33#include <machine/bus.h>3435#include <dev/fdt/simplebus.h>3637#include <dev/clk/clk.h>38#include <dev/clk/clk_fixed.h>3940#include <dev/ofw/ofw_bus.h>41#include <dev/ofw/ofw_bus_subr.h>4243#include "clkdev_if.h"44#include "periph.h"4546#define NB_DEV_COUNT 174748static struct clk_div_table a37x0_periph_clk_table_6 [] = {49{ .value = 1, .divider = 1 },50{ .value = 2, .divider = 2 },51{ .value = 3, .divider = 3 },52{ .value = 4, .divider = 4 },53{ .value = 5, .divider = 5 },54{ .value = 6, .divider = 6 },55{ .value = 0, .divider = 0 }56};5758static struct clk_div_table a37x0_periph_clk_table_2 [] = {59{ .value = 0, .divider = 1 },60{ .value = 1, .divider = 2 },61{ .value = 2, .divider = 4 },62{ .value = 3, .divider = 1 }63};6465static struct a37x0_periph_clknode_def a37x0_nb_devices [] = {66CLK_FULL_DD("mmc", 0, 2, 0, 0, DIV_SEL2, DIV_SEL2, 16, 13,67"tbg_mux_mmc_50", "div1_mmc_51", "div2_mmc_52", "clk_mux_mmc_53"),68CLK_FULL_DD("sata_host", 1, 3, 2, 1, DIV_SEL2, DIV_SEL2, 10, 7,69"tbg_sata_host_mmc_55", "div1_sata_host_56", "div2_sata_host_57",70"clk_sata_host_mmc_58"),71CLK_FULL_DD("sec_at", 2, 6, 4, 2, DIV_SEL1, DIV_SEL1, 3, 0,72"tbg_mux_sec_at_60", "div1_sec_at_61", "div2_sec_at_62",73"clk_mux_sec_at_63"),74CLK_FULL_DD("sec_dap", 3, 7, 6, 3, DIV_SEL1, DIV_SEL1, 9, 6,75"tbg_mux_sec_dap_65", "div1_sec_dap_67", "div2_sec_dap_68",76"clk_mux_sec_dap_69"),77CLK_FULL_DD("tsecm", 4, 8, 8, 4, DIV_SEL1, DIV_SEL1, 15, 12,78"tbg_mux_tsecm_71", "div1_tsecm_72", "div2_tsecm_73",79"clk_mux_tsecm_74"),80CLK_FULL("setm_tmx", 5, 10, 10, 5, DIV_SEL1, 18,81a37x0_periph_clk_table_6, "tbg_mux_setm_tmx_76",82"div1_setm_tmx_77", "clk_mux_setm_tmx_78"),83CLK_FIXED("avs", 6, 11, 6, "mux_avs_80", "fixed1_avs_82"),84CLK_FULL_DD("pwm", 7, 13, 14, 8, DIV_SEL0, DIV_SEL0, 3, 0,85"tbg_mux_pwm_83", "div1_pwm_84", "div2_pwm_85", "clk_mux_pwm_86"),86CLK_FULL_DD("sqf", 8, 12, 12, 7, DIV_SEL1, DIV_SEL1, 27, 14,87"tbg_mux_sqf_88", "div1_sqf_89", "div2_sqf_90", "clk_mux_sqf_91"),88CLK_GATE("i2c_2", 9, 16, NULL),89CLK_GATE("i2c_1", 10, 17, NULL),90CLK_MUX_GATE_FIXED("ddr_phy", 11, 19, 10, "mux_ddr_phy_95",91"gate_ddr_phy_96", "fixed1_ddr_phy_97"),92CLK_FULL_DD("ddr_fclk", 12, 21, 16, 11, DIV_SEL0, DIV_SEL0, 15, 12,93"tbg_mux_ddr_fclk_99", "div1_ddr_fclk_100", "div2_ddr_fclk_101",94"clk_mux_ddr_fclk_102"),95CLK_FULL("trace", 13, 22, 18, 12, DIV_SEL0, 20,96a37x0_periph_clk_table_6, "tbg_mux_trace_104", "div1_trace_105",97"clk_mux_trace_106"),98CLK_FULL("counter", 14, 23, 20, 13, DIV_SEL0, 23,99a37x0_periph_clk_table_6, "tbg_mux_counter_108",100"div1_counter_109", "clk_mux_counter_110"),101CLK_FULL_DD("eip97", 15, 26, 24, 9, DIV_SEL2, DIV_SEL2, 22, 19,102"tbg_mux_eip97_112", "div1_eip97_113", "div2_eip97_114",103"clk_mux_eip97_115"),104CLK_CPU("cpu", 16, 22, 15, DIV_SEL0, 28, a37x0_periph_clk_table_2,105"tbg_mux_cpu_117", "div1_cpu_118"),106};107108static struct ofw_compat_data a37x0_periph_compat_data [] = {109{ "marvell,armada-3700-periph-clock-nb", 1 },110{ NULL, 0 }111};112113static int a37x0_nb_periph_clk_attach(device_t);114static int a37x0_nb_periph_clk_probe(device_t);115116static device_method_t a37x0_nb_periph_clk_methods[] = {117DEVMETHOD(clkdev_device_unlock, a37x0_periph_clk_device_unlock),118DEVMETHOD(clkdev_device_lock, a37x0_periph_clk_device_lock),119DEVMETHOD(clkdev_read_4, a37x0_periph_clk_read_4),120121DEVMETHOD(device_attach, a37x0_nb_periph_clk_attach),122DEVMETHOD(device_detach, a37x0_periph_clk_detach),123DEVMETHOD(device_probe, a37x0_nb_periph_clk_probe),124125DEVMETHOD_END126};127128static driver_t a37x0_nb_periph_driver = {129"a37x0_nb_periph_driver",130a37x0_nb_periph_clk_methods,131sizeof(struct a37x0_periph_clk_softc)132};133134EARLY_DRIVER_MODULE(a37x0_nb_periph, simplebus, a37x0_nb_periph_driver, 0, 0,135BUS_PASS_TIMER + BUS_PASS_ORDER_LATE);136137static int138a37x0_nb_periph_clk_attach(device_t dev)139{140struct a37x0_periph_clk_softc *sc;141142sc = device_get_softc(dev);143sc->devices = a37x0_nb_devices;144sc->device_count = NB_DEV_COUNT;145146return (a37x0_periph_clk_attach(dev));147}148149static int150a37x0_nb_periph_clk_probe(device_t dev)151{152153if (!ofw_bus_status_okay(dev))154return (ENXIO);155156if (!ofw_bus_search_compatible(dev,157a37x0_periph_compat_data)->ocd_data)158return (ENXIO);159160device_set_desc(dev, "marvell,armada-3700-nb-periph-clock");161162return (BUS_PROBE_DEFAULT);163}164165166