Home | History | Annotate | Line # | Download | only in isa
      1  1.14   thorpej /*	$NetBSD: spkr_pcppi.c,v 1.14 2022/09/25 17:09:36 thorpej Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*
      4   1.1  christos  * Copyright (c) 1990 Eric S. Raymond (esr (at) snark.thyrsus.com)
      5   1.1  christos  * Copyright (c) 1990 Andrew A. Chernov (ache (at) astral.msk.su)
      6   1.1  christos  * Copyright (c) 1990 Lennart Augustsson (lennart (at) augustsson.net)
      7   1.1  christos  * All rights reserved.
      8   1.1  christos  *
      9   1.1  christos  * Redistribution and use in source and binary forms, with or without
     10   1.1  christos  * modification, are permitted provided that the following conditions
     11   1.1  christos  * are met:
     12   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     13   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     14   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     16   1.1  christos  *    documentation and/or other materials provided with the distribution.
     17   1.1  christos  * 3. All advertising materials mentioning features or use of this software
     18   1.1  christos  *    must display the following acknowledgement:
     19   1.1  christos  *	This product includes software developed by Eric S. Raymond
     20   1.1  christos  * 4. The name of the author may not be used to endorse or promote products
     21   1.1  christos  *    derived from this software without specific prior written permission.
     22   1.1  christos  *
     23   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24   1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     25   1.1  christos  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     26   1.1  christos  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     27   1.1  christos  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28   1.1  christos  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29   1.1  christos  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     31   1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     32   1.1  christos  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33   1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     34   1.1  christos  */
     35   1.1  christos 
     36   1.1  christos /*
     37   1.1  christos  * spkr.c -- device driver for console speaker on 80386
     38   1.1  christos  *
     39   1.1  christos  * v1.1 by Eric S. Raymond (esr (at) snark.thyrsus.com) Feb 1990
     40   1.1  christos  *      modified for 386bsd by Andrew A. Chernov <ache (at) astral.msk.su>
     41   1.1  christos  *      386bsd only clean version, all SYSV stuff removed
     42   1.1  christos  *      use hz value from param.c
     43   1.1  christos  */
     44   1.1  christos 
     45   1.1  christos #include <sys/cdefs.h>
     46  1.14   thorpej __KERNEL_RCSID(0, "$NetBSD: spkr_pcppi.c,v 1.14 2022/09/25 17:09:36 thorpej Exp $");
     47   1.1  christos 
     48   1.1  christos #include <sys/param.h>
     49   1.1  christos #include <sys/systm.h>
     50   1.1  christos #include <sys/kernel.h>
     51   1.1  christos #include <sys/errno.h>
     52   1.1  christos #include <sys/device.h>
     53   1.1  christos #include <sys/uio.h>
     54   1.1  christos #include <sys/proc.h>
     55   1.1  christos #include <sys/ioctl.h>
     56   1.1  christos #include <sys/conf.h>
     57   1.1  christos 
     58   1.1  christos #include <sys/bus.h>
     59   1.1  christos 
     60   1.1  christos #include <dev/isa/pcppivar.h>
     61   1.1  christos 
     62   1.3  christos #include <dev/spkrvar.h>
     63   1.2  christos #include <dev/spkrio.h>
     64   1.1  christos 
     65   1.5  christos struct spkr_pcppi_softc {
     66   1.6  christos 	struct spkr_softc sc_spkr;
     67   1.5  christos 	pcppi_tag_t sc_pcppicookie;
     68  1.11  pgoyette 	void (*sc_bell_func)(pcppi_tag_t, int, int, int);
     69   1.5  christos };
     70   1.5  christos 
     71   1.5  christos static int spkr_pcppi_probe(device_t, cfdata_t, void *);
     72   1.5  christos static void spkr_pcppi_attach(device_t, device_t, void *);
     73   1.5  christos static int spkr_pcppi_detach(device_t, int);
     74  1.10  pgoyette static int spkr_pcppi_rescan(device_t, const char *, const int *);
     75  1.10  pgoyette static void spkr_pcppi_childdet(device_t, device_t);
     76   1.1  christos 
     77  1.10  pgoyette CFATTACH_DECL3_NEW(spkr_pcppi, sizeof(struct spkr_pcppi_softc),
     78  1.10  pgoyette     spkr_pcppi_probe, spkr_pcppi_attach, spkr_pcppi_detach, NULL,
     79  1.10  pgoyette     spkr_pcppi_rescan, spkr_pcppi_childdet, 0);
     80   1.1  christos 
     81   1.1  christos /* emit tone of frequency hz for given number of ticks */
     82   1.5  christos static void
     83   1.5  christos spkr_pcppi_tone(device_t self, u_int xhz, u_int ticks)
     84   1.1  christos {
     85   1.5  christos #ifdef SPKRDEBUG
     86  1.12     isaki 	device_printf(self, "%s: %u %u\n", __func__, xhz, ticks);
     87   1.5  christos #endif /* SPKRDEBUG */
     88   1.5  christos 	struct spkr_pcppi_softc *sc = device_private(self);
     89  1.11  pgoyette 	(*sc->sc_bell_func)(sc->sc_pcppicookie, xhz, ticks, PCPPI_BELL_SLEEP);
     90   1.1  christos }
     91   1.1  christos 
     92   1.5  christos static int
     93   1.5  christos spkr_pcppi_probe(device_t parent, cfdata_t cf, void *aux)
     94   1.5  christos {
     95   1.5  christos 	return 1;
     96   1.1  christos }
     97   1.1  christos 
     98   1.2  christos static void
     99   1.5  christos spkr_pcppi_attach(device_t parent, device_t self, void *aux)
    100   1.1  christos {
    101   1.5  christos 	struct pcppi_attach_args *pa = aux;
    102   1.5  christos 	struct spkr_pcppi_softc *sc = device_private(self);
    103   1.5  christos 
    104   1.1  christos 	aprint_naive("\n");
    105   1.7  christos 	aprint_normal(": PC Speaker\n");
    106   1.5  christos 
    107   1.5  christos 	sc->sc_pcppicookie = pa->pa_cookie;
    108  1.11  pgoyette 	sc->sc_bell_func = pa->pa_bell_func;
    109  1.13     isaki 	spkr_attach(self, spkr_pcppi_tone);
    110   1.1  christos 	if (!pmf_device_register(self, NULL, NULL))
    111   1.1  christos 		aprint_error_dev(self, "couldn't establish power handler\n");
    112   1.1  christos }
    113   1.1  christos 
    114   1.2  christos static int
    115   1.5  christos spkr_pcppi_detach(device_t self, int flags)
    116   1.1  christos {
    117   1.5  christos 	struct spkr_pcppi_softc *sc = device_private(self);
    118   1.9  pgoyette 	int error;
    119   1.9  pgoyette 
    120   1.9  pgoyette 	if ((error = spkr_detach(self, flags)) != 0)
    121   1.9  pgoyette 		return error;
    122   1.1  christos 
    123   1.5  christos 	sc->sc_pcppicookie = NULL;
    124   1.1  christos 	pmf_device_deregister(self);
    125   1.1  christos 	return 0;
    126   1.1  christos }
    127  1.10  pgoyette 
    128  1.10  pgoyette static int
    129  1.10  pgoyette spkr_pcppi_rescan(device_t self, const char *iattr, const int *locators)
    130  1.10  pgoyette {
    131  1.10  pgoyette 
    132  1.10  pgoyette 	return spkr_rescan(self, iattr, locators);
    133  1.10  pgoyette }
    134  1.10  pgoyette 
    135  1.10  pgoyette static void
    136  1.10  pgoyette spkr_pcppi_childdet(device_t self, device_t child)
    137  1.10  pgoyette {
    138  1.10  pgoyette 
    139  1.10  pgoyette 	spkr_childdet(self, child);
    140  1.10  pgoyette }
    141