| @@ -1,814 +1,814 @@ | | | @@ -1,814 +1,814 @@ |
1 | /* $NetBSD: pad.c,v 1.26 2016/10/15 07:08:06 nat Exp $ */ | | 1 | /* $NetBSD: pad.c,v 1.27 2017/01/26 04:10:27 nat Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.26 2016/10/15 07:08:06 nat Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.27 2017/01/26 04:10:27 nat Exp $"); |
31 | | | 31 | |
32 | #include <sys/types.h> | | 32 | #include <sys/types.h> |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/conf.h> | | 34 | #include <sys/conf.h> |
35 | #include <sys/buf.h> | | 35 | #include <sys/buf.h> |
36 | #include <sys/kmem.h> | | 36 | #include <sys/kmem.h> |
37 | #include <sys/kernel.h> | | 37 | #include <sys/kernel.h> |
38 | #include <sys/device.h> | | 38 | #include <sys/device.h> |
39 | #include <sys/proc.h> | | 39 | #include <sys/proc.h> |
40 | #include <sys/condvar.h> | | 40 | #include <sys/condvar.h> |
41 | #include <sys/select.h> | | 41 | #include <sys/select.h> |
42 | #include <sys/audioio.h> | | 42 | #include <sys/audioio.h> |
43 | #include <sys/vnode.h> | | 43 | #include <sys/vnode.h> |
44 | #include <sys/module.h> | | 44 | #include <sys/module.h> |
45 | #include <sys/atomic.h> | | 45 | #include <sys/atomic.h> |
46 | #include <sys/time.h> | | 46 | #include <sys/time.h> |
47 | | | 47 | |
48 | #include <dev/audio_if.h> | | 48 | #include <dev/audio_if.h> |
49 | #include <dev/audiovar.h> | | 49 | #include <dev/audiovar.h> |
50 | #include <dev/auconv.h> | | 50 | #include <dev/auconv.h> |
51 | #include <dev/auvolconv.h> | | 51 | #include <dev/auvolconv.h> |
52 | | | 52 | |
53 | #include <dev/pad/padvar.h> | | 53 | #include <dev/pad/padvar.h> |
54 | | | 54 | |
55 | #define PADUNIT(x) minor(x) | | 55 | #define PADUNIT(x) minor(x) |
56 | | | 56 | |
57 | extern struct cfdriver pad_cd; | | 57 | extern struct cfdriver pad_cd; |
58 | | | 58 | |
59 | typedef struct pad_block { | | 59 | typedef struct pad_block { |
60 | uint8_t *pb_ptr; | | 60 | uint8_t *pb_ptr; |
61 | int pb_len; | | 61 | int pb_len; |
62 | } pad_block_t; | | 62 | } pad_block_t; |
63 | | | 63 | |
64 | enum { | | 64 | enum { |
65 | PAD_OUTPUT_CLASS, | | 65 | PAD_OUTPUT_CLASS, |
66 | PAD_INPUT_CLASS, | | 66 | PAD_INPUT_CLASS, |
67 | PAD_OUTPUT_MASTER_VOLUME, | | 67 | PAD_OUTPUT_MASTER_VOLUME, |
68 | PAD_INPUT_DAC_VOLUME, | | 68 | PAD_INPUT_DAC_VOLUME, |
69 | PAD_ENUM_LAST, | | 69 | PAD_ENUM_LAST, |
70 | }; | | 70 | }; |
71 | | | 71 | |
72 | static int pad_match(device_t, cfdata_t, void *); | | 72 | static int pad_match(device_t, cfdata_t, void *); |
73 | static void pad_attach(device_t, device_t, void *); | | 73 | static void pad_attach(device_t, device_t, void *); |
74 | static int pad_detach(device_t, int); | | 74 | static int pad_detach(device_t, int); |
75 | static void pad_childdet(device_t, device_t); | | 75 | static void pad_childdet(device_t, device_t); |
76 | | | 76 | |
77 | static int pad_audio_open(void *, int); | | 77 | static int pad_audio_open(void *, int); |
78 | static int pad_query_encoding(void *, struct audio_encoding *); | | 78 | static int pad_query_encoding(void *, struct audio_encoding *); |
79 | static int pad_set_params(void *, int, int, | | 79 | static int pad_set_params(void *, int, int, |
80 | audio_params_t *, audio_params_t *, | | 80 | audio_params_t *, audio_params_t *, |
81 | stream_filter_list_t *, stream_filter_list_t *); | | 81 | stream_filter_list_t *, stream_filter_list_t *); |
82 | static int pad_start_output(void *, void *, int, | | 82 | static int pad_start_output(void *, void *, int, |
83 | void (*)(void *), void *); | | 83 | void (*)(void *), void *); |
84 | static int pad_start_input(void *, void *, int, | | 84 | static int pad_start_input(void *, void *, int, |
85 | void (*)(void *), void *); | | 85 | void (*)(void *), void *); |
86 | static int pad_halt_output(void *); | | 86 | static int pad_halt_output(void *); |
87 | static int pad_halt_input(void *); | | 87 | static int pad_halt_input(void *); |
88 | static int pad_getdev(void *, struct audio_device *); | | 88 | static int pad_getdev(void *, struct audio_device *); |
89 | static int pad_set_port(void *, mixer_ctrl_t *); | | 89 | static int pad_set_port(void *, mixer_ctrl_t *); |
90 | static int pad_get_port(void *, mixer_ctrl_t *); | | 90 | static int pad_get_port(void *, mixer_ctrl_t *); |
91 | static int pad_query_devinfo(void *, mixer_devinfo_t *); | | 91 | static int pad_query_devinfo(void *, mixer_devinfo_t *); |
92 | static int pad_get_props(void *); | | 92 | static int pad_get_props(void *); |
93 | static int pad_round_blocksize(void *, int, int, const audio_params_t *); | | 93 | static int pad_round_blocksize(void *, int, int, const audio_params_t *); |
94 | static void pad_get_locks(void *, kmutex_t **, kmutex_t **); | | 94 | static void pad_get_locks(void *, kmutex_t **, kmutex_t **); |
95 | | | 95 | |
96 | static stream_filter_t *pad_swvol_filter_le(struct audio_softc *, | | 96 | static stream_filter_t *pad_swvol_filter_le(struct audio_softc *, |
97 | const audio_params_t *, const audio_params_t *); | | 97 | const audio_params_t *, const audio_params_t *); |
98 | static stream_filter_t *pad_swvol_filter_be(struct audio_softc *, | | 98 | static stream_filter_t *pad_swvol_filter_be(struct audio_softc *, |
99 | const audio_params_t *, const audio_params_t *); | | 99 | const audio_params_t *, const audio_params_t *); |
100 | static void pad_swvol_dtor(stream_filter_t *); | | 100 | static void pad_swvol_dtor(stream_filter_t *); |
101 | | | 101 | |
102 | static const struct audio_hw_if pad_hw_if = { | | 102 | static const struct audio_hw_if pad_hw_if = { |
103 | .open = pad_audio_open, | | 103 | .open = pad_audio_open, |
104 | .query_encoding = pad_query_encoding, | | 104 | .query_encoding = pad_query_encoding, |
105 | .set_params = pad_set_params, | | 105 | .set_params = pad_set_params, |
106 | .start_output = pad_start_output, | | 106 | .start_output = pad_start_output, |
107 | .start_input = pad_start_input, | | 107 | .start_input = pad_start_input, |
108 | .halt_output = pad_halt_output, | | 108 | .halt_output = pad_halt_output, |
109 | .halt_input = pad_halt_input, | | 109 | .halt_input = pad_halt_input, |
110 | .getdev = pad_getdev, | | 110 | .getdev = pad_getdev, |
111 | .set_port = pad_set_port, | | 111 | .set_port = pad_set_port, |
112 | .get_port = pad_get_port, | | 112 | .get_port = pad_get_port, |
113 | .query_devinfo = pad_query_devinfo, | | 113 | .query_devinfo = pad_query_devinfo, |
114 | .get_props = pad_get_props, | | 114 | .get_props = pad_get_props, |
115 | .round_blocksize = pad_round_blocksize, | | 115 | .round_blocksize = pad_round_blocksize, |
116 | .get_locks = pad_get_locks, | | 116 | .get_locks = pad_get_locks, |
117 | }; | | 117 | }; |
118 | | | 118 | |
119 | #define PAD_NFORMATS 1 | | 119 | #define PAD_NFORMATS 1 |
120 | static const struct audio_format pad_formats[PAD_NFORMATS] = { | | 120 | static const struct audio_format pad_formats[PAD_NFORMATS] = { |
121 | { NULL, AUMODE_PLAY|AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16, | | 121 | { NULL, AUMODE_PLAY|AUMODE_RECORD, AUDIO_ENCODING_SLINEAR_LE, 16, 16, |
122 | 2, AUFMT_STEREO, 1, { 44100 } }, | | 122 | 2, AUFMT_STEREO, 1, { 44100 } }, |
123 | }; | | 123 | }; |
124 | | | 124 | |
125 | extern void padattach(int); | | 125 | extern void padattach(int); |
126 | | | 126 | |
127 | static int pad_add_block(pad_softc_t *, uint8_t *, int); | | 127 | static int pad_add_block(pad_softc_t *, uint8_t *, int); |
128 | static int pad_get_block(pad_softc_t *, pad_block_t *, int); | | 128 | static int pad_get_block(pad_softc_t *, pad_block_t *, int); |
129 | | | 129 | |
130 | dev_type_open(pad_open); | | 130 | dev_type_open(pad_open); |
131 | dev_type_close(pad_close); | | 131 | dev_type_close(pad_close); |
132 | dev_type_read(pad_read); | | 132 | dev_type_read(pad_read); |
133 | | | 133 | |
134 | const struct cdevsw pad_cdevsw = { | | 134 | const struct cdevsw pad_cdevsw = { |
135 | .d_open = pad_open, | | 135 | .d_open = pad_open, |
136 | .d_close = pad_close, | | 136 | .d_close = pad_close, |
137 | .d_read = pad_read, | | 137 | .d_read = pad_read, |
138 | .d_write = nowrite, | | 138 | .d_write = nowrite, |
139 | .d_ioctl = noioctl, | | 139 | .d_ioctl = noioctl, |
140 | .d_stop = nostop, | | 140 | .d_stop = nostop, |
141 | .d_tty = notty, | | 141 | .d_tty = notty, |
142 | .d_poll = nopoll, | | 142 | .d_poll = nopoll, |
143 | .d_mmap = nommap, | | 143 | .d_mmap = nommap, |
144 | .d_kqfilter = nokqfilter, | | 144 | .d_kqfilter = nokqfilter, |
145 | .d_discard = nodiscard, | | 145 | .d_discard = nodiscard, |
146 | .d_flag = D_OTHER | D_MPSAFE, | | 146 | .d_flag = D_OTHER | D_MPSAFE, |
147 | }; | | 147 | }; |
148 | | | 148 | |
149 | CFATTACH_DECL2_NEW(pad, sizeof(pad_softc_t), pad_match, pad_attach, pad_detach, | | 149 | CFATTACH_DECL2_NEW(pad, sizeof(pad_softc_t), pad_match, pad_attach, pad_detach, |
150 | NULL, NULL, pad_childdet); | | 150 | NULL, NULL, pad_childdet); |
151 | | | 151 | |
152 | void | | 152 | void |
153 | padattach(int n) | | 153 | padattach(int n) |
154 | { | | 154 | { |
155 | int i, err; | | 155 | int i, err; |
156 | cfdata_t cf; | | 156 | cfdata_t cf; |
157 | | | 157 | |
158 | aprint_debug("pad: requested %d units\n", n); | | 158 | aprint_debug("pad: requested %d units\n", n); |
159 | | | 159 | |
160 | err = config_cfattach_attach(pad_cd.cd_name, &pad_ca); | | 160 | err = config_cfattach_attach(pad_cd.cd_name, &pad_ca); |
161 | if (err) { | | 161 | if (err) { |
162 | aprint_error("%s: couldn't register cfattach: %d\n", | | 162 | aprint_error("%s: couldn't register cfattach: %d\n", |
163 | pad_cd.cd_name, err); | | 163 | pad_cd.cd_name, err); |
164 | config_cfdriver_detach(&pad_cd); | | 164 | config_cfdriver_detach(&pad_cd); |
165 | return; | | 165 | return; |
166 | } | | 166 | } |
167 | | | 167 | |
168 | for (i = 0; i < n; i++) { | | 168 | for (i = 0; i < n; i++) { |
169 | cf = kmem_alloc(sizeof(struct cfdata), KM_SLEEP); | | 169 | cf = kmem_alloc(sizeof(struct cfdata), KM_SLEEP); |
170 | if (cf == NULL) { | | 170 | if (cf == NULL) { |
171 | aprint_error("%s: couldn't allocate cfdata\n", | | 171 | aprint_error("%s: couldn't allocate cfdata\n", |
172 | pad_cd.cd_name); | | 172 | pad_cd.cd_name); |
173 | continue; | | 173 | continue; |
174 | } | | 174 | } |
175 | cf->cf_name = pad_cd.cd_name; | | 175 | cf->cf_name = pad_cd.cd_name; |
176 | cf->cf_atname = pad_cd.cd_name; | | 176 | cf->cf_atname = pad_cd.cd_name; |
177 | cf->cf_unit = i; | | 177 | cf->cf_unit = i; |
178 | cf->cf_fstate = FSTATE_STAR; | | 178 | cf->cf_fstate = FSTATE_STAR; |
179 | | | 179 | |
180 | (void)config_attach_pseudo(cf); | | 180 | (void)config_attach_pseudo(cf); |
181 | } | | 181 | } |
182 | | | 182 | |
183 | return; | | 183 | return; |
184 | } | | 184 | } |
185 | | | 185 | |
186 | static int | | 186 | static int |
187 | pad_add_block(pad_softc_t *sc, uint8_t *blk, int blksize) | | 187 | pad_add_block(pad_softc_t *sc, uint8_t *blk, int blksize) |
188 | { | | 188 | { |
189 | int l; | | 189 | int l; |
190 | | | 190 | |
191 | if (sc->sc_open == 0) | | 191 | if (sc->sc_open == 0) |
192 | return EIO; | | 192 | return EIO; |
193 | | | 193 | |
194 | KASSERT(mutex_owned(&sc->sc_lock)); | | 194 | KASSERT(mutex_owned(&sc->sc_lock)); |
195 | | | 195 | |
196 | if (sc->sc_buflen + blksize > PAD_BUFSIZE) | | 196 | if (sc->sc_buflen + blksize > PAD_BUFSIZE) |
197 | return ENOBUFS; | | 197 | return ENOBUFS; |
198 | | | 198 | |
199 | if (sc->sc_wpos + blksize <= PAD_BUFSIZE) | | 199 | if (sc->sc_wpos + blksize <= PAD_BUFSIZE) |
200 | memcpy(sc->sc_audiobuf + sc->sc_wpos, blk, blksize); | | 200 | memcpy(sc->sc_audiobuf + sc->sc_wpos, blk, blksize); |
201 | else { | | 201 | else { |
202 | l = PAD_BUFSIZE - sc->sc_wpos; | | 202 | l = PAD_BUFSIZE - sc->sc_wpos; |
203 | memcpy(sc->sc_audiobuf + sc->sc_wpos, blk, l); | | 203 | memcpy(sc->sc_audiobuf + sc->sc_wpos, blk, l); |
204 | memcpy(sc->sc_audiobuf, blk + l, blksize - l); | | 204 | memcpy(sc->sc_audiobuf, blk + l, blksize - l); |
205 | } | | 205 | } |
206 | | | 206 | |
207 | sc->sc_wpos += blksize; | | 207 | sc->sc_wpos += blksize; |
208 | if (sc->sc_wpos > PAD_BUFSIZE) | | 208 | if (sc->sc_wpos > PAD_BUFSIZE) |
209 | sc->sc_wpos -= PAD_BUFSIZE; | | 209 | sc->sc_wpos -= PAD_BUFSIZE; |
210 | | | 210 | |
211 | sc->sc_buflen += blksize; | | 211 | sc->sc_buflen += blksize; |
212 | | | 212 | |
213 | return 0; | | 213 | return 0; |
214 | } | | 214 | } |
215 | | | 215 | |
216 | static int | | 216 | static int |
217 | pad_get_block(pad_softc_t *sc, pad_block_t *pb, int blksize) | | 217 | pad_get_block(pad_softc_t *sc, pad_block_t *pb, int blksize) |
218 | { | | 218 | { |
219 | int l; | | 219 | int l; |
220 | | | 220 | |
221 | KASSERT(mutex_owned(&sc->sc_lock)); | | 221 | KASSERT(mutex_owned(&sc->sc_lock)); |
222 | KASSERT(pb != NULL); | | 222 | KASSERT(pb != NULL); |
223 | | | 223 | |
224 | if (sc->sc_buflen < blksize) | | 224 | if (sc->sc_buflen < blksize) |
225 | return ERESTART; | | 225 | return ERESTART; |
226 | | | 226 | |
227 | pb->pb_ptr = (sc->sc_audiobuf + sc->sc_rpos); | | 227 | pb->pb_ptr = (sc->sc_audiobuf + sc->sc_rpos); |
228 | if (sc->sc_rpos + blksize < PAD_BUFSIZE) { | | 228 | if (sc->sc_rpos + blksize < PAD_BUFSIZE) { |
229 | pb->pb_len = blksize; | | 229 | pb->pb_len = blksize; |
230 | sc->sc_rpos += blksize; | | 230 | sc->sc_rpos += blksize; |
231 | } else { | | 231 | } else { |
232 | l = PAD_BUFSIZE - sc->sc_rpos; | | 232 | l = PAD_BUFSIZE - sc->sc_rpos; |
233 | pb->pb_len = l; | | 233 | pb->pb_len = l; |
234 | sc->sc_rpos = 0; | | 234 | sc->sc_rpos = 0; |
235 | } | | 235 | } |
236 | sc->sc_buflen -= pb->pb_len; | | 236 | sc->sc_buflen -= pb->pb_len; |
237 | | | 237 | |
238 | return 0; | | 238 | return 0; |
239 | } | | 239 | } |
240 | | | 240 | |
241 | static int | | 241 | static int |
242 | pad_match(device_t parent, cfdata_t data, void *opaque) | | 242 | pad_match(device_t parent, cfdata_t data, void *opaque) |
243 | { | | 243 | { |
244 | | | 244 | |
245 | return 1; | | 245 | return 1; |
246 | } | | 246 | } |
247 | | | 247 | |
248 | static void | | 248 | static void |
249 | pad_childdet(device_t self, device_t child) | | 249 | pad_childdet(device_t self, device_t child) |
250 | { | | 250 | { |
251 | pad_softc_t *sc = device_private(self); | | 251 | pad_softc_t *sc = device_private(self); |
252 | | | 252 | |
253 | sc->sc_audiodev = NULL; | | 253 | sc->sc_audiodev = NULL; |
254 | } | | 254 | } |
255 | | | 255 | |
256 | static void | | 256 | static void |
257 | pad_attach(device_t parent, device_t self, void *opaque) | | 257 | pad_attach(device_t parent, device_t self, void *opaque) |
258 | { | | 258 | { |
259 | pad_softc_t *sc = device_private(self); | | 259 | pad_softc_t *sc = device_private(self); |
260 | | | 260 | |
261 | aprint_normal_dev(self, "outputs: 44100Hz, 16-bit, stereo\n"); | | 261 | aprint_normal_dev(self, "outputs: 44100Hz, 16-bit, stereo\n"); |
262 | | | 262 | |
263 | sc->sc_dev = self; | | 263 | sc->sc_dev = self; |
264 | sc->sc_open = 0; | | 264 | sc->sc_open = 0; |
265 | if (auconv_create_encodings(pad_formats, PAD_NFORMATS, | | 265 | if (auconv_create_encodings(pad_formats, PAD_NFORMATS, |
266 | &sc->sc_encodings) != 0) { | | 266 | &sc->sc_encodings) != 0) { |
267 | aprint_error_dev(self, "couldn't create encodings\n"); | | 267 | aprint_error_dev(self, "couldn't create encodings\n"); |
268 | return; | | 268 | return; |
269 | } | | 269 | } |
270 | | | 270 | |
271 | cv_init(&sc->sc_condvar, device_xname(self)); | | 271 | cv_init(&sc->sc_condvar, device_xname(self)); |
272 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); | | 272 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); |
273 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_NONE); | | 273 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_NONE); |
274 | | | 274 | |
275 | sc->sc_swvol = 255; | | 275 | sc->sc_swvol = 255; |
276 | sc->sc_buflen = 0; | | 276 | sc->sc_buflen = 0; |
277 | sc->sc_rpos = sc->sc_wpos = 0; | | 277 | sc->sc_rpos = sc->sc_wpos = 0; |
278 | sc->sc_audiodev = (void *)audio_attach_mi(&pad_hw_if, sc, sc->sc_dev); | | 278 | sc->sc_audiodev = (void *)audio_attach_mi(&pad_hw_if, sc, sc->sc_dev); |
279 | | | 279 | |
280 | if (!pmf_device_register(self, NULL, NULL)) | | 280 | if (!pmf_device_register(self, NULL, NULL)) |
281 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 281 | aprint_error_dev(self, "couldn't establish power handler\n"); |
282 | | | 282 | |
283 | return; | | 283 | return; |
284 | } | | 284 | } |
285 | | | 285 | |
286 | static int | | 286 | static int |
287 | pad_detach(device_t self, int flags) | | 287 | pad_detach(device_t self, int flags) |
288 | { | | 288 | { |
289 | pad_softc_t *sc = device_private(self); | | 289 | pad_softc_t *sc = device_private(self); |
290 | int cmaj, mn, rc; | | 290 | int cmaj, mn, rc; |
291 | | | 291 | |
292 | cmaj = cdevsw_lookup_major(&pad_cdevsw); | | 292 | cmaj = cdevsw_lookup_major(&pad_cdevsw); |
293 | mn = device_unit(self); | | 293 | mn = device_unit(self); |
294 | vdevgone(cmaj, mn, mn, VCHR); | | 294 | vdevgone(cmaj, mn, mn, VCHR); |
295 | | | 295 | |
296 | if ((rc = config_detach_children(self, flags)) != 0) | | 296 | if ((rc = config_detach_children(self, flags)) != 0) |
297 | return rc; | | 297 | return rc; |
298 | | | 298 | |
299 | pmf_device_deregister(self); | | 299 | pmf_device_deregister(self); |
300 | | | 300 | |
301 | mutex_destroy(&sc->sc_lock); | | 301 | mutex_destroy(&sc->sc_lock); |
302 | mutex_destroy(&sc->sc_intr_lock); | | 302 | mutex_destroy(&sc->sc_intr_lock); |
303 | cv_destroy(&sc->sc_condvar); | | 303 | cv_destroy(&sc->sc_condvar); |
304 | | | 304 | |
305 | auconv_delete_encodings(sc->sc_encodings); | | 305 | auconv_delete_encodings(sc->sc_encodings); |
306 | | | 306 | |
307 | return 0; | | 307 | return 0; |
308 | } | | 308 | } |
309 | | | 309 | |
310 | int | | 310 | int |
311 | pad_open(dev_t dev, int flags, int fmt, struct lwp *l) | | 311 | pad_open(dev_t dev, int flags, int fmt, struct lwp *l) |
312 | { | | 312 | { |
313 | pad_softc_t *sc; | | 313 | pad_softc_t *sc; |
314 | | | 314 | |
315 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); | | 315 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); |
316 | if (sc == NULL) | | 316 | if (sc == NULL) |
317 | return ENXIO; | | 317 | return ENXIO; |
318 | | | 318 | |
319 | if (atomic_swap_uint(&sc->sc_open, 1) != 0) { | | 319 | if (atomic_swap_uint(&sc->sc_open, 1) != 0) { |
320 | return EBUSY; | | 320 | return EBUSY; |
321 | } | | 321 | } |
322 | | | 322 | |
323 | getmicrotime(&sc->sc_last); | | 323 | getmicrotime(&sc->sc_last); |
324 | sc->sc_bytes_count = 0; | | 324 | sc->sc_bytes_count = 0; |
325 | | | 325 | |
326 | return 0; | | 326 | return 0; |
327 | } | | 327 | } |
328 | | | 328 | |
329 | int | | 329 | int |
330 | pad_close(dev_t dev, int flags, int fmt, struct lwp *l) | | 330 | pad_close(dev_t dev, int flags, int fmt, struct lwp *l) |
331 | { | | 331 | { |
332 | pad_softc_t *sc; | | 332 | pad_softc_t *sc; |
333 | | | 333 | |
334 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); | | 334 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); |
335 | if (sc == NULL) | | 335 | if (sc == NULL) |
336 | return ENXIO; | | 336 | return ENXIO; |
337 | | | 337 | |
338 | KASSERT(sc->sc_open > 0); | | 338 | KASSERT(sc->sc_open > 0); |
339 | sc->sc_open = 0; | | 339 | sc->sc_open = 0; |
340 | | | 340 | |
341 | return 0; | | 341 | return 0; |
342 | } | | 342 | } |
343 | | | 343 | |
344 | #define PAD_BYTES_PER_SEC (44100 * sizeof(int16_t) * 2) | | 344 | #define PAD_BYTES_PER_SEC (44100 * sizeof(int16_t) * 2) |
345 | #define TIMENEXTREAD (20 * 1000) | | 345 | #define TIMENEXTREAD (20 * 1000) |
346 | #define BYTESTOSLEEP ((PAD_BYTES_PER_SEC / (1000000 / TIMENEXTREAD)) + PAD_BLKSIZE) | | 346 | #define BYTESTOSLEEP ((PAD_BYTES_PER_SEC / (1000000 / TIMENEXTREAD)) + PAD_BLKSIZE) |
347 | | | 347 | |
348 | int | | 348 | int |
349 | pad_read(dev_t dev, struct uio *uio, int flags) | | 349 | pad_read(dev_t dev, struct uio *uio, int flags) |
350 | { | | 350 | { |
351 | struct timeval now; | | 351 | struct timeval now; |
352 | uint64_t nowusec, lastusec; | | 352 | uint64_t nowusec, lastusec; |
353 | pad_softc_t *sc; | | 353 | pad_softc_t *sc; |
354 | pad_block_t pb; | | 354 | pad_block_t pb; |
355 | void (*intr)(void *); | | 355 | void (*intr)(void *); |
356 | void *intrarg; | | 356 | void *intrarg; |
357 | int err, wait_ticks; | | 357 | int err, wait_ticks; |
358 | | | 358 | |
359 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); | | 359 | sc = device_lookup_private(&pad_cd, PADUNIT(dev)); |
360 | if (sc == NULL) | | 360 | if (sc == NULL) |
361 | return ENXIO; | | 361 | return ENXIO; |
362 | | | 362 | |
363 | err = 0; | | 363 | err = 0; |
364 | | | 364 | |
365 | mutex_enter(&sc->sc_lock); | | | |
366 | intr = sc->sc_intr; | | | |
367 | intrarg = sc->sc_intrarg; | | | |
368 | | | | |
369 | while (uio->uio_resid > 0 && !err) { | | 365 | while (uio->uio_resid > 0 && !err) { |
| | | 366 | mutex_enter(&sc->sc_lock); |
| | | 367 | intr = sc->sc_intr; |
| | | 368 | intrarg = sc->sc_intrarg; |
| | | 369 | |
370 | getmicrotime(&now); | | 370 | getmicrotime(&now); |
371 | nowusec = (now.tv_sec * 1000000) + now.tv_usec; | | 371 | nowusec = (now.tv_sec * 1000000) + now.tv_usec; |
372 | lastusec = (sc->sc_last.tv_sec * 1000000) + | | 372 | lastusec = (sc->sc_last.tv_sec * 1000000) + |
373 | sc->sc_last.tv_usec; | | 373 | sc->sc_last.tv_usec; |
374 | if (lastusec + TIMENEXTREAD > nowusec && | | 374 | if (lastusec + TIMENEXTREAD > nowusec && |
375 | sc->sc_bytes_count >= BYTESTOSLEEP) { | | 375 | sc->sc_bytes_count >= BYTESTOSLEEP) { |
376 | wait_ticks = (hz * ((lastusec + TIMENEXTREAD) - | | 376 | wait_ticks = (hz * ((lastusec + TIMENEXTREAD) - |
377 | nowusec)) / 1000000; | | 377 | nowusec)) / 1000000; |
378 | if (wait_ticks > 0) { | | 378 | if (wait_ticks > 0) { |
379 | kpause("padwait", TRUE, wait_ticks, | | 379 | kpause("padwait", TRUE, wait_ticks, |
380 | &sc->sc_lock); | | 380 | &sc->sc_lock); |
381 | } | | 381 | } |
382 | | | 382 | |
383 | sc->sc_bytes_count -= BYTESTOSLEEP; | | 383 | sc->sc_bytes_count -= BYTESTOSLEEP; |
384 | getmicrotime(&sc->sc_last); | | 384 | getmicrotime(&sc->sc_last); |
385 | } else if (sc->sc_bytes_count >= BYTESTOSLEEP) { | | 385 | } else if (sc->sc_bytes_count >= BYTESTOSLEEP) { |
386 | sc->sc_bytes_count -= BYTESTOSLEEP; | | 386 | sc->sc_bytes_count -= BYTESTOSLEEP; |
387 | getmicrotime(&sc->sc_last); | | 387 | getmicrotime(&sc->sc_last); |
388 | } else if (lastusec + TIMENEXTREAD <= nowusec) | | 388 | } else if (lastusec + TIMENEXTREAD <= nowusec) |
389 | getmicrotime(&sc->sc_last); | | 389 | getmicrotime(&sc->sc_last); |
390 | | | 390 | |
391 | err = pad_get_block(sc, &pb, min(uio->uio_resid, PAD_BLKSIZE)); | | 391 | err = pad_get_block(sc, &pb, min(uio->uio_resid, PAD_BLKSIZE)); |
392 | if (!err) { | | 392 | if (!err) { |
393 | sc->sc_bytes_count += pb.pb_len; | | 393 | sc->sc_bytes_count += pb.pb_len; |
394 | | | 394 | |
395 | mutex_exit(&sc->sc_lock); | | 395 | mutex_exit(&sc->sc_lock); |
396 | err = uiomove(pb.pb_ptr, pb.pb_len, uio); | | 396 | err = uiomove(pb.pb_ptr, pb.pb_len, uio); |
397 | mutex_enter(&sc->sc_lock); | | | |
398 | continue; | | 397 | continue; |
399 | } | | 398 | } |
400 | | | 399 | |
401 | if (intr) { | | 400 | if (intr) { |
402 | mutex_enter(&sc->sc_intr_lock); | | 401 | mutex_enter(&sc->sc_intr_lock); |
403 | kpreempt_disable(); | | 402 | kpreempt_disable(); |
404 | (*intr)(intrarg); | | 403 | (*intr)(intrarg); |
405 | kpreempt_enable(); | | 404 | kpreempt_enable(); |
406 | mutex_exit(&sc->sc_intr_lock); | | 405 | mutex_exit(&sc->sc_intr_lock); |
407 | intr = sc->sc_intr; | | 406 | intr = sc->sc_intr; |
408 | intrarg = sc->sc_intrarg; | | 407 | intrarg = sc->sc_intrarg; |
409 | err = 0; | | 408 | err = 0; |
| | | 409 | mutex_exit(&sc->sc_lock); |
410 | continue; | | 410 | continue; |
411 | } | | 411 | } |
412 | err = cv_wait_sig(&sc->sc_condvar, &sc->sc_lock); | | 412 | err = cv_wait_sig(&sc->sc_condvar, &sc->sc_lock); |
413 | if (err != 0) | | 413 | if (err != 0) { |
| | | 414 | mutex_exit(&sc->sc_lock); |
414 | break; | | 415 | break; |
| | | 416 | } |
415 | | | 417 | |
416 | intr = sc->sc_intr; | | 418 | mutex_exit(&sc->sc_lock); |
417 | intrarg = sc->sc_intrarg; | | | |
418 | } | | 419 | } |
419 | mutex_exit(&sc->sc_lock); | | | |
420 | | | 420 | |
421 | return err; | | 421 | return err; |
422 | } | | 422 | } |
423 | | | 423 | |
424 | static int | | 424 | static int |
425 | pad_audio_open(void *opaque, int flags) | | 425 | pad_audio_open(void *opaque, int flags) |
426 | { | | 426 | { |
427 | pad_softc_t *sc; | | 427 | pad_softc_t *sc; |
428 | sc = opaque; | | 428 | sc = opaque; |
429 | | | 429 | |
430 | if (sc->sc_open == 0) | | 430 | if (sc->sc_open == 0) |
431 | return EIO; | | 431 | return EIO; |
432 | | | 432 | |
433 | getmicrotime(&sc->sc_last); | | 433 | getmicrotime(&sc->sc_last); |
434 | return 0; | | 434 | return 0; |
435 | } | | 435 | } |
436 | | | 436 | |
437 | static int | | 437 | static int |
438 | pad_query_encoding(void *opaque, struct audio_encoding *ae) | | 438 | pad_query_encoding(void *opaque, struct audio_encoding *ae) |
439 | { | | 439 | { |
440 | pad_softc_t *sc; | | 440 | pad_softc_t *sc; |
441 | | | 441 | |
442 | sc = (pad_softc_t *)opaque; | | 442 | sc = (pad_softc_t *)opaque; |
443 | | | 443 | |
444 | KASSERT(mutex_owned(&sc->sc_lock)); | | 444 | KASSERT(mutex_owned(&sc->sc_lock)); |
445 | | | 445 | |
446 | return auconv_query_encoding(sc->sc_encodings, ae); | | 446 | return auconv_query_encoding(sc->sc_encodings, ae); |
447 | } | | 447 | } |
448 | | | 448 | |
449 | static int | | 449 | static int |
450 | pad_set_params(void *opaque, int setmode, int usemode, | | 450 | pad_set_params(void *opaque, int setmode, int usemode, |
451 | audio_params_t *play, audio_params_t *rec, | | 451 | audio_params_t *play, audio_params_t *rec, |
452 | stream_filter_list_t *pfil, stream_filter_list_t *rfil) | | 452 | stream_filter_list_t *pfil, stream_filter_list_t *rfil) |
453 | { | | 453 | { |
454 | pad_softc_t *sc __diagused; | | 454 | pad_softc_t *sc __diagused; |
455 | | | 455 | |
456 | sc = (pad_softc_t *)opaque; | | 456 | sc = (pad_softc_t *)opaque; |
457 | | | 457 | |
458 | KASSERT(mutex_owned(&sc->sc_lock)); | | 458 | KASSERT(mutex_owned(&sc->sc_lock)); |
459 | | | 459 | |
460 | if (auconv_set_converter(pad_formats, PAD_NFORMATS, AUMODE_PLAY, | | 460 | if (auconv_set_converter(pad_formats, PAD_NFORMATS, AUMODE_PLAY, |
461 | play, true, pfil) < 0) | | 461 | play, true, pfil) < 0) |
462 | return EINVAL; | | 462 | return EINVAL; |
463 | if (auconv_set_converter(pad_formats, PAD_NFORMATS, AUMODE_RECORD, | | 463 | if (auconv_set_converter(pad_formats, PAD_NFORMATS, AUMODE_RECORD, |
464 | rec, true, rfil) < 0) | | 464 | rec, true, rfil) < 0) |
465 | return EINVAL; | | 465 | return EINVAL; |
466 | | | 466 | |
467 | if (pfil->req_size > 0) | | 467 | if (pfil->req_size > 0) |
468 | play = &pfil->filters[0].param; | | 468 | play = &pfil->filters[0].param; |
469 | switch (play->encoding) { | | 469 | switch (play->encoding) { |
470 | case AUDIO_ENCODING_SLINEAR_LE: | | 470 | case AUDIO_ENCODING_SLINEAR_LE: |
471 | if (play->precision == 16 && play->validbits == 16) | | 471 | if (play->precision == 16 && play->validbits == 16) |
472 | pfil->prepend(pfil, pad_swvol_filter_le, play); | | 472 | pfil->prepend(pfil, pad_swvol_filter_le, play); |
473 | break; | | 473 | break; |
474 | case AUDIO_ENCODING_SLINEAR_BE: | | 474 | case AUDIO_ENCODING_SLINEAR_BE: |
475 | if (play->precision == 16 && play->validbits == 16) | | 475 | if (play->precision == 16 && play->validbits == 16) |
476 | pfil->prepend(pfil, pad_swvol_filter_be, play); | | 476 | pfil->prepend(pfil, pad_swvol_filter_be, play); |
477 | break; | | 477 | break; |
478 | default: | | 478 | default: |
479 | break; | | 479 | break; |
480 | } | | 480 | } |
481 | | | 481 | |
482 | return 0; | | 482 | return 0; |
483 | } | | 483 | } |
484 | | | 484 | |
485 | static int | | 485 | static int |
486 | pad_start_output(void *opaque, void *block, int blksize, | | 486 | pad_start_output(void *opaque, void *block, int blksize, |
487 | void (*intr)(void *), void *intrarg) | | 487 | void (*intr)(void *), void *intrarg) |
488 | { | | 488 | { |
489 | pad_softc_t *sc; | | 489 | pad_softc_t *sc; |
490 | int err; | | 490 | int err; |
491 | | | 491 | |
492 | sc = (pad_softc_t *)opaque; | | 492 | sc = (pad_softc_t *)opaque; |
493 | | | 493 | |
494 | KASSERT(mutex_owned(&sc->sc_lock)); | | 494 | KASSERT(mutex_owned(&sc->sc_lock)); |
495 | if (!sc->sc_open) | | 495 | if (!sc->sc_open) |
496 | return EIO; | | 496 | return EIO; |
497 | | | 497 | |
498 | sc->sc_intr = intr; | | 498 | sc->sc_intr = intr; |
499 | sc->sc_intrarg = intrarg; | | 499 | sc->sc_intrarg = intrarg; |
500 | sc->sc_blksize = blksize; | | 500 | sc->sc_blksize = blksize; |
501 | | | 501 | |
502 | err = pad_add_block(sc, block, blksize); | | 502 | err = pad_add_block(sc, block, blksize); |
503 | | | 503 | |
504 | cv_broadcast(&sc->sc_condvar); | | 504 | cv_broadcast(&sc->sc_condvar); |
505 | | | 505 | |
506 | return err; | | 506 | return err; |
507 | } | | 507 | } |
508 | | | 508 | |
509 | static int | | 509 | static int |
510 | pad_start_input(void *opaque, void *block, int blksize, | | 510 | pad_start_input(void *opaque, void *block, int blksize, |
511 | void (*intr)(void *), void *intrarg) | | 511 | void (*intr)(void *), void *intrarg) |
512 | { | | 512 | { |
513 | pad_softc_t *sc __diagused; | | 513 | pad_softc_t *sc __diagused; |
514 | | | 514 | |
515 | sc = (pad_softc_t *)opaque; | | 515 | sc = (pad_softc_t *)opaque; |
516 | | | 516 | |
517 | KASSERT(mutex_owned(&sc->sc_lock)); | | 517 | KASSERT(mutex_owned(&sc->sc_lock)); |
518 | | | 518 | |
519 | return EOPNOTSUPP; | | 519 | return EOPNOTSUPP; |
520 | } | | 520 | } |
521 | | | 521 | |
522 | static int | | 522 | static int |
523 | pad_halt_output(void *opaque) | | 523 | pad_halt_output(void *opaque) |
524 | { | | 524 | { |
525 | pad_softc_t *sc; | | 525 | pad_softc_t *sc; |
526 | | | 526 | |
527 | sc = (pad_softc_t *)opaque; | | 527 | sc = (pad_softc_t *)opaque; |
528 | | | 528 | |
529 | KASSERT(mutex_owned(&sc->sc_lock)); | | 529 | KASSERT(mutex_owned(&sc->sc_lock)); |
530 | | | 530 | |
531 | sc->sc_intr = NULL; | | 531 | sc->sc_intr = NULL; |
532 | sc->sc_intrarg = NULL; | | 532 | sc->sc_intrarg = NULL; |
533 | sc->sc_buflen = 0; | | 533 | sc->sc_buflen = 0; |
534 | sc->sc_rpos = sc->sc_wpos = 0; | | 534 | sc->sc_rpos = sc->sc_wpos = 0; |
535 | | | 535 | |
536 | return 0; | | 536 | return 0; |
537 | } | | 537 | } |
538 | | | 538 | |
539 | static int | | 539 | static int |
540 | pad_halt_input(void *opaque) | | 540 | pad_halt_input(void *opaque) |
541 | { | | 541 | { |
542 | pad_softc_t *sc __diagused; | | 542 | pad_softc_t *sc __diagused; |
543 | | | 543 | |
544 | sc = (pad_softc_t *)opaque; | | 544 | sc = (pad_softc_t *)opaque; |
545 | | | 545 | |
546 | KASSERT(mutex_owned(&sc->sc_lock)); | | 546 | KASSERT(mutex_owned(&sc->sc_lock)); |
547 | | | 547 | |
548 | return 0; | | 548 | return 0; |
549 | } | | 549 | } |
550 | | | 550 | |
551 | static int | | 551 | static int |
552 | pad_getdev(void *opaque, struct audio_device *ret) | | 552 | pad_getdev(void *opaque, struct audio_device *ret) |
553 | { | | 553 | { |
554 | strlcpy(ret->name, "Virtual Audio", sizeof(ret->name)); | | 554 | strlcpy(ret->name, "Virtual Audio", sizeof(ret->name)); |
555 | strlcpy(ret->version, osrelease, sizeof(ret->version)); | | 555 | strlcpy(ret->version, osrelease, sizeof(ret->version)); |
556 | strlcpy(ret->config, "pad", sizeof(ret->config)); | | 556 | strlcpy(ret->config, "pad", sizeof(ret->config)); |
557 | | | 557 | |
558 | return 0; | | 558 | return 0; |
559 | } | | 559 | } |
560 | | | 560 | |
561 | static int | | 561 | static int |
562 | pad_set_port(void *opaque, mixer_ctrl_t *mc) | | 562 | pad_set_port(void *opaque, mixer_ctrl_t *mc) |
563 | { | | 563 | { |
564 | pad_softc_t *sc; | | 564 | pad_softc_t *sc; |
565 | | | 565 | |
566 | sc = (pad_softc_t *)opaque; | | 566 | sc = (pad_softc_t *)opaque; |
567 | | | 567 | |
568 | KASSERT(mutex_owned(&sc->sc_lock)); | | 568 | KASSERT(mutex_owned(&sc->sc_lock)); |
569 | | | 569 | |
570 | switch (mc->dev) { | | 570 | switch (mc->dev) { |
571 | case PAD_OUTPUT_MASTER_VOLUME: | | 571 | case PAD_OUTPUT_MASTER_VOLUME: |
572 | case PAD_INPUT_DAC_VOLUME: | | 572 | case PAD_INPUT_DAC_VOLUME: |
573 | sc->sc_swvol = mc->un.value.level[AUDIO_MIXER_LEVEL_MONO]; | | 573 | sc->sc_swvol = mc->un.value.level[AUDIO_MIXER_LEVEL_MONO]; |
574 | return 0; | | 574 | return 0; |
575 | } | | 575 | } |
576 | | | 576 | |
577 | return ENXIO; | | 577 | return ENXIO; |
578 | } | | 578 | } |
579 | | | 579 | |
580 | static int | | 580 | static int |
581 | pad_get_port(void *opaque, mixer_ctrl_t *mc) | | 581 | pad_get_port(void *opaque, mixer_ctrl_t *mc) |
582 | { | | 582 | { |
583 | pad_softc_t *sc; | | 583 | pad_softc_t *sc; |
584 | | | 584 | |
585 | sc = (pad_softc_t *)opaque; | | 585 | sc = (pad_softc_t *)opaque; |
586 | | | 586 | |
587 | KASSERT(mutex_owned(&sc->sc_lock)); | | 587 | KASSERT(mutex_owned(&sc->sc_lock)); |
588 | | | 588 | |
589 | switch (mc->dev) { | | 589 | switch (mc->dev) { |
590 | case PAD_OUTPUT_MASTER_VOLUME: | | 590 | case PAD_OUTPUT_MASTER_VOLUME: |
591 | case PAD_INPUT_DAC_VOLUME: | | 591 | case PAD_INPUT_DAC_VOLUME: |
592 | mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_swvol; | | 592 | mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_swvol; |
593 | return 0; | | 593 | return 0; |
594 | } | | 594 | } |
595 | | | 595 | |
596 | return ENXIO; | | 596 | return ENXIO; |
597 | } | | 597 | } |
598 | | | 598 | |
599 | static int | | 599 | static int |
600 | pad_query_devinfo(void *opaque, mixer_devinfo_t *di) | | 600 | pad_query_devinfo(void *opaque, mixer_devinfo_t *di) |
601 | { | | 601 | { |
602 | pad_softc_t *sc __diagused; | | 602 | pad_softc_t *sc __diagused; |
603 | | | 603 | |
604 | sc = (pad_softc_t *)opaque; | | 604 | sc = (pad_softc_t *)opaque; |
605 | | | 605 | |
606 | KASSERT(mutex_owned(&sc->sc_lock)); | | 606 | KASSERT(mutex_owned(&sc->sc_lock)); |
607 | | | 607 | |
608 | switch (di->index) { | | 608 | switch (di->index) { |
609 | case PAD_OUTPUT_CLASS: | | 609 | case PAD_OUTPUT_CLASS: |
610 | di->mixer_class = PAD_OUTPUT_CLASS; | | 610 | di->mixer_class = PAD_OUTPUT_CLASS; |
611 | strcpy(di->label.name, AudioCoutputs); | | 611 | strcpy(di->label.name, AudioCoutputs); |
612 | di->type = AUDIO_MIXER_CLASS; | | 612 | di->type = AUDIO_MIXER_CLASS; |
613 | di->next = di->prev = AUDIO_MIXER_LAST; | | 613 | di->next = di->prev = AUDIO_MIXER_LAST; |
614 | return 0; | | 614 | return 0; |
615 | case PAD_INPUT_CLASS: | | 615 | case PAD_INPUT_CLASS: |
616 | di->mixer_class = PAD_INPUT_CLASS; | | 616 | di->mixer_class = PAD_INPUT_CLASS; |
617 | strcpy(di->label.name, AudioCinputs); | | 617 | strcpy(di->label.name, AudioCinputs); |
618 | di->type = AUDIO_MIXER_CLASS; | | 618 | di->type = AUDIO_MIXER_CLASS; |
619 | di->next = di->prev = AUDIO_MIXER_LAST; | | 619 | di->next = di->prev = AUDIO_MIXER_LAST; |
620 | return 0; | | 620 | return 0; |
621 | case PAD_OUTPUT_MASTER_VOLUME: | | 621 | case PAD_OUTPUT_MASTER_VOLUME: |
622 | di->mixer_class = PAD_OUTPUT_CLASS; | | 622 | di->mixer_class = PAD_OUTPUT_CLASS; |
623 | strcpy(di->label.name, AudioNmaster); | | 623 | strcpy(di->label.name, AudioNmaster); |
624 | di->type = AUDIO_MIXER_VALUE; | | 624 | di->type = AUDIO_MIXER_VALUE; |
625 | di->next = di->prev = AUDIO_MIXER_LAST; | | 625 | di->next = di->prev = AUDIO_MIXER_LAST; |
626 | di->un.v.num_channels = 1; | | 626 | di->un.v.num_channels = 1; |
627 | strcpy(di->un.v.units.name, AudioNvolume); | | 627 | strcpy(di->un.v.units.name, AudioNvolume); |
628 | return 0; | | 628 | return 0; |
629 | case PAD_INPUT_DAC_VOLUME: | | 629 | case PAD_INPUT_DAC_VOLUME: |
630 | di->mixer_class = PAD_INPUT_CLASS; | | 630 | di->mixer_class = PAD_INPUT_CLASS; |
631 | strcpy(di->label.name, AudioNdac); | | 631 | strcpy(di->label.name, AudioNdac); |
632 | di->type = AUDIO_MIXER_VALUE; | | 632 | di->type = AUDIO_MIXER_VALUE; |
633 | di->next = di->prev = AUDIO_MIXER_LAST; | | 633 | di->next = di->prev = AUDIO_MIXER_LAST; |
634 | di->un.v.num_channels = 1; | | 634 | di->un.v.num_channels = 1; |
635 | strcpy(di->un.v.units.name, AudioNvolume); | | 635 | strcpy(di->un.v.units.name, AudioNvolume); |
636 | return 0; | | 636 | return 0; |
637 | } | | 637 | } |
638 | | | 638 | |
639 | return ENXIO; | | 639 | return ENXIO; |
640 | } | | 640 | } |
641 | | | 641 | |
642 | static int | | 642 | static int |
643 | pad_get_props(void *opaque) | | 643 | pad_get_props(void *opaque) |
644 | { | | 644 | { |
645 | pad_softc_t *sc __diagused; | | 645 | pad_softc_t *sc __diagused; |
646 | | | 646 | |
647 | sc = (pad_softc_t *)opaque; | | 647 | sc = (pad_softc_t *)opaque; |
648 | | | 648 | |
649 | KASSERT(mutex_owned(&sc->sc_lock)); | | 649 | KASSERT(mutex_owned(&sc->sc_lock)); |
650 | | | 650 | |
651 | return 0; | | 651 | return 0; |
652 | } | | 652 | } |
653 | | | 653 | |
654 | static int | | 654 | static int |
655 | pad_round_blocksize(void *opaque, int blksize, int mode, | | 655 | pad_round_blocksize(void *opaque, int blksize, int mode, |
656 | const audio_params_t *p) | | 656 | const audio_params_t *p) |
657 | { | | 657 | { |
658 | pad_softc_t *sc __diagused; | | 658 | pad_softc_t *sc __diagused; |
659 | | | 659 | |
660 | sc = (pad_softc_t *)opaque; | | 660 | sc = (pad_softc_t *)opaque; |
661 | KASSERT(mutex_owned(&sc->sc_lock)); | | 661 | KASSERT(mutex_owned(&sc->sc_lock)); |
662 | | | 662 | |
663 | return PAD_BLKSIZE; | | 663 | return PAD_BLKSIZE; |
664 | } | | 664 | } |
665 | | | 665 | |
666 | static void | | 666 | static void |
667 | pad_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread) | | 667 | pad_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread) |
668 | { | | 668 | { |
669 | pad_softc_t *sc; | | 669 | pad_softc_t *sc; |
670 | | | 670 | |
671 | sc = (pad_softc_t *)opaque; | | 671 | sc = (pad_softc_t *)opaque; |
672 | | | 672 | |
673 | *intr = &sc->sc_intr_lock; | | 673 | *intr = &sc->sc_intr_lock; |
674 | *thread = &sc->sc_lock; | | 674 | *thread = &sc->sc_lock; |
675 | } | | 675 | } |
676 | | | 676 | |
677 | static stream_filter_t * | | 677 | static stream_filter_t * |
678 | pad_swvol_filter_le(struct audio_softc *asc, | | 678 | pad_swvol_filter_le(struct audio_softc *asc, |
679 | const audio_params_t *from, const audio_params_t *to) | | 679 | const audio_params_t *from, const audio_params_t *to) |
680 | { | | 680 | { |
681 | auvolconv_filter_t *this; | | 681 | auvolconv_filter_t *this; |
682 | device_t dev = audio_get_device(asc); | | 682 | device_t dev = audio_get_device(asc); |
683 | struct pad_softc *sc = device_private(dev); | | 683 | struct pad_softc *sc = device_private(dev); |
684 | | | 684 | |
685 | this = kmem_alloc(sizeof(auvolconv_filter_t), KM_SLEEP); | | 685 | this = kmem_alloc(sizeof(auvolconv_filter_t), KM_SLEEP); |
686 | this->base.base.fetch_to = auvolconv_slinear16_le_fetch_to; | | 686 | this->base.base.fetch_to = auvolconv_slinear16_le_fetch_to; |
687 | this->base.dtor = pad_swvol_dtor; | | 687 | this->base.dtor = pad_swvol_dtor; |
688 | this->base.set_fetcher = stream_filter_set_fetcher; | | 688 | this->base.set_fetcher = stream_filter_set_fetcher; |
689 | this->base.set_inputbuffer = stream_filter_set_inputbuffer; | | 689 | this->base.set_inputbuffer = stream_filter_set_inputbuffer; |
690 | this->vol = &sc->sc_swvol; | | 690 | this->vol = &sc->sc_swvol; |
691 | | | 691 | |
692 | return (stream_filter_t *)this; | | 692 | return (stream_filter_t *)this; |
693 | } | | 693 | } |
694 | | | 694 | |
695 | static stream_filter_t * | | 695 | static stream_filter_t * |
696 | pad_swvol_filter_be(struct audio_softc *asc, | | 696 | pad_swvol_filter_be(struct audio_softc *asc, |
697 | const audio_params_t *from, const audio_params_t *to) | | 697 | const audio_params_t *from, const audio_params_t *to) |
698 | { | | 698 | { |
699 | auvolconv_filter_t *this; | | 699 | auvolconv_filter_t *this; |
700 | device_t dev = audio_get_device(asc); | | 700 | device_t dev = audio_get_device(asc); |
701 | struct pad_softc *sc = device_private(dev); | | 701 | struct pad_softc *sc = device_private(dev); |
702 | | | 702 | |
703 | this = kmem_alloc(sizeof(auvolconv_filter_t), KM_SLEEP); | | 703 | this = kmem_alloc(sizeof(auvolconv_filter_t), KM_SLEEP); |
704 | this->base.base.fetch_to = auvolconv_slinear16_be_fetch_to; | | 704 | this->base.base.fetch_to = auvolconv_slinear16_be_fetch_to; |
705 | this->base.dtor = pad_swvol_dtor; | | 705 | this->base.dtor = pad_swvol_dtor; |
706 | this->base.set_fetcher = stream_filter_set_fetcher; | | 706 | this->base.set_fetcher = stream_filter_set_fetcher; |
707 | this->base.set_inputbuffer = stream_filter_set_inputbuffer; | | 707 | this->base.set_inputbuffer = stream_filter_set_inputbuffer; |
708 | this->vol = &sc->sc_swvol; | | 708 | this->vol = &sc->sc_swvol; |
709 | | | 709 | |
710 | return (stream_filter_t *)this; | | 710 | return (stream_filter_t *)this; |
711 | } | | 711 | } |
712 | | | 712 | |
713 | static void | | 713 | static void |
714 | pad_swvol_dtor(stream_filter_t *this) | | 714 | pad_swvol_dtor(stream_filter_t *this) |
715 | { | | 715 | { |
716 | if (this) | | 716 | if (this) |
717 | kmem_free(this, sizeof(auvolconv_filter_t)); | | 717 | kmem_free(this, sizeof(auvolconv_filter_t)); |
718 | } | | 718 | } |
719 | | | 719 | |
720 | #ifdef _MODULE | | 720 | #ifdef _MODULE |
721 | | | 721 | |
722 | MODULE(MODULE_CLASS_DRIVER, pad, NULL); | | 722 | MODULE(MODULE_CLASS_DRIVER, pad, NULL); |
723 | | | 723 | |
724 | static const struct cfiattrdata audiobuscf_iattrdata = { | | 724 | static const struct cfiattrdata audiobuscf_iattrdata = { |
725 | "audiobus", 0, { { NULL, NULL, 0 }, } | | 725 | "audiobus", 0, { { NULL, NULL, 0 }, } |
726 | }; | | 726 | }; |
727 | static const struct cfiattrdata * const pad_attrs[] = { | | 727 | static const struct cfiattrdata * const pad_attrs[] = { |
728 | &audiobuscf_iattrdata, NULL | | 728 | &audiobuscf_iattrdata, NULL |
729 | }; | | 729 | }; |
730 | | | 730 | |
731 | CFDRIVER_DECL(pad, DV_DULL, pad_attrs); | | 731 | CFDRIVER_DECL(pad, DV_DULL, pad_attrs); |
732 | extern struct cfattach pad_ca; | | 732 | extern struct cfattach pad_ca; |
733 | static int padloc[] = { -1, -1 }; | | 733 | static int padloc[] = { -1, -1 }; |
734 | | | 734 | |
735 | static struct cfdata pad_cfdata[] = { | | 735 | static struct cfdata pad_cfdata[] = { |
736 | { | | 736 | { |
737 | .cf_name = "pad", | | 737 | .cf_name = "pad", |
738 | .cf_atname = "pad", | | 738 | .cf_atname = "pad", |
739 | .cf_unit = 0, | | 739 | .cf_unit = 0, |
740 | .cf_fstate = FSTATE_STAR, | | 740 | .cf_fstate = FSTATE_STAR, |
741 | .cf_loc = padloc, | | 741 | .cf_loc = padloc, |
742 | .cf_flags = 0, | | 742 | .cf_flags = 0, |
743 | .cf_pspec = NULL, | | 743 | .cf_pspec = NULL, |
744 | }, | | 744 | }, |
745 | { NULL, NULL, 0, 0, NULL, 0, NULL } | | 745 | { NULL, NULL, 0, 0, NULL, 0, NULL } |
746 | }; | | 746 | }; |
747 | | | 747 | |
748 | static int | | 748 | static int |
749 | pad_modcmd(modcmd_t cmd, void *arg) | | 749 | pad_modcmd(modcmd_t cmd, void *arg) |
750 | { | | 750 | { |
751 | devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR; | | 751 | devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR; |
752 | int error; | | 752 | int error; |
753 | | | 753 | |
754 | switch (cmd) { | | 754 | switch (cmd) { |
755 | case MODULE_CMD_INIT: | | 755 | case MODULE_CMD_INIT: |
756 | error = config_cfdriver_attach(&pad_cd); | | 756 | error = config_cfdriver_attach(&pad_cd); |
757 | if (error) { | | 757 | if (error) { |
758 | return error; | | 758 | return error; |
759 | } | | 759 | } |
760 | | | 760 | |
761 | error = config_cfattach_attach(pad_cd.cd_name, &pad_ca); | | 761 | error = config_cfattach_attach(pad_cd.cd_name, &pad_ca); |
762 | if (error) { | | 762 | if (error) { |
763 | config_cfdriver_detach(&pad_cd); | | 763 | config_cfdriver_detach(&pad_cd); |
764 | aprint_error("%s: unable to register cfattach\n", | | 764 | aprint_error("%s: unable to register cfattach\n", |
765 | pad_cd.cd_name); | | 765 | pad_cd.cd_name); |
766 | | | 766 | |
767 | return error; | | 767 | return error; |
768 | } | | 768 | } |
769 | | | 769 | |
770 | error = config_cfdata_attach(pad_cfdata, 1); | | 770 | error = config_cfdata_attach(pad_cfdata, 1); |
771 | if (error) { | | 771 | if (error) { |
772 | config_cfattach_detach(pad_cd.cd_name, &pad_ca); | | 772 | config_cfattach_detach(pad_cd.cd_name, &pad_ca); |
773 | config_cfdriver_detach(&pad_cd); | | 773 | config_cfdriver_detach(&pad_cd); |
774 | aprint_error("%s: unable to register cfdata\n", | | 774 | aprint_error("%s: unable to register cfdata\n", |
775 | pad_cd.cd_name); | | 775 | pad_cd.cd_name); |
776 | | | 776 | |
777 | return error; | | 777 | return error; |
778 | } | | 778 | } |
779 | | | 779 | |
780 | error = devsw_attach(pad_cd.cd_name, NULL, &bmajor, | | 780 | error = devsw_attach(pad_cd.cd_name, NULL, &bmajor, |
781 | &pad_cdevsw, &cmajor); | | 781 | &pad_cdevsw, &cmajor); |
782 | if (error) { | | 782 | if (error) { |
783 | error = config_cfdata_detach(pad_cfdata); | | 783 | error = config_cfdata_detach(pad_cfdata); |
784 | if (error) { | | 784 | if (error) { |
785 | return error; | | 785 | return error; |
786 | } | | 786 | } |
787 | config_cfattach_detach(pad_cd.cd_name, &pad_ca); | | 787 | config_cfattach_detach(pad_cd.cd_name, &pad_ca); |
788 | config_cfdriver_detach(&pad_cd); | | 788 | config_cfdriver_detach(&pad_cd); |
789 | aprint_error("%s: unable to register devsw\n", | | 789 | aprint_error("%s: unable to register devsw\n", |
790 | pad_cd.cd_name); | | 790 | pad_cd.cd_name); |
791 | | | 791 | |
792 | return error; | | 792 | return error; |
793 | } | | 793 | } |
794 | | | 794 | |
795 | (void)config_attach_pseudo(pad_cfdata); | | 795 | (void)config_attach_pseudo(pad_cfdata); |
796 | | | 796 | |
797 | return 0; | | 797 | return 0; |
798 | case MODULE_CMD_FINI: | | 798 | case MODULE_CMD_FINI: |
799 | error = config_cfdata_detach(pad_cfdata); | | 799 | error = config_cfdata_detach(pad_cfdata); |
800 | if (error) { | | 800 | if (error) { |
801 | return error; | | 801 | return error; |
802 | } | | 802 | } |
803 | | | 803 | |
804 | config_cfattach_detach(pad_cd.cd_name, &pad_ca); | | 804 | config_cfattach_detach(pad_cd.cd_name, &pad_ca); |
805 | config_cfdriver_detach(&pad_cd); | | 805 | config_cfdriver_detach(&pad_cd); |
806 | devsw_detach(NULL, &pad_cdevsw); | | 806 | devsw_detach(NULL, &pad_cdevsw); |
807 | | | 807 | |
808 | return 0; | | 808 | return 0; |
809 | default: | | 809 | default: |
810 | return ENOTTY; | | 810 | return ENOTTY; |
811 | } | | 811 | } |
812 | } | | 812 | } |
813 | | | 813 | |
814 | #endif | | 814 | #endif |