1 /* $SourceForge: bktr_os.c,v 1.5 2003/03/11 23:11:25 thomasklausner Exp $ */
3 /* $NetBSD: bktr_os.c,v 1.56 2009/05/06 09:25:17 cegger Exp $ */
4 /* $FreeBSD: src/sys/dev/bktr/bktr_os.c,v 1.20 2000/10/20 08:16:53 roger Exp$ */
7 * This is part of the Driver for Video Capture Cards (Frame grabbers)
8 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
10 * Copyright Roger Hardiman and Amancio Hasty.
12 * bktr_os : This has all the Operating System dependant code,
13 * probe/attach and open/close/ioctl/read/mmap
21 * 1. Redistributions of source code must retain the
22 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
23 * All rights reserved.
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * This product includes software developed by Amancio Hasty and
37 * 4. The name of the author may not be used to endorse or promote products
38 * derived from this software without specific prior written permission.
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
41 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
42 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
44 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
45 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
49 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50 * POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: bktr_os.c,v 1.56 2009/05/06 09:25:17 cegger Exp $");
58 #endif /* __FreeBSD__ */
60 #include "opt_bktr.h" /* include any kernel config options */
62 #define FIFO_RISC_DISABLED 0
63 #define ALL_INTS_DISABLED 0
70 #include <sys/param.h>
71 #include <sys/systm.h>
74 #include <sys/kernel.h>
75 #include <sys/signalvar.h>
78 #include <sys/select.h>
79 #include <sys/vnode.h>
82 #include <vm/vm_kern.h>
84 #include <vm/vm_extern.h>
86 #if (__FreeBSD_version >=400000) || (NSMBUS > 0)
87 #include <sys/bus.h> /* used by smbus and newbus */
90 #if (__FreeBSD_version >=300000)
91 #include <machine/bus_memio.h> /* used by bus space */
92 #include <sys/bus.h> /* used by bus space and newbus */
96 #if (__FreeBSD_version >=400000)
97 #include <sys/rman.h> /* used by newbus */
98 #include <machine/resource.h> /* used by newbus */
101 #if (__FreeBSD_version < 500000)
102 #include <machine/clock.h> /* for DELAY */
105 #include <pci/pcivar.h>
106 #include <pci/pcireg.h>
108 #include <sys/sysctl.h>
110 int bt848_tuner
= -1;
111 int bt848_reverse_mute
= -1;
112 int bt848_format
= -1;
113 int bt848_slow_msp_audio
= -1;
115 SYSCTL_NODE(_hw
, OID_AUTO
, bt848
, CTLFLAG_RW
, 0, "Bt848 Driver mgmt");
116 SYSCTL_INT(_hw_bt848
, OID_AUTO
, card
, CTLFLAG_RW
, &bt848_card
, -1, "");
117 SYSCTL_INT(_hw_bt848
, OID_AUTO
, tuner
, CTLFLAG_RW
, &bt848_tuner
, -1, "");
118 SYSCTL_INT(_hw_bt848
, OID_AUTO
, reverse_mute
, CTLFLAG_RW
, &bt848_reverse_mute
, -1, "");
119 SYSCTL_INT(_hw_bt848
, OID_AUTO
, format
, CTLFLAG_RW
, &bt848_format
, -1, "");
120 SYSCTL_INT(_hw_bt848
, OID_AUTO
, slow_msp_audio
, CTLFLAG_RW
, &bt848_slow_msp_audio
, -1, "");
122 #if (__FreeBSD__ == 2)
123 #define PCIR_REVID PCI_CLASS_REG
126 #endif /* end freebsd section */
134 #endif /* __bsdi__ */
137 /**************************/
138 /* *** OpenBSD/NetBSD *** */
139 /**************************/
140 #if defined(__NetBSD__) || defined(__OpenBSD__)
142 #include <sys/param.h>
143 #include <sys/systm.h>
144 #include <sys/conf.h>
146 #include <sys/kernel.h>
147 #include <sys/signalvar.h>
148 #include <sys/mman.h>
149 #include <sys/poll.h>
150 #include <sys/select.h>
151 #include <sys/vnode.h>
155 #include <vm/vm_kern.h>
157 #include <vm/vm_extern.h>
160 #include <sys/device.h>
161 #include <dev/pci/pcivar.h>
162 #include <dev/pci/pcireg.h>
163 #include <dev/pci/pcidevs.h>
168 #define DPR(x) if (bktr_debug) printf x
172 #endif /* __NetBSD__ || __OpenBSD__ */
175 dev_type_open(bktr_open
);
176 dev_type_close(bktr_close
);
177 dev_type_read(bktr_read
);
178 dev_type_write(bktr_write
);
179 dev_type_ioctl(bktr_ioctl
);
180 dev_type_mmap(bktr_mmap
);
182 const struct cdevsw bktr_cdevsw
= {
183 bktr_open
, bktr_close
, bktr_read
, bktr_write
, bktr_ioctl
,
184 nostop
, notty
, nopoll
, bktr_mmap
, nokqfilter
, D_OTHER
186 #endif /* __NetBSD __ */
189 #include <dev/ic/bt8xx.h> /* NetBSD location for .h files */
190 #include <dev/pci/bktr/bktr_reg.h>
191 #include <dev/pci/bktr/bktr_tuner.h>
192 #include <dev/pci/bktr/bktr_card.h>
193 #include <dev/pci/bktr/bktr_audio.h>
194 #include <dev/pci/bktr/bktr_core.h>
195 #include <dev/pci/bktr/bktr_os.h>
196 #else /* Traditional location for .h files */
197 #include <machine/ioctl_meteor.h>
198 #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */
199 #include <dev/bktr/bktr_reg.h>
200 #include <dev/bktr/bktr_tuner.h>
201 #include <dev/bktr/bktr_card.h>
202 #include <dev/bktr/bktr_audio.h>
203 #include <dev/bktr/bktr_core.h>
204 #include <dev/bktr/bktr_os.h>
205 #if defined(BKTR_USE_FREEBSD_SMBUS)
206 #include <dev/bktr/bktr_i2c.h>
210 /* Support for radio(4) under NetBSD */
214 #include <sys/radioio.h>
215 #include <dev/radio_if.h>
221 /****************************/
222 /* *** FreeBSD 4.x code *** */
223 /****************************/
224 #if (__FreeBSD_version >= 400000)
226 static int bktr_probe(device_t dev
);
227 static int bktr_attach(device_t dev
);
228 static int bktr_detach(device_t dev
);
229 static int bktr_shutdown(device_t dev
);
230 static void bktr_intr(void *arg
) { common_bktr_intr(arg
); }
232 static device_method_t bktr_methods
[] = {
233 /* Device interface */
234 DEVMETHOD(device_probe
, bktr_probe
),
235 DEVMETHOD(device_attach
, bktr_attach
),
236 DEVMETHOD(device_detach
, bktr_detach
),
237 DEVMETHOD(device_shutdown
, bktr_shutdown
),
242 static driver_t bktr_driver
= {
245 sizeof(struct bktr_softc
),
248 static devclass_t bktr_devclass
;
250 static d_open_t bktr_open
;
251 static d_close_t bktr_close
;
252 static d_read_t bktr_read
;
253 static d_write_t bktr_write
;
254 static d_ioctl_t bktr_ioctl
;
255 static d_mmap_t bktr_mmap
;
256 static d_poll_t bktr_poll
;
258 #define CDEV_MAJOR 92
259 static struct cdevsw bktr_cdevsw
= {
260 /* open */ bktr_open
,
261 /* close */ bktr_close
,
262 /* read */ bktr_read
,
263 /* write */ bktr_write
,
264 /* ioctl */ bktr_ioctl
,
265 /* poll */ bktr_poll
,
266 /* mmap */ bktr_mmap
,
267 /* strategy */ nostrategy
,
269 /* maj */ CDEV_MAJOR
,
276 DRIVER_MODULE(bktr
, pci
, bktr_driver
, bktr_devclass
, 0, 0);
277 #if (__FreeBSD_version > 410000)
278 MODULE_DEPEND(bktr
, bktr_mem
, 1,1,1);
279 MODULE_VERSION(bktr
, 1);
284 * the boot time probe routine.
287 bktr_probe(device_t dev
)
289 unsigned int type
= pci_get_devid(dev
);
290 unsigned int rev
= pci_get_revid(dev
);
292 if (PCI_VENDOR(type
) == PCI_VENDOR_BROOKTREE
)
294 switch (PCI_PRODUCT(type
)) {
295 case PCI_PRODUCT_BROOKTREE_BT848
:
297 device_set_desc(dev
, "BrookTree 848A");
299 device_set_desc(dev
, "BrookTree 848");
301 case PCI_PRODUCT_BROOKTREE_BT849
:
302 device_set_desc(dev
, "BrookTree 849A");
304 case PCI_PRODUCT_BROOKTREE_BT878
:
305 device_set_desc(dev
, "BrookTree 878");
307 case PCI_PRODUCT_BROOKTREE_BT879
:
308 device_set_desc(dev
, "BrookTree 879");
318 * the attach routine.
321 bktr_attach(device_t dev
)
330 u_int old_irq
, new_irq
;
333 struct bktr_softc
*bktr
= device_get_softc(dev
);
335 unit
= device_get_unit(dev
);
337 /* build the device name for bktr_name() */
338 snprintf(bktr
->bktr_xname
, sizeof(bktr
->bktr_xname
), "bktr%d",unit
);
341 * Enable bus mastering and Memory Mapped device
343 val
= pci_read_config(dev
, PCIR_COMMAND
, 4);
344 val
|= (PCIM_CMD_MEMEN
|PCIM_CMD_BUSMASTEREN
);
345 pci_write_config(dev
, PCIR_COMMAND
, val
, 4);
348 * Map control/status registers.
350 bktr
->mem_rid
= PCIR_MAPS
;
351 bktr
->res_mem
= bus_alloc_resource(dev
, SYS_RES_MEMORY
, &bktr
->mem_rid
,
352 0, ~0, 1, RF_ACTIVE
);
355 if (!bktr
->res_mem
) {
356 device_printf(dev
, "could not map memory\n");
360 bktr
->memt
= rman_get_bustag(bktr
->res_mem
);
361 bktr
->memh
= rman_get_bushandle(bktr
->res_mem
);
365 * Disable the brooktree device
367 OUTL(bktr
, BKTR_INT_MASK
, ALL_INTS_DISABLED
);
368 OUTW(bktr
, BKTR_GPIO_DMA_CTL
, FIFO_RISC_DISABLED
);
371 #ifdef BROOKTREE_IRQ /* from the configuration file */
372 old_irq
= pci_conf_read(tag
, PCI_INTERRUPT_REG
);
373 pci_conf_write(tag
, PCI_INTERRUPT_REG
, BROOKTREE_IRQ
);
374 new_irq
= pci_conf_read(tag
, PCI_INTERRUPT_REG
);
375 printf("bktr%d: attach: irq changed from %d to %d\n",
376 unit
, (old_irq
& 0xff), (new_irq
& 0xff));
380 * Allocate our interrupt.
383 bktr
->res_irq
= bus_alloc_resource(dev
, SYS_RES_IRQ
, &bktr
->irq_rid
,
384 0, ~0, 1, RF_SHAREABLE
| RF_ACTIVE
);
385 if (bktr
->res_irq
== NULL
) {
386 device_printf(dev
, "could not map interrupt\n");
391 error
= bus_setup_intr(dev
, bktr
->res_irq
, INTR_TYPE_TTY
,
392 bktr_intr
, bktr
, &bktr
->res_ih
);
394 device_printf(dev
, "could not setup irq\n");
400 /* Update the Device Control Register */
401 /* on Bt878 and Bt879 cards */
402 fun
= pci_read_config(dev
, 0x40, 2);
403 fun
= fun
| 1; /* Enable writes to the sub-system vendor ID */
405 #if defined(BKTR_430_FX_MODE)
406 if (bootverbose
) printf("Using 430 FX chipset compatibility mode\n");
407 fun
= fun
| 2; /* Enable Intel 430 FX compatibility mode */
410 #if defined(BKTR_SIS_VIA_MODE)
411 if (bootverbose
) printf("Using SiS/VIA chipset compatibility mode\n");
412 fun
= fun
| 4; /* Enable SiS/VIA compatibility mode (useful for
413 OPTi chipset motherboards too */
415 pci_write_config(dev
, 0x40, fun
, 2);
418 /* XXX call bt848_i2c dependent attach() routine */
419 #if defined(BKTR_USE_FREEBSD_SMBUS)
420 if (bt848_i2c_attach(unit
, bktr
, &bktr
->i2c_sc
))
421 printf("bktr%d: i2c_attach: can't attach\n", unit
);
426 * PCI latency timer. 32 is a good value for 4 bus mastering slots, if
427 * you have more than four, then 16 would probably be a better value.
429 #ifndef BROOKTREE_DEF_LATENCY_VALUE
430 #define BROOKTREE_DEF_LATENCY_VALUE 10
432 latency
= pci_read_config(dev
, PCI_LATENCY_TIMER
, 4);
433 latency
= (latency
>> 8) & 0xff;
436 printf("brooktree%d: PCI bus latency is", unit
);
438 printf("brooktree%d: PCI bus latency was 0 changing to",
442 latency
= BROOKTREE_DEF_LATENCY_VALUE
;
443 pci_write_config(dev
, PCI_LATENCY_TIMER
, latency
<<8, 4);
446 printf(" %d.\n", (int) latency
);
449 /* read the pci device id and revision id */
450 fun
= pci_get_devid(dev
);
451 rev
= pci_get_revid(dev
);
453 /* call the common attach code */
454 if (common_bktr_attach(bktr
, unit
, fun
, rev
) == 0)
457 /* make the device entries */
458 bktr
->bktrdev
= make_dev(&bktr_cdevsw
, unit
,
459 0, 0, 0444, "bktr%d", unit
);
460 bktr
->tunerdev
= make_dev(&bktr_cdevsw
, unit
+16,
461 0, 0, 0444, "tuner%d", unit
);
462 bktr
->vbidev
= make_dev(&bktr_cdevsw
, unit
+32,
463 0, 0, 0444, "vbi%d" , unit
);
466 /* if this is unit 0 (/dev/bktr0, /dev/tuner0, /dev/vbi0) then make */
467 /* alias entries to /dev/bktr /dev/tuner and /dev/vbi */
468 #if (__FreeBSD_version >=500000)
470 bktr
->bktrdev_alias
= make_dev_alias(bktr
->bktrdev
, "bktr");
471 bktr
->tunerdev_alias
= make_dev_alias(bktr
->tunerdev
, "tuner");
472 bktr
->vbidev_alias
= make_dev_alias(bktr
->vbidev
, "vbi");
480 bus_release_resource(dev
, SYS_RES_IRQ
, bktr
->irq_rid
, bktr
->res_irq
);
482 bus_release_resource(dev
, SYS_RES_IRQ
, bktr
->mem_rid
, bktr
->res_mem
);
488 * the detach routine.
491 bktr_detach(device_t dev
)
495 struct bktr_softc
*bktr
= device_get_softc(dev
);
497 unit
= device_get_unit(dev
);
499 /* Disable the brooktree device */
500 OUTL(bktr
, BKTR_INT_MASK
, ALL_INTS_DISABLED
);
501 OUTW(bktr
, BKTR_GPIO_DMA_CTL
, FIFO_RISC_DISABLED
);
503 /* Note: We do not free memory for RISC programs, grab buffer, vbi buffers */
504 /* The memory is retained by the bktr_mem module so we can unload and */
505 /* then reload the main bktr driver module */
507 /* Unregister the /dev/bktrN, tunerN and vbiN devices */
508 destroy_dev(bktr
->vbidev
);
509 destroy_dev(bktr
->tunerdev
);
510 destroy_dev(bktr
->bktrdev
);
512 /* If this is unit 0, then destroy the alias entries too */
513 #if (__FreeBSD_version >=500000)
515 destroy_dev(bktr
->vbidev_alias
);
516 destroy_dev(bktr
->tunerdev_alias
);
517 destroy_dev(bktr
->bktrdev_alias
);
520 seldestroy(&bktr
->vbi_select
);
523 * Deallocate resources.
525 bus_teardown_intr(dev
, bktr
->res_irq
, bktr
->res_ih
);
526 bus_release_resource(dev
, SYS_RES_IRQ
, bktr
->irq_rid
, bktr
->res_irq
);
527 bus_release_resource(dev
, SYS_RES_MEMORY
, bktr
->mem_rid
, bktr
->res_mem
);
533 * the shutdown routine.
536 bktr_shutdown(device_t dev
)
538 struct bktr_softc
*bktr
= device_get_softc(dev
);
540 /* Disable the brooktree device */
541 OUTL(bktr
, BKTR_INT_MASK
, ALL_INTS_DISABLED
);
542 OUTW(bktr
, BKTR_GPIO_DMA_CTL
, FIFO_RISC_DISABLED
);
549 * Special Memory Allocation
552 get_bktr_mem(int unit
, unsigned size
)
554 vm_offset_t addr
= 0;
556 addr
= vm_page_alloc_contig(size
, 0, 0xffffffff, 1<<24);
558 addr
= vm_page_alloc_contig(size
, 0, 0xffffffff, PAGE_SIZE
);
560 printf("bktr%d: Unable to allocate %d bytes of memory.\n",
568 /*---------------------------------------------------------
570 ** BrookTree 848 character device driver routines
572 **---------------------------------------------------------
575 #define VIDEO_DEV 0x00
576 #define TUNER_DEV 0x01
579 #define UNIT(x) ((x) & 0x0f)
580 #define FUNCTION(x) (x >> 4)
586 bktr_open(dev_t dev
, int flags
, int fmt
, struct lwp
*l
)
592 unit
= UNIT(minor(dev
));
594 /* Get the device data */
595 bktr
= (struct bktr_softc
*)devclass_get_softc(bktr_devclass
, unit
);
597 /* the device is no longer valid/functioning */
601 if (!(bktr
->flags
& METEOR_INITIALIZED
)) /* device not found */
604 /* Record that the device is now busy */
605 device_busy(devclass_get_device(bktr_devclass
, unit
));
608 if (bt848_card
!= -1) {
609 if ((bt848_card
>> 8 == unit
) &&
610 ((bt848_card
& 0xff) < Bt848_MAX_CARD
)) {
611 if (bktr
->bt848_card
!= (bt848_card
& 0xff)) {
612 bktr
->bt848_card
= (bt848_card
& 0xff);
613 probeCard(bktr
, FALSE
, unit
);
618 if (bt848_tuner
!= -1) {
619 if ((bt848_tuner
>> 8 == unit
) &&
620 ((bt848_tuner
& 0xff) < Bt848_MAX_TUNER
)) {
621 if (bktr
->bt848_tuner
!= (bt848_tuner
& 0xff)) {
622 bktr
->bt848_tuner
= (bt848_tuner
& 0xff);
623 probeCard(bktr
, FALSE
, unit
);
628 if (bt848_reverse_mute
!= -1) {
629 if ((bt848_reverse_mute
>> 8) == unit
) {
630 bktr
->reverse_mute
= bt848_reverse_mute
& 0xff;
634 if (bt848_slow_msp_audio
!= -1) {
635 if ((bt848_slow_msp_audio
>> 8) == unit
) {
636 bktr
->slow_msp_audio
= (bt848_slow_msp_audio
& 0xff);
640 switch (FUNCTION(minor(dev
))) {
642 result
= video_open(bktr
);
645 result
= tuner_open(bktr
);
648 result
= vbi_open(bktr
);
655 /* If there was an error opening the device, undo the busy status */
657 device_unbusy(devclass_get_device(bktr_devclass
, unit
));
666 bktr_close(dev_t dev
, int flags
, int fmt
, struct lwp
*l
)
672 unit
= UNIT(minor(dev
));
674 /* Get the device data */
675 bktr
= (struct bktr_softc
*)devclass_get_softc(bktr_devclass
, unit
);
677 /* the device is no longer valid/functioning */
681 switch (FUNCTION(minor(dev
))) {
683 result
= video_close(bktr
);
686 result
= tuner_close(bktr
);
689 result
= vbi_close(bktr
);
696 device_unbusy(devclass_get_device(bktr_devclass
, unit
));
705 bktr_read(dev_t dev
, struct uio
*uio
, int ioflag
)
710 unit
= UNIT(minor(dev
));
712 /* Get the device data */
713 bktr
= (struct bktr_softc
*)devclass_get_softc(bktr_devclass
, unit
);
715 /* the device is no longer valid/functioning */
719 switch (FUNCTION(minor(dev
))) {
721 return(video_read(bktr
, unit
, dev
, uio
));
723 return(vbi_read(bktr
, uio
, ioflag
));
733 bktr_write(dev_t dev
, struct uio
*uio
, int ioflag
)
735 return(EINVAL
); /* XXX or ENXIO ? */
743 bktr_ioctl(dev_t dev
, ioctl_cmd_t cmd
, void *arg
, int flag
, struct proc
* pr
)
748 unit
= UNIT(minor(dev
));
750 /* Get the device data */
751 bktr
= (struct bktr_softc
*)devclass_get_softc(bktr_devclass
, unit
);
753 /* the device is no longer valid/functioning */
757 if (bktr
->bigbuf
== 0) /* no frame buffer allocated (ioctl failed) */
760 switch (FUNCTION(minor(dev
))) {
762 return(video_ioctl(bktr
, unit
, cmd
, arg
, pr
));
764 return(tuner_ioctl(bktr
, unit
, cmd
, arg
, pr
));
775 bktr_mmap(dev_t dev
, vm_offset_t offset
, int nprot
)
780 unit
= UNIT(minor(dev
));
782 if (FUNCTION(minor(dev
)) > 0) /* only allow mmap on /dev/bktr[n] */
785 /* Get the device data */
786 bktr
= (struct bktr_softc
*)devclass_get_softc(bktr_devclass
, unit
);
788 /* the device is no longer valid/functioning */
792 if (nprot
& PROT_EXEC
)
798 if (offset
>= bktr
->alloc_pages
* PAGE_SIZE
)
801 return(atop(vtophys(bktr
->bigbuf
) + offset
));
804 int bktr_poll(dev_t dev
, int events
, struct lwp
*l
)
809 DECLARE_INTR_MASK(s
);
811 unit
= UNIT(minor(dev
));
813 /* Get the device data */
814 bktr
= (struct bktr_softc
*)devclass_get_softc(bktr_devclass
, unit
);
816 /* the device is no longer valid/functioning */
822 if (events
& (POLLIN
| POLLRDNORM
)) {
824 switch (FUNCTION(minor(dev
))) {
826 if(bktr
->vbisize
== 0)
827 selrecord(p
, &bktr
->vbi_select
);
829 revents
|= events
& (POLLIN
| POLLRDNORM
);
839 #endif /* FreeBSD 4.x specific kernel interface routines */
841 /**********************************/
842 /* *** FreeBSD 2.2.x and 3.x *** */
843 /**********************************/
845 #if ((__FreeBSD__ == 2) || (__FreeBSD__ == 3))
847 static bktr_reg_t brooktree
[NBKTR
];
849 static const char* bktr_probe(pcici_t tag
, pcidi_t type
);
850 static void bktr_attach(pcici_t tag
, int unit
);
851 static void bktr_intr(void *arg
) { common_bktr_intr(arg
); }
853 static u_int bktr_count
;
855 static struct pci_device bktr_device
= {
862 DATA_SET (pcidevice_set
, bktr_device
);
864 static d_open_t bktr_open
;
865 static d_close_t bktr_close
;
866 static d_read_t bktr_read
;
867 static d_write_t bktr_write
;
868 static d_ioctl_t bktr_ioctl
;
869 static d_mmap_t bktr_mmap
;
870 static d_poll_t bktr_poll
;
872 #define CDEV_MAJOR 92
873 static struct cdevsw bktr_cdevsw
=
875 bktr_open
, bktr_close
, bktr_read
, bktr_write
,
876 bktr_ioctl
, nostop
, nullreset
, nodevtotty
,
877 bktr_poll
, bktr_mmap
, NULL
, "bktr",
881 static int bktr_devsw_installed
;
884 bktr_drvinit(void *unused
)
888 if (! bktr_devsw_installed
) {
889 dev
= makedev(CDEV_MAJOR
, 0);
890 cdevsw_add(&dev
,&bktr_cdevsw
, NULL
);
891 bktr_devsw_installed
= 1;
895 SYSINIT(bktrdev
,SI_SUB_DRIVERS
,SI_ORDER_MIDDLE
+CDEV_MAJOR
,bktr_drvinit
,NULL
)
898 * the boot time probe routine.
901 bktr_probe(pcici_t tag
, pcidi_t type
)
903 unsigned int rev
= pci_conf_read(tag
, PCIR_REVID
) & 0x000000ff;
905 if (PCI_VENDOR(type
) == PCI_VENDOR_BROOKTREE
)
907 switch (PCI_PRODUCT(type
)) {
908 case PCI_PRODUCT_BROOKTREE_BT848
:
909 if (rev
== 0x12) return("BrookTree 848A");
910 else return("BrookTree 848");
911 case PCI_PRODUCT_BROOKTREE_BT849
:
912 return("BrookTree 849A");
913 case PCI_PRODUCT_BROOKTREE_BT878
:
914 return("BrookTree 878");
915 case PCI_PRODUCT_BROOKTREE_BT879
:
916 return("BrookTree 879");
924 * the attach routine.
927 bktr_attach(pcici_t tag
, int unit
)
935 u_int old_irq
, new_irq
;
938 bktr
= &brooktree
[unit
];
941 printf("brooktree%d: attach: only %d units configured.\n",
943 printf("brooktree%d: attach: invalid unit number.\n", unit
);
947 /* build the device name for bktr_name() */
948 snprintf(bktr
->bktr_xname
, sizeof(bktr
->bktr_xname
), "bktr%d",unit
);
950 /* Enable Memory Mapping */
951 fun
= pci_conf_read(tag
, PCI_COMMAND_STATUS_REG
);
952 pci_conf_write(tag
, PCI_COMMAND_STATUS_REG
, fun
| 2);
954 /* Enable Bus Mastering */
955 fun
= pci_conf_read(tag
, PCI_COMMAND_STATUS_REG
);
956 pci_conf_write(tag
, PCI_COMMAND_STATUS_REG
, fun
| 4);
962 * Map control/status registers
964 pci_map_mem(tag
, PCI_MAP_REG_START
, (vm_offset_t
*) &base
,
966 #if (__FreeBSD_version >= 300000)
967 bktr
->memt
= I386_BUS_SPACE_MEM
; /* XXX should use proper bus space */
968 bktr
->memh
= (bus_space_handle_t
)base
; /* XXX functions here */
972 * Disable the brooktree device
974 OUTL(bktr
, BKTR_INT_MASK
, ALL_INTS_DISABLED
);
975 OUTW(bktr
, BKTR_GPIO_DMA_CTL
, FIFO_RISC_DISABLED
);
977 #ifdef BROOKTREE_IRQ /* from the configuration file */
978 old_irq
= pci_conf_read(tag
, PCI_INTERRUPT_REG
);
979 pci_conf_write(tag
, PCI_INTERRUPT_REG
, BROOKTREE_IRQ
);
980 new_irq
= pci_conf_read(tag
, PCI_INTERRUPT_REG
);
981 printf("bktr%d: attach: irq changed from %d to %d\n",
982 unit
, (old_irq
& 0xff), (new_irq
& 0xff));
986 * setup the interrupt handling routine
988 pci_map_int(tag
, bktr_intr
, (void*) bktr
, &tty_imask
);
991 /* Update the Device Control Register */
992 /* on Bt878 and Bt879 cards */
993 fun
= pci_conf_read(tag
, 0x40);
994 fun
= fun
| 1; /* Enable writes to the sub-system vendor ID */
996 #if defined(BKTR_430_FX_MODE)
997 if (bootverbose
) printf("Using 430 FX chipset compatibility mode\n");
998 fun
= fun
| 2; /* Enable Intel 430 FX compatibility mode */
1001 #if defined(BKTR_SIS_VIA_MODE)
1002 if (bootverbose
) printf("Using SiS/VIA chipset compatibility mode\n");
1003 fun
= fun
| 4; /* Enable SiS/VIA compatibility mode (useful for
1004 OPTi chipset motherboards too */
1006 pci_conf_write(tag
, 0x40, fun
);
1009 /* XXX call bt848_i2c dependent attach() routine */
1010 #if defined(BKTR_USE_FREEBSD_SMBUS)
1011 if (bt848_i2c_attach(unit
, bktr
, &bktr
->i2c_sc
))
1012 printf("bktr%d: i2c_attach: can't attach\n", unit
);
1017 * PCI latency timer. 32 is a good value for 4 bus mastering slots, if
1018 * you have more than four, then 16 would probably be a better value.
1020 #ifndef BROOKTREE_DEF_LATENCY_VALUE
1021 #define BROOKTREE_DEF_LATENCY_VALUE 10
1023 latency
= pci_conf_read(tag
, PCI_LATENCY_TIMER
);
1024 latency
= (latency
>> 8) & 0xff;
1027 printf("brooktree%d: PCI bus latency is", unit
);
1029 printf("brooktree%d: PCI bus latency was 0 changing to",
1033 latency
= BROOKTREE_DEF_LATENCY_VALUE
;
1034 pci_conf_write(tag
, PCI_LATENCY_TIMER
, latency
<<8);
1037 printf(" %d.\n", (int) latency
);
1041 /* read the pci device id and revision id */
1042 fun
= pci_conf_read(tag
, PCI_ID_REG
);
1043 rev
= pci_conf_read(tag
, PCIR_REVID
) & 0x000000ff;
1045 /* call the common attach code */
1046 common_bktr_attach(bktr
, unit
, fun
, rev
);
1052 * Special Memory Allocation
1055 get_bktr_mem(int unit
, unsigned size
)
1057 vm_offset_t addr
= 0;
1059 addr
= vm_page_alloc_contig(size
, 0x100000, 0xffffffff, 1<<24);
1061 addr
= vm_page_alloc_contig(size
, 0x100000, 0xffffffff,
1064 printf("bktr%d: Unable to allocate %d bytes of memory.\n",
1071 /*---------------------------------------------------------
1073 ** BrookTree 848 character device driver routines
1075 **---------------------------------------------------------
1079 #define VIDEO_DEV 0x00
1080 #define TUNER_DEV 0x01
1081 #define VBI_DEV 0x02
1083 #define UNIT(x) ((x) & 0x0f)
1084 #define FUNCTION(x) ((x >> 4) & 0x0f)
1091 bktr_open(dev_t dev
, int flags
, int fmt
, struct lwp
*l
)
1096 unit
= UNIT(minor(dev
));
1097 if (unit
>= NBKTR
) /* unit out of range */
1100 bktr
= &(brooktree
[unit
]);
1102 if (!(bktr
->flags
& METEOR_INITIALIZED
)) /* device not found */
1106 if (bt848_card
!= -1) {
1107 if ((bt848_card
>> 8 == unit
) &&
1108 ((bt848_card
& 0xff) < Bt848_MAX_CARD
)) {
1109 if (bktr
->bt848_card
!= (bt848_card
& 0xff)) {
1110 bktr
->bt848_card
= (bt848_card
& 0xff);
1111 probeCard(bktr
, FALSE
, unit
);
1116 if (bt848_tuner
!= -1) {
1117 if ((bt848_tuner
>> 8 == unit
) &&
1118 ((bt848_tuner
& 0xff) < Bt848_MAX_TUNER
)) {
1119 if (bktr
->bt848_tuner
!= (bt848_tuner
& 0xff)) {
1120 bktr
->bt848_tuner
= (bt848_tuner
& 0xff);
1121 probeCard(bktr
, FALSE
, unit
);
1126 if (bt848_reverse_mute
!= -1) {
1127 if ((bt848_reverse_mute
>> 8) == unit
) {
1128 bktr
->reverse_mute
= bt848_reverse_mute
& 0xff;
1132 if (bt848_slow_msp_audio
!= -1) {
1133 if ((bt848_slow_msp_audio
>> 8) == unit
) {
1134 bktr
->slow_msp_audio
= (bt848_slow_msp_audio
& 0xff);
1138 switch (FUNCTION(minor(dev
))) {
1140 return(video_open(bktr
));
1142 return(tuner_open(bktr
));
1144 return(vbi_open(bktr
));
1154 bktr_close(dev_t dev
, int flags
, int fmt
, struct lwp
*l
)
1159 unit
= UNIT(minor(dev
));
1160 if (unit
>= NBKTR
) /* unit out of range */
1163 bktr
= &(brooktree
[unit
]);
1165 switch (FUNCTION(minor(dev
))) {
1167 return(video_close(bktr
));
1169 return(tuner_close(bktr
));
1171 return(vbi_close(bktr
));
1181 bktr_read(dev_t dev
, struct uio
*uio
, int ioflag
)
1186 unit
= UNIT(minor(dev
));
1187 if (unit
>= NBKTR
) /* unit out of range */
1190 bktr
= &(brooktree
[unit
]);
1192 switch (FUNCTION(minor(dev
))) {
1194 return(video_read(bktr
, unit
, dev
, uio
));
1196 return(vbi_read(bktr
, uio
, ioflag
));
1206 bktr_write(dev_t dev
, struct uio
*uio
, int ioflag
)
1208 return(EINVAL
); /* XXX or ENXIO ? */
1215 bktr_ioctl(dev_t dev
, ioctl_cmd_t cmd
, void *arg
, int flag
, struct proc
* pr
)
1220 unit
= UNIT(minor(dev
));
1221 if (unit
>= NBKTR
) /* unit out of range */
1224 bktr
= &(brooktree
[unit
]);
1226 if (bktr
->bigbuf
== 0) /* no frame buffer allocated (ioctl failed) */
1229 switch (FUNCTION(minor(dev
))) {
1231 return(video_ioctl(bktr
, unit
, cmd
, arg
, pr
));
1233 return(tuner_ioctl(bktr
, unit
, cmd
, arg
, pr
));
1241 * Note: 2.2.5/2.2.6/2.2.7/3.0 users must manually
1242 * edit the line below and change "vm_offset_t" to "int"
1244 int bktr_mmap(dev_t dev
, vm_offset_t offset
, int nprot
)
1250 unit
= UNIT(minor(dev
));
1252 if (unit
>= NBKTR
|| FUNCTION(minor(dev
)) > 0)
1255 bktr
= &(brooktree
[unit
]);
1257 if (nprot
& PROT_EXEC
)
1263 if (offset
>= bktr
->alloc_pages
* PAGE_SIZE
)
1266 return(i386_btop(vtophys(bktr
->bigbuf
) + offset
));
1269 int bktr_poll(dev_t dev
, int events
, struct lwp
*l
)
1275 unit
= UNIT(minor(dev
));
1280 bktr
= &(brooktree
[unit
]);
1284 if (events
& (POLLIN
| POLLRDNORM
)) {
1286 switch (FUNCTION(minor(dev
))) {
1288 if(bktr
->vbisize
== 0)
1289 selrecord(p
, &bktr
->vbi_select
);
1291 revents
|= events
& (POLLIN
| POLLRDNORM
);
1302 #endif /* FreeBSD 2.2.x and 3.x specific kernel interface routines */
1309 #if defined(__bsdi__)
1310 #endif /* __bsdi__ BSDI specific kernel interface routines */
1313 /*****************************/
1314 /* *** OpenBSD / NetBSD *** */
1315 /*****************************/
1316 #if defined(__NetBSD__) || defined(__OpenBSD__)
1318 #define IPL_VIDEO IPL_BIO /* XXX */
1320 static int bktr_intr(void *arg
) { return common_bktr_intr(arg
); }
1322 #if defined(__OpenBSD__)
1323 #define bktr_open bktropen
1324 #define bktr_close bktrclose
1325 #define bktr_read bktrread
1326 #define bktr_write bktrwrite
1327 #define bktr_ioctl bktrioctl
1328 #define bktr_mmap bktrmmap
1330 static int bktr_probe(struct device
*, void *, void *);
1332 static int bktr_probe(device_t
, cfdata_t
, void *);
1334 static void bktr_attach(device_t
, device_t
, void *);
1336 CFATTACH_DECL(bktr
, sizeof(struct bktr_softc
),
1337 bktr_probe
, bktr_attach
, NULL
, NULL
);
1339 #if defined(__NetBSD__)
1340 extern struct cfdriver bktr_cd
;
1342 struct cfdriver bktr_cd
= {
1343 NULL
, "bktr", DV_DULL
1350 int bktr_get_info(void *, struct radio_info
*);
1351 int bktr_set_info(void *, struct radio_info
*);
1353 static struct radio_hw_if bktr_hw_if
= {
1363 bktr_probe(device_t parent
, cfdata_t match
, void *aux
)
1365 struct pci_attach_args
*pa
= aux
;
1367 if (PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_BROOKTREE
&&
1368 (PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_BROOKTREE_BT848
||
1369 PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_BROOKTREE_BT849
||
1370 PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_BROOKTREE_BT878
||
1371 PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_BROOKTREE_BT879
))
1379 * the attach routine.
1382 bktr_attach(device_t parent
, device_t self
, void *aux
)
1387 #if defined(__OpenBSD__)
1390 struct pci_attach_args
*pa
= aux
;
1391 pci_chipset_tag_t pc
= pa
->pa_pc
;
1393 pci_intr_handle_t ih
;
1394 const char *intrstr
;
1398 bktr
= (bktr_ptr_t
)self
;
1399 unit
= bktr
->bktr_dev
.dv_unit
;
1401 bktr
->pc
= pa
->pa_pc
;
1402 bktr
->tag
= pa
->pa_tag
;
1403 bktr
->dmat
= pa
->pa_dmat
;
1408 bktr
->memt
= pa
->pa_memt
;
1409 retval
= pci_mem_find(pc
, pa
->pa_tag
, PCI_MAPREG_START
,
1410 &bktr
->phys_base
, &bktr
->obmemsz
, NULL
);
1412 retval
= bus_space_map(pa
->pa_memt
, bktr
->phys_base
,
1413 bktr
->obmemsz
, 0, &bktr
->memh
);
1415 printf(": couldn't map memory\n");
1423 if (pci_intr_map(pa
->pa_pc
, pa
->pa_intrtag
, pa
->pa_intrpin
,
1424 pa
->pa_intrline
, &ih
)) {
1425 printf(": couldn't map interrupt\n");
1428 intrstr
= pci_intr_string(pa
->pa_pc
, ih
);
1430 bktr
->ih
= pci_intr_establish(pa
->pa_pc
, ih
, IPL_VIDEO
,
1431 bktr_intr
, bktr
, device_xname(&bktr
->bktr_dev
));
1432 if (bktr
->ih
== NULL
) {
1433 printf(": couldn't establish interrupt");
1434 if (intrstr
!= NULL
)
1435 printf(" at %s", intrstr
);
1440 if (intrstr
!= NULL
)
1441 printf(": %s\n", intrstr
);
1442 #endif /* __OpenBSD__ */
1444 #if defined(__NetBSD__)
1445 struct pci_attach_args
*pa
= aux
;
1446 pci_intr_handle_t ih
;
1448 const char *intrstr
;
1452 bktr
= (bktr_ptr_t
)self
;
1453 unit
= device_unit(&bktr
->bktr_dev
);
1454 bktr
->dmat
= pa
->pa_dmat
;
1458 /* Enable Bus Master
1459 XXX: check if all old DMA is stopped first (e.g. after warm
1461 command
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
);
1462 command
|= PCI_COMMAND_MASTER_ENABLE
;
1463 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
, command
);
1468 retval
= pci_mapreg_map(pa
, PCI_MAPREG_START
,
1470 | PCI_MAPREG_MEM_TYPE_32BIT
, 0,
1471 &bktr
->memt
, &bktr
->memh
, NULL
,
1473 DPR(("pci_mapreg_map: memt %lx, memh %x, size %x\n",
1474 (unsigned long)bktr
->memt
, (u_int
)bktr
->memh
,
1475 (u_int
)bktr
->obmemsz
));
1477 printf("%s: couldn't map memory\n", bktr_name(bktr
));
1482 * Disable the brooktree device
1484 OUTL(bktr
, BKTR_INT_MASK
, ALL_INTS_DISABLED
);
1485 OUTW(bktr
, BKTR_GPIO_DMA_CTL
, FIFO_RISC_DISABLED
);
1490 if (pci_intr_map(pa
, &ih
)) {
1491 printf("%s: couldn't map interrupt\n",
1495 intrstr
= pci_intr_string(pa
->pa_pc
, ih
);
1496 bktr
->ih
= pci_intr_establish(pa
->pa_pc
, ih
, IPL_VIDEO
,
1498 if (bktr
->ih
== NULL
) {
1499 printf("%s: couldn't establish interrupt",
1501 if (intrstr
!= NULL
)
1502 printf(" at %s", intrstr
);
1506 if (intrstr
!= NULL
)
1507 printf("%s: interrupting at %s\n", bktr_name(bktr
),
1509 selinit(&bktr
->vbi_select
);
1510 #endif /* __NetBSD__ */
1513 * PCI latency timer. 32 is a good value for 4 bus mastering slots, if
1514 * you have more than four, then 16 would probably be a better value.
1516 #ifndef BROOKTREE_DEF_LATENCY_VALUE
1517 #define BROOKTREE_DEF_LATENCY_VALUE 0x10
1519 latency
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_LATENCY_TIMER
);
1520 latency
= (latency
>> 8) & 0xff;
1524 printf("%s: PCI bus latency was 0 changing to %d",
1525 bktr_name(bktr
), BROOKTREE_DEF_LATENCY_VALUE
);
1527 latency
= BROOKTREE_DEF_LATENCY_VALUE
;
1528 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
,
1529 PCI_LATENCY_TIMER
, latency
<<8);
1532 if (common_bktr_attach(bktr
, unit
, pa
->pa_id
,
1533 PCI_REVISION(pa
->pa_class
)) == 0)
1537 /* attach to radio(4) */
1538 if (bktr
->card
.tuner
->pllControl
[3] != 0x00)
1539 radio_attach_mi(&bktr_hw_if
, bktr
, &bktr
->bktr_dev
);
1545 * Special Memory Allocation
1547 #if defined (__NetBSD__)
1552 get_bktr_mem(bktr_ptr_t bktr
, bus_dmamap_t
*dmapp
, unsigned int size
)
1554 bus_dma_tag_t dmat
= bktr
->dmat
;
1555 bus_dma_segment_t seg
;
1561 * Allocate a DMA area
1564 if (bus_dmamem_alloc(dmat
, size
, align
, 0, &seg
, 1,
1565 &rseg
, BUS_DMA_NOWAIT
)) {
1567 if (bus_dmamem_alloc(dmat
, size
, align
, 0, &seg
, 1,
1568 &rseg
, BUS_DMA_NOWAIT
)) {
1569 printf("%s: Unable to dmamem_alloc of %d bytes\n",
1570 bktr_name(bktr
), size
);
1574 if (bus_dmamem_map(dmat
, &seg
, rseg
, size
,
1575 &kva
, BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
)) {
1576 printf("%s: Unable to dmamem_map of %d bytes\n",
1577 bktr_name(bktr
), size
);
1578 bus_dmamem_free(dmat
, &seg
, rseg
);
1582 bktr
->dm_mapsize
= size
;
1585 * Create and locd the DMA map for the DMA area
1587 if (bus_dmamap_create(dmat
, size
, 1, size
, 0, BUS_DMA_NOWAIT
, dmapp
)) {
1588 printf("%s: Unable to dmamap_create of %d bytes\n",
1589 bktr_name(bktr
), size
);
1590 bus_dmamem_unmap(dmat
, kva
, size
);
1591 bus_dmamem_free(dmat
, &seg
, rseg
);
1594 if (bus_dmamap_load(dmat
, *dmapp
, kva
, size
, NULL
, BUS_DMA_NOWAIT
)) {
1595 printf("%s: Unable to dmamap_load of %d bytes\n",
1596 bktr_name(bktr
), size
);
1597 bus_dmamem_unmap(dmat
, kva
, size
);
1598 bus_dmamem_free(dmat
, &seg
, rseg
);
1599 bus_dmamap_destroy(dmat
, *dmapp
);
1602 #if defined(__NetBSD__)
1603 return (vaddr_t
)kva
;
1605 return (vm_offset_t
)kva
;
1610 free_bktr_mem(bktr_ptr_t bktr
, bus_dmamap_t dmap
, vaddr_t kva
)
1612 bus_dma_tag_t dmat
= bktr
->dmat
;
1615 bus_dmamem_unmap(dmat
, (void *)kva
, dmap
->dm_mapsize
);
1617 bus_dmamem_unmap(dmat
, (void *)kva
, bktr
->dm_mapsize
);
1619 bus_dmamem_free(dmat
, dmap
->dm_segs
, 1);
1620 bus_dmamap_destroy(dmat
, dmap
);
1624 /*---------------------------------------------------------
1626 ** BrookTree 848 character device driver routines
1628 **---------------------------------------------------------
1632 #define VIDEO_DEV 0x00
1633 #define TUNER_DEV 0x01
1634 #define VBI_DEV 0x02
1636 #define UNIT(x) (minor((x) & 0x0f))
1637 #define FUNCTION(x) (minor((x >> 4) & 0x0f))
1643 bktr_open(dev_t dev
, int flags
, int fmt
,
1651 /* unit out of range */
1652 bktr
= device_lookup_private(&bktr_cd
, unit
);
1656 if (!(bktr
->flags
& METEOR_INITIALIZED
)) /* device not found */
1659 switch (FUNCTION(dev
)) {
1661 return(video_open(bktr
));
1663 return(tuner_open(bktr
));
1665 return(vbi_open(bktr
));
1676 bktr_close(dev_t dev
, int flags
, int fmt
,
1684 bktr
= device_lookup_private(&bktr_cd
, unit
);
1686 switch (FUNCTION(dev
)) {
1688 return(video_close(bktr
));
1690 return(tuner_close(bktr
));
1692 return(vbi_close(bktr
));
1702 bktr_read(dev_t dev
, struct uio
*uio
, int ioflag
)
1709 bktr
= device_lookup_private(&bktr_cd
, unit
);
1711 switch (FUNCTION(dev
)) {
1713 return(video_read(bktr
, unit
, dev
, uio
));
1715 return(vbi_read(bktr
, uio
, ioflag
));
1726 bktr_write(dev_t dev
, struct uio
*uio
, int ioflag
)
1728 /* operation not supported */
1736 bktr_ioctl(dev_t dev
, ioctl_cmd_t cmd
, void *arg
, int flag
,
1744 bktr
= device_lookup_private(&bktr_cd
, unit
);
1746 if (bktr
->bigbuf
== 0) /* no frame buffer allocated (ioctl failed) */
1749 switch (FUNCTION(dev
)) {
1751 return(video_ioctl(bktr
, unit
, cmd
, arg
, l
));
1753 return(tuner_ioctl(bktr
, unit
, cmd
, arg
, l
));
1763 bktr_mmap(dev_t dev
, off_t offset
, int nprot
)
1770 if (FUNCTION(dev
) > 0) /* only allow mmap on /dev/bktr[n] */
1773 bktr
= device_lookup_private(&bktr_cd
, unit
);
1775 if ((vaddr_t
)offset
>= bktr
->alloc_pages
* PAGE_SIZE
)
1779 return (bus_dmamem_mmap(bktr
->dmat
, bktr
->dm_mem
->dm_segs
, 1,
1780 (vaddr_t
)offset
, nprot
, BUS_DMA_WAITOK
));
1782 return(i386_btop(vtophys(bktr
->bigbuf
) + offset
));
1788 bktr_set_info(void *v
, struct radio_info
*ri
)
1790 struct bktr_softc
*sc
= v
;
1794 /* mute the audio stream by switching the mux */
1795 set_audio(sc
, AUDIO_MUTE
);
1797 /* disable drivers on the GPIO port that controls the MUXes */
1798 OUTL(sc
, BKTR_GPIO_OUT_EN
, INL(sc
, BKTR_GPIO_OUT_EN
) &
1799 ~sc
->card
.gpio_mux_bits
);
1801 /* enable drivers on the GPIO port that controls the MUXes */
1802 OUTL(sc
, BKTR_GPIO_OUT_EN
, INL(sc
, BKTR_GPIO_OUT_EN
) |
1803 sc
->card
.gpio_mux_bits
);
1805 /* unmute the audio stream */
1806 set_audio(sc
, AUDIO_UNMUTE
);
1807 init_audio_devices(sc
);
1810 freq
= ri
->freq
/ 10;
1811 set_audio(sc
, AUDIO_INTERN
); /* use internal audio */
1812 temp_mute(sc
, TRUE
);
1813 ri
->freq
= tv_freq(sc
, freq
, FM_RADIO_FREQUENCY
) * 10;
1814 temp_mute(sc
, FALSE
);
1820 bktr_get_info(void *v
, struct radio_info
*ri
)
1822 struct bktr_softc
*sc
= v
;
1823 struct TVTUNER
*tv
= &sc
->tuner
;
1826 status
= get_tuner_status(sc
);
1828 #define STATUSBIT_STEREO 0x10
1829 ri
->mute
= (int)sc
->audio_mute_state
? 1 : 0;
1830 ri
->stereo
= (status
& STATUSBIT_STEREO
) ? 1 : 0;
1831 ri
->caps
= RADIO_CAPS_DETECT_STEREO
| RADIO_CAPS_HW_AFC
;
1832 ri
->freq
= tv
->frequency
* 10;
1833 ri
->info
= (status
& STATUSBIT_STEREO
) ? RADIO_INFO_STEREO
: 0;
1834 #undef STATUSBIT_STEREO
1836 /* not yet supported */
1837 ri
->volume
= ri
->rfreq
= ri
->lock
= 0;
1845 #endif /* __NetBSD__ || __OpenBSD__ */
1847 #if defined(__NetBSD__)
1850 bktr_INB(struct bktr_softc
*bktr
, int offset
)
1852 u_int8_t val
= bus_space_read_1(bktr
->memt
, bktr
->memh
, offset
);
1853 bus_space_barrier(bktr
->memt
, bktr
->memh
, offset
, 1,
1854 BUS_SPACE_BARRIER_READ
);
1859 bktr_INW(struct bktr_softc
*bktr
, int offset
)
1861 u_int16_t val
= bus_space_read_2(bktr
->memt
, bktr
->memh
, offset
);
1862 bus_space_barrier(bktr
->memt
, bktr
->memh
, offset
, 2,
1863 BUS_SPACE_BARRIER_READ
);
1868 bktr_INL(struct bktr_softc
*bktr
, int offset
)
1870 u_int32_t val
= bus_space_read_4(bktr
->memt
, bktr
->memh
, offset
);
1871 bus_space_barrier(bktr
->memt
, bktr
->memh
, offset
, 4,
1872 BUS_SPACE_BARRIER_READ
);
1877 bktr_OUTB(struct bktr_softc
*bktr
, int offset
, u_int8_t value
)
1879 bus_space_write_1(bktr
->memt
, bktr
->memh
, offset
, value
);
1880 bus_space_barrier(bktr
->memt
, bktr
->memh
, offset
, 1,
1881 BUS_SPACE_BARRIER_WRITE
);
1885 bktr_OUTW(struct bktr_softc
*bktr
, int offset
, u_int16_t value
)
1887 bus_space_write_2(bktr
->memt
, bktr
->memh
, offset
, value
);
1888 bus_space_barrier(bktr
->memt
, bktr
->memh
, offset
, 2,
1889 BUS_SPACE_BARRIER_WRITE
);
1893 bktr_OUTL(struct bktr_softc
*bktr
, int offset
, u_int32_t value
)
1895 bus_space_write_4(bktr
->memt
, bktr
->memh
, offset
, value
);
1896 bus_space_barrier(bktr
->memt
, bktr
->memh
, offset
, 4,
1897 BUS_SPACE_BARRIER_WRITE
);
1900 #endif /* __NetBSD__ */