Path: blob/main/sys/arm/freescale/vybrid/vf_dmamux.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2014 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 Direct Memory Access Multiplexer (DMAMUX)30* Chapter 22, 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_common.h>53#include <arm/freescale/vybrid/vf_dmamux.h>5455#define DMAMUX_CHCFG(n) (0x1 * n) /* Channels 0-15 Cfg Reg */56#define CHCFG_ENBL (1 << 7) /* Channel Enable */57#define CHCFG_TRIG (1 << 6) /* Channel Trigger Enable */58#define CHCFG_SOURCE_MASK 0x3f /* Channel Source (Slot) */59#define CHCFG_SOURCE_SHIFT 06061struct dmamux_softc {62struct resource *res[4];63bus_space_tag_t bst[4];64bus_space_handle_t bsh[4];65};6667struct dmamux_softc *dmamux_sc;6869static struct resource_spec dmamux_spec[] = {70{ SYS_RES_MEMORY, 0, RF_ACTIVE }, /* DMAMUX0 */71{ SYS_RES_MEMORY, 1, RF_ACTIVE }, /* DMAMUX1 */72{ SYS_RES_MEMORY, 2, RF_ACTIVE }, /* DMAMUX2 */73{ SYS_RES_MEMORY, 3, RF_ACTIVE }, /* DMAMUX3 */74{ -1, 0 }75};7677static int78dmamux_probe(device_t dev)79{8081if (!ofw_bus_status_okay(dev))82return (ENXIO);8384if (!ofw_bus_is_compatible(dev, "fsl,mvf600-dmamux"))85return (ENXIO);8687device_set_desc(dev, "Vybrid Family Direct Memory Access Multiplexer");88return (BUS_PROBE_DEFAULT);89}9091int92dmamux_configure(int mux, int source, int channel, int enable)93{94struct dmamux_softc *sc;95int reg;9697sc = dmamux_sc;9899MUX_WRITE1(sc, mux, DMAMUX_CHCFG(channel), 0x0);100101reg = 0;102if (enable)103reg |= (CHCFG_ENBL);104105reg &= ~(CHCFG_SOURCE_MASK << CHCFG_SOURCE_SHIFT);106reg |= (source << CHCFG_SOURCE_SHIFT);107108MUX_WRITE1(sc, mux, DMAMUX_CHCFG(channel), reg);109110return (0);111}112113static int114dmamux_attach(device_t dev)115{116struct dmamux_softc *sc;117int i;118119sc = device_get_softc(dev);120121if (bus_alloc_resources(dev, dmamux_spec, sc->res)) {122device_printf(dev, "could not allocate resources\n");123return (ENXIO);124}125126/* Memory interface */127for (i = 0; i < 4; i++) {128sc->bst[i] = rman_get_bustag(sc->res[i]);129sc->bsh[i] = rman_get_bushandle(sc->res[i]);130}131132dmamux_sc = sc;133134return (0);135}136137static device_method_t dmamux_methods[] = {138DEVMETHOD(device_probe, dmamux_probe),139DEVMETHOD(device_attach, dmamux_attach),140{ 0, 0 }141};142143static driver_t dmamux_driver = {144"dmamux",145dmamux_methods,146sizeof(struct dmamux_softc),147};148149DRIVER_MODULE(dmamux, simplebus, dmamux_driver, 0, 0);150151152