/* $NetBSD: spkr_pcppi.c,v 1.4 2016/12/09 05:17:03 christos Exp $ */ /* * Copyright (c) 1990 Eric S. Raymond (esr@snark.thyrsus.com) * Copyright (c) 1990 Andrew A. Chernov (ache@astral.msk.su) * Copyright (c) 1990 Lennart Augustsson (lennart@augustsson.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Eric S. Raymond * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * spkr.c -- device driver for console speaker on 80386 * * v1.1 by Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990 * modified for 386bsd by Andrew A. Chernov * 386bsd only clean version, all SYSV stuff removed * use hz value from param.c */ #include __KERNEL_RCSID(0, "$NetBSD: spkr_pcppi.c,v 1.4 2016/12/09 05:17:03 christos Exp $"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern int spkr_attached; static void spkrattach(device_t, device_t, void *); static int spkrdetach(device_t, int); #include "ioconf.h" MODULE(MODULE_CLASS_DRIVER, spkr, NULL /* "pcppi" */); static int spkr_modcmd(modcmd_t cmd, void *arg) { return spkr__modcmd(cmd, arg); } CFATTACH_DECL_NEW(spkr_pcppi, 0, spkr_probe, spkrattach, spkrdetach, NULL); static pcppi_tag_t ppicookie; #define SPKRPRI (PZERO - 1) void spkr_tone(u_int xhz, u_int ticks) /* emit tone of frequency hz for given number of ticks */ { pcppi_bell(ppicookie, xhz, ticks, PCPPI_BELL_SLEEP); } void spkr_rest(int ticks) /* rest for given number of ticks */ { /* * Set timeout to endrest function, then give up the timeslice. * This is so other processes can execute while the rest is being * waited out. */ #ifdef SPKRDEBUG printf("%s: %d\n", __func__, ticks); #endif /* SPKRDEBUG */ if (ticks > 0) tsleep(spkr_rest, SPKRPRI | PCATCH, "rest", ticks); } static void spkrattach(device_t parent, device_t self, void *aux) { aprint_naive("\n"); aprint_normal("\n"); ppicookie = ((struct pcppi_attach_args *)aux)->pa_cookie; spkr_attached = 1; if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); } static int spkrdetach(device_t self, int flags) { pmf_device_deregister(self); spkr_attached = 0; ppicookie = NULL; return 0; }