The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/arm/versatile/versatile_scm.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2017 Oleksandr Tymoshenko <gonzo@freebsd.org>
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by Ben Gray.
   16  * 4. The name of the company nor the name of the author may be used to
   17  *    endorse or promote products derived from this software without specific
   18  *    prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``AS IS'' AND ANY EXPRESS OR
   21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   23  * IN NO EVENT SHALL BEN GRAY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
   26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 /*
   33  * SCM - System Control Module
   34  */
   35 #include <sys/cdefs.h>
   36 __FBSDID("$FreeBSD: releng/12.0/sys/arm/versatile/versatile_scm.c 316370 2017-04-01 20:10:08Z gonzo $");
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/kernel.h>
   41 #include <sys/module.h>
   42 #include <sys/bus.h>
   43 #include <sys/resource.h>
   44 #include <sys/rman.h>
   45 #include <sys/lock.h>
   46 #include <sys/mutex.h>
   47 
   48 #include <machine/bus.h>
   49 #include <machine/resource.h>
   50 
   51 #include <dev/ofw/openfirm.h>
   52 #include <dev/ofw/ofw_bus.h>
   53 #include <dev/ofw/ofw_bus_subr.h>
   54 
   55 #include "versatile_scm.h"
   56 
   57 struct versatile_scm_softc {
   58         device_t                sc_dev;
   59         struct resource *       sc_mem_res;
   60 };
   61 
   62 static struct versatile_scm_softc *versatile_scm_sc;
   63 
   64 #define versatile_scm_read_4(sc, reg)           \
   65     bus_read_4((sc)->sc_mem_res, (reg))
   66 #define versatile_scm_write_4(sc, reg, val)             \
   67     bus_write_4((sc)->sc_mem_res, (reg), (val))
   68 
   69 static int
   70 versatile_scm_probe(device_t dev)
   71 {
   72         if (!ofw_bus_status_okay(dev))
   73                 return (ENXIO);
   74 
   75         if (!ofw_bus_is_compatible(dev, "syscon"))
   76                 return (ENXIO);
   77 
   78         if (versatile_scm_sc) {
   79                 return (EEXIST);
   80         }
   81 
   82         device_set_desc(dev, "Versatile Control Module");
   83         return (BUS_PROBE_DEFAULT);
   84 }
   85 
   86 static int
   87 versatile_scm_attach(device_t dev)
   88 {
   89         struct versatile_scm_softc *sc;
   90         int rid;
   91 
   92         sc = device_get_softc(dev);
   93         sc->sc_dev = dev;
   94 
   95         rid = 0;
   96         sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
   97 
   98         if (sc->sc_mem_res == NULL) {
   99                 device_printf(dev, "could not allocate memory resources\n");
  100                 return (ENXIO);
  101         }
  102 
  103         versatile_scm_sc = sc;
  104 
  105         return (0);
  106 }
  107 
  108 int
  109 versatile_scm_reg_read_4(uint32_t reg, uint32_t *val)
  110 {
  111         if (!versatile_scm_sc)
  112                 return (ENXIO);
  113 
  114         *val = versatile_scm_read_4(versatile_scm_sc, reg);
  115         return (0);
  116 }
  117 
  118 int
  119 versatile_scm_reg_write_4(uint32_t reg, uint32_t val)
  120 {
  121         if (!versatile_scm_sc)
  122                 return (ENXIO);
  123 
  124         versatile_scm_write_4(versatile_scm_sc, reg, val);
  125         return (0);
  126 }
  127 
  128 static device_method_t versatile_scm_methods[] = {
  129         DEVMETHOD(device_probe,         versatile_scm_probe),
  130         DEVMETHOD(device_attach,        versatile_scm_attach),
  131 
  132         DEVMETHOD_END
  133 };
  134 
  135 static driver_t versatile_scm_driver = {
  136         "scm",
  137         versatile_scm_methods,
  138         sizeof(struct versatile_scm_softc),
  139 };
  140 
  141 static devclass_t versatile_scm_devclass;
  142 
  143 EARLY_DRIVER_MODULE(versatile_scm, simplebus, versatile_scm_driver, versatile_scm_devclass, 0, 0,
  144     BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);

Cache object: 7464750ddf07f62ac8ce3c17463e9fdb


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.