This source file includes following definitions.
- cy82c693_init
- cy82c693_read
- cy82c693_write
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 #include <sys/cdefs.h>
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 }