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