Path: blob/main/sys/arm/mv/clk/a37x0_sb_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 SB_DEV_COUNT 144748static struct a37x0_periph_clknode_def a37x0_sb_devices [] = {49CLK_MDD("gbe_50", 0, 6, 1, DIV_SEL2, DIV_SEL2, 6, 9,50"tbg_mux_gbe_50_120", "div1_gbe_50_121", "div2_gbe_50_122"),51CLK_MDD("gbe_core", 1, 8, 5, DIV_SEL1, DIV_SEL1, 18, 21,52"tbg_mux_gbe_core_124", "div1_gbe_core_125", "div2_gbe_core_126"),53CLK_MDD("gbe_125", 2, 10, 3, DIV_SEL1, DIV_SEL1, 6, 9,54"tbg_mux_gbe_125_128", "div1_gbe_50_129", "div2_gbe_50_130"),55CLK_GATE("gbe1_50", 3, 0, "gbe_50"),56CLK_GATE("gbe0_50", 4, 1, "gbe_50"),57CLK_GATE("gbe1_125", 5, 2, "gbe_125"),58CLK_GATE("gbe0_125", 6, 3, "gbe_125"),59CLK_MUX_GATE("gbe1_core", 7, 4, 13, "gbe_core",60"mux_gbe1_core_136", "fixed_gbe1_core_138"),61CLK_MUX_GATE("gbe0_core", 8, 5, 14, "gbe_core",62"mux_gbe0_core_139", "fixed_gbe0_core_141"),63CLK_MUX_GATE("gbe_bm", 9, 12, 12, "gbe_core",64"mux_gbe_bm_136", "fixed_gbe_bm_138"),65CLK_FULL_DD("sdio", 10, 11, 14, 7, DIV_SEL0, DIV_SEL0, 3, 6,66"tbg_mux_sdio_139", "div1_sdio_140", "div2_sdio_141",67"clk_mux_sdio_142"),68CLK_FULL_DD("usb32_usb2_sys", 11, 16, 16, 8, DIV_SEL0, DIV_SEL0, 9, 12,69"tbg_mux_usb32_usb2_sys_144", "div1_usb32_usb2_sys_145",70"div2_usb32_usb2_sys_146", "clk_mux_usb32_usb2_sys_147"),71CLK_FULL_DD("usb32_ss_sys", 12, 17, 18, 9, DIV_SEL0, DIV_SEL0, 15, 18,72"tbg_mux_usb32_ss_sys_149", "div1_usb32_ss_sys_150",73"div2_usb32_ss_sys_151", "clk_mux_usb32_ss_sys_152"),74CLK_GATE("pcie", 13, 14, "gbe_core")75};7677static struct ofw_compat_data a37x0_sb_periph_compat_data[] = {78{ "marvell,armada-3700-periph-clock-sb", 1 },79{ NULL, 0 }80};8182static int a37x0_sb_periph_clk_attach(device_t);83static int a37x0_sb_periph_clk_probe(device_t);8485static device_method_t a37x0_sb_periph_clk_methods[] = {86DEVMETHOD(clkdev_device_unlock, a37x0_periph_clk_device_unlock),87DEVMETHOD(clkdev_device_lock, a37x0_periph_clk_device_lock),88DEVMETHOD(clkdev_read_4, a37x0_periph_clk_read_4),8990DEVMETHOD(device_attach, a37x0_sb_periph_clk_attach),91DEVMETHOD(device_detach, a37x0_periph_clk_detach),92DEVMETHOD(device_probe, a37x0_sb_periph_clk_probe),9394DEVMETHOD_END95};9697static driver_t a37x0_sb_periph_driver = {98"a37x0_sb_periph_driver",99a37x0_sb_periph_clk_methods,100sizeof(struct a37x0_periph_clk_softc)101};102103EARLY_DRIVER_MODULE(a37x0_sb_periph, simplebus, a37x0_sb_periph_driver, 0, 0,104BUS_PASS_TIMER + BUS_PASS_ORDER_LATE);105106static int107a37x0_sb_periph_clk_attach(device_t dev)108{109struct a37x0_periph_clk_softc *sc;110111sc = device_get_softc(dev);112sc->devices = a37x0_sb_devices;113sc->device_count = SB_DEV_COUNT;114115return (a37x0_periph_clk_attach(dev));116}117118static int119a37x0_sb_periph_clk_probe(device_t dev)120{121122if (!ofw_bus_status_okay(dev))123return (ENXIO);124125if (!ofw_bus_search_compatible(dev,126a37x0_sb_periph_compat_data)->ocd_data)127return (ENXIO);128129device_set_desc(dev, "marvell,armada-3700-sb-periph-clock");130131return (BUS_PROBE_DEFAULT);132}133134135