Path: blob/main/sys/arm/freescale/vybrid/vf_tcon.c
39537 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 Timing Controller (TCON)30* Chapter 58, 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>5354#define TCON0_CTRL1 0x0055#define TCON_BYPASS (1 << 29)5657struct tcon_softc {58struct resource *res[1];59bus_space_tag_t bst;60bus_space_handle_t bsh;61};6263struct tcon_softc *tcon_sc;6465static struct resource_spec tcon_spec[] = {66{ SYS_RES_MEMORY, 0, RF_ACTIVE },67{ -1, 0 }68};6970uint32_t71tcon_bypass(void)72{7374if (tcon_sc == NULL)75return (1);7677WRITE4(tcon_sc, TCON0_CTRL1, TCON_BYPASS);7879return (0);80}8182static int83tcon_probe(device_t dev)84{8586if (!ofw_bus_status_okay(dev))87return (ENXIO);8889if (!ofw_bus_is_compatible(dev, "fsl,mvf600-tcon"))90return (ENXIO);9192device_set_desc(dev, "Vybrid Family Timing Controller (TCON)");93return (BUS_PROBE_DEFAULT);94}9596static int97tcon_attach(device_t dev)98{99struct tcon_softc *sc;100101sc = device_get_softc(dev);102103if (bus_alloc_resources(dev, tcon_spec, sc->res)) {104device_printf(dev, "could not allocate resources\n");105return (ENXIO);106}107108/* Memory interface */109sc->bst = rman_get_bustag(sc->res[0]);110sc->bsh = rman_get_bushandle(sc->res[0]);111112tcon_sc = sc;113114return (0);115}116117static device_method_t tcon_methods[] = {118DEVMETHOD(device_probe, tcon_probe),119DEVMETHOD(device_attach, tcon_attach),120{ 0, 0 }121};122123static driver_t tcon_driver = {124"tcon",125tcon_methods,126sizeof(struct tcon_softc),127};128129DRIVER_MODULE(tcon, simplebus, tcon_driver, 0, 0);130131132