1 /* $NetBSD: cy82c693.c,v 1.5 2008/01/04 21:18:01 ad Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Common routines to read/write control registers on the Cypress 82c693
34 * hyperCache(tm) Stand-Alone PCI Peripheral Controller with USB.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: cy82c693.c,v 1.5 2008/01/04 21:18:01 ad Exp $");
40 #include "opt_multiprocessor.h"
41 #include "opt_lockdebug.h"
43 #include <sys/param.h>
44 #include <sys/device.h>
45 #include <sys/systm.h>
47 #include <sys/simplelock.h>
49 #include <dev/pci/pcireg.h>
50 #include <dev/pci/pcivar.h>
52 #include <dev/pci/cy82c693reg.h>
53 #include <dev/pci/cy82c693var.h>
55 static struct cy82c693_handle cyhc_handle
;
56 static int cyhc_initialized
;
58 static struct simplelock cyhc_slock
= SIMPLELOCK_INITIALIZER
;
60 #define CYHC_LOCK(s) \
63 simple_lock(&cyhc_slock); \
66 #define CYHC_UNLOCK(s) \
68 simple_unlock(&cyhc_slock); \
72 const struct cy82c693_handle
*
73 cy82c693_init(bus_space_tag_t iot
)
75 bus_space_handle_t ioh
;
80 if (cyhc_initialized
) {
82 if (iot
!= cyhc_handle
.cyhc_iot
)
83 panic("cy82c693_init");
84 return (&cyhc_handle
);
87 if (bus_space_map(iot
, CYHC_CONFIG_ADDR
, 2, 0, &ioh
) != 0) {
92 cyhc_handle
.cyhc_iot
= iot
;
93 cyhc_handle
.cyhc_ioh
= ioh
;
99 return (&cyhc_handle
);
103 cy82c693_read(const struct cy82c693_handle
*cyhc
, int reg
)
110 if (cyhc_initialized
== 0) {
112 panic("cy82c693_read");
115 bus_space_write_1(cyhc
->cyhc_iot
, cyhc
->cyhc_ioh
, 0, reg
);
116 rv
= bus_space_read_1(cyhc
->cyhc_iot
, cyhc
->cyhc_ioh
, 1);
124 cy82c693_write(const struct cy82c693_handle
*cyhc
, int reg
, u_int8_t val
)
130 if (cyhc_initialized
== 0) {
132 panic("cy82c693_write");
135 bus_space_write_1(cyhc
->cyhc_iot
, cyhc
->cyhc_ioh
, 0, reg
);
136 bus_space_write_1(cyhc
->cyhc_iot
, cyhc
->cyhc_ioh
, 1, val
);