/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2013 Ruslan Bukin <[email protected]>4* All rights reserved.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/*29* Vybrid Family System Reset Controller (SRC)30* Chapter 18, Vybrid Reference Manual, Rev. 5, 07/201331*/3233#include <sys/param.h>34#include <sys/systm.h>35#include <sys/bus.h>36#include <sys/kernel.h>37#include <sys/module.h>38#include <sys/malloc.h>39#include <sys/rman.h>40#include <sys/timeet.h>41#include <sys/timetc.h>42#include <sys/watchdog.h>4344#include <dev/ofw/openfirm.h>45#include <dev/ofw/ofw_bus.h>46#include <dev/ofw/ofw_bus_subr.h>4748#include <machine/bus.h>49#include <machine/cpu.h>50#include <machine/intr.h>5152#include <arm/freescale/vybrid/vf_src.h>53#include <arm/freescale/vybrid/vf_common.h>5455#define SRC_SCR 0x00 /* SRC Control Register */56#define SRC_SBMR1 0x04 /* SRC Boot Mode Register 1 */57#define SRC_SRSR 0x08 /* SRC Status Register */58#define SRC_SECR 0x0C /* SRC_SECR */59#define SRC_SICR 0x14 /* SRC Reset Interrupt Configuration Register */60#define SRC_SIMR 0x18 /* SRC Interrupt Masking Register */61#define SRC_SBMR2 0x1C /* SRC Boot Mode Register 2 */62#define SRC_GPR0 0x20 /* General Purpose Register */63#define SRC_GPR1 0x24 /* General Purpose Register */64#define SRC_GPR2 0x28 /* General Purpose Register */65#define SRC_GPR3 0x2C /* General Purpose Register */66#define SRC_GPR4 0x30 /* General Purpose Register */67#define SRC_MISC0 0x4C /* MISC0 */68#define SRC_MISC1 0x50 /* MISC1 */69#define SRC_MISC2 0x54 /* MISC2 */70#define SRC_MISC3 0x58 /* MISC3 */7172struct src_softc {73struct resource *res[1];74bus_space_tag_t bst;75bus_space_handle_t bsh;76};7778struct src_softc *src_sc;7980static struct resource_spec src_spec[] = {81{ SYS_RES_MEMORY, 0, RF_ACTIVE },82{ -1, 0 }83};8485int86src_swreset(void)87{8889if (src_sc == NULL)90return (1);9192WRITE4(src_sc, SRC_SCR, SW_RST);9394return (0);95}9697static int98src_probe(device_t dev)99{100101if (!ofw_bus_status_okay(dev))102return (ENXIO);103104if (!ofw_bus_is_compatible(dev, "fsl,mvf600-src"))105return (ENXIO);106107device_set_desc(dev, "Vybrid Family System Reset Controller");108return (BUS_PROBE_DEFAULT);109}110111static int112src_attach(device_t dev)113{114struct src_softc *sc;115116sc = device_get_softc(dev);117118if (bus_alloc_resources(dev, src_spec, sc->res)) {119device_printf(dev, "could not allocate resources\n");120return (ENXIO);121}122123/* Memory interface */124sc->bst = rman_get_bustag(sc->res[0]);125sc->bsh = rman_get_bushandle(sc->res[0]);126127src_sc = sc;128129return (0);130}131132static device_method_t src_methods[] = {133DEVMETHOD(device_probe, src_probe),134DEVMETHOD(device_attach, src_attach),135{ 0, 0 }136};137138static driver_t src_driver = {139"src",140src_methods,141sizeof(struct src_softc),142};143144DRIVER_MODULE(src, simplebus, src_driver, 0, 0);145146147