Home | History | Annotate | Line # | Download | only in dev
radio.c revision 1.1
      1  1.1  augustss /* $NetBSD: radio.c,v 1.1 2002/01/01 21:51:38 augustss Exp $ */
      2  1.1  augustss /* $OpenBSD: radio.c,v 1.2 2001/12/05 10:27:06 mickey Exp $ */
      3  1.1  augustss /* $RuOBSD: radio.c,v 1.7 2001/12/04 06:03:05 tm Exp $ */
      4  1.1  augustss 
      5  1.1  augustss /*
      6  1.1  augustss  * Copyright (c) 2001 Maxim Tsyplakov <tm (at) oganer.net>
      7  1.1  augustss  * All rights reserved.
      8  1.1  augustss  *
      9  1.1  augustss  * Redistribution and use in source and binary forms, with or without
     10  1.1  augustss  * modification, are permitted provided that the following conditions
     11  1.1  augustss  * are met:
     12  1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     13  1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     14  1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  augustss  *    documentation and/or other materials provided with the distribution.
     17  1.1  augustss  *
     18  1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  augustss  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  augustss  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  augustss  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     22  1.1  augustss  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     23  1.1  augustss  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     24  1.1  augustss  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     25  1.1  augustss  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     26  1.1  augustss  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     27  1.1  augustss  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  augustss  */
     29  1.1  augustss 
     30  1.1  augustss /* This is the /dev/radio driver from OpenBSD */
     31  1.1  augustss 
     32  1.1  augustss #include <sys/param.h>
     33  1.1  augustss #include <sys/systm.h>
     34  1.1  augustss #include <sys/proc.h>
     35  1.1  augustss #include <sys/errno.h>
     36  1.1  augustss #include <sys/ioctl.h>
     37  1.1  augustss #include <sys/device.h>
     38  1.1  augustss #include <sys/radioio.h>
     39  1.1  augustss 
     40  1.1  augustss #include <dev/radio_if.h>
     41  1.1  augustss #include <dev/radiovar.h>
     42  1.1  augustss 
     43  1.1  augustss int	radioprobe(struct device *, struct cfdata *, void *);
     44  1.1  augustss void	radioattach(struct device *, struct device *, void *);
     45  1.1  augustss int	radioopen(dev_t, int, int, struct proc *);
     46  1.1  augustss int	radioclose(dev_t, int, int, struct proc *);
     47  1.1  augustss int	radioioctl(dev_t, u_long, caddr_t, int, struct proc *);
     48  1.1  augustss int	radioprint(void *, const char *);
     49  1.1  augustss 
     50  1.1  augustss struct cfattach radio_ca = {
     51  1.1  augustss 	sizeof(struct radio_softc), radioprobe, radioattach,
     52  1.1  augustss 	NULL, NULL
     53  1.1  augustss };
     54  1.1  augustss 
     55  1.1  augustss extern struct cfdriver radio_cd;
     56  1.1  augustss 
     57  1.1  augustss int
     58  1.1  augustss radioprobe(struct device *parent, struct cfdata *match, void *aux)
     59  1.1  augustss {
     60  1.1  augustss 	return (1);
     61  1.1  augustss }
     62  1.1  augustss 
     63  1.1  augustss void
     64  1.1  augustss radioattach(struct device *parent, struct device *self, void *aux)
     65  1.1  augustss {
     66  1.1  augustss 	struct radio_softc *sc = (void *)self;
     67  1.1  augustss 	struct radio_attach_args *sa = aux;
     68  1.1  augustss 	struct radio_hw_if *hwp = sa->hwif;
     69  1.1  augustss 	void  *hdlp = sa->hdl;
     70  1.1  augustss 
     71  1.1  augustss 	printf("\n");
     72  1.1  augustss 	sc->hw_if = hwp;
     73  1.1  augustss 	sc->hw_hdl = hdlp;
     74  1.1  augustss 	sc->sc_dev = parent;
     75  1.1  augustss }
     76  1.1  augustss 
     77  1.1  augustss int
     78  1.1  augustss radioopen(dev_t dev, int flags, int fmt, struct proc *p)
     79  1.1  augustss {
     80  1.1  augustss 	int	unit;
     81  1.1  augustss 	struct radio_softc *sc;
     82  1.1  augustss 
     83  1.1  augustss 	unit = RADIOUNIT(dev);
     84  1.1  augustss 	if (unit >= radio_cd.cd_ndevs ||
     85  1.1  augustss 	    (sc = radio_cd.cd_devs[unit]) == NULL ||
     86  1.1  augustss 	     sc->hw_if == NULL)
     87  1.1  augustss 		return (ENXIO);
     88  1.1  augustss 
     89  1.1  augustss 	if (sc->hw_if->open != NULL)
     90  1.1  augustss 		return (sc->hw_if->open(sc->hw_hdl, flags, fmt, p));
     91  1.1  augustss 	else
     92  1.1  augustss 		return (0);
     93  1.1  augustss }
     94  1.1  augustss 
     95  1.1  augustss int
     96  1.1  augustss radioclose(dev_t dev, int flags, int fmt, struct proc *p)
     97  1.1  augustss {
     98  1.1  augustss 	struct radio_softc *sc;
     99  1.1  augustss 
    100  1.1  augustss 	sc = radio_cd.cd_devs[RADIOUNIT(dev)];
    101  1.1  augustss 
    102  1.1  augustss 	if (sc->hw_if->close != NULL)
    103  1.1  augustss 		return (sc->hw_if->close(sc->hw_hdl, flags, fmt, p));
    104  1.1  augustss 	else
    105  1.1  augustss 		return (0);
    106  1.1  augustss }
    107  1.1  augustss 
    108  1.1  augustss int
    109  1.1  augustss radioioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
    110  1.1  augustss {
    111  1.1  augustss 	struct radio_softc *sc;
    112  1.1  augustss 	int unit, error;
    113  1.1  augustss 
    114  1.1  augustss 	unit = RADIOUNIT(dev);
    115  1.1  augustss 	if (unit >= radio_cd.cd_ndevs ||
    116  1.1  augustss 	    (sc = radio_cd.cd_devs[unit]) == NULL || sc->hw_if == NULL)
    117  1.1  augustss 		return (ENXIO);
    118  1.1  augustss 
    119  1.1  augustss 	error = EOPNOTSUPP;
    120  1.1  augustss 	switch (cmd) {
    121  1.1  augustss 	case RIOCGINFO:
    122  1.1  augustss 		if (sc->hw_if->get_info)
    123  1.1  augustss 			error = (sc->hw_if->get_info)(sc->hw_hdl,
    124  1.1  augustss 					(struct radio_info *)data);
    125  1.1  augustss 			break;
    126  1.1  augustss 	case RIOCSINFO:
    127  1.1  augustss 		if (sc->hw_if->set_info)
    128  1.1  augustss 			error = (sc->hw_if->set_info)(sc->hw_hdl,
    129  1.1  augustss 				(struct radio_info *)data);
    130  1.1  augustss 		break;
    131  1.1  augustss 	case RIOCSSRCH:
    132  1.1  augustss 		if (sc->hw_if->search)
    133  1.1  augustss 			error = (sc->hw_if->search)(sc->hw_hdl,
    134  1.1  augustss 					*(int *)data);
    135  1.1  augustss 		break;
    136  1.1  augustss 	default:
    137  1.1  augustss 		error = EINVAL;
    138  1.1  augustss 	}
    139  1.1  augustss 
    140  1.1  augustss 	return (error);
    141  1.1  augustss }
    142  1.1  augustss 
    143  1.1  augustss /*
    144  1.1  augustss  * Called from hardware driver. This is where the MI radio driver gets
    145  1.1  augustss  * probed/attached to the hardware driver
    146  1.1  augustss  */
    147  1.1  augustss struct device  *
    148  1.1  augustss radio_attach_mi(struct radio_hw_if *rhwp, void *hdlp, struct device *dev)
    149  1.1  augustss {
    150  1.1  augustss 	struct radio_attach_args arg;
    151  1.1  augustss 
    152  1.1  augustss 	arg.hwif = rhwp;
    153  1.1  augustss 	arg.hdl = hdlp;
    154  1.1  augustss 	return (config_found(dev, &arg, radioprint));
    155  1.1  augustss }
    156  1.1  augustss 
    157  1.1  augustss int
    158  1.1  augustss radioprint(void *aux, const char *pnp)
    159  1.1  augustss {
    160  1.1  augustss 	return UNCONF;
    161  1.1  augustss }
    162