root/dev/pci/cy82c693.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cy82c693_init
  2. cy82c693_read
  3. cy82c693_write

    1 /*      $OpenBSD: cy82c693.c,v 1.5 2004/06/13 21:49:25 niklas Exp $     */
    2 /* $NetBSD: cy82c693.c,v 1.1 2000/06/06 03:07:39 thorpej Exp $ */
    3 
    4 /*-
    5  * Copyright (c) 2000 The NetBSD Foundation, Inc.
    6  * All rights reserved.
    7  *
    8  * This code is derived from software contributed to The NetBSD Foundation
    9  * by Jason R. Thorpe.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. All advertising materials mentioning features or use of this software
   20  *    must display the following acknowledgement:
   21  *      This product includes software developed by the NetBSD
   22  *      Foundation, Inc. and its contributors.
   23  * 4. Neither the name of The NetBSD Foundation nor the names of its
   24  *    contributors may be used to endorse or promote products derived
   25  *    from this software without specific prior written permission.
   26  *
   27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   37  * POSSIBILITY OF SUCH DAMAGE.
   38  */
   39 
   40 /*
   41  * Common routines to read/write control registers on the Cypress 82c693
   42  * hyperCache(tm) Stand-Alone PCI Peripheral Controller with USB.
   43  */
   44 
   45 #include <sys/cdefs.h>                  /* RCS ID & Copyright macro defns */
   46 
   47 #include <sys/param.h>
   48 #include <sys/device.h>
   49 #include <sys/systm.h>
   50 #include <sys/lock.h>
   51 
   52 #include <machine/bus.h>
   53 
   54 #include <dev/pci/pcireg.h>
   55 #include <dev/pci/pcivar.h>
   56 
   57 #include <dev/pci/cy82c693reg.h>
   58 #include <dev/pci/cy82c693var.h>
   59 
   60 static struct cy82c693_handle cyhc_handle;
   61 static int cyhc_initialized;
   62 
   63 struct simplelock cyhc_slock;
   64 
   65 #define CYHC_LOCK(s)                                                    \
   66 do {                                                                    \
   67         s = splhigh();                                                  \
   68         simple_lock(&cyhc_slock);                                       \
   69 } while (0)
   70 
   71 #define CYHC_UNLOCK(s)                                                  \
   72 do {                                                                    \
   73         simple_unlock(&cyhc_slock);                                     \
   74         splx(s);                                                        \
   75 } while (0)
   76 
   77 const struct cy82c693_handle *
   78 cy82c693_init(bus_space_tag_t iot)
   79 {
   80         bus_space_handle_t ioh;
   81         int s;
   82         int error;
   83 
   84         simple_lock_init(&cyhc_slock);
   85 
   86         CYHC_LOCK(s);
   87 
   88         if (cyhc_initialized) {
   89                 CYHC_UNLOCK(s);
   90                 if (iot != cyhc_handle.cyhc_iot)
   91                         panic("cy82c693_init");
   92                 return (&cyhc_handle);
   93         }
   94 
   95         if ((error = bus_space_map(iot, CYHC_CONFIG_ADDR, 2, 0, &ioh)) != 0) {
   96                 CYHC_UNLOCK(s);
   97                 printf("cy82c693_init: bus_space_map failed (%d)", error);
   98                 return (NULL);
   99         }
  100 
  101         cyhc_handle.cyhc_iot = iot;
  102         cyhc_handle.cyhc_ioh = ioh;
  103 
  104         cyhc_initialized = 1;
  105 
  106         CYHC_UNLOCK(s);
  107 
  108         return (&cyhc_handle);
  109 }
  110 
  111 u_int8_t
  112 cy82c693_read(const struct cy82c693_handle *cyhc, int reg)
  113 {
  114         int s;
  115         u_int8_t rv;
  116 
  117         CYHC_LOCK(s);
  118 
  119         if (cyhc_initialized == 0) {
  120                 CYHC_UNLOCK(s);
  121                 panic("cy82c693_read");
  122         }
  123 
  124         bus_space_write_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 0, reg);
  125         rv = bus_space_read_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 1);
  126 
  127         CYHC_UNLOCK(s);
  128 
  129         return (rv);
  130 }
  131 
  132 void
  133 cy82c693_write(const struct cy82c693_handle *cyhc, int reg, u_int8_t val)
  134 {
  135         int s;
  136 
  137         CYHC_LOCK(s);
  138 
  139         if (cyhc_initialized == 0) {
  140                 CYHC_UNLOCK(s);
  141                 panic("cy82c693_write");
  142         }
  143 
  144         bus_space_write_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 0, reg);
  145         bus_space_write_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 1, val);
  146 
  147         CYHC_UNLOCK(s);
  148 }

/* [<][>][^][v][top][bottom][index][help] */