Home | History | Annotate | Line # | Download | only in dev
radio.c revision 1.11.2.5
      1  1.11.2.5     skrll /* $NetBSD: radio.c,v 1.11.2.5 2004/11/02 07:51:19 skrll 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.2  augustss #include <sys/cdefs.h>
     33  1.11.2.5     skrll __KERNEL_RCSID(0, "$NetBSD: radio.c,v 1.11.2.5 2004/11/02 07:51:19 skrll Exp $");
     34       1.2  augustss 
     35       1.1  augustss #include <sys/param.h>
     36       1.1  augustss #include <sys/systm.h>
     37       1.1  augustss #include <sys/proc.h>
     38       1.1  augustss #include <sys/errno.h>
     39       1.1  augustss #include <sys/ioctl.h>
     40       1.1  augustss #include <sys/device.h>
     41       1.2  augustss #include <sys/vnode.h>
     42       1.1  augustss #include <sys/radioio.h>
     43       1.2  augustss #include <sys/conf.h>
     44       1.1  augustss 
     45       1.1  augustss #include <dev/radio_if.h>
     46       1.1  augustss #include <dev/radiovar.h>
     47       1.1  augustss 
     48       1.1  augustss int	radioprobe(struct device *, struct cfdata *, void *);
     49       1.1  augustss void	radioattach(struct device *, struct device *, void *);
     50       1.1  augustss int	radioprint(void *, const char *);
     51       1.2  augustss int	radiodetach(struct device *, int);
     52       1.2  augustss int	radioactivate(struct device *, enum devact);
     53       1.1  augustss 
     54       1.6   thorpej CFATTACH_DECL(radio, sizeof(struct radio_softc),
     55       1.7   thorpej     radioprobe, radioattach, radiodetach, radioactivate);
     56       1.1  augustss 
     57       1.4   gehenna dev_type_open(radioopen);
     58       1.4   gehenna dev_type_close(radioclose);
     59       1.4   gehenna dev_type_ioctl(radioioctl);
     60       1.4   gehenna 
     61       1.4   gehenna const struct cdevsw radio_cdevsw = {
     62       1.4   gehenna 	radioopen, radioclose, noread, nowrite, radioioctl,
     63       1.8  jdolecek 	nostop, notty, nopoll, nommap, nokqfilter,
     64       1.4   gehenna };
     65       1.4   gehenna 
     66       1.1  augustss extern struct cfdriver radio_cd;
     67       1.1  augustss 
     68       1.1  augustss int
     69       1.1  augustss radioprobe(struct device *parent, struct cfdata *match, void *aux)
     70       1.1  augustss {
     71       1.1  augustss 	return (1);
     72       1.1  augustss }
     73       1.1  augustss 
     74       1.1  augustss void
     75       1.1  augustss radioattach(struct device *parent, struct device *self, void *aux)
     76       1.1  augustss {
     77       1.1  augustss 	struct radio_softc *sc = (void *)self;
     78       1.1  augustss 	struct radio_attach_args *sa = aux;
     79  1.11.2.5     skrll 	const struct radio_hw_if *hwp = sa->hwif;
     80       1.1  augustss 	void  *hdlp = sa->hdl;
     81       1.1  augustss 
     82       1.1  augustss 	printf("\n");
     83       1.1  augustss 	sc->hw_if = hwp;
     84       1.1  augustss 	sc->hw_hdl = hdlp;
     85       1.1  augustss 	sc->sc_dev = parent;
     86       1.1  augustss }
     87       1.1  augustss 
     88       1.1  augustss int
     89  1.11.2.4     skrll radioopen(dev_t dev, int flags, int fmt, struct lwp *l)
     90       1.1  augustss {
     91       1.1  augustss 	int	unit;
     92       1.1  augustss 	struct radio_softc *sc;
     93       1.1  augustss 
     94       1.1  augustss 	unit = RADIOUNIT(dev);
     95       1.1  augustss 	if (unit >= radio_cd.cd_ndevs ||
     96       1.1  augustss 	    (sc = radio_cd.cd_devs[unit]) == NULL ||
     97       1.1  augustss 	     sc->hw_if == NULL)
     98       1.1  augustss 		return (ENXIO);
     99       1.1  augustss 
    100       1.1  augustss 	if (sc->hw_if->open != NULL)
    101  1.11.2.4     skrll 		return (sc->hw_if->open(sc->hw_hdl, flags, fmt, l->l_proc));
    102       1.1  augustss 	else
    103       1.1  augustss 		return (0);
    104       1.1  augustss }
    105       1.1  augustss 
    106       1.1  augustss int
    107  1.11.2.4     skrll radioclose(dev_t dev, int flags, int fmt, struct lwp *l)
    108       1.1  augustss {
    109       1.1  augustss 	struct radio_softc *sc;
    110       1.1  augustss 
    111       1.1  augustss 	sc = radio_cd.cd_devs[RADIOUNIT(dev)];
    112       1.1  augustss 
    113       1.1  augustss 	if (sc->hw_if->close != NULL)
    114  1.11.2.4     skrll 		return (sc->hw_if->close(sc->hw_hdl, flags, fmt, l->l_proc));
    115       1.1  augustss 	else
    116       1.1  augustss 		return (0);
    117       1.1  augustss }
    118       1.1  augustss 
    119       1.1  augustss int
    120  1.11.2.4     skrll radioioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct lwp *l)
    121       1.1  augustss {
    122       1.1  augustss 	struct radio_softc *sc;
    123       1.1  augustss 	int unit, error;
    124       1.1  augustss 
    125       1.1  augustss 	unit = RADIOUNIT(dev);
    126       1.1  augustss 	if (unit >= radio_cd.cd_ndevs ||
    127       1.1  augustss 	    (sc = radio_cd.cd_devs[unit]) == NULL || sc->hw_if == NULL)
    128       1.1  augustss 		return (ENXIO);
    129       1.1  augustss 
    130       1.1  augustss 	error = EOPNOTSUPP;
    131       1.1  augustss 	switch (cmd) {
    132       1.1  augustss 	case RIOCGINFO:
    133       1.1  augustss 		if (sc->hw_if->get_info)
    134       1.1  augustss 			error = (sc->hw_if->get_info)(sc->hw_hdl,
    135       1.1  augustss 					(struct radio_info *)data);
    136       1.1  augustss 			break;
    137       1.1  augustss 	case RIOCSINFO:
    138       1.1  augustss 		if (sc->hw_if->set_info)
    139       1.1  augustss 			error = (sc->hw_if->set_info)(sc->hw_hdl,
    140       1.1  augustss 				(struct radio_info *)data);
    141       1.1  augustss 		break;
    142       1.1  augustss 	case RIOCSSRCH:
    143       1.1  augustss 		if (sc->hw_if->search)
    144       1.1  augustss 			error = (sc->hw_if->search)(sc->hw_hdl,
    145       1.1  augustss 					*(int *)data);
    146       1.1  augustss 		break;
    147       1.1  augustss 	default:
    148       1.1  augustss 		error = EINVAL;
    149       1.1  augustss 	}
    150       1.1  augustss 
    151       1.1  augustss 	return (error);
    152       1.1  augustss }
    153       1.1  augustss 
    154       1.1  augustss /*
    155       1.1  augustss  * Called from hardware driver. This is where the MI radio driver gets
    156       1.1  augustss  * probed/attached to the hardware driver
    157       1.1  augustss  */
    158       1.2  augustss struct device *
    159  1.11.2.5     skrll radio_attach_mi(const struct radio_hw_if *rhwp, void *hdlp, struct device *dev)
    160       1.1  augustss {
    161       1.1  augustss 	struct radio_attach_args arg;
    162       1.1  augustss 
    163       1.1  augustss 	arg.hwif = rhwp;
    164       1.1  augustss 	arg.hdl = hdlp;
    165       1.1  augustss 	return (config_found(dev, &arg, radioprint));
    166       1.1  augustss }
    167       1.1  augustss 
    168       1.1  augustss int
    169       1.1  augustss radioprint(void *aux, const char *pnp)
    170       1.1  augustss {
    171       1.2  augustss 	if (pnp != NULL)
    172       1.9   thorpej 		aprint_normal("radio at %s", pnp);
    173       1.2  augustss 	return (UNCONF);
    174       1.2  augustss }
    175       1.2  augustss 
    176       1.2  augustss int
    177       1.2  augustss radiodetach(struct device *self, int flags)
    178       1.2  augustss {
    179       1.2  augustss 	/*struct radio_softc *sc = (struct radio_softc *)self;*/
    180       1.2  augustss 	int maj, mn;
    181       1.2  augustss 
    182       1.2  augustss 	/* locate the major number */
    183       1.4   gehenna 	maj = cdevsw_lookup_major(&radio_cdevsw);
    184       1.2  augustss 
    185       1.2  augustss 	/* Nuke the vnodes for any open instances (calls close). */
    186       1.2  augustss 	mn = self->dv_unit;
    187       1.2  augustss 	vdevgone(maj, mn, mn, VCHR);
    188       1.2  augustss 
    189       1.2  augustss 	return (0);
    190       1.2  augustss }
    191       1.2  augustss 
    192       1.2  augustss int
    193       1.2  augustss radioactivate(struct device *self, enum devact act)
    194       1.2  augustss {
    195       1.2  augustss 	struct radio_softc *sc = (struct radio_softc *)self;
    196       1.2  augustss 
    197       1.2  augustss 	switch (act) {
    198       1.2  augustss 	case DVACT_ACTIVATE:
    199       1.2  augustss 		return (EOPNOTSUPP);
    200       1.2  augustss 
    201       1.2  augustss 	case DVACT_DEACTIVATE:
    202       1.2  augustss 		sc->sc_dying = 1;
    203       1.2  augustss 		break;
    204       1.2  augustss 	}
    205       1.2  augustss 	return (0);
    206       1.1  augustss }
    207