Path: blob/main/sys/dev/clk/xilinx/zynqmp_reset.c
105335 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2023 Beckhoff Automation GmbH & Co. KG4*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/cdefs.h>2829#include <sys/param.h>30#include <sys/systm.h>31#include <sys/kernel.h>32#include <sys/module.h>33#include <sys/malloc.h>34#include <sys/bus.h>35#include <sys/cpu.h>36#include <machine/bus.h>3738#include <dev/ofw/openfirm.h>39#include <dev/ofw/ofw_bus.h>40#include <dev/ofw/ofw_bus_subr.h>4142#include <dev/hwreset/hwreset.h>4344#include <dev/firmware/xilinx/pm_defs.h>4546#include "hwreset_if.h"47#include "zynqmp_firmware_if.h"4849#define ZYNQMP_RESET_PCIE_CFG 050#define ZYNQMP_RESET_PCIE_BRIDGE 151#define ZYNQMP_RESET_PCIE_CTRL 252#define ZYNQMP_RESET_DP 353#define ZYNQMP_RESET_SWDT_CRF 454#define ZYNQMP_RESET_AFI_FM5 555#define ZYNQMP_RESET_AFI_FM4 656#define ZYNQMP_RESET_AFI_FM3 757#define ZYNQMP_RESET_AFI_FM2 858#define ZYNQMP_RESET_AFI_FM1 959#define ZYNQMP_RESET_AFI_FM0 1060#define ZYNQMP_RESET_GDMA 1161#define ZYNQMP_RESET_GPU_PP1 1262#define ZYNQMP_RESET_GPU_PP0 1363#define ZYNQMP_RESET_GPU 1464#define ZYNQMP_RESET_GT 1565#define ZYNQMP_RESET_SATA 1666#define ZYNQMP_RESET_ACPU3_PWRON 1767#define ZYNQMP_RESET_ACPU2_PWRON 1868#define ZYNQMP_RESET_ACPU1_PWRON 1969#define ZYNQMP_RESET_ACPU0_PWRON 2070#define ZYNQMP_RESET_APU_L2 2171#define ZYNQMP_RESET_ACPU3 2272#define ZYNQMP_RESET_ACPU2 2373#define ZYNQMP_RESET_ACPU1 2474#define ZYNQMP_RESET_ACPU0 2575#define ZYNQMP_RESET_DDR 2676#define ZYNQMP_RESET_APM_FPD 2777#define ZYNQMP_RESET_SOFT 2878#define ZYNQMP_RESET_GEM0 2979#define ZYNQMP_RESET_GEM1 3080#define ZYNQMP_RESET_GEM2 3181#define ZYNQMP_RESET_GEM3 3282#define ZYNQMP_RESET_QSPI 3383#define ZYNQMP_RESET_UART0 3484#define ZYNQMP_RESET_UART1 3585#define ZYNQMP_RESET_SPI0 3686#define ZYNQMP_RESET_SPI1 3787#define ZYNQMP_RESET_SDIO0 3888#define ZYNQMP_RESET_SDIO1 3989#define ZYNQMP_RESET_CAN0 4090#define ZYNQMP_RESET_CAN1 4191#define ZYNQMP_RESET_I2C0 4292#define ZYNQMP_RESET_I2C1 4393#define ZYNQMP_RESET_TTC0 4494#define ZYNQMP_RESET_TTC1 4595#define ZYNQMP_RESET_TTC2 4696#define ZYNQMP_RESET_TTC3 4797#define ZYNQMP_RESET_SWDT_CRL 4898#define ZYNQMP_RESET_NAND 4999#define ZYNQMP_RESET_ADMA 50100#define ZYNQMP_RESET_GPIO 51101#define ZYNQMP_RESET_IOU_CC 52102#define ZYNQMP_RESET_TIMESTAMP 53103#define ZYNQMP_RESET_RPU_R50 54104#define ZYNQMP_RESET_RPU_R51 55105#define ZYNQMP_RESET_RPU_AMBA 56106#define ZYNQMP_RESET_OCM 57107#define ZYNQMP_RESET_RPU_PGE 58108#define ZYNQMP_RESET_USB0_CORERESET 59109#define ZYNQMP_RESET_USB1_CORERESET 60110#define ZYNQMP_RESET_USB0_HIBERRESET 61111#define ZYNQMP_RESET_USB1_HIBERRESET 62112#define ZYNQMP_RESET_USB0_APB 63113#define ZYNQMP_RESET_USB1_APB 64114#define ZYNQMP_RESET_IPI 65115#define ZYNQMP_RESET_APM_LPD 66116#define ZYNQMP_RESET_RTC 67117#define ZYNQMP_RESET_SYSMON 68118#define ZYNQMP_RESET_AFI_FM6 69119#define ZYNQMP_RESET_LPD_SWDT 70120#define ZYNQMP_RESET_FPD 71121#define ZYNQMP_RESET_RPU_DBG1 72122#define ZYNQMP_RESET_RPU_DBG0 73123#define ZYNQMP_RESET_DBG_LPD 74124#define ZYNQMP_RESET_DBG_FPD 75125#define ZYNQMP_RESET_APLL 76126#define ZYNQMP_RESET_DPLL 77127#define ZYNQMP_RESET_VPLL 78128#define ZYNQMP_RESET_IOPLL 79129#define ZYNQMP_RESET_RPLL 80130#define ZYNQMP_RESET_GPO3_PL_0 81131#define ZYNQMP_RESET_GPO3_PL_1 82132#define ZYNQMP_RESET_GPO3_PL_2 83133#define ZYNQMP_RESET_GPO3_PL_3 84134#define ZYNQMP_RESET_GPO3_PL_4 85135#define ZYNQMP_RESET_GPO3_PL_5 86136#define ZYNQMP_RESET_GPO3_PL_6 87137#define ZYNQMP_RESET_GPO3_PL_7 88138#define ZYNQMP_RESET_GPO3_PL_8 89139#define ZYNQMP_RESET_GPO3_PL_9 90140#define ZYNQMP_RESET_GPO3_PL_10 91141#define ZYNQMP_RESET_GPO3_PL_11 92142#define ZYNQMP_RESET_GPO3_PL_12 93143#define ZYNQMP_RESET_GPO3_PL_13 94144#define ZYNQMP_RESET_GPO3_PL_14 95145#define ZYNQMP_RESET_GPO3_PL_15 96146#define ZYNQMP_RESET_GPO3_PL_16 97147#define ZYNQMP_RESET_GPO3_PL_17 98148#define ZYNQMP_RESET_GPO3_PL_18 99149#define ZYNQMP_RESET_GPO3_PL_19 100150#define ZYNQMP_RESET_GPO3_PL_20 101151#define ZYNQMP_RESET_GPO3_PL_21 102152#define ZYNQMP_RESET_GPO3_PL_22 103153#define ZYNQMP_RESET_GPO3_PL_23 104154#define ZYNQMP_RESET_GPO3_PL_24 105155#define ZYNQMP_RESET_GPO3_PL_25 106156#define ZYNQMP_RESET_GPO3_PL_26 107157#define ZYNQMP_RESET_GPO3_PL_27 108158#define ZYNQMP_RESET_GPO3_PL_28 109159#define ZYNQMP_RESET_GPO3_PL_29 110160#define ZYNQMP_RESET_GPO3_PL_30 111161#define ZYNQMP_RESET_GPO3_PL_31 112162#define ZYNQMP_RESET_RPU_LS 113163#define ZYNQMP_RESET_PS_ONLY 114164#define ZYNQMP_RESET_PL 115165#define ZYNQMP_RESET_PS_PL0 116166#define ZYNQMP_RESET_PS_PL1 117167#define ZYNQMP_RESET_PS_PL2 118168#define ZYNQMP_RESET_PS_PL3 119169#define ZYNQMP_RESET_MAX ZYNQMP_RESET_PS_PL3170171struct zynqmp_reset_softc {172device_t dev;173device_t parent;174};175176static int177zynqmp_reset_assert(device_t dev, intptr_t id, bool reset)178{179struct zynqmp_reset_softc *sc;180int rv;181182if (id > ZYNQMP_RESET_MAX)183return (EINVAL);184sc = device_get_softc(dev);185rv = ZYNQMP_FIRMWARE_RESET_ASSERT(sc->parent, id, reset);186return (rv);187}188189static int190zynqmp_reset_is_asserted(device_t dev, intptr_t id, bool *reset)191{192struct zynqmp_reset_softc *sc;193int rv;194195if (id > ZYNQMP_RESET_MAX)196return (EINVAL);197sc = device_get_softc(dev);198rv = ZYNQMP_FIRMWARE_RESET_GET_STATUS(sc->parent, id, reset);199200return (rv);201}202203static int204zynqmp_reset_probe(device_t dev)205{206207if (!ofw_bus_status_okay(dev))208return (ENXIO);209if (!ofw_bus_is_compatible(dev, "xlnx,zynqmp-reset"))210return (ENXIO);211device_set_desc(dev, "ZynqMP Reset Controller");212213return (BUS_PROBE_DEFAULT);214}215216static int217zynqmp_reset_attach(device_t dev)218{219struct zynqmp_reset_softc *sc;220221sc = device_get_softc(dev);222sc->dev = dev;223sc->parent = device_get_parent(dev);224225/* register our self as a reset provider */226hwreset_register_ofw_provider(dev);227228return (0);229}230231static device_method_t zynqmp_reset_methods[] = {232/* device_if */233DEVMETHOD(device_probe, zynqmp_reset_probe),234DEVMETHOD(device_attach, zynqmp_reset_attach),235236/* Reset interface */237DEVMETHOD(hwreset_assert, zynqmp_reset_assert),238DEVMETHOD(hwreset_is_asserted, zynqmp_reset_is_asserted),239240DEVMETHOD_END241};242243static driver_t zynqmp_reset_driver = {244"zynqmp_reset",245zynqmp_reset_methods,246sizeof(struct zynqmp_reset_softc),247};248249EARLY_DRIVER_MODULE(zynqmp_reset, simplebus, zynqmp_reset_driver, 0, 0,250BUS_PASS_BUS + BUS_PASS_ORDER_LAST);251252253