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/ti/ti_scm.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 2010
    3  *      Ben Gray <ben.r.gray@gmail.com>.
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 3. All advertising materials mentioning features or use of this software
   15  *    must display the following acknowledgement:
   16  *      This product includes software developed by Ben Gray.
   17  * 4. The name of the company nor the name of the author may be used to
   18  *    endorse or promote products derived from this software without specific
   19  *    prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``AS IS'' AND ANY EXPRESS OR
   22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   24  * IN NO EVENT SHALL BEN GRAY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
   27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   30  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 /**
   34  *      SCM - System Control Module
   35  *
   36  *      Hopefully in the end this module will contain a bunch of utility functions
   37  *      for configuring and querying the general system control registers, but for
   38  *      now it only does pin(pad) multiplexing.
   39  *
   40  *      This is different from the GPIO module in that it is used to configure the
   41  *      pins between modules not just GPIO input/output.
   42  *
   43  *      This file contains the generic top level driver, however it relies on chip
   44  *      specific settings and therefore expects an array of ti_scm_padconf structs
   45  *      call ti_padconf_devmap to be located somewhere in the kernel.
   46  *
   47  */
   48 #include <sys/cdefs.h>
   49 __FBSDID("$FreeBSD$");
   50 
   51 #include <sys/param.h>
   52 #include <sys/systm.h>
   53 #include <sys/kernel.h>
   54 #include <sys/module.h>
   55 #include <sys/bus.h>
   56 #include <sys/resource.h>
   57 #include <sys/rman.h>
   58 #include <sys/lock.h>
   59 #include <sys/mutex.h>
   60 
   61 #include <machine/bus.h>
   62 #include <machine/resource.h>
   63 
   64 #include <dev/fdt/fdt_common.h>
   65 #include <dev/fdt/fdt_pinctrl.h>
   66 #include <dev/ofw/openfirm.h>
   67 #include <dev/ofw/ofw_bus.h>
   68 #include <dev/ofw/ofw_bus_subr.h>
   69 
   70 #include "ti_scm.h"
   71 
   72 static struct resource_spec ti_scm_res_spec[] = {
   73         { SYS_RES_MEMORY,       0,      RF_ACTIVE },    /* Control memory window */
   74         { -1, 0 }
   75 };
   76 
   77 static struct ti_scm_softc *ti_scm_sc;
   78 
   79 #define ti_scm_read_4(sc, reg)          \
   80     bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
   81 #define ti_scm_write_4(sc, reg, val)            \
   82     bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
   83 
   84 /*
   85  * Device part of OMAP SCM driver
   86  */
   87 static int
   88 ti_scm_probe(device_t dev)
   89 {
   90         if (!ofw_bus_status_okay(dev))
   91                 return (ENXIO);
   92 
   93         if (!ofw_bus_is_compatible(dev, "syscon"))
   94                 return (ENXIO);
   95 
   96         if (ti_scm_sc) {
   97                 return (EEXIST);
   98         }
   99 
  100         device_set_desc(dev, "TI Control Module");
  101         return (BUS_PROBE_DEFAULT);
  102 }
  103 
  104 /**
  105  *      ti_scm_attach - attaches the timer to the simplebus
  106  *      @dev: new device
  107  *
  108  *      Reserves memory and interrupt resources, stores the softc structure
  109  *      globally and registers both the timecount and eventtimer objects.
  110  *
  111  *      RETURNS
  112  *      Zero on success or ENXIO if an error occuried.
  113  */
  114 static int
  115 ti_scm_attach(device_t dev)
  116 {
  117         struct ti_scm_softc *sc = device_get_softc(dev);
  118 
  119         sc->sc_dev = dev;
  120 
  121         if (bus_alloc_resources(dev, ti_scm_res_spec, sc->sc_res)) {
  122                 device_printf(dev, "could not allocate resources\n");
  123                 return (ENXIO);
  124         }
  125 
  126         /* Global timer interface */
  127         sc->sc_bst = rman_get_bustag(sc->sc_res[0]);
  128         sc->sc_bsh = rman_get_bushandle(sc->sc_res[0]);
  129 
  130         ti_scm_sc = sc;
  131 
  132         /* Attach platform extensions, if any. */
  133         bus_generic_probe(dev);
  134 
  135         return (bus_generic_attach(dev));
  136 }
  137 
  138 int
  139 ti_scm_reg_read_4(uint32_t reg, uint32_t *val)
  140 {
  141         if (!ti_scm_sc)
  142                 return (ENXIO);
  143 
  144         *val = ti_scm_read_4(ti_scm_sc, reg);
  145         return (0);
  146 }
  147 
  148 int
  149 ti_scm_reg_write_4(uint32_t reg, uint32_t val)
  150 {
  151         if (!ti_scm_sc)
  152                 return (ENXIO);
  153 
  154         ti_scm_write_4(ti_scm_sc, reg, val);
  155         return (0);
  156 }
  157 
  158 
  159 static device_method_t ti_scm_methods[] = {
  160         DEVMETHOD(device_probe,         ti_scm_probe),
  161         DEVMETHOD(device_attach,        ti_scm_attach),
  162 
  163         { 0, 0 }
  164 };
  165 
  166 static driver_t ti_scm_driver = {
  167         "ti_scm",
  168         ti_scm_methods,
  169         sizeof(struct ti_scm_softc),
  170 };
  171 
  172 static devclass_t ti_scm_devclass;
  173 
  174 EARLY_DRIVER_MODULE(ti_scm, simplebus, ti_scm_driver, ti_scm_devclass, 0, 0,
  175     BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);

Cache object: c9a9780903ebbaa46e70ca385a78be01


[ 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.