/*-1* Copyright (c) 2018 Ruslan Bukin <[email protected]>2* All rights reserved.3*4* This software was developed by BAE Systems, the University of Cambridge5* Computer Laboratory, and Memorial University under DARPA/AFRL contract6* FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing7* (TC) research program.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#include <sys/param.h>32#include <sys/systm.h>33#include <sys/bus.h>34#include <sys/kthread.h>35#include <sys/rman.h>36#include <sys/kernel.h>37#include <sys/module.h>38#include <machine/bus.h>3940#include <dev/ofw/ofw_bus.h>41#include <dev/ofw/ofw_bus_subr.h>4243#define GCC_QDSS_BCR 0x2900044#define GCC_QDSS_BCR_BLK_ARES (1 << 0) /* Async software reset. */45#define GCC_QDSS_CFG_AHB_CBCR 0x2900846#define AHB_CBCR_CLK_ENABLE (1 << 0) /* AHB clk branch ctrl */47#define GCC_QDSS_ETR_USB_CBCR 0x2902848#define ETR_USB_CBCR_CLK_ENABLE (1 << 0) /* ETR USB clk branch ctrl */49#define GCC_QDSS_DAP_CBCR 0x2908450#define DAP_CBCR_CLK_ENABLE (1 << 0) /* DAP clk branch ctrl */5152static struct ofw_compat_data compat_data[] = {53{ "qcom,gcc-msm8916", 1 },54{ NULL, 0 }55};5657struct qcom_gcc_softc {58struct resource *res;59};6061static struct resource_spec qcom_gcc_spec[] = {62{ SYS_RES_MEMORY, 0, RF_ACTIVE },63{ -1, 0 }64};6566/*67* Qualcomm Debug Subsystem (QDSS)68* block enabling routine.69*/70static void71qcom_qdss_enable(struct qcom_gcc_softc *sc)72{7374/* Put QDSS block to reset */75bus_write_4(sc->res, GCC_QDSS_BCR, GCC_QDSS_BCR_BLK_ARES);7677/* Enable AHB clock branch */78bus_write_4(sc->res, GCC_QDSS_CFG_AHB_CBCR, AHB_CBCR_CLK_ENABLE);7980/* Enable DAP clock branch */81bus_write_4(sc->res, GCC_QDSS_DAP_CBCR, DAP_CBCR_CLK_ENABLE);8283/* Enable ETR USB clock branch */84bus_write_4(sc->res, GCC_QDSS_ETR_USB_CBCR, ETR_USB_CBCR_CLK_ENABLE);8586/* Out of reset */87bus_write_4(sc->res, GCC_QDSS_BCR, 0);88}8990static int91qcom_gcc_probe(device_t dev)92{93if (!ofw_bus_status_okay(dev))94return (ENXIO);9596if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)97return (ENXIO);9899device_set_desc(dev, "Qualcomm Global Clock Controller");100101return (BUS_PROBE_DEFAULT);102}103104static int105qcom_gcc_attach(device_t dev)106{107struct qcom_gcc_softc *sc;108109sc = device_get_softc(dev);110111if (bus_alloc_resources(dev, qcom_gcc_spec, &sc->res) != 0) {112device_printf(dev, "cannot allocate resources for device\n");113return (ENXIO);114}115116/*117* Enable debug unit.118* This is required for Coresight operation.119* This also enables USB clock branch.120*/121qcom_qdss_enable(sc);122123return (0);124}125126static device_method_t qcom_gcc_methods[] = {127/* Device interface */128DEVMETHOD(device_probe, qcom_gcc_probe),129DEVMETHOD(device_attach, qcom_gcc_attach),130131DEVMETHOD_END132};133134static driver_t qcom_gcc_driver = {135"qcom_gcc",136qcom_gcc_methods,137sizeof(struct qcom_gcc_softc),138};139140EARLY_DRIVER_MODULE(qcom_gcc, simplebus, qcom_gcc_driver, 0, 0,141BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);142MODULE_VERSION(qcom_gcc, 1);143144145