bktr_os.c revision 1.14.2.2 1 1.14.2.2 bouyer /* $NetBSD: bktr_os.c,v 1.14.2.2 2000/11/20 22:35:47 bouyer Exp $ */
2 1.14.2.2 bouyer
3 1.14.2.2 bouyer /* FreeBSD: src/sys/dev/bktr/bktr_os.c,v 1.10 2000/06/28 15:09:12 roger Exp */
4 1.14.2.2 bouyer
5 1.14.2.2 bouyer /*
6 1.14.2.2 bouyer * This is part of the Driver for Video Capture Cards (Frame grabbers)
7 1.14.2.2 bouyer * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
8 1.14.2.2 bouyer * chipset.
9 1.14.2.2 bouyer * Copyright Roger Hardiman and Amancio Hasty.
10 1.14.2.2 bouyer *
11 1.14.2.2 bouyer * bktr_os : This has all the Operating System dependant code,
12 1.14.2.2 bouyer * probe/attach and open/close/ioctl/read/mmap
13 1.14.2.2 bouyer * memory allocation
14 1.14.2.2 bouyer * PCI bus interfacing
15 1.14.2.2 bouyer *
16 1.14.2.2 bouyer *
17 1.14.2.2 bouyer */
18 1.14.2.2 bouyer
19 1.14.2.2 bouyer /*
20 1.14.2.2 bouyer * 1. Redistributions of source code must retain the
21 1.14.2.2 bouyer * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
22 1.14.2.2 bouyer * All rights reserved.
23 1.14.2.2 bouyer *
24 1.14.2.2 bouyer * Redistribution and use in source and binary forms, with or without
25 1.14.2.2 bouyer * modification, are permitted provided that the following conditions
26 1.14.2.2 bouyer * are met:
27 1.14.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
28 1.14.2.2 bouyer * notice, this list of conditions and the following disclaimer.
29 1.14.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
30 1.14.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
31 1.14.2.2 bouyer * documentation and/or other materials provided with the distribution.
32 1.14.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
33 1.14.2.2 bouyer * must display the following acknowledgement:
34 1.14.2.2 bouyer * This product includes software developed by Amancio Hasty and
35 1.14.2.2 bouyer * Roger Hardiman
36 1.14.2.2 bouyer * 4. The name of the author may not be used to endorse or promote products
37 1.14.2.2 bouyer * derived from this software without specific prior written permission.
38 1.14.2.2 bouyer *
39 1.14.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
40 1.14.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41 1.14.2.2 bouyer * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42 1.14.2.2 bouyer * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
43 1.14.2.2 bouyer * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
44 1.14.2.2 bouyer * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45 1.14.2.2 bouyer * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 1.14.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 1.14.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48 1.14.2.2 bouyer * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 1.14.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
50 1.14.2.2 bouyer */
51 1.14.2.2 bouyer
52 1.14.2.2 bouyer
53 1.14.2.2 bouyer #ifdef __FreeBSD__
54 1.14.2.2 bouyer #include "bktr.h"
55 1.14.2.2 bouyer #include "opt_devfs.h"
56 1.14.2.2 bouyer #endif /* __FreeBSD__ */
57 1.14.2.2 bouyer
58 1.14.2.2 bouyer #include "opt_bktr.h" /* include any kernel config options */
59 1.14.2.2 bouyer
60 1.14.2.2 bouyer #define FIFO_RISC_DISABLED 0
61 1.14.2.2 bouyer #define ALL_INTS_DISABLED 0
62 1.14.2.2 bouyer
63 1.14.2.2 bouyer
64 1.14.2.2 bouyer /*******************/
65 1.14.2.2 bouyer /* *** FreeBSD *** */
66 1.14.2.2 bouyer /*******************/
67 1.14.2.2 bouyer #ifdef __FreeBSD__
68 1.14.2.2 bouyer
69 1.14.2.2 bouyer #include <sys/param.h>
70 1.14.2.2 bouyer #include <sys/systm.h>
71 1.14.2.2 bouyer #include <sys/conf.h>
72 1.14.2.2 bouyer #include <sys/uio.h>
73 1.14.2.2 bouyer #include <sys/kernel.h>
74 1.14.2.2 bouyer #include <sys/signalvar.h>
75 1.14.2.2 bouyer #include <sys/mman.h>
76 1.14.2.2 bouyer #include <sys/poll.h>
77 1.14.2.2 bouyer #include <sys/select.h>
78 1.14.2.2 bouyer #include <sys/vnode.h>
79 1.14.2.2 bouyer
80 1.14.2.2 bouyer #include <vm/vm.h>
81 1.14.2.2 bouyer #include <vm/vm_kern.h>
82 1.14.2.2 bouyer #include <vm/pmap.h>
83 1.14.2.2 bouyer #include <vm/vm_extern.h>
84 1.14.2.2 bouyer
85 1.14.2.2 bouyer #if (__FreeBSD_version < 400000)
86 1.14.2.2 bouyer #ifdef DEVFS
87 1.14.2.2 bouyer #include <sys/devfsext.h>
88 1.14.2.2 bouyer #endif /* DEVFS */
89 1.14.2.2 bouyer #endif
90 1.14.2.2 bouyer
91 1.14.2.2 bouyer #if (__FreeBSD_version >=400000) || (NSMBUS > 0)
92 1.14.2.2 bouyer #include <sys/bus.h> /* used by smbus and newbus */
93 1.14.2.2 bouyer #endif
94 1.14.2.2 bouyer
95 1.14.2.2 bouyer #if (__FreeBSD_version >=300000)
96 1.14.2.2 bouyer #include <machine/bus_memio.h> /* used by bus space */
97 1.14.2.2 bouyer #include <machine/bus.h> /* used by bus space and newbus */
98 1.14.2.2 bouyer #include <sys/bus.h>
99 1.14.2.2 bouyer #endif
100 1.14.2.2 bouyer
101 1.14.2.2 bouyer #if (__FreeBSD_version >=400000)
102 1.14.2.2 bouyer #include <sys/rman.h> /* used by newbus */
103 1.14.2.2 bouyer #include <machine/resource.h> /* used by newbus */
104 1.14.2.2 bouyer #endif
105 1.14.2.2 bouyer
106 1.14.2.2 bouyer
107 1.14.2.2 bouyer #include <machine/clock.h> /* for DELAY */
108 1.14.2.2 bouyer #include <pci/pcivar.h>
109 1.14.2.2 bouyer #include <pci/pcireg.h>
110 1.14.2.2 bouyer
111 1.14.2.2 bouyer #if (NSMBUS > 0)
112 1.14.2.2 bouyer #include <dev/bktr/bktr_i2c.h>
113 1.14.2.2 bouyer #endif
114 1.14.2.2 bouyer
115 1.14.2.2 bouyer #include <sys/sysctl.h>
116 1.14.2.2 bouyer int bt848_card = -1;
117 1.14.2.2 bouyer int bt848_tuner = -1;
118 1.14.2.2 bouyer int bt848_reverse_mute = -1;
119 1.14.2.2 bouyer int bt848_format = -1;
120 1.14.2.2 bouyer int bt848_slow_msp_audio = -1;
121 1.14.2.2 bouyer
122 1.14.2.2 bouyer SYSCTL_NODE(_hw, OID_AUTO, bt848, CTLFLAG_RW, 0, "Bt848 Driver mgmt");
123 1.14.2.2 bouyer SYSCTL_INT(_hw_bt848, OID_AUTO, card, CTLFLAG_RW, &bt848_card, -1, "");
124 1.14.2.2 bouyer SYSCTL_INT(_hw_bt848, OID_AUTO, tuner, CTLFLAG_RW, &bt848_tuner, -1, "");
125 1.14.2.2 bouyer SYSCTL_INT(_hw_bt848, OID_AUTO, reverse_mute, CTLFLAG_RW, &bt848_reverse_mute, -1, "");
126 1.14.2.2 bouyer SYSCTL_INT(_hw_bt848, OID_AUTO, format, CTLFLAG_RW, &bt848_format, -1, "");
127 1.14.2.2 bouyer SYSCTL_INT(_hw_bt848, OID_AUTO, slow_msp_audio, CTLFLAG_RW, &bt848_slow_msp_audio, -1, "");
128 1.14.2.2 bouyer
129 1.14.2.2 bouyer #if (__FreeBSD__ == 2)
130 1.14.2.2 bouyer #define PCIR_REVID PCI_CLASS_REG
131 1.14.2.2 bouyer #endif
132 1.14.2.2 bouyer
133 1.14.2.2 bouyer #endif /* end freebsd section */
134 1.14.2.2 bouyer
135 1.14.2.2 bouyer
136 1.14.2.2 bouyer
137 1.14.2.2 bouyer /****************/
138 1.14.2.2 bouyer /* *** BSDI *** */
139 1.14.2.2 bouyer /****************/
140 1.14.2.2 bouyer #ifdef __bsdi__
141 1.14.2.2 bouyer #endif /* __bsdi__ */
142 1.14.2.2 bouyer
143 1.14.2.2 bouyer
144 1.14.2.2 bouyer /**************************/
145 1.14.2.2 bouyer /* *** OpenBSD/NetBSD *** */
146 1.14.2.2 bouyer /**************************/
147 1.14.2.2 bouyer #if defined(__NetBSD__) || defined(__OpenBSD__)
148 1.14.2.2 bouyer
149 1.14.2.2 bouyer #include <sys/param.h>
150 1.14.2.2 bouyer #include <sys/systm.h>
151 1.14.2.2 bouyer #include <sys/conf.h>
152 1.14.2.2 bouyer #include <sys/uio.h>
153 1.14.2.2 bouyer #include <sys/kernel.h>
154 1.14.2.2 bouyer #include <sys/signalvar.h>
155 1.14.2.2 bouyer #include <sys/mman.h>
156 1.14.2.2 bouyer #include <sys/poll.h>
157 1.14.2.2 bouyer #include <sys/select.h>
158 1.14.2.2 bouyer #include <sys/vnode.h>
159 1.14.2.2 bouyer
160 1.14.2.2 bouyer #ifndef __NetBSD__
161 1.14.2.2 bouyer #include <vm/vm.h>
162 1.14.2.2 bouyer #include <vm/vm_kern.h>
163 1.14.2.2 bouyer #include <vm/pmap.h>
164 1.14.2.2 bouyer #include <vm/vm_extern.h>
165 1.14.2.2 bouyer #endif
166 1.14.2.2 bouyer
167 1.14.2.2 bouyer #include <sys/device.h>
168 1.14.2.2 bouyer #include <dev/pci/pcivar.h>
169 1.14.2.2 bouyer #include <dev/pci/pcireg.h>
170 1.14.2.2 bouyer #include <dev/pci/pcidevs.h>
171 1.14.2.2 bouyer
172 1.14.2.2 bouyer #define BKTR_DEBUG
173 1.14.2.2 bouyer #ifdef BKTR_DEBUG
174 1.14.2.2 bouyer int bktr_debug = 0;
175 1.14.2.2 bouyer #define DPR(x) (bktr_debug ? printf x : 0)
176 1.14.2.2 bouyer #else
177 1.14.2.2 bouyer #define DPR(x)
178 1.14.2.2 bouyer #endif
179 1.14.2.2 bouyer #endif /* __NetBSD__ || __OpenBSD__ */
180 1.14.2.2 bouyer
181 1.14.2.2 bouyer
182 1.14.2.2 bouyer #ifdef __NetBSD__
183 1.14.2.2 bouyer #include <dev/ic/bt8xx.h> /* NetBSD location for .h files */
184 1.14.2.2 bouyer #include <dev/pci/bktr/bktr_reg.h>
185 1.14.2.2 bouyer #include <dev/pci/bktr/bktr_tuner.h>
186 1.14.2.2 bouyer #include <dev/pci/bktr/bktr_card.h>
187 1.14.2.2 bouyer #include <dev/pci/bktr/bktr_audio.h>
188 1.14.2.2 bouyer #include <dev/pci/bktr/bktr_core.h>
189 1.14.2.2 bouyer #include <dev/pci/bktr/bktr_os.h>
190 1.14.2.2 bouyer #else /* Traditional location for .h files */
191 1.14.2.2 bouyer #include <machine/ioctl_meteor.h>
192 1.14.2.2 bouyer #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */
193 1.14.2.2 bouyer #include <dev/bktr/bktr_reg.h>
194 1.14.2.2 bouyer #include <dev/bktr/bktr_tuner.h>
195 1.14.2.2 bouyer #include <dev/bktr/bktr_card.h>
196 1.14.2.2 bouyer #include <dev/bktr/bktr_audio.h>
197 1.14.2.2 bouyer #include <dev/bktr/bktr_core.h>
198 1.14.2.2 bouyer #include <dev/bktr/bktr_os.h>
199 1.14.2.2 bouyer #endif
200 1.14.2.2 bouyer
201 1.14.2.2 bouyer
202 1.14.2.2 bouyer
203 1.14.2.2 bouyer /****************************/
204 1.14.2.2 bouyer /* *** FreeBSD 4.x code *** */
205 1.14.2.2 bouyer /****************************/
206 1.14.2.2 bouyer #if (__FreeBSD_version >= 400000)
207 1.14.2.2 bouyer
208 1.14.2.2 bouyer static int bktr_probe( device_t dev );
209 1.14.2.2 bouyer static int bktr_attach( device_t dev );
210 1.14.2.2 bouyer static int bktr_detach( device_t dev );
211 1.14.2.2 bouyer static int bktr_shutdown( device_t dev );
212 1.14.2.2 bouyer static void bktr_intr(void *arg) { common_bktr_intr(arg); }
213 1.14.2.2 bouyer
214 1.14.2.2 bouyer static device_method_t bktr_methods[] = {
215 1.14.2.2 bouyer /* Device interface */
216 1.14.2.2 bouyer DEVMETHOD(device_probe, bktr_probe),
217 1.14.2.2 bouyer DEVMETHOD(device_attach, bktr_attach),
218 1.14.2.2 bouyer DEVMETHOD(device_detach, bktr_detach),
219 1.14.2.2 bouyer DEVMETHOD(device_shutdown, bktr_shutdown),
220 1.14.2.2 bouyer
221 1.14.2.2 bouyer { 0, 0 }
222 1.14.2.2 bouyer };
223 1.14.2.2 bouyer
224 1.14.2.2 bouyer static driver_t bktr_driver = {
225 1.14.2.2 bouyer "bktr",
226 1.14.2.2 bouyer bktr_methods,
227 1.14.2.2 bouyer sizeof(struct bktr_softc),
228 1.14.2.2 bouyer };
229 1.14.2.2 bouyer
230 1.14.2.2 bouyer static devclass_t bktr_devclass;
231 1.14.2.2 bouyer
232 1.14.2.2 bouyer static d_open_t bktr_open;
233 1.14.2.2 bouyer static d_close_t bktr_close;
234 1.14.2.2 bouyer static d_read_t bktr_read;
235 1.14.2.2 bouyer static d_write_t bktr_write;
236 1.14.2.2 bouyer static d_ioctl_t bktr_ioctl;
237 1.14.2.2 bouyer static d_mmap_t bktr_mmap;
238 1.14.2.2 bouyer static d_poll_t bktr_poll;
239 1.14.2.2 bouyer
240 1.14.2.2 bouyer #define CDEV_MAJOR 92
241 1.14.2.2 bouyer static struct cdevsw bktr_cdevsw = {
242 1.14.2.2 bouyer /* open */ bktr_open,
243 1.14.2.2 bouyer /* close */ bktr_close,
244 1.14.2.2 bouyer /* read */ bktr_read,
245 1.14.2.2 bouyer /* write */ bktr_write,
246 1.14.2.2 bouyer /* ioctl */ bktr_ioctl,
247 1.14.2.2 bouyer /* poll */ bktr_poll,
248 1.14.2.2 bouyer /* mmap */ bktr_mmap,
249 1.14.2.2 bouyer /* strategy */ nostrategy,
250 1.14.2.2 bouyer /* name */ "bktr",
251 1.14.2.2 bouyer /* maj */ CDEV_MAJOR,
252 1.14.2.2 bouyer /* dump */ nodump,
253 1.14.2.2 bouyer /* psize */ nopsize,
254 1.14.2.2 bouyer /* flags */ 0,
255 1.14.2.2 bouyer /* bmaj */ -1
256 1.14.2.2 bouyer };
257 1.14.2.2 bouyer
258 1.14.2.2 bouyer DRIVER_MODULE(bktr, pci, bktr_driver, bktr_devclass, 0, 0);
259 1.14.2.2 bouyer
260 1.14.2.2 bouyer
261 1.14.2.2 bouyer /*
262 1.14.2.2 bouyer * the boot time probe routine.
263 1.14.2.2 bouyer */
264 1.14.2.2 bouyer static int
265 1.14.2.2 bouyer bktr_probe( device_t dev )
266 1.14.2.2 bouyer {
267 1.14.2.2 bouyer unsigned int type = pci_get_devid(dev);
268 1.14.2.2 bouyer unsigned int rev = pci_get_revid(dev);
269 1.14.2.2 bouyer
270 1.14.2.2 bouyer if (PCI_VENDOR(type) == PCI_VENDOR_BROOKTREE)
271 1.14.2.2 bouyer {
272 1.14.2.2 bouyer switch (PCI_PRODUCT(type)) {
273 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT848:
274 1.14.2.2 bouyer if (rev == 0x12)
275 1.14.2.2 bouyer device_set_desc(dev, "BrookTree 848A");
276 1.14.2.2 bouyer else
277 1.14.2.2 bouyer device_set_desc(dev, "BrookTree 848");
278 1.14.2.2 bouyer return 0;
279 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT849:
280 1.14.2.2 bouyer device_set_desc(dev, "BrookTree 849A");
281 1.14.2.2 bouyer return 0;
282 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT878:
283 1.14.2.2 bouyer device_set_desc(dev, "BrookTree 878");
284 1.14.2.2 bouyer return 0;
285 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT879:
286 1.14.2.2 bouyer device_set_desc(dev, "BrookTree 879");
287 1.14.2.2 bouyer return 0;
288 1.14.2.2 bouyer }
289 1.14.2.2 bouyer };
290 1.14.2.2 bouyer
291 1.14.2.2 bouyer return ENXIO;
292 1.14.2.2 bouyer }
293 1.14.2.2 bouyer
294 1.14.2.2 bouyer
295 1.14.2.2 bouyer /*
296 1.14.2.2 bouyer * the attach routine.
297 1.14.2.2 bouyer */
298 1.14.2.2 bouyer static int
299 1.14.2.2 bouyer bktr_attach( device_t dev )
300 1.14.2.2 bouyer {
301 1.14.2.2 bouyer u_long latency;
302 1.14.2.2 bouyer u_long fun;
303 1.14.2.2 bouyer u_long val;
304 1.14.2.2 bouyer unsigned int rev;
305 1.14.2.2 bouyer unsigned int unit;
306 1.14.2.2 bouyer int error = 0;
307 1.14.2.2 bouyer int rid;
308 1.14.2.2 bouyer #ifdef BROOKTREE_IRQ
309 1.14.2.2 bouyer u_long old_irq, new_irq;
310 1.14.2.2 bouyer #endif
311 1.14.2.2 bouyer
312 1.14.2.2 bouyer struct bktr_softc *bktr = device_get_softc(dev);
313 1.14.2.2 bouyer
314 1.14.2.2 bouyer unit = device_get_unit(dev);
315 1.14.2.2 bouyer
316 1.14.2.2 bouyer /* build the device name for bktr_name() */
317 1.14.2.2 bouyer snprintf(bktr->bktr_xname, sizeof(bktr->bktr_xname), "bktr%d",unit);
318 1.14.2.2 bouyer
319 1.14.2.2 bouyer /*
320 1.14.2.2 bouyer * Enable bus mastering and Memory Mapped device
321 1.14.2.2 bouyer */
322 1.14.2.2 bouyer val = pci_read_config(dev, PCIR_COMMAND, 4);
323 1.14.2.2 bouyer val |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
324 1.14.2.2 bouyer pci_write_config(dev, PCIR_COMMAND, val, 4);
325 1.14.2.2 bouyer
326 1.14.2.2 bouyer /*
327 1.14.2.2 bouyer * Map control/status registers.
328 1.14.2.2 bouyer */
329 1.14.2.2 bouyer rid = PCIR_MAPS;
330 1.14.2.2 bouyer bktr->res_mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
331 1.14.2.2 bouyer 0, ~0, 1, RF_ACTIVE);
332 1.14.2.2 bouyer
333 1.14.2.2 bouyer if (!bktr->res_mem) {
334 1.14.2.2 bouyer device_printf(dev, "could not map memory\n");
335 1.14.2.2 bouyer error = ENXIO;
336 1.14.2.2 bouyer goto fail;
337 1.14.2.2 bouyer }
338 1.14.2.2 bouyer bktr->memt = rman_get_bustag(bktr->res_mem);
339 1.14.2.2 bouyer bktr->memh = rman_get_bushandle(bktr->res_mem);
340 1.14.2.2 bouyer
341 1.14.2.2 bouyer
342 1.14.2.2 bouyer /*
343 1.14.2.2 bouyer * Disable the brooktree device
344 1.14.2.2 bouyer */
345 1.14.2.2 bouyer OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
346 1.14.2.2 bouyer OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
347 1.14.2.2 bouyer
348 1.14.2.2 bouyer
349 1.14.2.2 bouyer #ifdef BROOKTREE_IRQ /* from the configuration file */
350 1.14.2.2 bouyer old_irq = pci_conf_read(tag, PCI_INTERRUPT_REG);
351 1.14.2.2 bouyer pci_conf_write(tag, PCI_INTERRUPT_REG, BROOKTREE_IRQ);
352 1.14.2.2 bouyer new_irq = pci_conf_read(tag, PCI_INTERRUPT_REG);
353 1.14.2.2 bouyer printf("bktr%d: attach: irq changed from %d to %d\n",
354 1.14.2.2 bouyer unit, (old_irq & 0xff), (new_irq & 0xff));
355 1.14.2.2 bouyer #endif
356 1.14.2.2 bouyer
357 1.14.2.2 bouyer /*
358 1.14.2.2 bouyer * Allocate our interrupt.
359 1.14.2.2 bouyer */
360 1.14.2.2 bouyer rid = 0;
361 1.14.2.2 bouyer bktr->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
362 1.14.2.2 bouyer RF_SHAREABLE | RF_ACTIVE);
363 1.14.2.2 bouyer if (bktr->res_irq == NULL) {
364 1.14.2.2 bouyer device_printf(dev, "could not map interrupt\n");
365 1.14.2.2 bouyer error = ENXIO;
366 1.14.2.2 bouyer goto fail;
367 1.14.2.2 bouyer }
368 1.14.2.2 bouyer
369 1.14.2.2 bouyer error = bus_setup_intr(dev, bktr->res_irq, INTR_TYPE_TTY,
370 1.14.2.2 bouyer bktr_intr, bktr, &bktr->res_ih);
371 1.14.2.2 bouyer if (error) {
372 1.14.2.2 bouyer device_printf(dev, "could not setup irq\n");
373 1.14.2.2 bouyer goto fail;
374 1.14.2.2 bouyer
375 1.14.2.2 bouyer }
376 1.14.2.2 bouyer
377 1.14.2.2 bouyer
378 1.14.2.2 bouyer /* Update the Device Control Register */
379 1.14.2.2 bouyer /* on Bt878 and Bt879 cards */
380 1.14.2.2 bouyer fun = pci_read_config( dev, 0x40, 2);
381 1.14.2.2 bouyer fun = fun | 1; /* Enable writes to the sub-system vendor ID */
382 1.14.2.2 bouyer
383 1.14.2.2 bouyer #if defined( BKTR_430_FX_MODE )
384 1.14.2.2 bouyer if (bootverbose) printf("Using 430 FX chipset compatibilty mode\n");
385 1.14.2.2 bouyer fun = fun | 2; /* Enable Intel 430 FX compatibility mode */
386 1.14.2.2 bouyer #endif
387 1.14.2.2 bouyer
388 1.14.2.2 bouyer #if defined( BKTR_SIS_VIA_MODE )
389 1.14.2.2 bouyer if (bootverbose) printf("Using SiS/VIA chipset compatibilty mode\n");
390 1.14.2.2 bouyer fun = fun | 4; /* Enable SiS/VIA compatibility mode (usefull for
391 1.14.2.2 bouyer OPTi chipset motherboards too */
392 1.14.2.2 bouyer #endif
393 1.14.2.2 bouyer pci_write_config(dev, 0x40, fun, 2);
394 1.14.2.2 bouyer
395 1.14.2.2 bouyer
396 1.14.2.2 bouyer /* XXX call bt848_i2c dependent attach() routine */
397 1.14.2.2 bouyer #if (NSMBUS > 0)
398 1.14.2.2 bouyer if (bt848_i2c_attach(unit, bktr, &bktr->i2c_sc))
399 1.14.2.2 bouyer printf("bktr%d: i2c_attach: can't attach\n", unit);
400 1.14.2.2 bouyer #endif
401 1.14.2.2 bouyer
402 1.14.2.2 bouyer
403 1.14.2.2 bouyer /*
404 1.14.2.2 bouyer * PCI latency timer. 32 is a good value for 4 bus mastering slots, if
405 1.14.2.2 bouyer * you have more than four, then 16 would probably be a better value.
406 1.14.2.2 bouyer */
407 1.14.2.2 bouyer #ifndef BROOKTREE_DEF_LATENCY_VALUE
408 1.14.2.2 bouyer #define BROOKTREE_DEF_LATENCY_VALUE 10
409 1.14.2.2 bouyer #endif
410 1.14.2.2 bouyer latency = pci_read_config(dev, PCI_LATENCY_TIMER, 4);
411 1.14.2.2 bouyer latency = (latency >> 8) & 0xff;
412 1.14.2.2 bouyer if ( bootverbose ) {
413 1.14.2.2 bouyer if (latency)
414 1.14.2.2 bouyer printf("brooktree%d: PCI bus latency is", unit);
415 1.14.2.2 bouyer else
416 1.14.2.2 bouyer printf("brooktree%d: PCI bus latency was 0 changing to",
417 1.14.2.2 bouyer unit);
418 1.14.2.2 bouyer }
419 1.14.2.2 bouyer if ( !latency ) {
420 1.14.2.2 bouyer latency = BROOKTREE_DEF_LATENCY_VALUE;
421 1.14.2.2 bouyer pci_write_config(dev, PCI_LATENCY_TIMER, latency<<8, 4);
422 1.14.2.2 bouyer }
423 1.14.2.2 bouyer if ( bootverbose ) {
424 1.14.2.2 bouyer printf(" %d.\n", (int) latency);
425 1.14.2.2 bouyer }
426 1.14.2.2 bouyer
427 1.14.2.2 bouyer /* read the pci device id and revision id */
428 1.14.2.2 bouyer fun = pci_get_devid(dev);
429 1.14.2.2 bouyer rev = pci_get_revid(dev);
430 1.14.2.2 bouyer
431 1.14.2.2 bouyer /* call the common attach code */
432 1.14.2.2 bouyer common_bktr_attach( bktr, unit, fun, rev );
433 1.14.2.2 bouyer
434 1.14.2.2 bouyer make_dev(&bktr_cdevsw, unit, 0, 0, 0444, "bktr%d", unit);
435 1.14.2.2 bouyer make_dev(&bktr_cdevsw, unit+16, 0, 0, 0444, "tuner%d", unit);
436 1.14.2.2 bouyer make_dev(&bktr_cdevsw, unit+32, 0, 0, 0444, "vbi%d", unit);
437 1.14.2.2 bouyer
438 1.14.2.2 bouyer return 0;
439 1.14.2.2 bouyer
440 1.14.2.2 bouyer fail:
441 1.14.2.2 bouyer return error;
442 1.14.2.2 bouyer
443 1.14.2.2 bouyer }
444 1.14.2.2 bouyer
445 1.14.2.2 bouyer /*
446 1.14.2.2 bouyer * the detach routine.
447 1.14.2.2 bouyer */
448 1.14.2.2 bouyer static int
449 1.14.2.2 bouyer bktr_detach( device_t dev )
450 1.14.2.2 bouyer {
451 1.14.2.2 bouyer struct bktr_softc *bktr = device_get_softc(dev);
452 1.14.2.2 bouyer
453 1.14.2.2 bouyer /* Disable the brooktree device */
454 1.14.2.2 bouyer OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
455 1.14.2.2 bouyer OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
456 1.14.2.2 bouyer
457 1.14.2.2 bouyer /* FIXME - Free memory for RISC programs, grab buffer, vbi buffers */
458 1.14.2.2 bouyer
459 1.14.2.2 bouyer /*
460 1.14.2.2 bouyer * Deallocate resources.
461 1.14.2.2 bouyer */
462 1.14.2.2 bouyer bus_teardown_intr(dev, bktr->res_irq, bktr->res_ih);
463 1.14.2.2 bouyer bus_release_resource(dev, SYS_RES_IRQ, 0, bktr->res_irq);
464 1.14.2.2 bouyer bus_release_resource(dev, SYS_RES_MEMORY, PCIR_MAPS, bktr->res_mem);
465 1.14.2.2 bouyer
466 1.14.2.2 bouyer return 0;
467 1.14.2.2 bouyer }
468 1.14.2.2 bouyer
469 1.14.2.2 bouyer /*
470 1.14.2.2 bouyer * the shutdown routine.
471 1.14.2.2 bouyer */
472 1.14.2.2 bouyer static int
473 1.14.2.2 bouyer bktr_shutdown( device_t dev )
474 1.14.2.2 bouyer {
475 1.14.2.2 bouyer struct bktr_softc *bktr = device_get_softc(dev);
476 1.14.2.2 bouyer
477 1.14.2.2 bouyer /* Disable the brooktree device */
478 1.14.2.2 bouyer OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
479 1.14.2.2 bouyer OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
480 1.14.2.2 bouyer
481 1.14.2.2 bouyer return 0;
482 1.14.2.2 bouyer }
483 1.14.2.2 bouyer
484 1.14.2.2 bouyer
485 1.14.2.2 bouyer /*
486 1.14.2.2 bouyer * Special Memory Allocation
487 1.14.2.2 bouyer */
488 1.14.2.2 bouyer vm_offset_t
489 1.14.2.2 bouyer get_bktr_mem( int unit, unsigned size )
490 1.14.2.2 bouyer {
491 1.14.2.2 bouyer vm_offset_t addr = 0;
492 1.14.2.2 bouyer
493 1.14.2.2 bouyer addr = vm_page_alloc_contig(size, 0, 0xffffffff, 1<<24);
494 1.14.2.2 bouyer if (addr == 0)
495 1.14.2.2 bouyer addr = vm_page_alloc_contig(size, 0, 0xffffffff, PAGE_SIZE);
496 1.14.2.2 bouyer if (addr == 0) {
497 1.14.2.2 bouyer printf("bktr%d: Unable to allocate %d bytes of memory.\n",
498 1.14.2.2 bouyer unit, size);
499 1.14.2.2 bouyer }
500 1.14.2.2 bouyer
501 1.14.2.2 bouyer return( addr );
502 1.14.2.2 bouyer }
503 1.14.2.2 bouyer
504 1.14.2.2 bouyer
505 1.14.2.2 bouyer /*---------------------------------------------------------
506 1.14.2.2 bouyer **
507 1.14.2.2 bouyer ** BrookTree 848 character device driver routines
508 1.14.2.2 bouyer **
509 1.14.2.2 bouyer **---------------------------------------------------------
510 1.14.2.2 bouyer */
511 1.14.2.2 bouyer
512 1.14.2.2 bouyer #define VIDEO_DEV 0x00
513 1.14.2.2 bouyer #define TUNER_DEV 0x01
514 1.14.2.2 bouyer #define VBI_DEV 0x02
515 1.14.2.2 bouyer
516 1.14.2.2 bouyer #define UNIT(x) ((x) & 0x0f)
517 1.14.2.2 bouyer #define FUNCTION(x) (x >> 4)
518 1.14.2.2 bouyer
519 1.14.2.2 bouyer /*
520 1.14.2.2 bouyer *
521 1.14.2.2 bouyer */
522 1.14.2.2 bouyer int
523 1.14.2.2 bouyer bktr_open( dev_t dev, int flags, int fmt, struct proc *p )
524 1.14.2.2 bouyer {
525 1.14.2.2 bouyer bktr_ptr_t bktr;
526 1.14.2.2 bouyer int unit;
527 1.14.2.2 bouyer int result;
528 1.14.2.2 bouyer
529 1.14.2.2 bouyer unit = UNIT( minor(dev) );
530 1.14.2.2 bouyer
531 1.14.2.2 bouyer /* Get the device data */
532 1.14.2.2 bouyer bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit);
533 1.14.2.2 bouyer if (bktr == NULL) {
534 1.14.2.2 bouyer /* the device is no longer valid/functioning */
535 1.14.2.2 bouyer return (ENXIO);
536 1.14.2.2 bouyer }
537 1.14.2.2 bouyer
538 1.14.2.2 bouyer if (!(bktr->flags & METEOR_INITALIZED)) /* device not found */
539 1.14.2.2 bouyer return( ENXIO );
540 1.14.2.2 bouyer
541 1.14.2.2 bouyer /* Record that the device is now busy */
542 1.14.2.2 bouyer device_busy(devclass_get_device(bktr_devclass, unit));
543 1.14.2.2 bouyer
544 1.14.2.2 bouyer
545 1.14.2.2 bouyer if (bt848_card != -1) {
546 1.14.2.2 bouyer if ((bt848_card >> 8 == unit ) &&
547 1.14.2.2 bouyer ( (bt848_card & 0xff) < Bt848_MAX_CARD )) {
548 1.14.2.2 bouyer if ( bktr->bt848_card != (bt848_card & 0xff) ) {
549 1.14.2.2 bouyer bktr->bt848_card = (bt848_card & 0xff);
550 1.14.2.2 bouyer probeCard(bktr, FALSE, unit);
551 1.14.2.2 bouyer }
552 1.14.2.2 bouyer }
553 1.14.2.2 bouyer }
554 1.14.2.2 bouyer
555 1.14.2.2 bouyer if (bt848_tuner != -1) {
556 1.14.2.2 bouyer if ((bt848_tuner >> 8 == unit ) &&
557 1.14.2.2 bouyer ( (bt848_tuner & 0xff) < Bt848_MAX_TUNER )) {
558 1.14.2.2 bouyer if ( bktr->bt848_tuner != (bt848_tuner & 0xff) ) {
559 1.14.2.2 bouyer bktr->bt848_tuner = (bt848_tuner & 0xff);
560 1.14.2.2 bouyer probeCard(bktr, FALSE, unit);
561 1.14.2.2 bouyer }
562 1.14.2.2 bouyer }
563 1.14.2.2 bouyer }
564 1.14.2.2 bouyer
565 1.14.2.2 bouyer if (bt848_reverse_mute != -1) {
566 1.14.2.2 bouyer if ((bt848_reverse_mute >> 8) == unit ) {
567 1.14.2.2 bouyer bktr->reverse_mute = bt848_reverse_mute & 0xff;
568 1.14.2.2 bouyer }
569 1.14.2.2 bouyer }
570 1.14.2.2 bouyer
571 1.14.2.2 bouyer if (bt848_slow_msp_audio != -1) {
572 1.14.2.2 bouyer if ((bt848_slow_msp_audio >> 8) == unit ) {
573 1.14.2.2 bouyer bktr->slow_msp_audio = (bt848_slow_msp_audio & 0xff);
574 1.14.2.2 bouyer }
575 1.14.2.2 bouyer }
576 1.14.2.2 bouyer
577 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
578 1.14.2.2 bouyer case VIDEO_DEV:
579 1.14.2.2 bouyer result = video_open( bktr );
580 1.14.2.2 bouyer break;
581 1.14.2.2 bouyer case TUNER_DEV:
582 1.14.2.2 bouyer result = tuner_open( bktr );
583 1.14.2.2 bouyer break;
584 1.14.2.2 bouyer case VBI_DEV:
585 1.14.2.2 bouyer result = vbi_open( bktr );
586 1.14.2.2 bouyer break;
587 1.14.2.2 bouyer default:
588 1.14.2.2 bouyer result = ENXIO;
589 1.14.2.2 bouyer break;
590 1.14.2.2 bouyer }
591 1.14.2.2 bouyer
592 1.14.2.2 bouyer /* If there was an error opening the device, undo the busy status */
593 1.14.2.2 bouyer if (result != 0)
594 1.14.2.2 bouyer device_unbusy(devclass_get_device(bktr_devclass, unit));
595 1.14.2.2 bouyer return( result );
596 1.14.2.2 bouyer }
597 1.14.2.2 bouyer
598 1.14.2.2 bouyer
599 1.14.2.2 bouyer /*
600 1.14.2.2 bouyer *
601 1.14.2.2 bouyer */
602 1.14.2.2 bouyer int
603 1.14.2.2 bouyer bktr_close( dev_t dev, int flags, int fmt, struct proc *p )
604 1.14.2.2 bouyer {
605 1.14.2.2 bouyer bktr_ptr_t bktr;
606 1.14.2.2 bouyer int unit;
607 1.14.2.2 bouyer int result;
608 1.14.2.2 bouyer
609 1.14.2.2 bouyer unit = UNIT( minor(dev) );
610 1.14.2.2 bouyer
611 1.14.2.2 bouyer /* Get the device data */
612 1.14.2.2 bouyer bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit);
613 1.14.2.2 bouyer if (bktr == NULL) {
614 1.14.2.2 bouyer /* the device is no longer valid/functioning */
615 1.14.2.2 bouyer return (ENXIO);
616 1.14.2.2 bouyer }
617 1.14.2.2 bouyer
618 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
619 1.14.2.2 bouyer case VIDEO_DEV:
620 1.14.2.2 bouyer result = video_close( bktr );
621 1.14.2.2 bouyer break;
622 1.14.2.2 bouyer case TUNER_DEV:
623 1.14.2.2 bouyer result = tuner_close( bktr );
624 1.14.2.2 bouyer break;
625 1.14.2.2 bouyer case VBI_DEV:
626 1.14.2.2 bouyer result = vbi_close( bktr );
627 1.14.2.2 bouyer break;
628 1.14.2.2 bouyer default:
629 1.14.2.2 bouyer return (ENXIO);
630 1.14.2.2 bouyer break;
631 1.14.2.2 bouyer }
632 1.14.2.2 bouyer
633 1.14.2.2 bouyer device_unbusy(devclass_get_device(bktr_devclass, unit));
634 1.14.2.2 bouyer return( result );
635 1.14.2.2 bouyer }
636 1.14.2.2 bouyer
637 1.14.2.2 bouyer
638 1.14.2.2 bouyer /*
639 1.14.2.2 bouyer *
640 1.14.2.2 bouyer */
641 1.14.2.2 bouyer int
642 1.14.2.2 bouyer bktr_read( dev_t dev, struct uio *uio, int ioflag )
643 1.14.2.2 bouyer {
644 1.14.2.2 bouyer bktr_ptr_t bktr;
645 1.14.2.2 bouyer int unit;
646 1.14.2.2 bouyer
647 1.14.2.2 bouyer unit = UNIT(minor(dev));
648 1.14.2.2 bouyer
649 1.14.2.2 bouyer /* Get the device data */
650 1.14.2.2 bouyer bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit);
651 1.14.2.2 bouyer if (bktr == NULL) {
652 1.14.2.2 bouyer /* the device is no longer valid/functioning */
653 1.14.2.2 bouyer return (ENXIO);
654 1.14.2.2 bouyer }
655 1.14.2.2 bouyer
656 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
657 1.14.2.2 bouyer case VIDEO_DEV:
658 1.14.2.2 bouyer return( video_read( bktr, unit, dev, uio ) );
659 1.14.2.2 bouyer case VBI_DEV:
660 1.14.2.2 bouyer return( vbi_read( bktr, uio, ioflag ) );
661 1.14.2.2 bouyer }
662 1.14.2.2 bouyer return( ENXIO );
663 1.14.2.2 bouyer }
664 1.14.2.2 bouyer
665 1.14.2.2 bouyer
666 1.14.2.2 bouyer /*
667 1.14.2.2 bouyer *
668 1.14.2.2 bouyer */
669 1.14.2.2 bouyer int
670 1.14.2.2 bouyer bktr_write( dev_t dev, struct uio *uio, int ioflag )
671 1.14.2.2 bouyer {
672 1.14.2.2 bouyer return( EINVAL ); /* XXX or ENXIO ? */
673 1.14.2.2 bouyer }
674 1.14.2.2 bouyer
675 1.14.2.2 bouyer
676 1.14.2.2 bouyer /*
677 1.14.2.2 bouyer *
678 1.14.2.2 bouyer */
679 1.14.2.2 bouyer int
680 1.14.2.2 bouyer bktr_ioctl( dev_t dev, ioctl_cmd_t cmd, caddr_t arg, int flag, struct proc* pr )
681 1.14.2.2 bouyer {
682 1.14.2.2 bouyer bktr_ptr_t bktr;
683 1.14.2.2 bouyer int unit;
684 1.14.2.2 bouyer
685 1.14.2.2 bouyer unit = UNIT(minor(dev));
686 1.14.2.2 bouyer
687 1.14.2.2 bouyer /* Get the device data */
688 1.14.2.2 bouyer bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit);
689 1.14.2.2 bouyer if (bktr == NULL) {
690 1.14.2.2 bouyer /* the device is no longer valid/functioning */
691 1.14.2.2 bouyer return (ENXIO);
692 1.14.2.2 bouyer }
693 1.14.2.2 bouyer
694 1.14.2.2 bouyer if (bktr->bigbuf == 0) /* no frame buffer allocated (ioctl failed) */
695 1.14.2.2 bouyer return( ENOMEM );
696 1.14.2.2 bouyer
697 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
698 1.14.2.2 bouyer case VIDEO_DEV:
699 1.14.2.2 bouyer return( video_ioctl( bktr, unit, cmd, arg, pr ) );
700 1.14.2.2 bouyer case TUNER_DEV:
701 1.14.2.2 bouyer return( tuner_ioctl( bktr, unit, cmd, arg, pr ) );
702 1.14.2.2 bouyer }
703 1.14.2.2 bouyer
704 1.14.2.2 bouyer return( ENXIO );
705 1.14.2.2 bouyer }
706 1.14.2.2 bouyer
707 1.14.2.2 bouyer
708 1.14.2.2 bouyer /*
709 1.14.2.2 bouyer *
710 1.14.2.2 bouyer */
711 1.14.2.2 bouyer int
712 1.14.2.2 bouyer bktr_mmap( dev_t dev, vm_offset_t offset, int nprot )
713 1.14.2.2 bouyer {
714 1.14.2.2 bouyer int unit;
715 1.14.2.2 bouyer bktr_ptr_t bktr;
716 1.14.2.2 bouyer
717 1.14.2.2 bouyer unit = UNIT(minor(dev));
718 1.14.2.2 bouyer
719 1.14.2.2 bouyer if (FUNCTION(minor(dev)) > 0) /* only allow mmap on /dev/bktr[n] */
720 1.14.2.2 bouyer return( -1 );
721 1.14.2.2 bouyer
722 1.14.2.2 bouyer /* Get the device data */
723 1.14.2.2 bouyer bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit);
724 1.14.2.2 bouyer if (bktr == NULL) {
725 1.14.2.2 bouyer /* the device is no longer valid/functioning */
726 1.14.2.2 bouyer return (ENXIO);
727 1.14.2.2 bouyer }
728 1.14.2.2 bouyer
729 1.14.2.2 bouyer if (nprot & PROT_EXEC)
730 1.14.2.2 bouyer return( -1 );
731 1.14.2.2 bouyer
732 1.14.2.2 bouyer if (offset < 0)
733 1.14.2.2 bouyer return( -1 );
734 1.14.2.2 bouyer
735 1.14.2.2 bouyer if (offset >= bktr->alloc_pages * PAGE_SIZE)
736 1.14.2.2 bouyer return( -1 );
737 1.14.2.2 bouyer
738 1.14.2.2 bouyer return( atop(vtophys(bktr->bigbuf) + offset) );
739 1.14.2.2 bouyer }
740 1.14.2.2 bouyer
741 1.14.2.2 bouyer int bktr_poll( dev_t dev, int events, struct proc *p)
742 1.14.2.2 bouyer {
743 1.14.2.2 bouyer int unit;
744 1.14.2.2 bouyer bktr_ptr_t bktr;
745 1.14.2.2 bouyer int revents = 0;
746 1.14.2.2 bouyer DECLARE_INTR_MASK(s);
747 1.14.2.2 bouyer
748 1.14.2.2 bouyer unit = UNIT(minor(dev));
749 1.14.2.2 bouyer
750 1.14.2.2 bouyer /* Get the device data */
751 1.14.2.2 bouyer bktr = (struct bktr_softc*)devclass_get_softc(bktr_devclass, unit);
752 1.14.2.2 bouyer if (bktr == NULL) {
753 1.14.2.2 bouyer /* the device is no longer valid/functioning */
754 1.14.2.2 bouyer return (ENXIO);
755 1.14.2.2 bouyer }
756 1.14.2.2 bouyer
757 1.14.2.2 bouyer DISABLE_INTR(s);
758 1.14.2.2 bouyer
759 1.14.2.2 bouyer if (events & (POLLIN | POLLRDNORM)) {
760 1.14.2.2 bouyer
761 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
762 1.14.2.2 bouyer case VBI_DEV:
763 1.14.2.2 bouyer if(bktr->vbisize == 0)
764 1.14.2.2 bouyer selrecord(p, &bktr->vbi_select);
765 1.14.2.2 bouyer else
766 1.14.2.2 bouyer revents |= events & (POLLIN | POLLRDNORM);
767 1.14.2.2 bouyer break;
768 1.14.2.2 bouyer }
769 1.14.2.2 bouyer }
770 1.14.2.2 bouyer
771 1.14.2.2 bouyer ENABLE_INTR(s);
772 1.14.2.2 bouyer
773 1.14.2.2 bouyer return (revents);
774 1.14.2.2 bouyer }
775 1.14.2.2 bouyer
776 1.14.2.2 bouyer #endif /* FreeBSD 4.x specific kernel interface routines */
777 1.14.2.2 bouyer
778 1.14.2.2 bouyer /**********************************/
779 1.14.2.2 bouyer /* *** FreeBSD 2.2.x and 3.x *** */
780 1.14.2.2 bouyer /**********************************/
781 1.14.2.2 bouyer
782 1.14.2.2 bouyer #if ((__FreeBSD__ == 2) || (__FreeBSD__ == 3))
783 1.14.2.2 bouyer
784 1.14.2.2 bouyer static bktr_reg_t brooktree[ NBKTR ];
785 1.14.2.2 bouyer
786 1.14.2.2 bouyer static const char* bktr_probe( pcici_t tag, pcidi_t type );
787 1.14.2.2 bouyer static void bktr_attach( pcici_t tag, int unit );
788 1.14.2.2 bouyer static void bktr_intr(void *arg) { common_bktr_intr(arg); }
789 1.14.2.2 bouyer
790 1.14.2.2 bouyer static u_long bktr_count;
791 1.14.2.2 bouyer
792 1.14.2.2 bouyer static struct pci_device bktr_device = {
793 1.14.2.2 bouyer "bktr",
794 1.14.2.2 bouyer bktr_probe,
795 1.14.2.2 bouyer bktr_attach,
796 1.14.2.2 bouyer &bktr_count
797 1.14.2.2 bouyer };
798 1.14.2.2 bouyer
799 1.14.2.2 bouyer DATA_SET (pcidevice_set, bktr_device);
800 1.14.2.2 bouyer
801 1.14.2.2 bouyer static d_open_t bktr_open;
802 1.14.2.2 bouyer static d_close_t bktr_close;
803 1.14.2.2 bouyer static d_read_t bktr_read;
804 1.14.2.2 bouyer static d_write_t bktr_write;
805 1.14.2.2 bouyer static d_ioctl_t bktr_ioctl;
806 1.14.2.2 bouyer static d_mmap_t bktr_mmap;
807 1.14.2.2 bouyer static d_poll_t bktr_poll;
808 1.14.2.2 bouyer
809 1.14.2.2 bouyer #define CDEV_MAJOR 92
810 1.14.2.2 bouyer static struct cdevsw bktr_cdevsw =
811 1.14.2.2 bouyer {
812 1.14.2.2 bouyer bktr_open, bktr_close, bktr_read, bktr_write,
813 1.14.2.2 bouyer bktr_ioctl, nostop, nullreset, nodevtotty,
814 1.14.2.2 bouyer bktr_poll, bktr_mmap, NULL, "bktr",
815 1.14.2.2 bouyer NULL, -1
816 1.14.2.2 bouyer };
817 1.14.2.2 bouyer
818 1.14.2.2 bouyer static int bktr_devsw_installed;
819 1.14.2.2 bouyer
820 1.14.2.2 bouyer static void
821 1.14.2.2 bouyer bktr_drvinit( void *unused )
822 1.14.2.2 bouyer {
823 1.14.2.2 bouyer dev_t dev;
824 1.14.2.2 bouyer
825 1.14.2.2 bouyer if ( ! bktr_devsw_installed ) {
826 1.14.2.2 bouyer dev = makedev(CDEV_MAJOR, 0);
827 1.14.2.2 bouyer cdevsw_add(&dev,&bktr_cdevsw, NULL);
828 1.14.2.2 bouyer bktr_devsw_installed = 1;
829 1.14.2.2 bouyer }
830 1.14.2.2 bouyer }
831 1.14.2.2 bouyer
832 1.14.2.2 bouyer SYSINIT(bktrdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,bktr_drvinit,NULL)
833 1.14.2.2 bouyer
834 1.14.2.2 bouyer /*
835 1.14.2.2 bouyer * the boot time probe routine.
836 1.14.2.2 bouyer */
837 1.14.2.2 bouyer static const char*
838 1.14.2.2 bouyer bktr_probe( pcici_t tag, pcidi_t type )
839 1.14.2.2 bouyer {
840 1.14.2.2 bouyer unsigned int rev = pci_conf_read( tag, PCIR_REVID) & 0x000000ff;
841 1.14.2.2 bouyer
842 1.14.2.2 bouyer if (PCI_VENDOR(type) == PCI_VENDOR_BROOKTREE)
843 1.14.2.2 bouyer {
844 1.14.2.2 bouyer switch (PCI_PRODUCT(type)) {
845 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT848:
846 1.14.2.2 bouyer if (rev == 0x12) return("BrookTree 848A");
847 1.14.2.2 bouyer else return("BrookTree 848");
848 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT849:
849 1.14.2.2 bouyer return("BrookTree 849A");
850 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT878:
851 1.14.2.2 bouyer return("BrookTree 878");
852 1.14.2.2 bouyer case PCI_PRODUCT_BROOKTREE_BT879:
853 1.14.2.2 bouyer return("BrookTree 879");
854 1.14.2.2 bouyer }
855 1.14.2.2 bouyer };
856 1.14.2.2 bouyer
857 1.14.2.2 bouyer return ((char *)0);
858 1.14.2.2 bouyer }
859 1.14.2.2 bouyer
860 1.14.2.2 bouyer /*
861 1.14.2.2 bouyer * the attach routine.
862 1.14.2.2 bouyer */
863 1.14.2.2 bouyer static void
864 1.14.2.2 bouyer bktr_attach( pcici_t tag, int unit )
865 1.14.2.2 bouyer {
866 1.14.2.2 bouyer bktr_ptr_t bktr;
867 1.14.2.2 bouyer u_long latency;
868 1.14.2.2 bouyer u_long fun;
869 1.14.2.2 bouyer unsigned int rev;
870 1.14.2.2 bouyer unsigned long base;
871 1.14.2.2 bouyer #ifdef BROOKTREE_IRQ
872 1.14.2.2 bouyer u_long old_irq, new_irq;
873 1.14.2.2 bouyer #endif
874 1.14.2.2 bouyer
875 1.14.2.2 bouyer bktr = &brooktree[unit];
876 1.14.2.2 bouyer
877 1.14.2.2 bouyer if (unit >= NBKTR) {
878 1.14.2.2 bouyer printf("brooktree%d: attach: only %d units configured.\n",
879 1.14.2.2 bouyer unit, NBKTR);
880 1.14.2.2 bouyer printf("brooktree%d: attach: invalid unit number.\n", unit);
881 1.14.2.2 bouyer return;
882 1.14.2.2 bouyer }
883 1.14.2.2 bouyer
884 1.14.2.2 bouyer /* build the device name for bktr_name() */
885 1.14.2.2 bouyer snprintf(bktr->bktr_xname, sizeof(bktr->bktr_xname), "bktr%d",unit);
886 1.14.2.2 bouyer
887 1.14.2.2 bouyer /* Enable Memory Mapping */
888 1.14.2.2 bouyer fun = pci_conf_read(tag, PCI_COMMAND_STATUS_REG);
889 1.14.2.2 bouyer pci_conf_write(tag, PCI_COMMAND_STATUS_REG, fun | 2);
890 1.14.2.2 bouyer
891 1.14.2.2 bouyer /* Enable Bus Mastering */
892 1.14.2.2 bouyer fun = pci_conf_read(tag, PCI_COMMAND_STATUS_REG);
893 1.14.2.2 bouyer pci_conf_write(tag, PCI_COMMAND_STATUS_REG, fun | 4);
894 1.14.2.2 bouyer
895 1.14.2.2 bouyer bktr->tag = tag;
896 1.14.2.2 bouyer
897 1.14.2.2 bouyer
898 1.14.2.2 bouyer /*
899 1.14.2.2 bouyer * Map control/status registers
900 1.14.2.2 bouyer */
901 1.14.2.2 bouyer pci_map_mem( tag, PCI_MAP_REG_START, (vm_offset_t *) &base,
902 1.14.2.2 bouyer &bktr->phys_base );
903 1.14.2.2 bouyer #if (__FreeBSD_version >= 300000)
904 1.14.2.2 bouyer bktr->memt = I386_BUS_SPACE_MEM; /* XXX should use proper bus space */
905 1.14.2.2 bouyer bktr->memh = (bus_space_handle_t)base; /* XXX functions here */
906 1.14.2.2 bouyer #endif
907 1.14.2.2 bouyer
908 1.14.2.2 bouyer /*
909 1.14.2.2 bouyer * Disable the brooktree device
910 1.14.2.2 bouyer */
911 1.14.2.2 bouyer OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
912 1.14.2.2 bouyer OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
913 1.14.2.2 bouyer
914 1.14.2.2 bouyer #ifdef BROOKTREE_IRQ /* from the configuration file */
915 1.14.2.2 bouyer old_irq = pci_conf_read(tag, PCI_INTERRUPT_REG);
916 1.14.2.2 bouyer pci_conf_write(tag, PCI_INTERRUPT_REG, BROOKTREE_IRQ);
917 1.14.2.2 bouyer new_irq = pci_conf_read(tag, PCI_INTERRUPT_REG);
918 1.14.2.2 bouyer printf("bktr%d: attach: irq changed from %d to %d\n",
919 1.14.2.2 bouyer unit, (old_irq & 0xff), (new_irq & 0xff));
920 1.14.2.2 bouyer #endif
921 1.14.2.2 bouyer
922 1.14.2.2 bouyer /*
923 1.14.2.2 bouyer * setup the interrupt handling routine
924 1.14.2.2 bouyer */
925 1.14.2.2 bouyer pci_map_int(tag, bktr_intr, (void*) bktr, &tty_imask);
926 1.14.2.2 bouyer
927 1.14.2.2 bouyer
928 1.14.2.2 bouyer /* Update the Device Control Register */
929 1.14.2.2 bouyer /* on Bt878 and Bt879 cards */
930 1.14.2.2 bouyer fun = pci_conf_read(tag, 0x40);
931 1.14.2.2 bouyer fun = fun | 1; /* Enable writes to the sub-system vendor ID */
932 1.14.2.2 bouyer
933 1.14.2.2 bouyer #if defined( BKTR_430_FX_MODE )
934 1.14.2.2 bouyer if (bootverbose) printf("Using 430 FX chipset compatibilty mode\n");
935 1.14.2.2 bouyer fun = fun | 2; /* Enable Intel 430 FX compatibility mode */
936 1.14.2.2 bouyer #endif
937 1.14.2.2 bouyer
938 1.14.2.2 bouyer #if defined( BKTR_SIS_VIA_MODE )
939 1.14.2.2 bouyer if (bootverbose) printf("Using SiS/VIA chipset compatibilty mode\n");
940 1.14.2.2 bouyer fun = fun | 4; /* Enable SiS/VIA compatibility mode (usefull for
941 1.14.2.2 bouyer OPTi chipset motherboards too */
942 1.14.2.2 bouyer #endif
943 1.14.2.2 bouyer pci_conf_write(tag, 0x40, fun);
944 1.14.2.2 bouyer
945 1.14.2.2 bouyer
946 1.14.2.2 bouyer /* XXX call bt848_i2c dependent attach() routine */
947 1.14.2.2 bouyer #if (NSMBUS > 0)
948 1.14.2.2 bouyer if (bt848_i2c_attach(unit, bktr, &bktr->i2c_sc))
949 1.14.2.2 bouyer printf("bktr%d: i2c_attach: can't attach\n", unit);
950 1.14.2.2 bouyer #endif
951 1.14.2.2 bouyer
952 1.14.2.2 bouyer
953 1.14.2.2 bouyer /*
954 1.14.2.2 bouyer * PCI latency timer. 32 is a good value for 4 bus mastering slots, if
955 1.14.2.2 bouyer * you have more than four, then 16 would probably be a better value.
956 1.14.2.2 bouyer */
957 1.14.2.2 bouyer #ifndef BROOKTREE_DEF_LATENCY_VALUE
958 1.14.2.2 bouyer #define BROOKTREE_DEF_LATENCY_VALUE 10
959 1.14.2.2 bouyer #endif
960 1.14.2.2 bouyer latency = pci_conf_read(tag, PCI_LATENCY_TIMER);
961 1.14.2.2 bouyer latency = (latency >> 8) & 0xff;
962 1.14.2.2 bouyer if ( bootverbose ) {
963 1.14.2.2 bouyer if (latency)
964 1.14.2.2 bouyer printf("brooktree%d: PCI bus latency is", unit);
965 1.14.2.2 bouyer else
966 1.14.2.2 bouyer printf("brooktree%d: PCI bus latency was 0 changing to",
967 1.14.2.2 bouyer unit);
968 1.14.2.2 bouyer }
969 1.14.2.2 bouyer if ( !latency ) {
970 1.14.2.2 bouyer latency = BROOKTREE_DEF_LATENCY_VALUE;
971 1.14.2.2 bouyer pci_conf_write(tag, PCI_LATENCY_TIMER, latency<<8);
972 1.14.2.2 bouyer }
973 1.14.2.2 bouyer if ( bootverbose ) {
974 1.14.2.2 bouyer printf(" %d.\n", (int) latency);
975 1.14.2.2 bouyer }
976 1.14.2.2 bouyer
977 1.14.2.2 bouyer
978 1.14.2.2 bouyer /* read the pci device id and revision id */
979 1.14.2.2 bouyer fun = pci_conf_read(tag, PCI_ID_REG);
980 1.14.2.2 bouyer rev = pci_conf_read(tag, PCIR_REVID) & 0x000000ff;
981 1.14.2.2 bouyer
982 1.14.2.2 bouyer /* call the common attach code */
983 1.14.2.2 bouyer common_bktr_attach( bktr, unit, fun, rev );
984 1.14.2.2 bouyer
985 1.14.2.2 bouyer #ifdef DEVFS
986 1.14.2.2 bouyer /* XXX This just throw away the token, which should probably be fixed when
987 1.14.2.2 bouyer DEVFS is finally made really operational. */
988 1.14.2.2 bouyer devfs_add_devswf(&bktr_cdevsw, unit, DV_CHR, 0, 0, 0444, "bktr%d", unit);
989 1.14.2.2 bouyer devfs_add_devswf(&bktr_cdevsw, unit+16, DV_CHR, 0, 0, 0444, "tuner%d", unit);
990 1.14.2.2 bouyer devfs_add_devswf(&bktr_cdevsw, unit+32, DV_CHR, 0, 0, 0444, "vbi%d", unit);
991 1.14.2.2 bouyer #endif /* DEVFS */
992 1.14.2.2 bouyer
993 1.14.2.2 bouyer }
994 1.14.2.2 bouyer
995 1.14.2.2 bouyer
996 1.14.2.2 bouyer /*
997 1.14.2.2 bouyer * Special Memory Allocation
998 1.14.2.2 bouyer */
999 1.14.2.2 bouyer vm_offset_t
1000 1.14.2.2 bouyer get_bktr_mem( int unit, unsigned size )
1001 1.14.2.2 bouyer {
1002 1.14.2.2 bouyer vm_offset_t addr = 0;
1003 1.14.2.2 bouyer
1004 1.14.2.2 bouyer addr = vm_page_alloc_contig(size, 0x100000, 0xffffffff, 1<<24);
1005 1.14.2.2 bouyer if (addr == 0)
1006 1.14.2.2 bouyer addr = vm_page_alloc_contig(size, 0x100000, 0xffffffff,
1007 1.14.2.2 bouyer PAGE_SIZE);
1008 1.14.2.2 bouyer if (addr == 0) {
1009 1.14.2.2 bouyer printf("bktr%d: Unable to allocate %d bytes of memory.\n",
1010 1.14.2.2 bouyer unit, size);
1011 1.14.2.2 bouyer }
1012 1.14.2.2 bouyer
1013 1.14.2.2 bouyer return( addr );
1014 1.14.2.2 bouyer }
1015 1.14.2.2 bouyer
1016 1.14.2.2 bouyer /*---------------------------------------------------------
1017 1.14.2.2 bouyer **
1018 1.14.2.2 bouyer ** BrookTree 848 character device driver routines
1019 1.14.2.2 bouyer **
1020 1.14.2.2 bouyer **---------------------------------------------------------
1021 1.14.2.2 bouyer */
1022 1.14.2.2 bouyer
1023 1.14.2.2 bouyer
1024 1.14.2.2 bouyer #define VIDEO_DEV 0x00
1025 1.14.2.2 bouyer #define TUNER_DEV 0x01
1026 1.14.2.2 bouyer #define VBI_DEV 0x02
1027 1.14.2.2 bouyer
1028 1.14.2.2 bouyer #define UNIT(x) ((x) & 0x0f)
1029 1.14.2.2 bouyer #define FUNCTION(x) ((x >> 4) & 0x0f)
1030 1.14.2.2 bouyer
1031 1.14.2.2 bouyer
1032 1.14.2.2 bouyer /*
1033 1.14.2.2 bouyer *
1034 1.14.2.2 bouyer */
1035 1.14.2.2 bouyer int
1036 1.14.2.2 bouyer bktr_open( dev_t dev, int flags, int fmt, struct proc *p )
1037 1.14.2.2 bouyer {
1038 1.14.2.2 bouyer bktr_ptr_t bktr;
1039 1.14.2.2 bouyer int unit;
1040 1.14.2.2 bouyer
1041 1.14.2.2 bouyer unit = UNIT( minor(dev) );
1042 1.14.2.2 bouyer if (unit >= NBKTR) /* unit out of range */
1043 1.14.2.2 bouyer return( ENXIO );
1044 1.14.2.2 bouyer
1045 1.14.2.2 bouyer bktr = &(brooktree[ unit ]);
1046 1.14.2.2 bouyer
1047 1.14.2.2 bouyer if (!(bktr->flags & METEOR_INITALIZED)) /* device not found */
1048 1.14.2.2 bouyer return( ENXIO );
1049 1.14.2.2 bouyer
1050 1.14.2.2 bouyer
1051 1.14.2.2 bouyer if (bt848_card != -1) {
1052 1.14.2.2 bouyer if ((bt848_card >> 8 == unit ) &&
1053 1.14.2.2 bouyer ( (bt848_card & 0xff) < Bt848_MAX_CARD )) {
1054 1.14.2.2 bouyer if ( bktr->bt848_card != (bt848_card & 0xff) ) {
1055 1.14.2.2 bouyer bktr->bt848_card = (bt848_card & 0xff);
1056 1.14.2.2 bouyer probeCard(bktr, FALSE, unit);
1057 1.14.2.2 bouyer }
1058 1.14.2.2 bouyer }
1059 1.14.2.2 bouyer }
1060 1.14.2.2 bouyer
1061 1.14.2.2 bouyer if (bt848_tuner != -1) {
1062 1.14.2.2 bouyer if ((bt848_tuner >> 8 == unit ) &&
1063 1.14.2.2 bouyer ( (bt848_tuner & 0xff) < Bt848_MAX_TUNER )) {
1064 1.14.2.2 bouyer if ( bktr->bt848_tuner != (bt848_tuner & 0xff) ) {
1065 1.14.2.2 bouyer bktr->bt848_tuner = (bt848_tuner & 0xff);
1066 1.14.2.2 bouyer probeCard(bktr, FALSE, unit);
1067 1.14.2.2 bouyer }
1068 1.14.2.2 bouyer }
1069 1.14.2.2 bouyer }
1070 1.14.2.2 bouyer
1071 1.14.2.2 bouyer if (bt848_reverse_mute != -1) {
1072 1.14.2.2 bouyer if ((bt848_reverse_mute >> 8) == unit ) {
1073 1.14.2.2 bouyer bktr->reverse_mute = bt848_reverse_mute & 0xff;
1074 1.14.2.2 bouyer }
1075 1.14.2.2 bouyer }
1076 1.14.2.2 bouyer
1077 1.14.2.2 bouyer if (bt848_slow_msp_audio != -1) {
1078 1.14.2.2 bouyer if ((bt848_slow_msp_audio >> 8) == unit ) {
1079 1.14.2.2 bouyer bktr->slow_msp_audio = (bt848_slow_msp_audio & 0xff);
1080 1.14.2.2 bouyer }
1081 1.14.2.2 bouyer }
1082 1.14.2.2 bouyer
1083 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
1084 1.14.2.2 bouyer case VIDEO_DEV:
1085 1.14.2.2 bouyer return( video_open( bktr ) );
1086 1.14.2.2 bouyer case TUNER_DEV:
1087 1.14.2.2 bouyer return( tuner_open( bktr ) );
1088 1.14.2.2 bouyer case VBI_DEV:
1089 1.14.2.2 bouyer return( vbi_open( bktr ) );
1090 1.14.2.2 bouyer }
1091 1.14.2.2 bouyer return( ENXIO );
1092 1.14.2.2 bouyer }
1093 1.14.2.2 bouyer
1094 1.14.2.2 bouyer
1095 1.14.2.2 bouyer /*
1096 1.14.2.2 bouyer *
1097 1.14.2.2 bouyer */
1098 1.14.2.2 bouyer int
1099 1.14.2.2 bouyer bktr_close( dev_t dev, int flags, int fmt, struct proc *p )
1100 1.14.2.2 bouyer {
1101 1.14.2.2 bouyer bktr_ptr_t bktr;
1102 1.14.2.2 bouyer int unit;
1103 1.14.2.2 bouyer
1104 1.14.2.2 bouyer unit = UNIT( minor(dev) );
1105 1.14.2.2 bouyer if (unit >= NBKTR) /* unit out of range */
1106 1.14.2.2 bouyer return( ENXIO );
1107 1.14.2.2 bouyer
1108 1.14.2.2 bouyer bktr = &(brooktree[ unit ]);
1109 1.14.2.2 bouyer
1110 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
1111 1.14.2.2 bouyer case VIDEO_DEV:
1112 1.14.2.2 bouyer return( video_close( bktr ) );
1113 1.14.2.2 bouyer case TUNER_DEV:
1114 1.14.2.2 bouyer return( tuner_close( bktr ) );
1115 1.14.2.2 bouyer case VBI_DEV:
1116 1.14.2.2 bouyer return( vbi_close( bktr ) );
1117 1.14.2.2 bouyer }
1118 1.14.2.2 bouyer
1119 1.14.2.2 bouyer return( ENXIO );
1120 1.14.2.2 bouyer }
1121 1.14.2.2 bouyer
1122 1.14.2.2 bouyer /*
1123 1.14.2.2 bouyer *
1124 1.14.2.2 bouyer */
1125 1.14.2.2 bouyer int
1126 1.14.2.2 bouyer bktr_read( dev_t dev, struct uio *uio, int ioflag )
1127 1.14.2.2 bouyer {
1128 1.14.2.2 bouyer bktr_ptr_t bktr;
1129 1.14.2.2 bouyer int unit;
1130 1.14.2.2 bouyer
1131 1.14.2.2 bouyer unit = UNIT(minor(dev));
1132 1.14.2.2 bouyer if (unit >= NBKTR) /* unit out of range */
1133 1.14.2.2 bouyer return( ENXIO );
1134 1.14.2.2 bouyer
1135 1.14.2.2 bouyer bktr = &(brooktree[unit]);
1136 1.14.2.2 bouyer
1137 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
1138 1.14.2.2 bouyer case VIDEO_DEV:
1139 1.14.2.2 bouyer return( video_read( bktr, unit, dev, uio ) );
1140 1.14.2.2 bouyer case VBI_DEV:
1141 1.14.2.2 bouyer return( vbi_read( bktr, uio, ioflag ) );
1142 1.14.2.2 bouyer }
1143 1.14.2.2 bouyer return( ENXIO );
1144 1.14.2.2 bouyer }
1145 1.14.2.2 bouyer
1146 1.14.2.2 bouyer
1147 1.14.2.2 bouyer /*
1148 1.14.2.2 bouyer *
1149 1.14.2.2 bouyer */
1150 1.14.2.2 bouyer int
1151 1.14.2.2 bouyer bktr_write( dev_t dev, struct uio *uio, int ioflag )
1152 1.14.2.2 bouyer {
1153 1.14.2.2 bouyer return( EINVAL ); /* XXX or ENXIO ? */
1154 1.14.2.2 bouyer }
1155 1.14.2.2 bouyer
1156 1.14.2.2 bouyer /*
1157 1.14.2.2 bouyer *
1158 1.14.2.2 bouyer */
1159 1.14.2.2 bouyer int
1160 1.14.2.2 bouyer bktr_ioctl( dev_t dev, ioctl_cmd_t cmd, caddr_t arg, int flag, struct proc* pr )
1161 1.14.2.2 bouyer {
1162 1.14.2.2 bouyer bktr_ptr_t bktr;
1163 1.14.2.2 bouyer int unit;
1164 1.14.2.2 bouyer
1165 1.14.2.2 bouyer unit = UNIT(minor(dev));
1166 1.14.2.2 bouyer if (unit >= NBKTR) /* unit out of range */
1167 1.14.2.2 bouyer return( ENXIO );
1168 1.14.2.2 bouyer
1169 1.14.2.2 bouyer bktr = &(brooktree[ unit ]);
1170 1.14.2.2 bouyer
1171 1.14.2.2 bouyer if (bktr->bigbuf == 0) /* no frame buffer allocated (ioctl failed) */
1172 1.14.2.2 bouyer return( ENOMEM );
1173 1.14.2.2 bouyer
1174 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
1175 1.14.2.2 bouyer case VIDEO_DEV:
1176 1.14.2.2 bouyer return( video_ioctl( bktr, unit, cmd, arg, pr ) );
1177 1.14.2.2 bouyer case TUNER_DEV:
1178 1.14.2.2 bouyer return( tuner_ioctl( bktr, unit, cmd, arg, pr ) );
1179 1.14.2.2 bouyer }
1180 1.14.2.2 bouyer
1181 1.14.2.2 bouyer return( ENXIO );
1182 1.14.2.2 bouyer }
1183 1.14.2.2 bouyer
1184 1.14.2.2 bouyer /*
1185 1.14.2.2 bouyer * bktr_mmap.
1186 1.14.2.2 bouyer * Note: 2.2.5/2.2.6/2.2.7/3.0 users must manually
1187 1.14.2.2 bouyer * edit the line below and change "vm_offset_t" to "int"
1188 1.14.2.2 bouyer */
1189 1.14.2.2 bouyer int bktr_mmap( dev_t dev, vm_offset_t offset, int nprot )
1190 1.14.2.2 bouyer
1191 1.14.2.2 bouyer {
1192 1.14.2.2 bouyer int unit;
1193 1.14.2.2 bouyer bktr_ptr_t bktr;
1194 1.14.2.2 bouyer
1195 1.14.2.2 bouyer unit = UNIT(minor(dev));
1196 1.14.2.2 bouyer
1197 1.14.2.2 bouyer if (unit >= NBKTR || FUNCTION(minor(dev)) > 0)
1198 1.14.2.2 bouyer return( -1 );
1199 1.14.2.2 bouyer
1200 1.14.2.2 bouyer bktr = &(brooktree[ unit ]);
1201 1.14.2.2 bouyer
1202 1.14.2.2 bouyer if (nprot & PROT_EXEC)
1203 1.14.2.2 bouyer return( -1 );
1204 1.14.2.2 bouyer
1205 1.14.2.2 bouyer if (offset < 0)
1206 1.14.2.2 bouyer return( -1 );
1207 1.14.2.2 bouyer
1208 1.14.2.2 bouyer if (offset >= bktr->alloc_pages * PAGE_SIZE)
1209 1.14.2.2 bouyer return( -1 );
1210 1.14.2.2 bouyer
1211 1.14.2.2 bouyer return( i386_btop(vtophys(bktr->bigbuf) + offset) );
1212 1.14.2.2 bouyer }
1213 1.14.2.2 bouyer
1214 1.14.2.2 bouyer int bktr_poll( dev_t dev, int events, struct proc *p)
1215 1.14.2.2 bouyer {
1216 1.14.2.2 bouyer int unit;
1217 1.14.2.2 bouyer bktr_ptr_t bktr;
1218 1.14.2.2 bouyer int revents = 0;
1219 1.14.2.2 bouyer
1220 1.14.2.2 bouyer unit = UNIT(minor(dev));
1221 1.14.2.2 bouyer
1222 1.14.2.2 bouyer if (unit >= NBKTR)
1223 1.14.2.2 bouyer return( -1 );
1224 1.14.2.2 bouyer
1225 1.14.2.2 bouyer bktr = &(brooktree[ unit ]);
1226 1.14.2.2 bouyer
1227 1.14.2.2 bouyer disable_intr();
1228 1.14.2.2 bouyer
1229 1.14.2.2 bouyer if (events & (POLLIN | POLLRDNORM)) {
1230 1.14.2.2 bouyer
1231 1.14.2.2 bouyer switch ( FUNCTION( minor(dev) ) ) {
1232 1.14.2.2 bouyer case VBI_DEV:
1233 1.14.2.2 bouyer if(bktr->vbisize == 0)
1234 1.14.2.2 bouyer selrecord(p, &bktr->vbi_select);
1235 1.14.2.2 bouyer else
1236 1.14.2.2 bouyer revents |= events & (POLLIN | POLLRDNORM);
1237 1.14.2.2 bouyer break;
1238 1.14.2.2 bouyer }
1239 1.14.2.2 bouyer }
1240 1.14.2.2 bouyer
1241 1.14.2.2 bouyer enable_intr();
1242 1.14.2.2 bouyer
1243 1.14.2.2 bouyer return (revents);
1244 1.14.2.2 bouyer }
1245 1.14.2.2 bouyer
1246 1.14.2.2 bouyer
1247 1.14.2.2 bouyer #endif /* FreeBSD 2.2.x and 3.x specific kernel interface routines */
1248 1.14.2.2 bouyer
1249 1.14.2.2 bouyer
1250 1.14.2.2 bouyer /*****************/
1251 1.14.2.2 bouyer /* *** BSDI *** */
1252 1.14.2.2 bouyer /*****************/
1253 1.14.2.2 bouyer
1254 1.14.2.2 bouyer #if defined(__bsdi__)
1255 1.14.2.2 bouyer #endif /* __bsdi__ BSDI specific kernel interface routines */
1256 1.14.2.2 bouyer
1257 1.14.2.2 bouyer
1258 1.14.2.2 bouyer /*****************************/
1259 1.14.2.2 bouyer /* *** OpenBSD / NetBSD *** */
1260 1.14.2.2 bouyer /*****************************/
1261 1.14.2.2 bouyer #if defined(__NetBSD__) || defined(__OpenBSD__)
1262 1.14.2.2 bouyer
1263 1.14.2.2 bouyer #define IPL_VIDEO IPL_BIO /* XXX */
1264 1.14.2.2 bouyer
1265 1.14.2.2 bouyer static int bktr_intr(void *arg) { return common_bktr_intr(arg); }
1266 1.14.2.2 bouyer
1267 1.14.2.2 bouyer #define bktr_open bktropen
1268 1.14.2.2 bouyer #define bktr_close bktrclose
1269 1.14.2.2 bouyer #define bktr_read bktrread
1270 1.14.2.2 bouyer #define bktr_write bktrwrite
1271 1.14.2.2 bouyer #define bktr_ioctl bktrioctl
1272 1.14.2.2 bouyer #define bktr_mmap bktrmmap
1273 1.14.2.2 bouyer
1274 1.14.2.2 bouyer vm_offset_t vm_page_alloc_contig(vm_offset_t, vm_offset_t,
1275 1.14.2.2 bouyer vm_offset_t, vm_offset_t);
1276 1.14.2.2 bouyer
1277 1.14.2.2 bouyer #if defined(__OpenBSD__)
1278 1.14.2.2 bouyer static int bktr_probe __P((struct device *, void *, void *));
1279 1.14.2.2 bouyer #else
1280 1.14.2.2 bouyer static int bktr_probe __P((struct device *, struct cfdata *, void *));
1281 1.14.2.2 bouyer #endif
1282 1.14.2.2 bouyer static void bktr_attach __P((struct device *, struct device *, void *));
1283 1.14.2.2 bouyer
1284 1.14.2.2 bouyer struct cfattach bktr_ca = {
1285 1.14.2.2 bouyer sizeof(struct bktr_softc), bktr_probe, bktr_attach
1286 1.14.2.2 bouyer };
1287 1.14.2.2 bouyer
1288 1.14.2.2 bouyer #if defined(__NetBSD__)
1289 1.14.2.2 bouyer extern struct cfdriver bktr_cd;
1290 1.14.2.2 bouyer #else
1291 1.14.2.2 bouyer struct cfdriver bktr_cd = {
1292 1.14.2.2 bouyer NULL, "bktr", DV_DULL
1293 1.14.2.2 bouyer };
1294 1.14.2.2 bouyer #endif
1295 1.14.2.2 bouyer
1296 1.14.2.2 bouyer int
1297 1.14.2.2 bouyer bktr_probe(parent, match, aux)
1298 1.14.2.2 bouyer struct device *parent;
1299 1.14.2.2 bouyer #if defined(__OpenBSD__)
1300 1.14.2.2 bouyer void *match;
1301 1.14.2.2 bouyer #else
1302 1.14.2.2 bouyer struct cfdata *match;
1303 1.14.2.2 bouyer #endif
1304 1.14.2.2 bouyer void *aux;
1305 1.14.2.2 bouyer {
1306 1.14.2.2 bouyer struct pci_attach_args *pa = aux;
1307 1.14.2.2 bouyer
1308 1.14.2.2 bouyer if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_BROOKTREE &&
1309 1.14.2.2 bouyer (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT848 ||
1310 1.14.2.2 bouyer PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT849 ||
1311 1.14.2.2 bouyer PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT878 ||
1312 1.14.2.2 bouyer PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BROOKTREE_BT879))
1313 1.14.2.2 bouyer return 1;
1314 1.14.2.2 bouyer
1315 1.14.2.2 bouyer return 0;
1316 1.14.2.2 bouyer }
1317 1.14.2.2 bouyer
1318 1.14.2.2 bouyer
1319 1.14.2.2 bouyer /*
1320 1.14.2.2 bouyer * the attach routine.
1321 1.14.2.2 bouyer */
1322 1.14.2.2 bouyer static void
1323 1.14.2.2 bouyer bktr_attach(struct device *parent, struct device *self, void *aux)
1324 1.14.2.2 bouyer {
1325 1.14.2.2 bouyer bktr_ptr_t bktr;
1326 1.14.2.2 bouyer u_long latency;
1327 1.14.2.2 bouyer u_long fun;
1328 1.14.2.2 bouyer unsigned int rev;
1329 1.14.2.2 bouyer
1330 1.14.2.2 bouyer #if defined(__OpenBSD__)
1331 1.14.2.2 bouyer struct pci_attach_args *pa = aux;
1332 1.14.2.2 bouyer pci_chipset_tag_t pc = pa->pa_pc;
1333 1.14.2.2 bouyer
1334 1.14.2.2 bouyer pci_intr_handle_t ih;
1335 1.14.2.2 bouyer const char *intrstr;
1336 1.14.2.2 bouyer int retval;
1337 1.14.2.2 bouyer int unit;
1338 1.14.2.2 bouyer
1339 1.14.2.2 bouyer bktr = (bktr_ptr_t)self;
1340 1.14.2.2 bouyer unit = bktr->bktr_dev.dv_unit;
1341 1.14.2.2 bouyer
1342 1.14.2.2 bouyer bktr->pc = pa->pa_pc;
1343 1.14.2.2 bouyer bktr->tag = pa->pa_tag;
1344 1.14.2.2 bouyer bktr->dmat = pa->pa_dmat;
1345 1.14.2.2 bouyer
1346 1.14.2.2 bouyer /*
1347 1.14.2.2 bouyer * map memory
1348 1.14.2.2 bouyer */
1349 1.14.2.2 bouyer bktr->memt = pa->pa_memt;
1350 1.14.2.2 bouyer retval = pci_mem_find(pc, pa->pa_tag, PCI_MAPREG_START,
1351 1.14.2.2 bouyer &bktr->phys_base, &bktr->obmemsz, NULL);
1352 1.14.2.2 bouyer if (!retval)
1353 1.14.2.2 bouyer retval = bus_space_map(pa->pa_memt, bktr->phys_base,
1354 1.14.2.2 bouyer bktr->obmemsz, 0, &bktr->memh);
1355 1.14.2.2 bouyer if (retval) {
1356 1.14.2.2 bouyer printf(": couldn't map memory\n");
1357 1.14.2.2 bouyer return;
1358 1.14.2.2 bouyer }
1359 1.14.2.2 bouyer
1360 1.14.2.2 bouyer
1361 1.14.2.2 bouyer /*
1362 1.14.2.2 bouyer * map interrupt
1363 1.14.2.2 bouyer */
1364 1.14.2.2 bouyer if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
1365 1.14.2.2 bouyer pa->pa_intrline, &ih)) {
1366 1.14.2.2 bouyer printf(": couldn't map interrupt\n");
1367 1.14.2.2 bouyer return;
1368 1.14.2.2 bouyer }
1369 1.14.2.2 bouyer intrstr = pci_intr_string(pa->pa_pc, ih);
1370 1.14.2.2 bouyer
1371 1.14.2.2 bouyer bktr->ih = pci_intr_establish(pa->pa_pc, ih, IPL_VIDEO,
1372 1.14.2.2 bouyer bktr_intr, bktr, bktr->bktr_dev.dv_xname);
1373 1.14.2.2 bouyer if (bktr->ih == NULL) {
1374 1.14.2.2 bouyer printf(": couldn't establish interrupt");
1375 1.14.2.2 bouyer if (intrstr != NULL)
1376 1.14.2.2 bouyer printf(" at %s", intrstr);
1377 1.14.2.2 bouyer printf("\n");
1378 1.14.2.2 bouyer return;
1379 1.14.2.2 bouyer }
1380 1.14.2.2 bouyer
1381 1.14.2.2 bouyer if (intrstr != NULL)
1382 1.14.2.2 bouyer printf(": %s\n", intrstr);
1383 1.14.2.2 bouyer #endif /* __OpenBSD__ */
1384 1.14.2.2 bouyer
1385 1.14.2.2 bouyer #if defined(__NetBSD__)
1386 1.14.2.2 bouyer struct pci_attach_args *pa = aux;
1387 1.14.2.2 bouyer pci_intr_handle_t ih;
1388 1.14.2.2 bouyer const char *intrstr;
1389 1.14.2.2 bouyer int retval;
1390 1.14.2.2 bouyer int unit;
1391 1.14.2.2 bouyer
1392 1.14.2.2 bouyer bktr = (bktr_ptr_t)self;
1393 1.14.2.2 bouyer unit = bktr->bktr_dev.dv_unit;
1394 1.14.2.2 bouyer bktr->dmat = pa->pa_dmat;
1395 1.14.2.2 bouyer
1396 1.14.2.2 bouyer printf("\n");
1397 1.14.2.2 bouyer
1398 1.14.2.2 bouyer /*
1399 1.14.2.2 bouyer * map memory
1400 1.14.2.2 bouyer */
1401 1.14.2.2 bouyer retval = pci_mapreg_map(pa, PCI_MAPREG_START,
1402 1.14.2.2 bouyer PCI_MAPREG_TYPE_MEM
1403 1.14.2.2 bouyer | PCI_MAPREG_MEM_TYPE_32BIT, 0,
1404 1.14.2.2 bouyer &bktr->memt, &bktr->memh, NULL,
1405 1.14.2.2 bouyer &bktr->obmemsz);
1406 1.14.2.2 bouyer DPR(("pci_mapreg_map: memt %x, memh %x, size %x\n",
1407 1.14.2.2 bouyer bktr->memt, (u_int)bktr->memh, (u_int)bktr->obmemsz));
1408 1.14.2.2 bouyer if (retval) {
1409 1.14.2.2 bouyer printf("%s: couldn't map memory\n", bktr_name(bktr));
1410 1.14.2.2 bouyer return;
1411 1.14.2.2 bouyer }
1412 1.14.2.2 bouyer
1413 1.14.2.2 bouyer /*
1414 1.14.2.2 bouyer * Disable the brooktree device
1415 1.14.2.2 bouyer */
1416 1.14.2.2 bouyer OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
1417 1.14.2.2 bouyer OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
1418 1.14.2.2 bouyer
1419 1.14.2.2 bouyer /*
1420 1.14.2.2 bouyer * map interrupt
1421 1.14.2.2 bouyer */
1422 1.14.2.2 bouyer if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
1423 1.14.2.2 bouyer pa->pa_intrline, &ih)) {
1424 1.14.2.2 bouyer printf("%s: couldn't map interrupt\n",
1425 1.14.2.2 bouyer bktr_name(bktr));
1426 1.14.2.2 bouyer return;
1427 1.14.2.2 bouyer }
1428 1.14.2.2 bouyer intrstr = pci_intr_string(pa->pa_pc, ih);
1429 1.14.2.2 bouyer bktr->ih = pci_intr_establish(pa->pa_pc, ih, IPL_VIDEO,
1430 1.14.2.2 bouyer bktr_intr, bktr);
1431 1.14.2.2 bouyer if (bktr->ih == NULL) {
1432 1.14.2.2 bouyer printf("%s: couldn't establish interrupt",
1433 1.14.2.2 bouyer bktr_name(bktr));
1434 1.14.2.2 bouyer if (intrstr != NULL)
1435 1.14.2.2 bouyer printf(" at %s", intrstr);
1436 1.14.2.2 bouyer printf("\n");
1437 1.14.2.2 bouyer return;
1438 1.14.2.2 bouyer }
1439 1.14.2.2 bouyer if (intrstr != NULL)
1440 1.14.2.2 bouyer printf("%s: interrupting at %s\n", bktr_name(bktr),
1441 1.14.2.2 bouyer intrstr);
1442 1.14.2.2 bouyer #endif /* __NetBSD__ */
1443 1.14.2.2 bouyer
1444 1.14.2.2 bouyer /*
1445 1.14.2.2 bouyer * PCI latency timer. 32 is a good value for 4 bus mastering slots, if
1446 1.14.2.2 bouyer * you have more than four, then 16 would probably be a better value.
1447 1.14.2.2 bouyer */
1448 1.14.2.2 bouyer #ifndef BROOKTREE_DEF_LATENCY_VALUE
1449 1.14.2.2 bouyer #define BROOKTREE_DEF_LATENCY_VALUE 10
1450 1.14.2.2 bouyer #endif
1451 1.14.2.2 bouyer latency = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_LATENCY_TIMER);
1452 1.14.2.2 bouyer latency = (latency >> 8) & 0xff;
1453 1.14.2.2 bouyer
1454 1.14.2.2 bouyer if (!latency) {
1455 1.14.2.2 bouyer if (bootverbose) {
1456 1.14.2.2 bouyer printf("%s: PCI bus latency was 0 changing to %d",
1457 1.14.2.2 bouyer bktr_name(bktr), BROOKTREE_DEF_LATENCY_VALUE);
1458 1.14.2.2 bouyer }
1459 1.14.2.2 bouyer latency = BROOKTREE_DEF_LATENCY_VALUE;
1460 1.14.2.2 bouyer pci_conf_write(pa->pa_pc, pa->pa_tag,
1461 1.14.2.2 bouyer PCI_LATENCY_TIMER, latency<<8);
1462 1.14.2.2 bouyer }
1463 1.14.2.2 bouyer
1464 1.14.2.2 bouyer
1465 1.14.2.2 bouyer /* Enabled Bus Master
1466 1.14.2.2 bouyer XXX: check if all old DMA is stopped first (e.g. after warm
1467 1.14.2.2 bouyer boot) */
1468 1.14.2.2 bouyer fun = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
1469 1.14.2.2 bouyer pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
1470 1.14.2.2 bouyer fun | PCI_COMMAND_MASTER_ENABLE);
1471 1.14.2.2 bouyer
1472 1.14.2.2 bouyer /* read the pci id and determine the card type */
1473 1.14.2.2 bouyer fun = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_ID_REG);
1474 1.14.2.2 bouyer rev = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG) & 0x000000ff;
1475 1.14.2.2 bouyer
1476 1.14.2.2 bouyer common_bktr_attach(bktr, unit, fun, rev);
1477 1.14.2.2 bouyer }
1478 1.14.2.2 bouyer
1479 1.14.2.2 bouyer
1480 1.14.2.2 bouyer /*
1481 1.14.2.2 bouyer * Special Memory Allocation
1482 1.14.2.2 bouyer */
1483 1.14.2.2 bouyer vm_offset_t
1484 1.14.2.2 bouyer get_bktr_mem(bktr, dmapp, size)
1485 1.14.2.2 bouyer bktr_ptr_t bktr;
1486 1.14.2.2 bouyer bus_dmamap_t *dmapp;
1487 1.14.2.2 bouyer unsigned int size;
1488 1.14.2.2 bouyer {
1489 1.14.2.2 bouyer bus_dma_tag_t dmat = bktr->dmat;
1490 1.14.2.2 bouyer bus_dma_segment_t seg;
1491 1.14.2.2 bouyer bus_size_t align;
1492 1.14.2.2 bouyer int rseg;
1493 1.14.2.2 bouyer caddr_t kva;
1494 1.14.2.2 bouyer
1495 1.14.2.2 bouyer /*
1496 1.14.2.2 bouyer * Allocate a DMA area
1497 1.14.2.2 bouyer */
1498 1.14.2.2 bouyer align = 1 << 24;
1499 1.14.2.2 bouyer if (bus_dmamem_alloc(dmat, size, align, 0, &seg, 1,
1500 1.14.2.2 bouyer &rseg, BUS_DMA_NOWAIT)) {
1501 1.14.2.2 bouyer align = PAGE_SIZE;
1502 1.14.2.2 bouyer if (bus_dmamem_alloc(dmat, size, align, 0, &seg, 1,
1503 1.14.2.2 bouyer &rseg, BUS_DMA_NOWAIT)) {
1504 1.14.2.2 bouyer printf("%s: Unable to dmamem_alloc of %d bytes\n",
1505 1.14.2.2 bouyer bktr_name(bktr), size);
1506 1.14.2.2 bouyer return 0;
1507 1.14.2.2 bouyer }
1508 1.14.2.2 bouyer }
1509 1.14.2.2 bouyer if (bus_dmamem_map(dmat, &seg, rseg, size,
1510 1.14.2.2 bouyer &kva, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
1511 1.14.2.2 bouyer printf("%s: Unable to dmamem_map of %d bytes\n",
1512 1.14.2.2 bouyer bktr_name(bktr), size);
1513 1.14.2.2 bouyer bus_dmamem_free(dmat, &seg, rseg);
1514 1.14.2.2 bouyer return 0;
1515 1.14.2.2 bouyer }
1516 1.14.2.2 bouyer #ifdef __OpenBSD__
1517 1.14.2.2 bouyer bktr->dm_mapsize = size;
1518 1.14.2.2 bouyer #endif
1519 1.14.2.2 bouyer /*
1520 1.14.2.2 bouyer * Create and locd the DMA map for the DMA area
1521 1.14.2.2 bouyer */
1522 1.14.2.2 bouyer if (bus_dmamap_create(dmat, size, 1, size, 0, BUS_DMA_NOWAIT, dmapp)) {
1523 1.14.2.2 bouyer printf("%s: Unable to dmamap_create of %d bytes\n",
1524 1.14.2.2 bouyer bktr_name(bktr), size);
1525 1.14.2.2 bouyer bus_dmamem_unmap(dmat, kva, size);
1526 1.14.2.2 bouyer bus_dmamem_free(dmat, &seg, rseg);
1527 1.14.2.2 bouyer return 0;
1528 1.14.2.2 bouyer }
1529 1.14.2.2 bouyer if (bus_dmamap_load(dmat, *dmapp, kva, size, NULL, BUS_DMA_NOWAIT)) {
1530 1.14.2.2 bouyer printf("%s: Unable to dmamap_load of %d bytes\n",
1531 1.14.2.2 bouyer bktr_name(bktr), size);
1532 1.14.2.2 bouyer bus_dmamem_unmap(dmat, kva, size);
1533 1.14.2.2 bouyer bus_dmamem_free(dmat, &seg, rseg);
1534 1.14.2.2 bouyer bus_dmamap_destroy(dmat, *dmapp);
1535 1.14.2.2 bouyer return 0;
1536 1.14.2.2 bouyer }
1537 1.14.2.2 bouyer return (vm_offset_t)kva;
1538 1.14.2.2 bouyer }
1539 1.14.2.2 bouyer
1540 1.14.2.2 bouyer void
1541 1.14.2.2 bouyer free_bktr_mem(bktr, dmap, kva)
1542 1.14.2.2 bouyer bktr_ptr_t bktr;
1543 1.14.2.2 bouyer bus_dmamap_t dmap;
1544 1.14.2.2 bouyer vm_offset_t kva;
1545 1.14.2.2 bouyer {
1546 1.14.2.2 bouyer bus_dma_tag_t dmat = bktr->dmat;
1547 1.14.2.2 bouyer
1548 1.14.2.2 bouyer #ifdef __NetBSD__
1549 1.14.2.2 bouyer bus_dmamem_unmap(dmat, (caddr_t)kva, dmap->dm_mapsize);
1550 1.14.2.2 bouyer #else
1551 1.14.2.2 bouyer bus_dmamem_unmap(dmat, (caddr_t)kva, bktr->dm_mapsize);
1552 1.14.2.2 bouyer #endif
1553 1.14.2.2 bouyer bus_dmamem_free(dmat, dmap->dm_segs, 1);
1554 1.14.2.2 bouyer bus_dmamap_destroy(dmat, dmap);
1555 1.14.2.2 bouyer }
1556 1.14.2.2 bouyer
1557 1.14.2.2 bouyer
1558 1.14.2.2 bouyer /*---------------------------------------------------------
1559 1.14.2.2 bouyer **
1560 1.14.2.2 bouyer ** BrookTree 848 character device driver routines
1561 1.14.2.2 bouyer **
1562 1.14.2.2 bouyer **---------------------------------------------------------
1563 1.14.2.2 bouyer */
1564 1.14.2.2 bouyer
1565 1.14.2.2 bouyer
1566 1.14.2.2 bouyer #define VIDEO_DEV 0x00
1567 1.14.2.2 bouyer #define TUNER_DEV 0x01
1568 1.14.2.2 bouyer #define VBI_DEV 0x02
1569 1.14.2.2 bouyer
1570 1.14.2.2 bouyer #define UNIT(x) (minor((x) & 0x0f))
1571 1.14.2.2 bouyer #define FUNCTION(x) (minor((x >> 4) & 0x0f))
1572 1.14.2.2 bouyer
1573 1.14.2.2 bouyer /*
1574 1.14.2.2 bouyer *
1575 1.14.2.2 bouyer */
1576 1.14.2.2 bouyer int
1577 1.14.2.2 bouyer bktr_open(dev_t dev, int flags, int fmt, struct proc *p)
1578 1.14.2.2 bouyer {
1579 1.14.2.2 bouyer bktr_ptr_t bktr;
1580 1.14.2.2 bouyer int unit;
1581 1.14.2.2 bouyer
1582 1.14.2.2 bouyer unit = UNIT(dev);
1583 1.14.2.2 bouyer
1584 1.14.2.2 bouyer /* unit out of range */
1585 1.14.2.2 bouyer if ((unit > bktr_cd.cd_ndevs) || (bktr_cd.cd_devs[unit] == NULL))
1586 1.14.2.2 bouyer return(ENXIO);
1587 1.14.2.2 bouyer
1588 1.14.2.2 bouyer bktr = bktr_cd.cd_devs[unit];
1589 1.14.2.2 bouyer
1590 1.14.2.2 bouyer if (!(bktr->flags & METEOR_INITALIZED)) /* device not found */
1591 1.14.2.2 bouyer return(ENXIO);
1592 1.14.2.2 bouyer
1593 1.14.2.2 bouyer switch (FUNCTION(dev)) {
1594 1.14.2.2 bouyer case VIDEO_DEV:
1595 1.14.2.2 bouyer return(video_open(bktr));
1596 1.14.2.2 bouyer case TUNER_DEV:
1597 1.14.2.2 bouyer return(tuner_open(bktr));
1598 1.14.2.2 bouyer case VBI_DEV:
1599 1.14.2.2 bouyer return(vbi_open(bktr));
1600 1.14.2.2 bouyer }
1601 1.14.2.2 bouyer
1602 1.14.2.2 bouyer return(ENXIO);
1603 1.14.2.2 bouyer }
1604 1.14.2.2 bouyer
1605 1.14.2.2 bouyer
1606 1.14.2.2 bouyer /*
1607 1.14.2.2 bouyer *
1608 1.14.2.2 bouyer */
1609 1.14.2.2 bouyer int
1610 1.14.2.2 bouyer bktr_close(dev_t dev, int flags, int fmt, struct proc *p)
1611 1.14.2.2 bouyer {
1612 1.14.2.2 bouyer bktr_ptr_t bktr;
1613 1.14.2.2 bouyer int unit;
1614 1.14.2.2 bouyer
1615 1.14.2.2 bouyer unit = UNIT(dev);
1616 1.14.2.2 bouyer
1617 1.14.2.2 bouyer bktr = bktr_cd.cd_devs[unit];
1618 1.14.2.2 bouyer
1619 1.14.2.2 bouyer switch (FUNCTION(dev)) {
1620 1.14.2.2 bouyer case VIDEO_DEV:
1621 1.14.2.2 bouyer return(video_close(bktr));
1622 1.14.2.2 bouyer case TUNER_DEV:
1623 1.14.2.2 bouyer return(tuner_close(bktr));
1624 1.14.2.2 bouyer case VBI_DEV:
1625 1.14.2.2 bouyer return(vbi_close(bktr));
1626 1.14.2.2 bouyer }
1627 1.14.2.2 bouyer
1628 1.14.2.2 bouyer return(ENXIO);
1629 1.14.2.2 bouyer }
1630 1.14.2.2 bouyer
1631 1.14.2.2 bouyer /*
1632 1.14.2.2 bouyer *
1633 1.14.2.2 bouyer */
1634 1.14.2.2 bouyer int
1635 1.14.2.2 bouyer bktr_read(dev_t dev, struct uio *uio, int ioflag)
1636 1.14.2.2 bouyer {
1637 1.14.2.2 bouyer bktr_ptr_t bktr;
1638 1.14.2.2 bouyer int unit;
1639 1.14.2.2 bouyer
1640 1.14.2.2 bouyer unit = UNIT(dev);
1641 1.14.2.2 bouyer
1642 1.14.2.2 bouyer bktr = bktr_cd.cd_devs[unit];
1643 1.14.2.2 bouyer
1644 1.14.2.2 bouyer switch (FUNCTION(dev)) {
1645 1.14.2.2 bouyer case VIDEO_DEV:
1646 1.14.2.2 bouyer return(video_read(bktr, unit, dev, uio));
1647 1.14.2.2 bouyer case VBI_DEV:
1648 1.14.2.2 bouyer return(vbi_read(bktr, uio, ioflag));
1649 1.14.2.2 bouyer }
1650 1.14.2.2 bouyer
1651 1.14.2.2 bouyer return(ENXIO);
1652 1.14.2.2 bouyer }
1653 1.14.2.2 bouyer
1654 1.14.2.2 bouyer
1655 1.14.2.2 bouyer /*
1656 1.14.2.2 bouyer *
1657 1.14.2.2 bouyer */
1658 1.14.2.2 bouyer int
1659 1.14.2.2 bouyer bktr_write(dev_t dev, struct uio *uio, int ioflag)
1660 1.14.2.2 bouyer {
1661 1.14.2.2 bouyer /* operation not supported */
1662 1.14.2.2 bouyer return(EOPNOTSUPP);
1663 1.14.2.2 bouyer }
1664 1.14.2.2 bouyer
1665 1.14.2.2 bouyer /*
1666 1.14.2.2 bouyer *
1667 1.14.2.2 bouyer */
1668 1.14.2.2 bouyer int
1669 1.14.2.2 bouyer bktr_ioctl(dev_t dev, ioctl_cmd_t cmd, caddr_t arg, int flag, struct proc* pr)
1670 1.14.2.2 bouyer {
1671 1.14.2.2 bouyer bktr_ptr_t bktr;
1672 1.14.2.2 bouyer int unit;
1673 1.14.2.2 bouyer
1674 1.14.2.2 bouyer unit = UNIT(dev);
1675 1.14.2.2 bouyer
1676 1.14.2.2 bouyer bktr = bktr_cd.cd_devs[unit];
1677 1.14.2.2 bouyer
1678 1.14.2.2 bouyer if (bktr->bigbuf == 0) /* no frame buffer allocated (ioctl failed) */
1679 1.14.2.2 bouyer return(ENOMEM);
1680 1.14.2.2 bouyer
1681 1.14.2.2 bouyer switch (FUNCTION(dev)) {
1682 1.14.2.2 bouyer case VIDEO_DEV:
1683 1.14.2.2 bouyer return(video_ioctl(bktr, unit, cmd, arg, pr));
1684 1.14.2.2 bouyer case TUNER_DEV:
1685 1.14.2.2 bouyer return(tuner_ioctl(bktr, unit, cmd, arg, pr));
1686 1.14.2.2 bouyer }
1687 1.14.2.2 bouyer
1688 1.14.2.2 bouyer return(ENXIO);
1689 1.14.2.2 bouyer }
1690 1.14.2.2 bouyer
1691 1.14.2.2 bouyer /*
1692 1.14.2.2 bouyer *
1693 1.14.2.2 bouyer */
1694 1.14.2.2 bouyer paddr_t
1695 1.14.2.2 bouyer bktr_mmap(dev_t dev, off_t offset, int nprot)
1696 1.14.2.2 bouyer {
1697 1.14.2.2 bouyer int unit;
1698 1.14.2.2 bouyer bktr_ptr_t bktr;
1699 1.14.2.2 bouyer
1700 1.14.2.2 bouyer unit = UNIT(dev);
1701 1.14.2.2 bouyer
1702 1.14.2.2 bouyer if (FUNCTION(dev) > 0) /* only allow mmap on /dev/bktr[n] */
1703 1.14.2.2 bouyer return(-1);
1704 1.14.2.2 bouyer
1705 1.14.2.2 bouyer bktr = bktr_cd.cd_devs[unit];
1706 1.14.2.2 bouyer
1707 1.14.2.2 bouyer if ((vaddr_t)offset < 0)
1708 1.14.2.2 bouyer return(-1);
1709 1.14.2.2 bouyer
1710 1.14.2.2 bouyer if ((vaddr_t)offset >= bktr->alloc_pages * PAGE_SIZE)
1711 1.14.2.2 bouyer return(-1);
1712 1.14.2.2 bouyer
1713 1.14.2.2 bouyer #ifdef __NetBSD__
1714 1.14.2.2 bouyer return (bus_dmamem_mmap(bktr->dmat, bktr->dm_mem->dm_segs, 1,
1715 1.14.2.2 bouyer (vaddr_t)offset, nprot, BUS_DMA_WAITOK));
1716 1.14.2.2 bouyer #else
1717 1.14.2.2 bouyer return(i386_btop(vtophys(bktr->bigbuf) + offset));
1718 1.14.2.2 bouyer #endif
1719 1.14.2.2 bouyer }
1720 1.14.2.2 bouyer
1721 1.14.2.2 bouyer #endif /* __NetBSD__ || __OpenBSD__ */
1722