wsbell.c revision 1.2 1 1.2 pgoyette /* $NetBSD: wsbell.c,v 1.2 2017/06/11 22:14:55 pgoyette Exp $ */
2 1.1 nat
3 1.1 nat /*-
4 1.1 nat * Copyright (c) 2017 Nathanial Sloss <nathanialsloss (at) yahoo.com.au>
5 1.1 nat * All rights reserved.
6 1.1 nat *
7 1.1 nat * Copyright (c) 2006 The NetBSD Foundation, Inc.
8 1.1 nat * All rights reserved.
9 1.1 nat *
10 1.1 nat * This code is derived from software contributed to The NetBSD Foundation
11 1.1 nat * by Julio M. Merino Vidal.
12 1.1 nat *
13 1.1 nat * Redistribution and use in source and binary forms, with or without
14 1.1 nat * modification, are permitted provided that the following conditions
15 1.1 nat * are met:
16 1.1 nat * 1. Redistributions of source code must retain the above copyright
17 1.1 nat * notice, this list of conditions and the following disclaimer.
18 1.1 nat * 2. Redistributions in binary form must reproduce the above copyright
19 1.1 nat * notice, this list of conditions and the following disclaimer in the
20 1.1 nat * documentation and/or other materials provided with the distribution.
21 1.1 nat *
22 1.1 nat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.1 nat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.1 nat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1 nat * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.1 nat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 nat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 nat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 nat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 nat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 nat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 nat * POSSIBILITY OF SUCH DAMAGE.
33 1.1 nat */
34 1.1 nat
35 1.1 nat /*
36 1.1 nat * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
37 1.1 nat *
38 1.1 nat * Redistribution and use in source and binary forms, with or without
39 1.1 nat * modification, are permitted provided that the following conditions
40 1.1 nat * are met:
41 1.1 nat * 1. Redistributions of source code must retain the above copyright
42 1.1 nat * notice, this list of conditions and the following disclaimer.
43 1.1 nat * 2. Redistributions in binary form must reproduce the above copyright
44 1.1 nat * notice, this list of conditions and the following disclaimer in the
45 1.1 nat * documentation and/or other materials provided with the distribution.
46 1.1 nat * 3. All advertising materials mentioning features or use of this software
47 1.1 nat * must display the following acknowledgement:
48 1.1 nat * This product includes software developed by Christopher G. Demetriou
49 1.1 nat * for the NetBSD Project.
50 1.1 nat * 4. The name of the author may not be used to endorse or promote products
51 1.1 nat * derived from this software without specific prior written permission
52 1.1 nat *
53 1.1 nat * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 1.1 nat * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 1.1 nat * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 1.1 nat * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 1.1 nat * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 1.1 nat * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 1.1 nat * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 1.1 nat * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 1.1 nat * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 1.1 nat * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 1.1 nat */
64 1.1 nat
65 1.1 nat /*
66 1.1 nat * Copyright (c) 1992, 1993
67 1.1 nat * The Regents of the University of California. All rights reserved.
68 1.1 nat *
69 1.1 nat * This software was developed by the Computer Systems Engineering group
70 1.1 nat * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
71 1.1 nat * contributed to Berkeley.
72 1.1 nat *
73 1.1 nat * All advertising materials mentioning features or use of this software
74 1.1 nat * must display the following acknowledgement:
75 1.1 nat * This product includes software developed by the University of
76 1.1 nat * California, Lawrence Berkeley Laboratory.
77 1.1 nat *
78 1.1 nat * Redistribution and use in source and binary forms, with or without
79 1.1 nat * modification, are permitted provided that the following conditions
80 1.1 nat * are met:
81 1.1 nat * 1. Redistributions of source code must retain the above copyright
82 1.1 nat * notice, this list of conditions and the following disclaimer.
83 1.1 nat * 2. Redistributions in binary form must reproduce the above copyright
84 1.1 nat * notice, this list of conditions and the following disclaimer in the
85 1.1 nat * documentation and/or other materials provided with the distribution.
86 1.1 nat * 3. Neither the name of the University nor the names of its contributors
87 1.1 nat * may be used to endorse or promote products derived from this software
88 1.1 nat * without specific prior written permission.
89 1.1 nat *
90 1.1 nat * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
91 1.1 nat * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 1.1 nat * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 1.1 nat * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
94 1.1 nat * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 1.1 nat * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 1.1 nat * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 1.1 nat * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 1.1 nat * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 1.1 nat * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 1.1 nat * SUCH DAMAGE.
101 1.1 nat *
102 1.1 nat * @(#)ms.c 8.1 (Berkeley) 6/11/93
103 1.1 nat */
104 1.1 nat
105 1.1 nat /*
106 1.1 nat * Keyboard Bell driver.
107 1.1 nat */
108 1.1 nat
109 1.1 nat #include <sys/cdefs.h>
110 1.2 pgoyette __KERNEL_RCSID(0, "$NetBSD: wsbell.c,v 1.2 2017/06/11 22:14:55 pgoyette Exp $");
111 1.1 nat
112 1.2 pgoyette #if defined(_KERNEL_OPT)
113 1.1 nat #include "wsmux.h"
114 1.2 pgoyette #endif
115 1.1 nat
116 1.1 nat #include <sys/param.h>
117 1.1 nat #include <sys/conf.h>
118 1.1 nat #include <sys/ioctl.h>
119 1.1 nat #include <sys/poll.h>
120 1.1 nat #include <sys/fcntl.h>
121 1.1 nat #include <sys/kernel.h>
122 1.1 nat #include <sys/condvar.h>
123 1.1 nat #include <sys/mutex.h>
124 1.1 nat #include <sys/kthread.h>
125 1.1 nat #include <sys/proc.h>
126 1.1 nat #include <sys/syslog.h>
127 1.1 nat #include <sys/systm.h>
128 1.1 nat #include <sys/tty.h>
129 1.1 nat #include <sys/signalvar.h>
130 1.1 nat #include <sys/device.h>
131 1.1 nat #include <sys/vnode.h>
132 1.1 nat #include <sys/callout.h>
133 1.1 nat #include <sys/malloc.h>
134 1.2 pgoyette #include <sys/module.h>
135 1.1 nat
136 1.1 nat #include <dev/wscons/wsconsio.h>
137 1.1 nat #include <dev/wscons/wsbellvar.h>
138 1.1 nat #include <dev/wscons/wsbellmuxvar.h>
139 1.1 nat #include <dev/wscons/wsbelldata.h>
140 1.1 nat
141 1.1 nat #include <dev/spkrio.h>
142 1.1 nat
143 1.2 pgoyette #include "ioconf.h"
144 1.2 pgoyette
145 1.1 nat #if defined(WSMUX_DEBUG) && NWSMUX > 0
146 1.1 nat #define DPRINTF(x) if (wsmuxdebug) printf x
147 1.1 nat #define DPRINTFN(n,x) if (wsmuxdebug > (n)) printf x
148 1.1 nat extern int wsmuxdebug;
149 1.1 nat #else
150 1.1 nat #define DPRINTF(x)
151 1.1 nat #define DPRINTFN(n,x)
152 1.1 nat #endif
153 1.1 nat
154 1.1 nat static void bell_thread(void *);
155 1.1 nat static inline void spkr_audio_play(struct wsbell_softc *, u_int, u_int, u_int);
156 1.1 nat
157 1.1 nat static int wsbell_match(device_t, cfdata_t, void *);
158 1.1 nat static void wsbell_attach(device_t, device_t, void *);
159 1.1 nat static int wsbell_detach(device_t, int);
160 1.1 nat static int wsbell_activate(device_t, enum devact);
161 1.1 nat
162 1.1 nat #if NWSMUX > 0
163 1.1 nat static int wsbell_mux_open(struct wsevsrc *, struct wseventvar *);
164 1.1 nat static int wsbell_mux_close(struct wsevsrc *);
165 1.1 nat
166 1.1 nat static int wsbelldoopen(struct wsbell_softc *, struct wseventvar *);
167 1.1 nat static int wsbelldoioctl(device_t, u_long, void *, int, struct lwp *);
168 1.1 nat
169 1.1 nat static int wsbell_do_ioctl(struct wsbell_softc *, u_long, void *,
170 1.1 nat int, struct lwp *);
171 1.1 nat
172 1.1 nat #endif
173 1.1 nat
174 1.1 nat CFATTACH_DECL_NEW(wsbell, sizeof (struct wsbell_softc),
175 1.1 nat wsbell_match, wsbell_attach, wsbell_detach, wsbell_activate);
176 1.1 nat
177 1.1 nat extern struct cfdriver wsbell_cd;
178 1.1 nat
179 1.1 nat extern dev_type_open(spkropen);
180 1.1 nat extern dev_type_close(spkrclose);
181 1.1 nat extern dev_type_ioctl(spkrioctl);
182 1.1 nat
183 1.1 nat const struct cdevsw wsbell_cdevsw = {
184 1.1 nat .d_open = noopen,
185 1.1 nat .d_close = noclose,
186 1.1 nat .d_read = noread,
187 1.1 nat .d_write = nowrite,
188 1.1 nat .d_ioctl = noioctl,
189 1.1 nat .d_stop = nostop,
190 1.1 nat .d_tty = notty,
191 1.1 nat .d_poll = nopoll,
192 1.1 nat .d_mmap = nommap,
193 1.1 nat .d_kqfilter = nokqfilter,
194 1.1 nat .d_discard = nodiscard,
195 1.1 nat .d_flag = D_OTHER
196 1.1 nat };
197 1.1 nat
198 1.1 nat #if NWSMUX > 0
199 1.1 nat struct wssrcops wsbell_srcops = {
200 1.1 nat WSMUX_BELL,
201 1.1 nat wsbell_mux_open, wsbell_mux_close, wsbelldoioctl, wsbelldoioctl, NULL
202 1.1 nat };
203 1.1 nat #endif
204 1.1 nat
205 1.1 nat int
206 1.1 nat wsbell_match(device_t parent, cfdata_t match, void *aux)
207 1.1 nat {
208 1.1 nat return (1);
209 1.1 nat }
210 1.1 nat
211 1.1 nat void
212 1.1 nat wsbell_attach(device_t parent, device_t self, void *aux)
213 1.1 nat {
214 1.1 nat struct wsbell_softc *sc = device_private(self);
215 1.1 nat struct wsbelldev_attach_args *ap = aux;
216 1.1 nat #if NWSMUX > 0
217 1.1 nat int mux, error;
218 1.1 nat #endif
219 1.1 nat
220 1.1 nat sc->sc_base.me_dv = self;
221 1.1 nat sc->sc_accesscookie = ap->accesscookie;
222 1.1 nat
223 1.1 nat sc->sc_spkr = device_unit(parent);
224 1.1 nat sc->sc_bell_data = wskbd_default_bell_data;
225 1.1 nat #if NWSMUX > 0
226 1.1 nat sc->sc_base.me_ops = &wsbell_srcops;
227 1.1 nat mux = device_cfdata(self)->wsbelldevcf_mux;
228 1.1 nat if (mux >= 0) {
229 1.1 nat error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base);
230 1.1 nat if (error)
231 1.1 nat aprint_error(" attach error=%d", error);
232 1.1 nat else
233 1.1 nat aprint_normal(" mux %d", mux);
234 1.1 nat }
235 1.1 nat #else
236 1.1 nat if (device_cfdata(self)->wsbelldevcf_mux >= 0)
237 1.1 nat aprint_normal(" (mux ignored)");
238 1.1 nat #endif
239 1.1 nat
240 1.1 nat aprint_naive("\n");
241 1.1 nat aprint_normal("\n");
242 1.1 nat
243 1.1 nat if (!pmf_device_register(self, NULL, NULL))
244 1.1 nat aprint_error_dev(self, "couldn't establish power handler\n");
245 1.1 nat
246 1.1 nat mutex_init(&sc->sc_bellock, MUTEX_DEFAULT, IPL_SCHED);
247 1.1 nat cv_init(&sc->sc_bellcv, "bellcv");
248 1.1 nat
249 1.1 nat kthread_create(PRI_BIO, KTHREAD_MPSAFE | KTHREAD_MUSTJOIN, NULL,
250 1.1 nat bell_thread, sc, &sc->sc_bellthread, "%s", device_xname(self));
251 1.1 nat }
252 1.1 nat
253 1.1 nat int
254 1.1 nat wsbell_activate(device_t self, enum devact act)
255 1.1 nat {
256 1.1 nat struct wsbell_softc *sc = device_private(self);
257 1.1 nat
258 1.1 nat if (act == DVACT_DEACTIVATE)
259 1.1 nat sc->sc_dying = 1;
260 1.1 nat return (0);
261 1.1 nat }
262 1.1 nat
263 1.1 nat int
264 1.1 nat wsbell_detach(device_t self, int flags)
265 1.1 nat {
266 1.1 nat struct wsbell_softc *sc = device_private(self);
267 1.1 nat struct wseventvar *evar;
268 1.1 nat int maj, mn;
269 1.1 nat int s;
270 1.1 nat
271 1.1 nat #if NWSMUX > 0
272 1.1 nat /* Tell parent mux we're leaving. */
273 1.1 nat if (sc->sc_base.me_parent != NULL) {
274 1.1 nat DPRINTF(("wsbell_detach:\n"));
275 1.1 nat wsmux_detach_sc(&sc->sc_base);
276 1.1 nat }
277 1.1 nat #endif
278 1.1 nat
279 1.1 nat /* If we're open ... */
280 1.1 nat evar = sc->sc_base.me_evp;
281 1.1 nat if (evar != NULL && evar->io != NULL) {
282 1.1 nat s = spltty();
283 1.1 nat if (--sc->sc_refcnt >= 0) {
284 1.1 nat struct wscons_event event;
285 1.1 nat
286 1.1 nat /* Wake everyone by generating a dummy event. */
287 1.1 nat event.type = 0;
288 1.1 nat event.value = 0;
289 1.1 nat if (wsevent_inject(evar, &event, 1) != 0)
290 1.1 nat wsevent_wakeup(evar);
291 1.1 nat
292 1.1 nat /* Wait for processes to go away. */
293 1.1 nat if (tsleep(sc, PZERO, "wsmdet", hz * 60))
294 1.1 nat printf("wsbell_detach: %s didn't detach\n",
295 1.1 nat device_xname(self));
296 1.1 nat }
297 1.1 nat splx(s);
298 1.1 nat }
299 1.1 nat
300 1.1 nat /* locate the major number */
301 1.1 nat maj = cdevsw_lookup_major(&wsbell_cdevsw);
302 1.1 nat
303 1.1 nat /* Nuke the vnodes for any open instances (calls close). */
304 1.1 nat mn = device_unit(self);
305 1.1 nat vdevgone(maj, mn, mn, VCHR);
306 1.1 nat
307 1.1 nat mutex_enter(&sc->sc_bellock);
308 1.1 nat sc->sc_bell_args.dying = true;
309 1.1 nat
310 1.1 nat cv_broadcast(&sc->sc_bellcv);
311 1.1 nat mutex_exit(&sc->sc_bellock);
312 1.1 nat
313 1.1 nat kthread_join(sc->sc_bellthread);
314 1.1 nat cv_destroy(&sc->sc_bellcv);
315 1.1 nat mutex_destroy(&sc->sc_bellock);
316 1.1 nat
317 1.1 nat return (0);
318 1.1 nat }
319 1.1 nat
320 1.1 nat #if NWSMUX > 0
321 1.1 nat int
322 1.1 nat wsbelldoopen(struct wsbell_softc *sc, struct wseventvar *evp)
323 1.1 nat {
324 1.1 nat return (0);
325 1.1 nat }
326 1.1 nat
327 1.1 nat /* A wrapper around the ioctl() workhorse to make reference counting easy. */
328 1.1 nat int
329 1.1 nat wsbelldoioctl(device_t dv, u_long cmd, void *data, int flag,
330 1.1 nat struct lwp *l)
331 1.1 nat {
332 1.1 nat struct wsbell_softc *sc = device_private(dv);
333 1.1 nat int error;
334 1.1 nat
335 1.1 nat sc->sc_refcnt++;
336 1.1 nat error = wsbell_do_ioctl(sc, cmd, data, flag, l);
337 1.1 nat if (--sc->sc_refcnt < 0)
338 1.1 nat wakeup(sc);
339 1.1 nat return (error);
340 1.1 nat }
341 1.1 nat
342 1.1 nat int
343 1.1 nat wsbell_do_ioctl(struct wsbell_softc *sc, u_long cmd, void *data,
344 1.1 nat int flag, struct lwp *l)
345 1.1 nat {
346 1.1 nat struct wskbd_bell_data *ubdp, *kbdp;
347 1.1 nat if (sc->sc_dying)
348 1.1 nat return (EIO);
349 1.1 nat
350 1.1 nat /*
351 1.1 nat * Try the wsbell specific ioctls.
352 1.1 nat */
353 1.1 nat switch (cmd) {
354 1.1 nat #define SETBELL(dstp, srcp, dfltp) \
355 1.1 nat do { \
356 1.1 nat (dstp)->pitch = ((srcp)->which & WSKBD_BELL_DOPITCH) ? \
357 1.1 nat (srcp)->pitch : (dfltp)->pitch; \
358 1.1 nat (dstp)->period = ((srcp)->which & WSKBD_BELL_DOPERIOD) ? \
359 1.1 nat (srcp)->period : (dfltp)->period; \
360 1.1 nat (dstp)->volume = ((srcp)->which & WSKBD_BELL_DOVOLUME) ? \
361 1.1 nat (srcp)->volume : (dfltp)->volume; \
362 1.1 nat (dstp)->which = WSKBD_BELL_DOALL; \
363 1.1 nat } while (0)
364 1.1 nat
365 1.1 nat case WSKBDIO_SETBELL:
366 1.1 nat if ((flag & FWRITE) == 0)
367 1.1 nat return (EACCES);
368 1.1 nat kbdp = &sc->sc_bell_data;
369 1.1 nat ubdp = (struct wskbd_bell_data *)data;
370 1.1 nat SETBELL(kbdp, ubdp, kbdp);
371 1.1 nat return (0);
372 1.1 nat
373 1.1 nat case WSKBDIO_GETBELL:
374 1.1 nat kbdp = &sc->sc_bell_data;
375 1.1 nat ubdp = (struct wskbd_bell_data *)data;
376 1.1 nat SETBELL(ubdp, kbdp, kbdp);
377 1.1 nat return (0);
378 1.1 nat
379 1.1 nat case WSKBDIO_BELL:
380 1.1 nat if ((flag & FWRITE) == 0)
381 1.1 nat return (EACCES);
382 1.1 nat spkr_audio_play(sc, sc->sc_bell_data.pitch,
383 1.1 nat sc->sc_bell_data.period, sc->sc_bell_data.volume);
384 1.1 nat
385 1.1 nat return 0;
386 1.1 nat
387 1.1 nat case WSKBDIO_COMPLEXBELL:
388 1.1 nat if ((flag & FWRITE) == 0)
389 1.1 nat return (EACCES);
390 1.1 nat if (data == NULL)
391 1.1 nat return 0;
392 1.1 nat #define d ((struct wskbd_bell_data *)data)
393 1.1 nat spkr_audio_play(sc, d->pitch, d->period, d->volume);
394 1.1 nat #undef d
395 1.1 nat return 0;
396 1.1 nat }
397 1.1 nat
398 1.1 nat return (EPASSTHROUGH);
399 1.1 nat }
400 1.1 nat #endif
401 1.1 nat
402 1.1 nat static void
403 1.1 nat bell_thread(void *arg)
404 1.1 nat {
405 1.1 nat struct wsbell_softc *sc = arg;
406 1.1 nat struct vbell_args *vb = &sc->sc_bell_args;
407 1.1 nat tone_t tone;
408 1.1 nat u_int vol;
409 1.1 nat
410 1.1 nat for (;;) {
411 1.1 nat mutex_enter(&sc->sc_bellock);
412 1.1 nat cv_wait_sig(&sc->sc_bellcv, &sc->sc_bellock);
413 1.1 nat
414 1.1 nat if (vb->dying == true) {
415 1.1 nat mutex_exit(&sc->sc_bellock);
416 1.1 nat kthread_exit(0);
417 1.1 nat }
418 1.1 nat
419 1.1 nat tone.frequency = vb->pitch;
420 1.1 nat tone.duration = vb->period;
421 1.1 nat vol = vb->volume;
422 1.1 nat mutex_exit(&sc->sc_bellock);
423 1.1 nat
424 1.1 nat if (spkropen(sc->sc_spkr, FWRITE, 0, NULL) != 0)
425 1.1 nat continue;
426 1.1 nat spkrioctl(sc->sc_spkr, SPKRSETVOL, &vol, 0, curlwp);
427 1.1 nat spkrioctl(sc->sc_spkr, SPKRTONE, &tone, 0, curlwp);
428 1.1 nat spkrclose(sc->sc_spkr, FWRITE, 0, curlwp);
429 1.1 nat }
430 1.1 nat }
431 1.1 nat
432 1.1 nat static inline void
433 1.1 nat spkr_audio_play(struct wsbell_softc *sc, u_int pitch, u_int period, u_int volume)
434 1.1 nat {
435 1.1 nat
436 1.1 nat mutex_enter(&sc->sc_bellock);
437 1.1 nat sc->sc_bell_args.dying = false;
438 1.1 nat sc->sc_bell_args.pitch = pitch;
439 1.1 nat sc->sc_bell_args.period = period / 5;
440 1.1 nat sc->sc_bell_args.volume = volume;
441 1.1 nat
442 1.1 nat cv_broadcast(&sc->sc_bellcv);
443 1.1 nat mutex_exit(&sc->sc_bellock);
444 1.1 nat }
445 1.1 nat
446 1.1 nat #if NWSMUX > 0
447 1.1 nat int
448 1.1 nat wsbell_mux_open(struct wsevsrc *me, struct wseventvar *evp)
449 1.1 nat {
450 1.1 nat struct wsbell_softc *sc = (struct wsbell_softc *)me;
451 1.1 nat
452 1.1 nat if (sc->sc_base.me_evp != NULL)
453 1.1 nat return (EBUSY);
454 1.1 nat
455 1.1 nat return wsbelldoopen(sc, evp);
456 1.1 nat }
457 1.1 nat
458 1.1 nat int
459 1.1 nat wsbell_mux_close(struct wsevsrc *me)
460 1.1 nat {
461 1.1 nat struct wsbell_softc *sc = (struct wsbell_softc *)me;
462 1.1 nat
463 1.1 nat sc->sc_base.me_evp = NULL;
464 1.1 nat
465 1.1 nat return (0);
466 1.1 nat }
467 1.1 nat #endif /* NWSMUX > 0 */
468 1.2 pgoyette
469 1.2 pgoyette MODULE(MODULE_CLASS_DRIVER, wsbell, "spkr");
470 1.2 pgoyette
471 1.2 pgoyette #ifdef _MODULE
472 1.2 pgoyette int wsbell_bmajor = -1, wsbell_cmajor = -1;
473 1.2 pgoyette
474 1.2 pgoyette #include "ioconf.c"
475 1.2 pgoyette #endif
476 1.2 pgoyette
477 1.2 pgoyette static int
478 1.2 pgoyette wsbell_modcmd(modcmd_t cmd, void *arg)
479 1.2 pgoyette {
480 1.2 pgoyette int error = 0;
481 1.2 pgoyette
482 1.2 pgoyette switch (cmd) {
483 1.2 pgoyette case MODULE_CMD_INIT:
484 1.2 pgoyette #ifdef _MODULE
485 1.2 pgoyette error = devsw_attach("wsbell", NULL, &wsbell_bmajor,
486 1.2 pgoyette &wsbell_cdevsw, &wsbell_cmajor);
487 1.2 pgoyette if (error)
488 1.2 pgoyette break;
489 1.2 pgoyette
490 1.2 pgoyette error = config_init_component(cfdriver_ioconf_wsbell,
491 1.2 pgoyette cfattach_ioconf_wsbell, cfdata_ioconf_wsbell);
492 1.2 pgoyette if (error)
493 1.2 pgoyette devsw_detach(NULL, &wsbell_cdevsw);
494 1.2 pgoyette #endif
495 1.2 pgoyette break;
496 1.2 pgoyette
497 1.2 pgoyette case MODULE_CMD_FINI:
498 1.2 pgoyette #ifdef _MODULE
499 1.2 pgoyette devsw_detach(NULL, &wsbell_cdevsw);
500 1.2 pgoyette error = config_fini_component(cfdriver_ioconf_wsbell,
501 1.2 pgoyette cfattach_ioconf_wsbell, cfdata_ioconf_wsbell);
502 1.2 pgoyette if (error)
503 1.2 pgoyette devsw_attach("wsbell", NULL, &wsbell_bmajor,
504 1.2 pgoyette &wsbell_cdevsw, &wsbell_cmajor);
505 1.2 pgoyette #endif
506 1.2 pgoyette break;
507 1.2 pgoyette
508 1.2 pgoyette default:
509 1.2 pgoyette error = ENOTTY;
510 1.2 pgoyette break;
511 1.2 pgoyette }
512 1.2 pgoyette
513 1.2 pgoyette return error;
514 1.2 pgoyette }
515