xref: /freebsd/sys/arm/freescale/vybrid/vf_mscm.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
15c263f43SRuslan Bukin /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3af3dc4a7SPedro F. Giffuni  *
45c263f43SRuslan Bukin  * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com>
55c263f43SRuslan Bukin  * All rights reserved.
65c263f43SRuslan Bukin  *
75c263f43SRuslan Bukin  * Redistribution and use in source and binary forms, with or without
85c263f43SRuslan Bukin  * modification, are permitted provided that the following conditions
95c263f43SRuslan Bukin  * are met:
105c263f43SRuslan Bukin  * 1. Redistributions of source code must retain the above copyright
115c263f43SRuslan Bukin  *    notice, this list of conditions and the following disclaimer.
125c263f43SRuslan Bukin  * 2. Redistributions in binary form must reproduce the above copyright
135c263f43SRuslan Bukin  *    notice, this list of conditions and the following disclaimer in the
145c263f43SRuslan Bukin  *    documentation and/or other materials provided with the distribution.
155c263f43SRuslan Bukin  *
165c263f43SRuslan Bukin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
175c263f43SRuslan Bukin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
185c263f43SRuslan Bukin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
195c263f43SRuslan Bukin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
205c263f43SRuslan Bukin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
215c263f43SRuslan Bukin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
225c263f43SRuslan Bukin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
235c263f43SRuslan Bukin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
245c263f43SRuslan Bukin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
255c263f43SRuslan Bukin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
265c263f43SRuslan Bukin  * SUCH DAMAGE.
275c263f43SRuslan Bukin  */
285c263f43SRuslan Bukin 
295c263f43SRuslan Bukin /*
305c263f43SRuslan Bukin  * Vybrid Family Miscellaneous System Control Module (MSCM)
315c263f43SRuslan Bukin  * Chapter 66, Vybrid Reference Manual, Rev. 5, 07/2013
325c263f43SRuslan Bukin  */
335c263f43SRuslan Bukin 
345c263f43SRuslan Bukin #include <sys/param.h>
355c263f43SRuslan Bukin #include <sys/systm.h>
365c263f43SRuslan Bukin #include <sys/bus.h>
375c263f43SRuslan Bukin #include <sys/kernel.h>
385c263f43SRuslan Bukin #include <sys/module.h>
395c263f43SRuslan Bukin #include <sys/malloc.h>
405c263f43SRuslan Bukin #include <sys/rman.h>
415c263f43SRuslan Bukin #include <sys/timeet.h>
425c263f43SRuslan Bukin #include <sys/timetc.h>
435c263f43SRuslan Bukin #include <sys/watchdog.h>
445c263f43SRuslan Bukin 
455c263f43SRuslan Bukin #include <dev/ofw/openfirm.h>
465c263f43SRuslan Bukin #include <dev/ofw/ofw_bus.h>
475c263f43SRuslan Bukin #include <dev/ofw/ofw_bus_subr.h>
485c263f43SRuslan Bukin 
495c263f43SRuslan Bukin #include <machine/bus.h>
505c263f43SRuslan Bukin #include <machine/cpu.h>
515c263f43SRuslan Bukin #include <machine/intr.h>
525c263f43SRuslan Bukin 
535c263f43SRuslan Bukin #include <arm/freescale/vybrid/vf_common.h>
545c263f43SRuslan Bukin 
555c263f43SRuslan Bukin #define	VF_NINT	112	/* Total number of interrupts */
565c263f43SRuslan Bukin 
575c263f43SRuslan Bukin /* Int Router Shared Peripheral Routing Control */
585c263f43SRuslan Bukin #define	MSCM_IRSPRC(n)	(0x880 + 2 * n)
595c263f43SRuslan Bukin 
605c263f43SRuslan Bukin struct mscm_softc {
615c263f43SRuslan Bukin 	struct resource		*res[1];
625c263f43SRuslan Bukin 	bus_space_tag_t		bst;
635c263f43SRuslan Bukin 	bus_space_handle_t	bsh;
645c263f43SRuslan Bukin };
655c263f43SRuslan Bukin 
665c263f43SRuslan Bukin static struct resource_spec mscm_spec[] = {
675c263f43SRuslan Bukin 	{ SYS_RES_MEMORY,       0,      RF_ACTIVE },
685c263f43SRuslan Bukin 	{ -1, 0 }
695c263f43SRuslan Bukin };
705c263f43SRuslan Bukin 
715c263f43SRuslan Bukin static int
mscm_probe(device_t dev)725c263f43SRuslan Bukin mscm_probe(device_t dev)
735c263f43SRuslan Bukin {
745c263f43SRuslan Bukin 
75add35ed5SIan Lepore 	if (!ofw_bus_status_okay(dev))
76add35ed5SIan Lepore 		return (ENXIO);
77add35ed5SIan Lepore 
785c263f43SRuslan Bukin 	if (!ofw_bus_is_compatible(dev, "fsl,mvf600-mscm"))
795c263f43SRuslan Bukin 		return (ENXIO);
805c263f43SRuslan Bukin 
815c263f43SRuslan Bukin 	device_set_desc(dev, "Vybrid Family Miscellaneous System Control Module");
825c263f43SRuslan Bukin 	return (BUS_PROBE_DEFAULT);
835c263f43SRuslan Bukin }
845c263f43SRuslan Bukin 
855c263f43SRuslan Bukin static int
mscm_attach(device_t dev)865c263f43SRuslan Bukin mscm_attach(device_t dev)
875c263f43SRuslan Bukin {
885c263f43SRuslan Bukin 	struct mscm_softc *sc;
895c263f43SRuslan Bukin 	int i;
905c263f43SRuslan Bukin 
915c263f43SRuslan Bukin 	sc = device_get_softc(dev);
925c263f43SRuslan Bukin 
935c263f43SRuslan Bukin 	if (bus_alloc_resources(dev, mscm_spec, sc->res)) {
945c263f43SRuslan Bukin 		device_printf(dev, "could not allocate resources\n");
955c263f43SRuslan Bukin 		return (ENXIO);
965c263f43SRuslan Bukin 	}
975c263f43SRuslan Bukin 
985c263f43SRuslan Bukin 	/* Memory interface */
995c263f43SRuslan Bukin 	sc->bst = rman_get_bustag(sc->res[0]);
1005c263f43SRuslan Bukin 	sc->bsh = rman_get_bushandle(sc->res[0]);
1015c263f43SRuslan Bukin 
1025c263f43SRuslan Bukin 	/* Route all the interrupts to CP0 */
1035c263f43SRuslan Bukin 	for (i = 0; i < VF_NINT; i++)
1045c263f43SRuslan Bukin 		WRITE2(sc, MSCM_IRSPRC(i), 1);
1055c263f43SRuslan Bukin 
1065c263f43SRuslan Bukin 	return (0);
1075c263f43SRuslan Bukin }
1085c263f43SRuslan Bukin 
1095c263f43SRuslan Bukin static device_method_t mscm_methods[] = {
1105c263f43SRuslan Bukin 	DEVMETHOD(device_probe,		mscm_probe),
1115c263f43SRuslan Bukin 	DEVMETHOD(device_attach,	mscm_attach),
1125c263f43SRuslan Bukin 	{ 0, 0 }
1135c263f43SRuslan Bukin };
1145c263f43SRuslan Bukin 
1155c263f43SRuslan Bukin static driver_t mscm_driver = {
1165c263f43SRuslan Bukin 	"mscm",
1175c263f43SRuslan Bukin 	mscm_methods,
1185c263f43SRuslan Bukin 	sizeof(struct mscm_softc),
1195c263f43SRuslan Bukin };
1205c263f43SRuslan Bukin 
121ea538dabSJohn Baldwin DRIVER_MODULE(mscm, simplebus, mscm_driver, 0, 0);
122