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/dev/iicbus/iicoc_pci.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  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (c) 2003-2012 Broadcom Corporation
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions are met:
    9  *
   10  * 1. Redistributions of source code must retain the above copyright notice,
   11  *    this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright notice,
   13  *    this list of conditions and the following disclaimer in the documentation
   14  *    and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
   18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
   20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
   23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
   26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD$");
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/kernel.h>
   35 #include <sys/module.h>
   36 #include <sys/bus.h>
   37 #include <sys/lock.h>
   38 #include <sys/mutex.h>
   39 #include <sys/rman.h>
   40 
   41 #include <dev/iicbus/iicbus.h>
   42 #include <dev/iicbus/iiconf.h>
   43 
   44 #include <dev/pci/pcireg.h>
   45 #include <dev/pci/pcivar.h>
   46 
   47 #include "iicbus_if.h"
   48 #include "iicoc.h"
   49 
   50 static int
   51 iicoc_detach(device_t dev)
   52 {
   53         struct iicoc_softc *sc;
   54 
   55         sc = device_get_softc(dev);
   56         device_delete_children(dev);
   57         bus_generic_detach(dev);
   58         bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res);
   59         mtx_destroy(&sc->sc_mtx);
   60 
   61         return (0);
   62 }
   63 
   64 /*
   65  * We add all the devices which we know about.
   66  * The generic attach routine will attach them if they are alive.
   67  */
   68 static int
   69 iicoc_attach(device_t dev)
   70 {
   71         struct iicoc_softc *sc;
   72 
   73         sc = device_get_softc(dev);
   74 
   75         sc->dev = dev;
   76         mtx_init(&sc->sc_mtx, "iicoc", "iicoc", MTX_DEF);
   77         sc->mem_rid = 0;
   78         sc->mem_res = bus_alloc_resource_anywhere(dev,
   79             SYS_RES_MEMORY, &sc->mem_rid, 0x100, RF_ACTIVE);
   80 
   81         if (sc->mem_res == NULL) {
   82                 device_printf(dev, "Could not allocate bus resource.\n");
   83                 return (-1);
   84         }
   85         iicoc_init(dev);
   86         sc->iicbus = device_add_child(dev, "iicbus", -1);
   87         if (sc->iicbus == NULL) {
   88                 device_printf(dev, "Could not allocate iicbus instance.\n");
   89                 bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid,
   90                     sc->mem_res);
   91                 mtx_destroy(&sc->sc_mtx);
   92                 return (-1);
   93         }
   94         bus_generic_attach(dev);
   95 
   96         return (0);
   97 }
   98 
   99 static int
  100 iicoc_probe(device_t dev)
  101 {
  102         struct iicoc_softc *sc;
  103 
  104         sc = device_get_softc(dev);
  105         if ((pci_get_vendor(dev) == 0x184e) &&
  106             (pci_get_device(dev) == 0x1011)) {
  107                 sc->clockfreq = XLP_I2C_CLKFREQ;
  108                 sc->i2cfreq = XLP_I2C_FREQ;
  109                 sc->reg_shift = 2;
  110                 device_set_desc(dev, "Netlogic XLP I2C Controller");
  111                 return (BUS_PROBE_DEFAULT);
  112         }
  113         return (ENXIO);
  114 }
  115 
  116 static device_method_t iicoc_methods[] = {
  117         /* device interface */
  118         DEVMETHOD(device_probe, iicoc_probe),
  119         DEVMETHOD(device_attach, iicoc_attach),
  120         DEVMETHOD(device_detach, iicoc_detach),
  121 
  122         /* iicbus interface */
  123         DEVMETHOD(iicbus_callback, iicbus_null_callback),
  124         DEVMETHOD(iicbus_repeated_start, iicoc_iicbus_repeated_start),
  125         DEVMETHOD(iicbus_start, iicoc_iicbus_start),
  126         DEVMETHOD(iicbus_stop, iicoc_iicbus_stop),
  127         DEVMETHOD(iicbus_reset, iicoc_iicbus_reset),
  128         DEVMETHOD(iicbus_write, iicoc_iicbus_write),
  129         DEVMETHOD(iicbus_read, iicoc_iicbus_read),
  130         DEVMETHOD(iicbus_transfer, iicbus_transfer_gen),
  131 
  132         DEVMETHOD_END
  133 };
  134 
  135 static driver_t iicoc_driver = {
  136         "iicoc",
  137         iicoc_methods,
  138         sizeof(struct iicoc_softc),
  139 };
  140 
  141 DRIVER_MODULE(iicoc, pci, iicoc_driver, 0, 0);

Cache object: 151e19341575cb689b5bdc3e52653489


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