2 * 1. Redistributions of source code must retain the
3 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Amancio Hasty and
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 * 1. Redistributions of source code must retain the
35 * Copyright (c) 1995 Mark Tinguely and Jim Lowe
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by Mark Tinguely and Jim Lowe
49 * 4. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
56 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
58 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
60 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
61 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
62 * POSSIBILITY OF SUCH DAMAGE.
65 #include <sys/cdefs.h>
66 __FBSDID("$FreeBSD$");
69 * This is part of the Driver for Video Capture Cards (Frame grabbers)
70 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
72 * Copyright Roger Hardiman and Amancio Hasty.
74 * bktr_core : This deals with the Bt848/849/878/879 PCI Frame Grabber,
75 * Handles all the open, close, ioctl and read userland calls.
76 * Sets the Bt848 registers and generates RISC pograms.
77 * Controls the i2c bus and GPIO interface.
78 * Contains the interface to the kernel.
79 * (eg probe/attach and open/close/ioctl)
83 The Brooktree BT848 Driver driver is based upon Mark Tinguely and
84 Jim Lowe's driver for the Matrox Meteor PCI card . The
85 Philips SAA 7116 and SAA 7196 are very different chipsets than
88 The original copyright notice by Mark and Jim is included mostly
89 to honor their fantastic work in the Matrox Meteor driver!
92 #include "opt_bktr.h" /* Include any kernel config options */
95 (defined(__FreeBSD__)) \
96 || (defined(__bsdi__)) \
97 || (defined(__OpenBSD__)) \
98 || (defined(__NetBSD__)) \
102 /*******************/
103 /* *** FreeBSD *** */
104 /*******************/
107 #include <sys/param.h>
108 #include <sys/systm.h>
109 #include <sys/kernel.h>
110 #include <sys/fcntl.h>
111 #include <sys/lock.h>
112 #include <sys/mutex.h>
113 #include <sys/proc.h>
114 #include <sys/signalvar.h>
115 #include <sys/selinfo.h>
119 #include <vm/vm_kern.h>
121 #include <vm/vm_extern.h>
123 #include <sys/bus.h> /* used by smbus and newbus */
125 #if (__FreeBSD_version < 500000)
126 #include <machine/clock.h> /* for DELAY */
128 #define PROC_UNLOCK(p)
129 #include <pci/pcivar.h>
131 #include <dev/pci/pcivar.h>
134 #include <machine/bus.h>
137 #include <dev/bktr/ioctl_meteor.h>
138 #include <dev/bktr/ioctl_bt848.h> /* extensions to ioctl_meteor.h */
139 #include <dev/bktr/bktr_reg.h>
140 #include <dev/bktr/bktr_tuner.h>
141 #include <dev/bktr/bktr_card.h>
142 #include <dev/bktr/bktr_audio.h>
143 #include <dev/bktr/bktr_os.h>
144 #include <dev/bktr/bktr_core.h>
145 #if defined(BKTR_FREEBSD_MODULE)
146 #include <dev/bktr/bktr_mem.h>
149 #if defined(BKTR_USE_FREEBSD_SMBUS)
150 #include <dev/bktr/bktr_i2c.h>
151 #include <dev/smbus/smbconf.h>
152 #include <dev/iicbus/iiconf.h>
153 #include "smbus_if.h"
154 #include "iicbus_if.h"
158 bktr_name(bktr_ptr_t bktr)
160 return bktr->bktr_xname;
164 #endif /* __FreeBSD__ */
172 #define PROC_UNLOCK(p)
173 #endif /* __bsdi__ */
176 /**************************/
177 /* *** OpenBSD/NetBSD *** */
178 /**************************/
179 #if defined(__NetBSD__) || defined(__OpenBSD__)
181 #include <sys/param.h>
182 #include <sys/systm.h>
183 #include <sys/kernel.h>
184 #include <sys/signalvar.h>
185 #include <sys/vnode.h>
188 #include <uvm/uvm_extern.h>
191 #include <vm/vm_kern.h>
193 #include <vm/vm_extern.h>
196 #include <sys/inttypes.h> /* uintptr_t */
197 #include <dev/ic/bt8xx.h>
198 #include <dev/pci/bktr/bktr_reg.h>
199 #include <dev/pci/bktr/bktr_tuner.h>
200 #include <dev/pci/bktr/bktr_card.h>
201 #include <dev/pci/bktr/bktr_audio.h>
202 #include <dev/pci/bktr/bktr_core.h>
203 #include <dev/pci/bktr/bktr_os.h>
205 static int bt848_format = -1;
208 bktr_name(bktr_ptr_t bktr)
210 return (bktr->bktr_dev.dv_xname);
214 #define PROC_UNLOCK(p)
216 #endif /* __NetBSD__ || __OpenBSD__ */
219 typedef u_char bool_t;
221 #define BKTRPRI (PZERO+8)|PCATCH
222 #define VBIPRI (PZERO-4)|PCATCH
226 * memory allocated for DMA programs
228 #define DMA_PROG_ALLOC (8 * PAGE_SIZE)
230 /* When to split a dma transfer , the bt848 has timing as well as
231 dma transfer size limitations so that we have to split dma
232 transfers into two dma requests
234 #define DMA_BT848_SPLIT 319*2
237 * Allocate enough memory for:
238 * 768x576 RGB 16 or YUV (16 storage bits/pixel) = 884736 = 216 pages
240 * You may override this using the options "BROOKTREE_ALLOC_PAGES=value"
241 * in your kernel configuration file.
244 #ifndef BROOKTREE_ALLOC_PAGES
245 #define BROOKTREE_ALLOC_PAGES 217*4
247 #define BROOKTREE_ALLOC (BROOKTREE_ALLOC_PAGES * PAGE_SIZE)
249 /* Definitions for VBI capture.
250 * There are 16 VBI lines in a PAL video field (32 in a frame),
251 * and we take 2044 samples from each line (placed in a 2048 byte buffer
253 * VBI lines are held in a circular buffer before being read by a
254 * user program from /dev/vbi.
257 #define MAX_VBI_LINES 16 /* Maximum for all vidoe formats */
258 #define VBI_LINE_SIZE 2048 /* Store upto 2048 bytes per line */
259 #define VBI_BUFFER_ITEMS 20 /* Number of frames we buffer */
260 #define VBI_DATA_SIZE (VBI_LINE_SIZE * MAX_VBI_LINES * 2)
261 #define VBI_BUFFER_SIZE (VBI_DATA_SIZE * VBI_BUFFER_ITEMS)
264 /* Defines for fields */
270 * Parameters describing size of transmitted image.
273 static struct format_params format_params[] = {
274 /* # define BT848_IFORM_F_AUTO (0x0) - don't matter. */
275 { 525, 26, 480, 910, 135, 754, 640, 780, 30, 0x68, 0x5d, BT848_IFORM_X_AUTO,
277 /* # define BT848_IFORM_F_NTSCM (0x1) */
278 { 525, 26, 480, 910, 135, 754, 640, 780, 30, 0x68, 0x5d, BT848_IFORM_X_XT0,
280 /* # define BT848_IFORM_F_NTSCJ (0x2) */
281 { 525, 22, 480, 910, 135, 754, 640, 780, 30, 0x68, 0x5d, BT848_IFORM_X_XT0,
283 /* # define BT848_IFORM_F_PALBDGHI (0x3) */
284 { 625, 32, 576, 1135, 186, 924, 768, 944, 25, 0x7f, 0x72, BT848_IFORM_X_XT1,
286 /* # define BT848_IFORM_F_PALM (0x4) */
287 { 525, 22, 480, 910, 135, 754, 640, 780, 30, 0x68, 0x5d, BT848_IFORM_X_XT0,
289 /* # define BT848_IFORM_F_PALN (0x5) */
290 { 625, 32, 576, 1135, 186, 924, 768, 944, 25, 0x7f, 0x72, BT848_IFORM_X_XT1,
292 /* # define BT848_IFORM_F_SECAM (0x6) */
293 { 625, 32, 576, 1135, 186, 924, 768, 944, 25, 0x7f, 0xa0, BT848_IFORM_X_XT1,
295 /* # define BT848_IFORM_F_RSVD (0x7) - ???? */
296 { 625, 32, 576, 1135, 186, 924, 768, 944, 25, 0x7f, 0x72, BT848_IFORM_X_XT0,
301 * Table of supported Pixel Formats
304 static struct meteor_pixfmt_internal {
305 struct meteor_pixfmt public;
309 { { 0, METEOR_PIXTYPE_RGB, 2, { 0x7c00, 0x03e0, 0x001f }, 0,0 }, 0x33 },
310 { { 0, METEOR_PIXTYPE_RGB, 2, { 0x7c00, 0x03e0, 0x001f }, 1,0 }, 0x33 },
312 { { 0, METEOR_PIXTYPE_RGB, 2, { 0xf800, 0x07e0, 0x001f }, 0,0 }, 0x22 },
313 { { 0, METEOR_PIXTYPE_RGB, 2, { 0xf800, 0x07e0, 0x001f }, 1,0 }, 0x22 },
315 { { 0, METEOR_PIXTYPE_RGB, 3, { 0xff0000,0x00ff00,0x0000ff }, 1,0 }, 0x11 },
317 { { 0, METEOR_PIXTYPE_RGB, 4, { 0xff0000,0x00ff00,0x0000ff }, 0,0 }, 0x00 },
318 { { 0, METEOR_PIXTYPE_RGB, 4, { 0xff0000,0x00ff00,0x0000ff }, 0,1 }, 0x00 },
319 { { 0, METEOR_PIXTYPE_RGB, 4, { 0xff0000,0x00ff00,0x0000ff }, 1,0 }, 0x00 },
320 { { 0, METEOR_PIXTYPE_RGB, 4, { 0xff0000,0x00ff00,0x0000ff }, 1,1 }, 0x00 },
321 { { 0, METEOR_PIXTYPE_YUV, 2, { 0xff0000,0x00ff00,0x0000ff }, 1,1 }, 0x88 },
322 { { 0, METEOR_PIXTYPE_YUV_PACKED, 2, { 0xff0000,0x00ff00,0x0000ff }, 0,1 }, 0x44 },
323 { { 0, METEOR_PIXTYPE_YUV_12, 2, { 0xff0000,0x00ff00,0x0000ff }, 1,1 }, 0x88 },
326 #define PIXFMT_TABLE_SIZE ( sizeof(pixfmt_table) / sizeof(pixfmt_table[0]) )
329 * Table of Meteor-supported Pixel Formats (for SETGEO compatibility)
332 /* FIXME: Also add YUV_422 and YUV_PACKED as well */
334 u_long meteor_format;
335 struct meteor_pixfmt public;
336 } meteor_pixfmt_table[] = {
338 { 0, METEOR_PIXTYPE_YUV_12, 2, { 0xff0000,0x00ff00,0x0000ff }, 1,1 }
341 /* FIXME: Should byte swap flag be on for this one; negative in drvr? */
342 { METEOR_GEO_YUV_422,
343 { 0, METEOR_PIXTYPE_YUV, 2, { 0xff0000,0x00ff00,0x0000ff }, 1,1 }
345 { METEOR_GEO_YUV_PACKED,
346 { 0, METEOR_PIXTYPE_YUV_PACKED, 2, { 0xff0000,0x00ff00,0x0000ff }, 0,1 }
349 { 0, METEOR_PIXTYPE_RGB, 2, { 0x7c00, 0x03e0, 0x001f }, 0, 0 }
352 { 0, METEOR_PIXTYPE_RGB, 4, { 0xff0000, 0x00ff00, 0x0000ff }, 0, 0 }
356 #define METEOR_PIXFMT_TABLE_SIZE ( sizeof(meteor_pixfmt_table) / \
357 sizeof(meteor_pixfmt_table[0]) )
360 #define BSWAP (BT848_COLOR_CTL_BSWAP_ODD | BT848_COLOR_CTL_BSWAP_EVEN)
361 #define WSWAP (BT848_COLOR_CTL_WSWAP_ODD | BT848_COLOR_CTL_WSWAP_EVEN)
365 /* sync detect threshold */
367 #define SYNC_LEVEL (BT848_ADC_RESERVED | \
368 BT848_ADC_CRUSH) /* threshold ~125 mV */
370 #define SYNC_LEVEL (BT848_ADC_RESERVED | \
371 BT848_ADC_SYNC_T) /* threshold ~75 mV */
377 /* debug utility for holding previous INT_STAT contents */
379 static u_long status_sum = 0;
382 * defines to make certain bit-fiddles understandable
384 #define FIFO_ENABLED BT848_DMA_CTL_FIFO_EN
385 #define RISC_ENABLED BT848_DMA_CTL_RISC_EN
386 #define FIFO_RISC_ENABLED (BT848_DMA_CTL_FIFO_EN | BT848_DMA_CTL_RISC_EN)
387 #define FIFO_RISC_DISABLED 0
389 #define ALL_INTS_DISABLED 0
390 #define ALL_INTS_CLEARED 0xffffffff
391 #define CAPTURE_OFF 0
393 #define BIT_SEVEN_HIGH (1<<7)
394 #define BIT_EIGHT_HIGH (1<<8)
396 #define I2C_BITS (BT848_INT_RACK | BT848_INT_I2CDONE)
397 #define TDEC_BITS (BT848_INT_FDSR | BT848_INT_FBUS)
401 static int oformat_meteor_to_bt( u_long format );
403 static u_int pixfmt_swap_flags( int pixfmt );
406 * bt848 RISC programming routines.
409 static int dump_bt848( bktr_ptr_t bktr );
412 static void yuvpack_prog( bktr_ptr_t bktr, char i_flag, int cols,
413 int rows, int interlace );
414 static void yuv422_prog( bktr_ptr_t bktr, char i_flag, int cols,
415 int rows, int interlace );
416 static void yuv12_prog( bktr_ptr_t bktr, char i_flag, int cols,
417 int rows, int interlace );
418 static void rgb_prog( bktr_ptr_t bktr, char i_flag, int cols,
419 int rows, int interlace );
420 static void rgb_vbi_prog( bktr_ptr_t bktr, char i_flag, int cols,
421 int rows, int interlace );
422 static void build_dma_prog( bktr_ptr_t bktr, char i_flag );
424 static bool_t getline(bktr_reg_t *, int);
425 static bool_t notclipped(bktr_reg_t * , int , int);
426 static bool_t split(bktr_reg_t *, volatile uint32_t **, int, u_long, int,
427 volatile u_char ** , int );
429 static void start_capture( bktr_ptr_t bktr, unsigned type );
430 static void set_fps( bktr_ptr_t bktr, u_short fps );
435 * Remote Control Functions
437 static void remote_read(bktr_ptr_t bktr, struct bktr_remote *remote);
441 * ioctls common to both video & tuner.
443 static int common_ioctl( bktr_ptr_t bktr, ioctl_cmd_t cmd, caddr_t arg );
446 #if !defined(BKTR_USE_FREEBSD_SMBUS)
448 * i2c primitives for low level control of i2c bus. Added for MSP34xx control
450 static void i2c_start( bktr_ptr_t bktr);
451 static void i2c_stop( bktr_ptr_t bktr);
452 static int i2c_write_byte( bktr_ptr_t bktr, unsigned char data);
453 static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last );
459 * the common attach code, used by all OS versions.
462 common_bktr_attach( bktr_ptr_t bktr, int unit, u_long pci_id, u_int rev )
465 int need_to_allocate_memory = 1;
466 #ifdef BKTR_NEW_MSP34XX_DRIVER
470 /***************************************/
471 /* *** OS Specific memory routines *** */
472 /***************************************/
473 #if defined(__NetBSD__) || defined(__OpenBSD__)
474 /* allocate space for dma program */
475 bktr->dma_prog = get_bktr_mem(bktr, &bktr->dm_prog,
477 bktr->odd_dma_prog = get_bktr_mem(bktr, &bktr->dm_oprog,
480 /* allocate space for the VBI buffer */
481 bktr->vbidata = get_bktr_mem(bktr, &bktr->dm_vbidata,
483 bktr->vbibuffer = get_bktr_mem(bktr, &bktr->dm_vbibuffer,
486 /* allocate space for pixel buffer */
487 if ( BROOKTREE_ALLOC )
488 buf = get_bktr_mem(bktr, &bktr->dm_mem, BROOKTREE_ALLOC);
493 #if defined(__FreeBSD__) || defined(__bsdi__)
495 /* If this is a module, check if there is any currently saved contiguous memory */
496 #if defined(BKTR_FREEBSD_MODULE)
497 if (bktr_has_stored_addresses(unit) == 1) {
498 /* recover the addresses */
499 bktr->dma_prog = bktr_retrieve_address(unit, BKTR_MEM_DMA_PROG);
500 bktr->odd_dma_prog = bktr_retrieve_address(unit, BKTR_MEM_ODD_DMA_PROG);
501 bktr->vbidata = bktr_retrieve_address(unit, BKTR_MEM_VBIDATA);
502 bktr->vbibuffer = bktr_retrieve_address(unit, BKTR_MEM_VBIBUFFER);
503 buf = bktr_retrieve_address(unit, BKTR_MEM_BUF);
504 need_to_allocate_memory = 0;
508 if (need_to_allocate_memory == 1) {
509 /* allocate space for dma program */
510 bktr->dma_prog = get_bktr_mem(unit, DMA_PROG_ALLOC);
511 bktr->odd_dma_prog = get_bktr_mem(unit, DMA_PROG_ALLOC);
513 /* allocte space for the VBI buffer */
514 bktr->vbidata = get_bktr_mem(unit, VBI_DATA_SIZE);
515 bktr->vbibuffer = get_bktr_mem(unit, VBI_BUFFER_SIZE);
517 /* allocate space for pixel buffer */
518 if ( BROOKTREE_ALLOC )
519 buf = get_bktr_mem(unit, BROOKTREE_ALLOC);
523 #endif /* FreeBSD or BSDi */
526 mtx_init(&bktr->vbimutex, "bktr vbi lock", NULL, MTX_DEF);
529 /* If this is a module, save the current contiguous memory */
530 #if defined(BKTR_FREEBSD_MODULE)
531 bktr_store_address(unit, BKTR_MEM_DMA_PROG, bktr->dma_prog);
532 bktr_store_address(unit, BKTR_MEM_ODD_DMA_PROG, bktr->odd_dma_prog);
533 bktr_store_address(unit, BKTR_MEM_VBIDATA, bktr->vbidata);
534 bktr_store_address(unit, BKTR_MEM_VBIBUFFER, bktr->vbibuffer);
535 bktr_store_address(unit, BKTR_MEM_BUF, buf);
540 printf("%s: buffer size %d, addr %p\n",
541 bktr_name(bktr), (int)BROOKTREE_ALLOC,
542 (void *)(uintptr_t)vtophys(buf));
547 bktr->alloc_pages = BROOKTREE_ALLOC_PAGES;
548 bzero((caddr_t) bktr->bigbuf, BROOKTREE_ALLOC);
550 bktr->alloc_pages = 0;
554 bktr->flags = METEOR_INITALIZED | METEOR_AUTOMODE |
555 METEOR_DEV0 | METEOR_RGB16;
556 bktr->dma_prog_loaded = FALSE;
559 bktr->frames = 1; /* one frame */
560 bktr->format = METEOR_GEO_RGB16;
561 bktr->pixfmt = oformat_meteor_to_bt( bktr->format );
562 bktr->pixfmt_compat = TRUE;
571 /* using the pci device id and revision id */
572 /* and determine the card type */
573 if (PCI_VENDOR(pci_id) == PCI_VENDOR_BROOKTREE)
575 switch (PCI_PRODUCT(pci_id)) {
576 case PCI_PRODUCT_BROOKTREE_BT848:
578 bktr->id = BROOKTREE_848A;
580 bktr->id = BROOKTREE_848;
582 case PCI_PRODUCT_BROOKTREE_BT849:
583 bktr->id = BROOKTREE_849A;
585 case PCI_PRODUCT_BROOKTREE_BT878:
586 bktr->id = BROOKTREE_878;
588 case PCI_PRODUCT_BROOKTREE_BT879:
589 bktr->id = BROOKTREE_879;
594 bktr->clr_on_start = FALSE;
596 /* defaults for the tuner section of the card */
597 bktr->tflags = TUNER_INITALIZED;
598 bktr->tuner.frequency = 0;
599 bktr->tuner.channel = 0;
600 bktr->tuner.chnlset = DEFAULT_CHNLSET;
602 bktr->tuner.radio_mode = 0;
603 bktr->audio_mux_select = 0;
604 bktr->audio_mute_state = FALSE;
605 bktr->bt848_card = -1;
606 bktr->bt848_tuner = -1;
607 bktr->reverse_mute = -1;
608 bktr->slow_msp_audio = 0;
609 bktr->msp_use_mono_source = 0;
610 bktr->msp_source_selected = -1;
611 bktr->audio_mux_present = 1;
613 #if defined(__FreeBSD__)
614 #ifdef BKTR_NEW_MSP34XX_DRIVER
615 /* get hint on short programming of the msp34xx, so we know */
616 /* if the decision what thread to start should be overwritten */
617 if ( (err = resource_int_value("bktr", unit, "mspsimple",
618 &(bktr->mspsimple)) ) != 0 )
619 bktr->mspsimple = -1; /* fall back to default */
623 probeCard( bktr, TRUE, unit );
625 /* Initialise any MSP34xx or TDA98xx audio chips */
626 init_audio_devices( bktr );
628 #ifdef BKTR_NEW_MSP34XX_DRIVER
629 /* setup the kenrel thread */
630 err = msp_attach( bktr );
631 if ( err != 0 ) /* error doing kernel thread stuff, disable msp3400c */
632 bktr->card.msp3400c = 0;
639 /* Copy the vbi lines from 'vbidata' into the circular buffer, 'vbibuffer'.
640 * The circular buffer holds 'n' fixed size data blocks.
641 * vbisize is the number of bytes in the circular buffer
642 * vbiread is the point we reading data out of the circular buffer
643 * vbiinsert is the point we insert data into the circular buffer
645 static void vbidecode(bktr_ptr_t bktr) {
647 unsigned int *seq_dest;
649 /* Check if there is room in the buffer to insert the data. */
650 if (bktr->vbisize + VBI_DATA_SIZE > VBI_BUFFER_SIZE) return;
652 /* Copy the VBI data into the next free slot in the buffer. */
653 /* 'dest' is the point in vbibuffer where we want to insert new data */
654 dest = (unsigned char *)bktr->vbibuffer + bktr->vbiinsert;
655 memcpy(dest, (unsigned char*)bktr->vbidata, VBI_DATA_SIZE);
657 /* Write the VBI sequence number to the end of the vbi data */
658 /* This is used by the AleVT teletext program */
659 seq_dest = (unsigned int *)((unsigned char *)bktr->vbibuffer
661 + (VBI_DATA_SIZE - sizeof(bktr->vbi_sequence_number)));
662 *seq_dest = bktr->vbi_sequence_number;
664 /* And increase the VBI sequence number */
665 /* This can wrap around */
666 bktr->vbi_sequence_number++;
669 /* Increment the vbiinsert pointer */
670 /* This can wrap around */
671 bktr->vbiinsert += VBI_DATA_SIZE;
672 bktr->vbiinsert = (bktr->vbiinsert % VBI_BUFFER_SIZE);
674 /* And increase the amount of vbi data in the buffer */
675 bktr->vbisize = bktr->vbisize + VBI_DATA_SIZE;
681 * the common interrupt handler.
682 * Returns a 0 or 1 depending on whether the interrupt has handled.
683 * In the OS specific section, bktr_intr() is defined which calls this
684 * common interrupt handler.
687 common_bktr_intr( void *arg )
696 bktr = (bktr_ptr_t) arg;
699 * check to see if any interrupts are unmasked on this device. If
700 * none are, then we likely got here by way of being on a PCI shared
701 * interrupt dispatch list.
703 if (INL(bktr, BKTR_INT_MASK) == ALL_INTS_DISABLED)
704 return 0; /* bail out now, before we do something we
707 if (!(bktr->flags & METEOR_OPEN)) {
708 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
709 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
713 /* record and clear the INTerrupt status bits */
714 bktr_status = INL(bktr, BKTR_INT_STAT);
715 OUTL(bktr, BKTR_INT_STAT, bktr_status & ~I2C_BITS); /* don't touch i2c */
717 /* record and clear the device status register */
718 dstatus = INB(bktr, BKTR_DSTATUS);
719 OUTB(bktr, BKTR_DSTATUS, 0x00);
721 #if defined( STATUS_SUM )
722 /* add any new device status or INTerrupt status bits */
723 status_sum |= (bktr_status & ~(BT848_INT_RSV0|BT848_INT_RSV1));
724 status_sum |= ((dstatus & (BT848_DSTATUS_COF|BT848_DSTATUS_LOF)) << 6);
725 #endif /* STATUS_SUM */
726 /* printf( "%s: STATUS %x %x %x \n", bktr_name(bktr),
727 dstatus, bktr_status, INL(bktr, BKTR_RISC_COUNT) );
731 /* if risc was disabled re-start process again */
732 /* if there was one of the following errors re-start again */
733 if ( !(bktr_status & BT848_INT_RISC_EN) ||
734 ((bktr_status &(/* BT848_INT_FBUS | */
735 /* BT848_INT_FTRGT | */
736 /* BT848_INT_FDSR | */
738 BT848_INT_RIPERR | BT848_INT_PABORT |
739 BT848_INT_OCERR | BT848_INT_SCERR) ) != 0)
740 || ((INB(bktr, BKTR_TDEC) == 0) && (bktr_status & TDEC_BITS)) ) {
742 u_short tdec_save = INB(bktr, BKTR_TDEC);
744 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
745 OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF);
747 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
749 /* Reset temporal decimation counter */
750 OUTB(bktr, BKTR_TDEC, 0);
751 OUTB(bktr, BKTR_TDEC, tdec_save);
753 /* Reset to no-fields captured state */
754 if (bktr->flags & (METEOR_CONTIN | METEOR_SYNCAP)) {
755 switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
756 case METEOR_ONLY_ODD_FIELDS:
757 bktr->flags |= METEOR_WANT_ODD;
759 case METEOR_ONLY_EVEN_FIELDS:
760 bktr->flags |= METEOR_WANT_EVEN;
763 bktr->flags |= METEOR_WANT_MASK;
768 OUTL(bktr, BKTR_RISC_STRT_ADD, vtophys(bktr->dma_prog));
769 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
770 OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol);
772 OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT |
777 OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl);
781 /* If this is not a RISC program interrupt, return */
782 if (!(bktr_status & BT848_INT_RISCI))
786 printf( "%s: intr status %x %x %x\n", bktr_name(bktr),
787 bktr_status, dstatus, INL(bktr, BKTR_RISC_COUNT) );
792 * Disable future interrupts if a capture mode is not selected.
793 * This can happen when we are in the process of closing or
794 * changing capture modes, otherwise it shouldn't happen.
796 if (!(bktr->flags & METEOR_CAP_MASK))
797 OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF);
800 /* Determine which field generated this interrupt */
801 field = ( bktr_status & BT848_INT_FIELD ) ? EVEN_F : ODD_F;
805 * Process the VBI data if it is being captured. We do this once
806 * both Odd and Even VBI data is captured. Therefore we do this
807 * in the Even field interrupt handler.
810 if ( (bktr->vbiflags & VBI_CAPTURE)
811 &&(bktr->vbiflags & VBI_OPEN)
813 /* Put VBI data into circular buffer */
816 /* If someone is blocked on reading from /dev/vbi, wake them */
817 if (bktr->vbi_read_blocked) {
818 bktr->vbi_read_blocked = FALSE;
822 /* If someone has a select() on /dev/vbi, inform them */
823 if (SEL_WAITING(&bktr->vbi_select)) {
824 selwakeuppri(&bktr->vbi_select, VBIPRI);
832 * Register the completed field
833 * (For dual-field mode, require fields from the same frame)
835 switch ( bktr->flags & METEOR_WANT_MASK ) {
836 case METEOR_WANT_ODD : w_field = ODD_F ; break;
837 case METEOR_WANT_EVEN : w_field = EVEN_F ; break;
838 default : w_field = (ODD_F|EVEN_F); break;
840 switch ( bktr->flags & METEOR_ONLY_FIELDS_MASK ) {
841 case METEOR_ONLY_ODD_FIELDS : req_field = ODD_F ; break;
842 case METEOR_ONLY_EVEN_FIELDS : req_field = EVEN_F ; break;
843 default : req_field = (ODD_F|EVEN_F);
847 if (( field == EVEN_F ) && ( w_field == EVEN_F ))
848 bktr->flags &= ~METEOR_WANT_EVEN;
849 else if (( field == ODD_F ) && ( req_field == ODD_F ) &&
850 ( w_field == ODD_F ))
851 bktr->flags &= ~METEOR_WANT_ODD;
852 else if (( field == ODD_F ) && ( req_field == (ODD_F|EVEN_F) ) &&
853 ( w_field == (ODD_F|EVEN_F) ))
854 bktr->flags &= ~METEOR_WANT_ODD;
855 else if (( field == ODD_F ) && ( req_field == (ODD_F|EVEN_F) ) &&
856 ( w_field == ODD_F )) {
857 bktr->flags &= ~METEOR_WANT_ODD;
858 bktr->flags |= METEOR_WANT_EVEN;
861 /* We're out of sync. Start over. */
862 if (bktr->flags & (METEOR_CONTIN | METEOR_SYNCAP)) {
863 switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
864 case METEOR_ONLY_ODD_FIELDS:
865 bktr->flags |= METEOR_WANT_ODD;
867 case METEOR_ONLY_EVEN_FIELDS:
868 bktr->flags |= METEOR_WANT_EVEN;
871 bktr->flags |= METEOR_WANT_MASK;
879 * If we have a complete frame.
881 if (!(bktr->flags & METEOR_WANT_MASK)) {
882 bktr->frames_captured++;
884 * post the completion time.
886 if (bktr->flags & METEOR_WANT_TS) {
889 if ((u_int) bktr->alloc_pages * PAGE_SIZE
890 <= (bktr->frame_size + sizeof(struct timeval))) {
891 ts =(struct timeval *)bktr->bigbuf +
893 /* doesn't work in synch mode except
902 * Wake up the user in single capture mode.
904 if (bktr->flags & METEOR_SINGLE) {
907 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
909 /* disable risc, leave fifo running */
910 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
915 * If the user requested to be notified via signal,
916 * let them know the frame is complete.
919 if (bktr->proc != NULL) {
920 PROC_LOCK(bktr->proc);
921 kern_psignal( bktr->proc, bktr->signal);
922 PROC_UNLOCK(bktr->proc);
926 * Reset the want flags if in continuous or
927 * synchronous capture mode.
931 * currently we only support 3 capture modes: odd only, even only,
932 * odd+even interlaced (odd field first). A fourth mode (non interlaced,
933 * either even OR odd) could provide 60 (50 for PAL) pictures per
934 * second, but it would require this routine to toggle the desired frame
935 * each time, and one more different DMA program for the Bt848.
936 * As a consequence, this fourth mode is currently unsupported.
939 if (bktr->flags & (METEOR_CONTIN | METEOR_SYNCAP)) {
940 switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
941 case METEOR_ONLY_ODD_FIELDS:
942 bktr->flags |= METEOR_WANT_ODD;
944 case METEOR_ONLY_EVEN_FIELDS:
945 bktr->flags |= METEOR_WANT_EVEN;
948 bktr->flags |= METEOR_WANT_MASK;
963 extern int bt848_format; /* used to set the default format, PAL or NTSC */
965 video_open( bktr_ptr_t bktr )
967 int frame_rate, video_format=0;
969 if (bktr->flags & METEOR_OPEN) /* device is busy */
972 bktr->flags |= METEOR_OPEN;
978 bktr->clr_on_start = FALSE;
980 OUTB(bktr, BKTR_DSTATUS, 0x00); /* clear device status reg. */
982 OUTB(bktr, BKTR_ADC, SYNC_LEVEL);
984 #if defined(BKTR_SYSTEM_DEFAULT) && BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
990 if (bt848_format == 0 )
993 if (bt848_format == 1 )
996 if (video_format == 1 ) {
997 OUTB(bktr, BKTR_IFORM, BT848_IFORM_F_NTSCM);
998 bktr->format_params = BT848_IFORM_F_NTSCM;
1001 OUTB(bktr, BKTR_IFORM, BT848_IFORM_F_PALBDGHI);
1002 bktr->format_params = BT848_IFORM_F_PALBDGHI;
1006 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | format_params[bktr->format_params].iform_xtsel);
1008 /* work around for new Hauppauge 878 cards */
1009 if ((bktr->card.card_id == CARD_HAUPPAUGE) &&
1010 (bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) )
1011 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX3);
1013 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX1);
1015 OUTB(bktr, BKTR_ADELAY, format_params[bktr->format_params].adelay);
1016 OUTB(bktr, BKTR_BDELAY, format_params[bktr->format_params].bdelay);
1017 frame_rate = format_params[bktr->format_params].frame_rate;
1019 /* enable PLL mode using 28Mhz crystal for PAL/SECAM users */
1020 if (bktr->xtal_pll_mode == BT848_USE_PLL) {
1021 OUTB(bktr, BKTR_TGCTRL, 0);
1022 OUTB(bktr, BKTR_PLL_F_LO, 0xf9);
1023 OUTB(bktr, BKTR_PLL_F_HI, 0xdc);
1024 OUTB(bktr, BKTR_PLL_F_XCI, 0x8e);
1027 bktr->flags = (bktr->flags & ~METEOR_DEV_MASK) | METEOR_DEV0;
1029 bktr->max_clip_node = 0;
1031 OUTB(bktr, BKTR_COLOR_CTL, BT848_COLOR_CTL_GAMMA | BT848_COLOR_CTL_RGB_DED);
1033 OUTB(bktr, BKTR_E_HSCALE_LO, 170);
1034 OUTB(bktr, BKTR_O_HSCALE_LO, 170);
1036 OUTB(bktr, BKTR_E_DELAY_LO, 0x72);
1037 OUTB(bktr, BKTR_O_DELAY_LO, 0x72);
1038 OUTB(bktr, BKTR_E_SCLOOP, 0);
1039 OUTB(bktr, BKTR_O_SCLOOP, 0);
1041 OUTB(bktr, BKTR_VBI_PACK_SIZE, 0);
1042 OUTB(bktr, BKTR_VBI_PACK_DEL, 0);
1044 bktr->fifo_errors = 0;
1045 bktr->dma_errors = 0;
1046 bktr->frames_captured = 0;
1047 bktr->even_fields_captured = 0;
1048 bktr->odd_fields_captured = 0;
1050 set_fps(bktr, frame_rate);
1051 bktr->video.addr = 0;
1052 bktr->video.width = 0;
1053 bktr->video.banksize = 0;
1054 bktr->video.ramsize = 0;
1055 bktr->pixfmt_compat = TRUE;
1056 bktr->format = METEOR_GEO_RGB16;
1057 bktr->pixfmt = oformat_meteor_to_bt( bktr->format );
1059 bktr->capture_area_enabled = FALSE;
1061 OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT); /* if you take this out triton
1062 based motherboards will
1063 operate unreliably */
1068 vbi_open( bktr_ptr_t bktr )
1073 if (bktr->vbiflags & VBI_OPEN) { /* device is busy */
1078 bktr->vbiflags |= VBI_OPEN;
1080 /* reset the VBI circular buffer pointers and clear the buffers */
1081 bktr->vbiinsert = 0;
1084 bktr->vbi_sequence_number = 0;
1085 bktr->vbi_read_blocked = FALSE;
1087 bzero((caddr_t) bktr->vbibuffer, VBI_BUFFER_SIZE);
1088 bzero((caddr_t) bktr->vbidata, VBI_DATA_SIZE);
1099 tuner_open( bktr_ptr_t bktr )
1101 if ( !(bktr->tflags & TUNER_INITALIZED) ) /* device not found */
1104 if ( bktr->tflags & TUNER_OPEN ) /* already open */
1107 bktr->tflags |= TUNER_OPEN;
1108 bktr->tuner.frequency = 0;
1109 bktr->tuner.channel = 0;
1110 bktr->tuner.chnlset = DEFAULT_CHNLSET;
1111 bktr->tuner.afc = 0;
1112 bktr->tuner.radio_mode = 0;
1114 /* enable drivers on the GPIO port that control the MUXes */
1115 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | bktr->card.gpio_mux_bits);
1117 /* unmute the audio stream */
1118 set_audio( bktr, AUDIO_UNMUTE );
1120 /* Initialise any audio chips, eg MSP34xx or TDA98xx */
1121 init_audio_devices( bktr );
1133 video_close( bktr_ptr_t bktr )
1135 bktr->flags &= ~(METEOR_OPEN |
1140 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
1141 OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF);
1143 bktr->dma_prog_loaded = FALSE;
1144 OUTB(bktr, BKTR_TDEC, 0);
1145 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
1147 /** FIXME: is 0xf magic, wouldn't 0x00 work ??? */
1148 OUTL(bktr, BKTR_SRESET, 0xf);
1149 OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED);
1156 * tuner close handle,
1157 * place holder for tuner specific operations on a close.
1160 tuner_close( bktr_ptr_t bktr )
1162 bktr->tflags &= ~TUNER_OPEN;
1164 /* mute the audio by switching the mux */
1165 set_audio( bktr, AUDIO_MUTE );
1167 /* disable drivers on the GPIO port that control the MUXes */
1168 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) & ~bktr->card.gpio_mux_bits);
1174 vbi_close( bktr_ptr_t bktr )
1179 bktr->vbiflags &= ~VBI_OPEN;
1190 video_read(bktr_ptr_t bktr, int unit, struct cdev *dev, struct uio *uio)
1196 if (bktr->bigbuf == 0) /* no frame buffer allocated (ioctl failed) */
1199 if (bktr->flags & METEOR_CAP_MASK)
1200 return( EIO ); /* already capturing */
1202 OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl);
1205 count = bktr->rows * bktr->cols *
1206 pixfmt_table[ bktr->pixfmt ].public.Bpp;
1208 if ((int) uio->uio_iov->iov_len < count)
1211 bktr->flags &= ~(METEOR_CAP_MASK | METEOR_WANT_MASK);
1213 /* capture one frame */
1214 start_capture(bktr, METEOR_SINGLE);
1215 /* wait for capture to complete */
1216 OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED);
1217 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
1218 OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol);
1219 OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT |
1225 status = tsleep(BKTR_SLEEP, BKTRPRI, "captur", 0);
1226 if (!status) /* successful capture */
1227 status = uiomove((caddr_t)bktr->bigbuf, count, uio);
1229 printf ("%s: read: tsleep error %d\n",
1230 bktr_name(bktr), status);
1232 bktr->flags &= ~(METEOR_SINGLE | METEOR_WANT_MASK);
1238 * Read VBI data from the vbi circular buffer
1239 * The buffer holds vbi data blocks which are the same size
1240 * vbiinsert is the position we will insert the next item into the buffer
1241 * vbistart is the actual position in the buffer we want to read from
1242 * vbisize is the exact number of bytes in the buffer left to read
1245 vbi_read(bktr_ptr_t bktr, struct uio *uio, int ioflag)
1247 int readsize, readsize2, start;
1251 * XXX - vbi_read() should be protected against being re-entered
1252 * while it is unlocked for the uiomove.
1256 while(bktr->vbisize == 0) {
1257 if (ioflag & FNDELAY) {
1258 status = EWOULDBLOCK;
1262 bktr->vbi_read_blocked = TRUE;
1264 if ((status = msleep(VBI_SLEEP, &bktr->vbimutex, VBIPRI, "vbi",
1269 if ((status = tsleep(VBI_SLEEP, VBIPRI, "vbi", 0))) {
1275 /* Now we have some data to give to the user */
1277 /* We cannot read more bytes than there are in
1278 * the circular buffer
1280 readsize = (int)uio->uio_iov->iov_len;
1282 if (readsize > bktr->vbisize) readsize = bktr->vbisize;
1284 /* Check if we can read this number of bytes without having
1285 * to wrap around the circular buffer */
1286 if((bktr->vbistart + readsize) >= VBI_BUFFER_SIZE) {
1287 /* We need to wrap around */
1289 readsize2 = VBI_BUFFER_SIZE - bktr->vbistart;
1290 start = bktr->vbistart;
1292 status = uiomove((caddr_t)bktr->vbibuffer + start, readsize2, uio);
1294 status = uiomove((caddr_t)bktr->vbibuffer, (readsize - readsize2), uio);
1297 /* We do not need to wrap around */
1298 status = uiomove((caddr_t)bktr->vbibuffer + bktr->vbistart, readsize, uio);
1303 /* Update the number of bytes left to read */
1304 bktr->vbisize -= readsize;
1306 /* Update vbistart */
1307 bktr->vbistart += readsize;
1308 bktr->vbistart = bktr->vbistart % VBI_BUFFER_SIZE; /* wrap around if needed */
1323 video_ioctl( bktr_ptr_t bktr, int unit, ioctl_cmd_t cmd, caddr_t arg, struct thread* td )
1325 volatile u_char c_temp;
1327 unsigned int temp_iform;
1329 struct meteor_geomet *geo;
1330 struct meteor_counts *counts;
1331 struct meteor_video *video;
1332 struct bktr_capture_area *cap_area;
1340 case BT848SCLIP: /* set clip region */
1341 bktr->max_clip_node = 0;
1342 memcpy(&bktr->clip_list, arg, sizeof(bktr->clip_list));
1344 for (i = 0; i < BT848_MAX_CLIP_NODE; i++) {
1345 if (bktr->clip_list[i].y_min == 0 &&
1346 bktr->clip_list[i].y_max == 0)
1349 bktr->max_clip_node = i;
1351 /* make sure that the list contains a valid clip secquence */
1352 /* the clip rectangles should be sorted by x then by y as the
1353 second order sort key */
1355 /* clip rectangle list is terminated by y_min and y_max set to 0 */
1357 /* to disable clipping set y_min and y_max to 0 in the first
1358 clip rectangle . The first clip rectangle is clip_list[0].
1363 if (bktr->max_clip_node == 0 &&
1364 (bktr->clip_list[0].y_min != 0 &&
1365 bktr->clip_list[0].y_max != 0)) {
1369 for (i = 0; i < BT848_MAX_CLIP_NODE - 1 ; i++) {
1370 if (bktr->clip_list[i].y_min == 0 &&
1371 bktr->clip_list[i].y_max == 0) {
1374 if ( bktr->clip_list[i+1].y_min != 0 &&
1375 bktr->clip_list[i+1].y_max != 0 &&
1376 bktr->clip_list[i].x_min > bktr->clip_list[i+1].x_min ) {
1378 bktr->max_clip_node = 0;
1383 if (bktr->clip_list[i].x_min >= bktr->clip_list[i].x_max ||
1384 bktr->clip_list[i].y_min >= bktr->clip_list[i].y_max ||
1385 bktr->clip_list[i].x_min < 0 ||
1386 bktr->clip_list[i].x_max < 0 ||
1387 bktr->clip_list[i].y_min < 0 ||
1388 bktr->clip_list[i].y_max < 0 ) {
1389 bktr->max_clip_node = 0;
1394 bktr->dma_prog_loaded = FALSE;
1398 case METEORSTATUS: /* get Bt848 status */
1399 c_temp = INB(bktr, BKTR_DSTATUS);
1401 if (!(c_temp & 0x40)) temp |= METEOR_STATUS_HCLK;
1402 if (!(c_temp & 0x10)) temp |= METEOR_STATUS_FIDT;
1403 *(u_short *)arg = temp;
1406 case BT848SFMT: /* set input format */
1407 temp = *(unsigned long*)arg & BT848_IFORM_FORMAT;
1408 temp_iform = INB(bktr, BKTR_IFORM);
1409 temp_iform &= ~BT848_IFORM_FORMAT;
1410 temp_iform &= ~BT848_IFORM_XTSEL;
1411 OUTB(bktr, BKTR_IFORM, (temp_iform | temp | format_params[temp].iform_xtsel));
1413 case BT848_IFORM_F_AUTO:
1414 bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) |
1418 case BT848_IFORM_F_NTSCM:
1419 case BT848_IFORM_F_NTSCJ:
1420 bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) |
1422 OUTB(bktr, BKTR_ADELAY, format_params[temp].adelay);
1423 OUTB(bktr, BKTR_BDELAY, format_params[temp].bdelay);
1424 bktr->format_params = temp;
1427 case BT848_IFORM_F_PALBDGHI:
1428 case BT848_IFORM_F_PALN:
1429 case BT848_IFORM_F_SECAM:
1430 case BT848_IFORM_F_RSVD:
1431 case BT848_IFORM_F_PALM:
1432 bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) |
1434 OUTB(bktr, BKTR_ADELAY, format_params[temp].adelay);
1435 OUTB(bktr, BKTR_BDELAY, format_params[temp].bdelay);
1436 bktr->format_params = temp;
1440 bktr->dma_prog_loaded = FALSE;
1443 case METEORSFMT: /* set input format */
1444 temp_iform = INB(bktr, BKTR_IFORM);
1445 temp_iform &= ~BT848_IFORM_FORMAT;
1446 temp_iform &= ~BT848_IFORM_XTSEL;
1447 switch(*(unsigned long *)arg & METEOR_FORM_MASK ) {
1448 case 0: /* default */
1449 case METEOR_FMT_NTSC:
1450 bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) |
1452 OUTB(bktr, BKTR_IFORM, temp_iform | BT848_IFORM_F_NTSCM |
1453 format_params[BT848_IFORM_F_NTSCM].iform_xtsel);
1454 OUTB(bktr, BKTR_ADELAY, format_params[BT848_IFORM_F_NTSCM].adelay);
1455 OUTB(bktr, BKTR_BDELAY, format_params[BT848_IFORM_F_NTSCM].bdelay);
1456 bktr->format_params = BT848_IFORM_F_NTSCM;
1459 case METEOR_FMT_PAL:
1460 bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) |
1462 OUTB(bktr, BKTR_IFORM, temp_iform | BT848_IFORM_F_PALBDGHI |
1463 format_params[BT848_IFORM_F_PALBDGHI].iform_xtsel);
1464 OUTB(bktr, BKTR_ADELAY, format_params[BT848_IFORM_F_PALBDGHI].adelay);
1465 OUTB(bktr, BKTR_BDELAY, format_params[BT848_IFORM_F_PALBDGHI].bdelay);
1466 bktr->format_params = BT848_IFORM_F_PALBDGHI;
1469 case METEOR_FMT_AUTOMODE:
1470 bktr->flags = (bktr->flags & ~METEOR_FORM_MASK) |
1472 OUTB(bktr, BKTR_IFORM, temp_iform | BT848_IFORM_F_AUTO |
1473 format_params[BT848_IFORM_F_AUTO].iform_xtsel);
1479 bktr->dma_prog_loaded = FALSE;
1482 case METEORGFMT: /* get input format */
1483 *(u_long *)arg = bktr->flags & METEOR_FORM_MASK;
1487 case BT848GFMT: /* get input format */
1488 *(u_long *)arg = INB(bktr, BKTR_IFORM) & BT848_IFORM_FORMAT;
1491 case METEORSCOUNT: /* (re)set error counts */
1492 counts = (struct meteor_counts *) arg;
1493 bktr->fifo_errors = counts->fifo_errors;
1494 bktr->dma_errors = counts->dma_errors;
1495 bktr->frames_captured = counts->frames_captured;
1496 bktr->even_fields_captured = counts->even_fields_captured;
1497 bktr->odd_fields_captured = counts->odd_fields_captured;
1500 case METEORGCOUNT: /* get error counts */
1501 counts = (struct meteor_counts *) arg;
1502 counts->fifo_errors = bktr->fifo_errors;
1503 counts->dma_errors = bktr->dma_errors;
1504 counts->frames_captured = bktr->frames_captured;
1505 counts->even_fields_captured = bktr->even_fields_captured;
1506 counts->odd_fields_captured = bktr->odd_fields_captured;
1510 video = (struct meteor_video *)arg;
1511 video->addr = bktr->video.addr;
1512 video->width = bktr->video.width;
1513 video->banksize = bktr->video.banksize;
1514 video->ramsize = bktr->video.ramsize;
1518 video = (struct meteor_video *)arg;
1519 bktr->video.addr = video->addr;
1520 bktr->video.width = video->width;
1521 bktr->video.banksize = video->banksize;
1522 bktr->video.ramsize = video->ramsize;
1526 set_fps(bktr, *(u_short *)arg);
1530 *(u_short *)arg = bktr->fps;
1533 case METEORSHUE: /* set hue */
1534 OUTB(bktr, BKTR_HUE, (*(u_char *) arg) & 0xff);
1537 case METEORGHUE: /* get hue */
1538 *(u_char *)arg = INB(bktr, BKTR_HUE);
1541 case METEORSBRIG: /* set brightness */
1542 char_temp = ( *(u_char *)arg & 0xff) - 128;
1543 OUTB(bktr, BKTR_BRIGHT, char_temp);
1547 case METEORGBRIG: /* get brightness */
1548 *(u_char *)arg = INB(bktr, BKTR_BRIGHT);
1551 case METEORSCSAT: /* set chroma saturation */
1552 temp = (int)*(u_char *)arg;
1554 OUTB(bktr, BKTR_SAT_U_LO, (temp << 1) & 0xff);
1555 OUTB(bktr, BKTR_SAT_V_LO, (temp << 1) & 0xff);
1556 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL)
1557 & ~(BT848_E_CONTROL_SAT_U_MSB
1558 | BT848_E_CONTROL_SAT_V_MSB));
1559 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL)
1560 & ~(BT848_O_CONTROL_SAT_U_MSB |
1561 BT848_O_CONTROL_SAT_V_MSB));
1563 if ( temp & BIT_SEVEN_HIGH ) {
1564 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL)
1565 | (BT848_E_CONTROL_SAT_U_MSB
1566 | BT848_E_CONTROL_SAT_V_MSB));
1567 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL)
1568 | (BT848_O_CONTROL_SAT_U_MSB
1569 | BT848_O_CONTROL_SAT_V_MSB));
1573 case METEORGCSAT: /* get chroma saturation */
1574 temp = (INB(bktr, BKTR_SAT_V_LO) >> 1) & 0xff;
1575 if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_V_MSB )
1576 temp |= BIT_SEVEN_HIGH;
1577 *(u_char *)arg = (u_char)temp;
1580 case METEORSCONT: /* set contrast */
1581 temp = (int)*(u_char *)arg & 0xff;
1583 OUTB(bktr, BKTR_CONTRAST_LO, temp & 0xff);
1584 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_CON_MSB);
1585 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_CON_MSB);
1586 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) |
1587 (((temp & 0x100) >> 6 ) & BT848_E_CONTROL_CON_MSB));
1588 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) |
1589 (((temp & 0x100) >> 6 ) & BT848_O_CONTROL_CON_MSB));
1592 case METEORGCONT: /* get contrast */
1593 temp = (int)INB(bktr, BKTR_CONTRAST_LO) & 0xff;
1594 temp |= ((int)INB(bktr, BKTR_O_CONTROL) & 0x04) << 6;
1595 *(u_char *)arg = (u_char)((temp >> 1) & 0xff);
1598 case BT848SCBUF: /* set Clear-Buffer-on-start flag */
1599 bktr->clr_on_start = (*(int *)arg != 0);
1602 case BT848GCBUF: /* get Clear-Buffer-on-start flag */
1603 *(int *)arg = (int) bktr->clr_on_start;
1608 /* Historically, applications used METEOR_SIG_MODE_MASK
1609 * to reset signal delivery.
1611 if (sig == METEOR_SIG_MODE_MASK)
1613 if (sig < 0 || sig > _SIG_MAXSIG)
1616 bktr->proc = sig ? td->td_proc : NULL;
1620 *(int *)arg = bktr->signal;
1625 switch (*(int *) arg) {
1626 case METEOR_CAP_SINGLE:
1628 if (bktr->bigbuf==0) /* no frame buffer allocated */
1630 /* already capturing */
1631 if (temp & METEOR_CAP_MASK)
1636 start_capture(bktr, METEOR_SINGLE);
1638 /* wait for capture to complete */
1639 OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED);
1640 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
1641 OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol);
1643 OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT |
1648 OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl);
1649 error = tsleep(BKTR_SLEEP, BKTRPRI, "captur", hz);
1650 if (error && (error != ERESTART)) {
1651 /* Here if we didn't get complete frame */
1653 printf( "%s: ioctl: tsleep error %d %x\n",
1654 bktr_name(bktr), error,
1655 INL(bktr, BKTR_RISC_COUNT));
1659 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
1661 /* disable risc, leave fifo running */
1662 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
1665 bktr->flags &= ~(METEOR_SINGLE|METEOR_WANT_MASK);
1666 /* FIXME: should we set bt848->int_stat ??? */
1669 case METEOR_CAP_CONTINOUS:
1670 if (bktr->bigbuf==0) /* no frame buffer allocated */
1672 /* already capturing */
1673 if (temp & METEOR_CAP_MASK)
1677 start_capture(bktr, METEOR_CONTIN);
1679 /* Clear the interrypt status register */
1680 OUTL(bktr, BKTR_INT_STAT, INL(bktr, BKTR_INT_STAT));
1682 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
1683 OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol);
1684 OUTB(bktr, BKTR_CAP_CTL, bktr->bktr_cap_ctl);
1686 OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT |
1691 dump_bt848( bt848 );
1695 case METEOR_CAP_STOP_CONT:
1696 if (bktr->flags & METEOR_CONTIN) {
1697 /* turn off capture */
1698 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
1699 OUTB(bktr, BKTR_CAP_CTL, CAPTURE_OFF);
1700 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
1702 ~(METEOR_CONTIN | METEOR_WANT_MASK);
1709 /* can't change parameters while capturing */
1710 if (bktr->flags & METEOR_CAP_MASK)
1714 geo = (struct meteor_geomet *) arg;
1717 /* Either even or odd, if even & odd, then these a zero */
1718 if ((geo->oformat & METEOR_GEO_ODD_ONLY) &&
1719 (geo->oformat & METEOR_GEO_EVEN_ONLY)) {
1720 printf( "%s: ioctl: Geometry odd or even only.\n",
1725 /* set/clear even/odd flags */
1726 if (geo->oformat & METEOR_GEO_ODD_ONLY)
1727 bktr->flags |= METEOR_ONLY_ODD_FIELDS;
1729 bktr->flags &= ~METEOR_ONLY_ODD_FIELDS;
1730 if (geo->oformat & METEOR_GEO_EVEN_ONLY)
1731 bktr->flags |= METEOR_ONLY_EVEN_FIELDS;
1733 bktr->flags &= ~METEOR_ONLY_EVEN_FIELDS;
1735 if (geo->columns <= 0) {
1737 "%s: ioctl: %d: columns must be greater than zero.\n",
1738 bktr_name(bktr), geo->columns);
1741 else if ((geo->columns & 0x3fe) != geo->columns) {
1743 "%s: ioctl: %d: columns too large or not even.\n",
1744 bktr_name(bktr), geo->columns);
1748 if (geo->rows <= 0) {
1750 "%s: ioctl: %d: rows must be greater than zero.\n",
1751 bktr_name(bktr), geo->rows);
1754 else if (((geo->rows & 0x7fe) != geo->rows) ||
1755 ((geo->oformat & METEOR_GEO_FIELD_MASK) &&
1756 ((geo->rows & 0x3fe) != geo->rows)) ) {
1758 "%s: ioctl: %d: rows too large or not even.\n",
1759 bktr_name(bktr), geo->rows);
1763 if (geo->frames > 32) {
1764 printf("%s: ioctl: too many frames.\n",
1773 bktr->dma_prog_loaded = FALSE;
1774 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
1776 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
1778 if ((temp=(geo->rows * geo->columns * geo->frames * 2))) {
1779 if (geo->oformat & METEOR_GEO_RGB24) temp = temp * 2;
1781 /* meteor_mem structure for SYNC Capture */
1782 if (geo->frames > 1) temp += PAGE_SIZE;
1785 if ((int) temp > bktr->alloc_pages
1786 && bktr->video.addr == 0) {
1788 /*****************************/
1789 /* *** OS Dependant code *** */
1790 /*****************************/
1791 #if defined(__NetBSD__) || defined(__OpenBSD__)
1792 bus_dmamap_t dmamap;
1794 buf = get_bktr_mem(bktr, &dmamap,
1797 free_bktr_mem(bktr, bktr->dm_mem,
1799 bktr->dm_mem = dmamap;
1802 buf = get_bktr_mem(unit, temp*PAGE_SIZE);
1804 kmem_free(kernel_map, bktr->bigbuf,
1805 (bktr->alloc_pages * PAGE_SIZE));
1809 bktr->alloc_pages = temp;
1811 printf("%s: ioctl: Allocating %d bytes\n",
1812 bktr_name(bktr), (int)(temp*PAGE_SIZE));
1822 bktr->rows = geo->rows;
1823 bktr->cols = geo->columns;
1824 bktr->frames = geo->frames;
1826 /* Pixel format (if in meteor pixfmt compatibility mode) */
1827 if ( bktr->pixfmt_compat ) {
1828 bktr->format = METEOR_GEO_YUV_422;
1829 switch (geo->oformat & METEOR_GEO_OUTPUT_MASK) {
1830 case 0: /* default */
1831 case METEOR_GEO_RGB16:
1832 bktr->format = METEOR_GEO_RGB16;
1834 case METEOR_GEO_RGB24:
1835 bktr->format = METEOR_GEO_RGB24;
1837 case METEOR_GEO_YUV_422:
1838 bktr->format = METEOR_GEO_YUV_422;
1839 if (geo->oformat & METEOR_GEO_YUV_12)
1840 bktr->format = METEOR_GEO_YUV_12;
1842 case METEOR_GEO_YUV_PACKED:
1843 bktr->format = METEOR_GEO_YUV_PACKED;
1846 bktr->pixfmt = oformat_meteor_to_bt( bktr->format );
1849 if (bktr->flags & METEOR_CAP_MASK) {
1851 if (bktr->flags & (METEOR_CONTIN|METEOR_SYNCAP)) {
1852 switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
1853 case METEOR_ONLY_ODD_FIELDS:
1854 bktr->flags |= METEOR_WANT_ODD;
1856 case METEOR_ONLY_EVEN_FIELDS:
1857 bktr->flags |= METEOR_WANT_EVEN;
1860 bktr->flags |= METEOR_WANT_MASK;
1864 start_capture(bktr, METEOR_CONTIN);
1865 OUTL(bktr, BKTR_INT_STAT, INL(bktr, BKTR_INT_STAT));
1866 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_ENABLED);
1867 OUTW(bktr, BKTR_GPIO_DMA_CTL, bktr->capcontrol);
1868 OUTL(bktr, BKTR_INT_MASK, BT848_INT_MYSTERYBIT |
1874 /* end of METEORSETGEO */
1876 /* FIXME. The Capture Area currently has the following restrictions:
1878 y_offset may need to be even in interlaced modes
1879 RGB24 - Interlaced mode
1880 x_size must be greater than or equal to 1.666*METEORSETGEO width (cols)
1881 y_size must be greater than or equal to METEORSETGEO height (rows)
1882 RGB24 - Even Only (or Odd Only) mode
1883 x_size must be greater than or equal to 1.666*METEORSETGEO width (cols)
1884 y_size must be greater than or equal to 2*METEORSETGEO height (rows)
1885 YUV12 - Interlaced mode
1886 x_size must be greater than or equal to METEORSETGEO width (cols)
1887 y_size must be greater than or equal to METEORSETGEO height (rows)
1888 YUV12 - Even Only (or Odd Only) mode
1889 x_size must be greater than or equal to METEORSETGEO width (cols)
1890 y_size must be greater than or equal to 2*METEORSETGEO height (rows)
1893 case BT848_SCAPAREA: /* set capture area of each video frame */
1894 /* can't change parameters while capturing */
1895 if (bktr->flags & METEOR_CAP_MASK)
1898 cap_area = (struct bktr_capture_area *) arg;
1899 bktr->capture_area_x_offset = cap_area->x_offset;
1900 bktr->capture_area_y_offset = cap_area->y_offset;
1901 bktr->capture_area_x_size = cap_area->x_size;
1902 bktr->capture_area_y_size = cap_area->y_size;
1903 bktr->capture_area_enabled = TRUE;
1905 bktr->dma_prog_loaded = FALSE;
1908 case BT848_GCAPAREA: /* get capture area of each video frame */
1909 cap_area = (struct bktr_capture_area *) arg;
1910 if (bktr->capture_area_enabled == FALSE) {
1911 cap_area->x_offset = 0;
1912 cap_area->y_offset = 0;
1913 cap_area->x_size = format_params[
1914 bktr->format_params].scaled_hactive;
1915 cap_area->y_size = format_params[
1916 bktr->format_params].vactive;
1918 cap_area->x_offset = bktr->capture_area_x_offset;
1919 cap_area->y_offset = bktr->capture_area_y_offset;
1920 cap_area->x_size = bktr->capture_area_x_size;
1921 cap_area->y_size = bktr->capture_area_y_size;
1926 return common_ioctl( bktr, cmd, arg );
1936 tuner_ioctl( bktr_ptr_t bktr, int unit, ioctl_cmd_t cmd, caddr_t arg, struct thread* td )
1939 unsigned int temp, temp1;
1952 /* Read the last key pressed by the Remote Control */
1953 if (bktr->remote_control == 0) return (EINVAL);
1954 remote_read(bktr, (struct bktr_remote *)arg);
1957 #if defined( TUNER_AFC )
1958 case TVTUNER_SETAFC:
1959 bktr->tuner.afc = (*(int *)arg != 0);
1962 case TVTUNER_GETAFC:
1963 *(int *)arg = bktr->tuner.afc;
1964 /* XXX Perhaps use another bit to indicate AFC success? */
1966 #endif /* TUNER_AFC */
1968 case TVTUNER_SETCHNL:
1969 temp_mute( bktr, TRUE );
1970 temp = tv_channel( bktr, (int)*(unsigned long *)arg );
1972 temp_mute( bktr, FALSE );
1975 *(unsigned long *)arg = temp;
1977 /* after every channel change, we must restart the MSP34xx */
1978 /* audio chip to reselect NICAM STEREO or MONO audio */
1979 if ( bktr->card.msp3400c )
1980 msp_autodetect( bktr );
1982 /* after every channel change, we must restart the DPL35xx */
1983 if ( bktr->card.dpl3518a )
1984 dpl_autodetect( bktr );
1986 temp_mute( bktr, FALSE );
1989 case TVTUNER_GETCHNL:
1990 *(unsigned long *)arg = bktr->tuner.channel;
1993 case TVTUNER_SETTYPE:
1994 temp = *(unsigned long *)arg;
1995 if ( (temp < CHNLSET_MIN) || (temp > CHNLSET_MAX) )
1997 bktr->tuner.chnlset = temp;
2000 case TVTUNER_GETTYPE:
2001 *(unsigned long *)arg = bktr->tuner.chnlset;
2004 case TVTUNER_GETSTATUS:
2005 temp = get_tuner_status( bktr );
2006 *(unsigned long *)arg = temp & 0xff;
2009 case TVTUNER_SETFREQ:
2010 temp_mute( bktr, TRUE );
2011 temp = tv_freq( bktr, (int)*(unsigned long *)arg, TV_FREQUENCY);
2012 temp_mute( bktr, FALSE );
2014 temp_mute( bktr, FALSE );
2017 *(unsigned long *)arg = temp;
2019 /* after every channel change, we must restart the MSP34xx */
2020 /* audio chip to reselect NICAM STEREO or MONO audio */
2021 if ( bktr->card.msp3400c )
2022 msp_autodetect( bktr );
2024 /* after every channel change, we must restart the DPL35xx */
2025 if ( bktr->card.dpl3518a )
2026 dpl_autodetect( bktr );
2028 temp_mute( bktr, FALSE );
2031 case TVTUNER_GETFREQ:
2032 *(unsigned long *)arg = bktr->tuner.frequency;
2035 case TVTUNER_GETCHNLSET:
2036 return tuner_getchnlset((struct bktr_chnlset *)arg);
2038 case BT848_SAUDIO: /* set audio channel */
2039 if ( set_audio( bktr, *(int*)arg ) < 0 )
2043 /* hue is a 2's compliment number, -90' to +89.3' in 0.7' steps */
2044 case BT848_SHUE: /* set hue */
2045 OUTB(bktr, BKTR_HUE, (u_char)(*(int*)arg & 0xff));
2048 case BT848_GHUE: /* get hue */
2049 *(int*)arg = (signed char)(INB(bktr, BKTR_HUE) & 0xff);
2052 /* brightness is a 2's compliment #, -50 to +%49.6% in 0.39% steps */
2053 case BT848_SBRIG: /* set brightness */
2054 OUTB(bktr, BKTR_BRIGHT, (u_char)(*(int *)arg & 0xff));
2057 case BT848_GBRIG: /* get brightness */
2058 *(int *)arg = (signed char)(INB(bktr, BKTR_BRIGHT) & 0xff);
2062 case BT848_SCSAT: /* set chroma saturation */
2063 tmp_int = *(int*)arg;
2065 temp = INB(bktr, BKTR_E_CONTROL);
2066 temp1 = INB(bktr, BKTR_O_CONTROL);
2067 if ( tmp_int & BIT_EIGHT_HIGH ) {
2068 temp |= (BT848_E_CONTROL_SAT_U_MSB |
2069 BT848_E_CONTROL_SAT_V_MSB);
2070 temp1 |= (BT848_O_CONTROL_SAT_U_MSB |
2071 BT848_O_CONTROL_SAT_V_MSB);
2074 temp &= ~(BT848_E_CONTROL_SAT_U_MSB |
2075 BT848_E_CONTROL_SAT_V_MSB);
2076 temp1 &= ~(BT848_O_CONTROL_SAT_U_MSB |
2077 BT848_O_CONTROL_SAT_V_MSB);
2080 OUTB(bktr, BKTR_SAT_U_LO, (u_char)(tmp_int & 0xff));
2081 OUTB(bktr, BKTR_SAT_V_LO, (u_char)(tmp_int & 0xff));
2082 OUTB(bktr, BKTR_E_CONTROL, temp);
2083 OUTB(bktr, BKTR_O_CONTROL, temp1);
2086 case BT848_GCSAT: /* get chroma saturation */
2087 tmp_int = (int)(INB(bktr, BKTR_SAT_V_LO) & 0xff);
2088 if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_V_MSB )
2089 tmp_int |= BIT_EIGHT_HIGH;
2090 *(int*)arg = tmp_int;
2094 case BT848_SVSAT: /* set chroma V saturation */
2095 tmp_int = *(int*)arg;
2097 temp = INB(bktr, BKTR_E_CONTROL);
2098 temp1 = INB(bktr, BKTR_O_CONTROL);
2099 if ( tmp_int & BIT_EIGHT_HIGH) {
2100 temp |= BT848_E_CONTROL_SAT_V_MSB;
2101 temp1 |= BT848_O_CONTROL_SAT_V_MSB;
2104 temp &= ~BT848_E_CONTROL_SAT_V_MSB;
2105 temp1 &= ~BT848_O_CONTROL_SAT_V_MSB;
2108 OUTB(bktr, BKTR_SAT_V_LO, (u_char)(tmp_int & 0xff));
2109 OUTB(bktr, BKTR_E_CONTROL, temp);
2110 OUTB(bktr, BKTR_O_CONTROL, temp1);
2113 case BT848_GVSAT: /* get chroma V saturation */
2114 tmp_int = (int)INB(bktr, BKTR_SAT_V_LO) & 0xff;
2115 if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_V_MSB )
2116 tmp_int |= BIT_EIGHT_HIGH;
2117 *(int*)arg = tmp_int;
2121 case BT848_SUSAT: /* set chroma U saturation */
2122 tmp_int = *(int*)arg;
2124 temp = INB(bktr, BKTR_E_CONTROL);
2125 temp1 = INB(bktr, BKTR_O_CONTROL);
2126 if ( tmp_int & BIT_EIGHT_HIGH ) {
2127 temp |= BT848_E_CONTROL_SAT_U_MSB;
2128 temp1 |= BT848_O_CONTROL_SAT_U_MSB;
2131 temp &= ~BT848_E_CONTROL_SAT_U_MSB;
2132 temp1 &= ~BT848_O_CONTROL_SAT_U_MSB;
2135 OUTB(bktr, BKTR_SAT_U_LO, (u_char)(tmp_int & 0xff));
2136 OUTB(bktr, BKTR_E_CONTROL, temp);
2137 OUTB(bktr, BKTR_O_CONTROL, temp1);
2140 case BT848_GUSAT: /* get chroma U saturation */
2141 tmp_int = (int)INB(bktr, BKTR_SAT_U_LO) & 0xff;
2142 if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_SAT_U_MSB )
2143 tmp_int |= BIT_EIGHT_HIGH;
2144 *(int*)arg = tmp_int;
2147 /* lr 970528 luma notch etc - 3 high bits of e_control/o_control */
2149 case BT848_SLNOTCH: /* set luma notch */
2150 tmp_int = (*(int *)arg & 0x7) << 5 ;
2151 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~0xe0);
2152 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~0xe0);
2153 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) | tmp_int);
2154 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) | tmp_int);
2157 case BT848_GLNOTCH: /* get luma notch */
2158 *(int *)arg = (int) ( (INB(bktr, BKTR_E_CONTROL) & 0xe0) >> 5) ;
2163 case BT848_SCONT: /* set contrast */
2164 tmp_int = *(int*)arg;
2166 temp = INB(bktr, BKTR_E_CONTROL);
2167 temp1 = INB(bktr, BKTR_O_CONTROL);
2168 if ( tmp_int & BIT_EIGHT_HIGH ) {
2169 temp |= BT848_E_CONTROL_CON_MSB;
2170 temp1 |= BT848_O_CONTROL_CON_MSB;
2173 temp &= ~BT848_E_CONTROL_CON_MSB;
2174 temp1 &= ~BT848_O_CONTROL_CON_MSB;
2177 OUTB(bktr, BKTR_CONTRAST_LO, (u_char)(tmp_int & 0xff));
2178 OUTB(bktr, BKTR_E_CONTROL, temp);
2179 OUTB(bktr, BKTR_O_CONTROL, temp1);
2182 case BT848_GCONT: /* get contrast */
2183 tmp_int = (int)INB(bktr, BKTR_CONTRAST_LO) & 0xff;
2184 if ( INB(bktr, BKTR_E_CONTROL) & BT848_E_CONTROL_CON_MSB )
2185 tmp_int |= BIT_EIGHT_HIGH;
2186 *(int*)arg = tmp_int;
2189 /* FIXME: SCBARS and CCBARS require a valid int * */
2190 /* argument to succeed, but its not used; consider */
2191 /* using the arg to store the on/off state so */
2192 /* there's only one ioctl() needed to turn cbars on/off */
2193 case BT848_SCBARS: /* set colorbar output */
2194 OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_COLOR_BARS);
2197 case BT848_CCBARS: /* clear colorbar output */
2198 OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) & ~(BT848_COLOR_CTL_COLOR_BARS));
2201 case BT848_GAUDIO: /* get audio channel */
2202 temp = bktr->audio_mux_select;
2203 if ( bktr->audio_mute_state == TRUE )
2208 case BT848_SBTSC: /* set audio channel */
2209 if ( set_BTSC( bktr, *(int*)arg ) < 0 )
2213 case BT848_WEEPROM: /* write eeprom */
2214 offset = (((struct eeProm *)arg)->offset);
2215 count = (((struct eeProm *)arg)->count);
2216 buf = &(((struct eeProm *)arg)->bytes[ 0 ]);
2217 if ( writeEEProm( bktr, offset, count, buf ) < 0 )
2221 case BT848_REEPROM: /* read eeprom */
2222 offset = (((struct eeProm *)arg)->offset);
2223 count = (((struct eeProm *)arg)->count);
2224 buf = &(((struct eeProm *)arg)->bytes[ 0 ]);
2225 if ( readEEProm( bktr, offset, count, buf ) < 0 )
2229 case BT848_SIGNATURE:
2230 offset = (((struct eeProm *)arg)->offset);
2231 count = (((struct eeProm *)arg)->count);
2232 buf = &(((struct eeProm *)arg)->bytes[ 0 ]);
2233 if ( signCard( bktr, offset, count, buf ) < 0 )
2237 /* Ioctl's for direct gpio access */
2238 #ifdef BKTR_GPIO_ACCESS
2239 case BT848_GPIO_GET_EN:
2240 *(int*)arg = INL(bktr, BKTR_GPIO_OUT_EN);
2243 case BT848_GPIO_SET_EN:
2244 OUTL(bktr, BKTR_GPIO_OUT_EN, *(int*)arg);
2247 case BT848_GPIO_GET_DATA:
2248 *(int*)arg = INL(bktr, BKTR_GPIO_DATA);
2251 case BT848_GPIO_SET_DATA:
2252 OUTL(bktr, BKTR_GPIO_DATA, *(int*)arg);
2254 #endif /* BKTR_GPIO_ACCESS */
2256 /* Ioctl's for running the tuner device in radio mode */
2259 *(unsigned char *)arg = bktr->tuner.radio_mode;
2263 bktr->tuner.radio_mode = *(unsigned char *)arg;
2267 *(unsigned long *)arg = bktr->tuner.frequency;
2271 /* The argument to this ioctl is NOT freq*16. It is
2275 temp=(int)*(unsigned long *)arg;
2277 #ifdef BKTR_RADIO_DEBUG
2278 printf("%s: arg=%d temp=%d\n", bktr_name(bktr),
2279 (int)*(unsigned long *)arg, temp);
2282 #ifndef BKTR_RADIO_NOFREQCHECK
2283 /* According to the spec. sheet the band: 87.5MHz-108MHz */
2285 if(temp<8750 || temp>10800) {
2286 printf("%s: Radio frequency out of range\n", bktr_name(bktr));
2290 temp_mute( bktr, TRUE );
2291 temp = tv_freq( bktr, temp, FM_RADIO_FREQUENCY );
2292 temp_mute( bktr, FALSE );
2293 #ifdef BKTR_RADIO_DEBUG
2295 printf("%s: tv_freq returned: %d\n", bktr_name(bktr), temp);
2299 *(unsigned long *)arg = temp;
2302 /* Luigi's I2CWR ioctl */
2304 par = *(u_long *)arg;
2305 write = (par >> 24) & 0xff ;
2306 i2c_addr = (par >> 16) & 0xff ;
2307 i2c_port = (par >> 8) & 0xff ;
2308 data = (par) & 0xff ;
2311 i2cWrite( bktr, i2c_addr, i2c_port, data);
2313 data = i2cRead( bktr, i2c_addr);
2315 *(u_long *)arg = (par & 0xffffff00) | ( data & 0xff );
2319 #ifdef BT848_MSP_READ
2320 /* I2C ioctls to allow userland access to the MSP chip */
2321 case BT848_MSP_READ:
2323 struct bktr_msp_control *msp;
2324 msp = (struct bktr_msp_control *) arg;
2325 msp->data = msp_dpl_read(bktr, bktr->msp_addr,
2326 msp->function, msp->address);
2330 case BT848_MSP_WRITE:
2332 struct bktr_msp_control *msp;
2333 msp = (struct bktr_msp_control *) arg;
2334 msp_dpl_write(bktr, bktr->msp_addr, msp->function,
2335 msp->address, msp->data );
2339 case BT848_MSP_RESET:
2340 msp_dpl_reset(bktr, bktr->msp_addr);
2345 return common_ioctl( bktr, cmd, arg );
2356 common_ioctl( bktr_ptr_t bktr, ioctl_cmd_t cmd, caddr_t arg )
2360 struct meteor_pixfmt *pf_pub;
2364 case METEORSINPUT: /* set input device */
2365 /*Bt848 has 3 MUX Inputs. Bt848A/849A/878/879 has 4 MUX Inputs*/
2366 /* On the original bt848 boards, */
2367 /* Tuner is MUX0, RCA is MUX1, S-Video is MUX2 */
2368 /* On the Hauppauge bt878 boards, */
2369 /* Tuner is MUX0, RCA is MUX3 */
2370 /* Unfortunatly Meteor driver codes DEV_RCA as DEV_0, so we */
2371 /* stick with this system in our Meteor Emulation */
2373 switch(*(unsigned long *)arg & METEOR_DEV_MASK) {
2375 /* this is the RCA video input */
2376 case 0: /* default */
2377 case METEOR_INPUT_DEV0:
2378 /* METEOR_INPUT_DEV_RCA: */
2379 bktr->flags = (bktr->flags & ~METEOR_DEV_MASK)
2381 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM)
2382 & ~BT848_IFORM_MUXSEL);
2384 /* work around for new Hauppauge 878 cards */
2385 if ((bktr->card.card_id == CARD_HAUPPAUGE) &&
2386 (bktr->id==BROOKTREE_878 ||
2387 bktr->id==BROOKTREE_879) )
2388 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX3);
2390 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX1);
2392 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP);
2393 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_COMP);
2394 set_audio( bktr, AUDIO_EXTERN );
2397 /* this is the tuner input */
2398 case METEOR_INPUT_DEV1:
2399 bktr->flags = (bktr->flags & ~METEOR_DEV_MASK)
2401 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL);
2402 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX0);
2403 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP);
2404 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_COMP);
2405 set_audio( bktr, AUDIO_TUNER );
2408 /* this is the S-VHS input, but with a composite camera */
2409 case METEOR_INPUT_DEV2:
2410 bktr->flags = (bktr->flags & ~METEOR_DEV_MASK)
2412 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL);
2413 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX2);
2414 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP);
2415 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_O_CONTROL_COMP);
2416 set_audio( bktr, AUDIO_EXTERN );
2419 /* this is the S-VHS input */
2420 case METEOR_INPUT_DEV_SVIDEO:
2421 bktr->flags = (bktr->flags & ~METEOR_DEV_MASK)
2422 | METEOR_DEV_SVIDEO;
2423 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL);
2424 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX2);
2425 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) | BT848_E_CONTROL_COMP);
2426 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) | BT848_O_CONTROL_COMP);
2427 set_audio( bktr, AUDIO_EXTERN );
2430 case METEOR_INPUT_DEV3:
2431 if ((bktr->id == BROOKTREE_848A) ||
2432 (bktr->id == BROOKTREE_849A) ||
2433 (bktr->id == BROOKTREE_878) ||
2434 (bktr->id == BROOKTREE_879) ) {
2435 bktr->flags = (bktr->flags & ~METEOR_DEV_MASK)
2437 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) & ~BT848_IFORM_MUXSEL);
2439 /* work around for new Hauppauge 878 cards */
2440 if ((bktr->card.card_id == CARD_HAUPPAUGE) &&
2441 (bktr->id==BROOKTREE_878 ||
2442 bktr->id==BROOKTREE_879) )
2443 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX1);
2445 OUTB(bktr, BKTR_IFORM, INB(bktr, BKTR_IFORM) | BT848_IFORM_M_MUX3);
2447 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) & ~BT848_E_CONTROL_COMP);
2448 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) & ~BT848_O_CONTROL_COMP);
2449 set_audio( bktr, AUDIO_EXTERN );
2459 case METEORGINPUT: /* get input device */
2460 *(u_long *)arg = bktr->flags & METEOR_DEV_MASK;
2463 case METEORSACTPIXFMT:
2464 if (( *(int *)arg < 0 ) ||
2465 ( *(int *)arg >= PIXFMT_TABLE_SIZE ))
2468 bktr->pixfmt = *(int *)arg;
2469 OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0)
2470 | pixfmt_swap_flags( bktr->pixfmt ));
2471 bktr->pixfmt_compat = FALSE;
2474 case METEORGACTPIXFMT:
2475 *(int *)arg = bktr->pixfmt;
2478 case METEORGSUPPIXFMT :
2479 pf_pub = (struct meteor_pixfmt *)arg;
2480 pixfmt = pf_pub->index;
2482 if (( pixfmt < 0 ) || ( pixfmt >= PIXFMT_TABLE_SIZE ))
2485 memcpy( pf_pub, &pixfmt_table[ pixfmt ].public,
2486 sizeof( *pf_pub ) );
2488 /* Patch in our format index */
2489 pf_pub->index = pixfmt;
2492 #if defined( STATUS_SUM )
2493 case BT848_GSTATUS: /* reap status */
2495 DECLARE_INTR_MASK(s);
2500 *(u_int*)arg = temp;
2503 #endif /* STATUS_SUM */
2515 /******************************************************************************
2516 * bt848 RISC programming routines:
2525 dump_bt848( bktr_ptr_t bktr )
2528 4, 8, 0xc, 0x8c, 0x10, 0x90, 0x14, 0x94,
2529 0x18, 0x98, 0x1c, 0x9c, 0x20, 0xa0, 0x24, 0xa4,
2530 0x28, 0x2c, 0xac, 0x30, 0x34, 0x38, 0x3c, 0x40,
2531 0xc0, 0x48, 0x4c, 0xcc, 0x50, 0xd0, 0xd4, 0x60,
2532 0x64, 0x68, 0x6c, 0xec, 0xd8, 0xdc, 0xe0, 0xe4,
2537 for (i = 0; i < 40; i+=4) {
2538 printf("%s: Reg:value : \t%x:%x \t%x:%x \t %x:%x \t %x:%x\n",
2540 r[i], INL(bktr, r[i]),
2541 r[i+1], INL(bktr, r[i+1]),
2542 r[i+2], INL(bktr, r[i+2]),
2543 r[i+3], INL(bktr, r[i+3]]));
2546 printf("%s: INT STAT %x \n", bktr_name(bktr),
2547 INL(bktr, BKTR_INT_STAT));
2548 printf("%s: Reg INT_MASK %x \n", bktr_name(bktr),
2549 INL(bktr, BKTR_INT_MASK));
2550 printf("%s: Reg GPIO_DMA_CTL %x \n", bktr_name(bktr),
2551 INW(bktr, BKTR_GPIO_DMA_CTL));
2559 * build write instruction
2561 #define BKTR_FM1 0x6 /* packed data to follow */
2562 #define BKTR_FM3 0xe /* planar data to follow */
2563 #define BKTR_VRE 0x4 /* Marks the end of the even field */
2564 #define BKTR_VRO 0xC /* Marks the end of the odd field */
2565 #define BKTR_PXV 0x0 /* valid word (never used) */
2566 #define BKTR_EOL 0x1 /* last dword, 4 bytes */
2567 #define BKTR_SOL 0x2 /* first dword */
2569 #define OP_WRITE (0x1 << 28)
2570 #define OP_SKIP (0x2 << 28)
2571 #define OP_WRITEC (0x5 << 28)
2572 #define OP_JUMP (0x7 << 28)
2573 #define OP_SYNC (0x8 << 28)
2574 #define OP_WRITE123 (0x9 << 28)
2575 #define OP_WRITES123 (0xb << 28)
2576 #define OP_SOL (1 << 27) /* first instr for scanline */
2577 #define OP_EOL (1 << 26)
2579 #define BKTR_RESYNC (1 << 15)
2580 #define BKTR_GEN_IRQ (1 << 24)
2583 * The RISC status bits can be set/cleared in the RISC programs
2584 * and tested in the Interrupt Handler
2586 #define BKTR_SET_RISC_STATUS_BIT0 (1 << 16)
2587 #define BKTR_SET_RISC_STATUS_BIT1 (1 << 17)
2588 #define BKTR_SET_RISC_STATUS_BIT2 (1 << 18)
2589 #define BKTR_SET_RISC_STATUS_BIT3 (1 << 19)
2591 #define BKTR_CLEAR_RISC_STATUS_BIT0 (1 << 20)
2592 #define BKTR_CLEAR_RISC_STATUS_BIT1 (1 << 21)
2593 #define BKTR_CLEAR_RISC_STATUS_BIT2 (1 << 22)
2594 #define BKTR_CLEAR_RISC_STATUS_BIT3 (1 << 23)
2596 #define BKTR_TEST_RISC_STATUS_BIT0 (1 << 28)
2597 #define BKTR_TEST_RISC_STATUS_BIT1 (1 << 29)
2598 #define BKTR_TEST_RISC_STATUS_BIT2 (1 << 30)
2599 #define BKTR_TEST_RISC_STATUS_BIT3 (1 << 31)
2601 static bool_t notclipped (bktr_reg_t * bktr, int x, int width) {
2603 bktr_clip_t * clip_node;
2604 bktr->clip_start = -1;
2608 bktr->line_length = width;
2611 bktr->current_col = 0;
2613 if (bktr->max_clip_node == 0 ) return TRUE;
2614 clip_node = (bktr_clip_t *) &bktr->clip_list[0];
2617 for (i = 0; i < bktr->max_clip_node; i++ ) {
2618 clip_node = (bktr_clip_t *) &bktr->clip_list[i];
2619 if (x >= clip_node->x_min && x <= clip_node->x_max ) {
2620 bktr->clip_start = i;
2628 static bool_t getline(bktr_reg_t *bktr, int x ) {
2630 bktr_clip_t * clip_node ;
2632 if (bktr->line_length == 0 ||
2633 bktr->current_col >= bktr->line_length) return FALSE;
2635 bktr->y = min(bktr->last_y, bktr->line_length);
2636 bktr->y2 = bktr->line_length;
2638 bktr->yclip = bktr->yclip2 = -1;
2639 for (i = bktr->clip_start; i < bktr->max_clip_node; i++ ) {
2640 clip_node = (bktr_clip_t *) &bktr->clip_list[i];
2641 if (x >= clip_node->x_min && x <= clip_node->x_max) {
2642 if (bktr->last_y <= clip_node->y_min) {
2643 bktr->y = min(bktr->last_y, bktr->line_length);
2644 bktr->y2 = min(clip_node->y_min, bktr->line_length);
2645 bktr->yclip = min(clip_node->y_min, bktr->line_length);
2646 bktr->yclip2 = min(clip_node->y_max, bktr->line_length);
2647 bktr->last_y = bktr->yclip2;
2648 bktr->clip_start = i;
2650 for (j = i+1; j < bktr->max_clip_node; j++ ) {
2651 clip_node = (bktr_clip_t *) &bktr->clip_list[j];
2652 if (x >= clip_node->x_min && x <= clip_node->x_max) {
2653 if (bktr->last_y >= clip_node->y_min) {
2654 bktr->yclip2 = min(clip_node->y_max, bktr->line_length);
2655 bktr->last_y = bktr->yclip2;
2656 bktr->clip_start = j;
2665 if (bktr->current_col <= bktr->line_length) {
2666 bktr->current_col = bktr->line_length;
2672 static bool_t split(bktr_reg_t * bktr, volatile uint32_t **dma_prog, int width ,
2673 u_long operation, int pixel_width,
2674 volatile u_char ** target_buffer, int cols ) {
2677 struct meteor_pixfmt *pf = &pixfmt_table[ bktr->pixfmt ].public;
2678 u_int skip, start_skip;
2680 /* For RGB24, we need to align the component in FIFO Byte Lane 0 */
2681 /* to the 1st byte in the mem dword containing our start addr. */
2682 /* BTW, we know this pixfmt's 1st byte is Blue; thus the start addr */
2685 if (( pf->type == METEOR_PIXTYPE_RGB ) && ( pf->Bpp == 3 ))
2686 switch ( ((uintptr_t) (volatile void *) *target_buffer) % 4 ) {
2687 case 2 : start_skip = 4 ; break;
2688 case 1 : start_skip = 8 ; break;
2691 if ((width * pixel_width) < DMA_BT848_SPLIT ) {
2692 if ( width == cols) {
2693 flag = OP_SOL | OP_EOL;
2694 } else if (bktr->current_col == 0 ) {
2696 } else if (bktr->current_col == cols) {
2701 if (( flag & OP_SOL ) && ( start_skip > 0 )) {
2702 *(*dma_prog)++ = OP_SKIP | OP_SOL | start_skip;
2707 *(*dma_prog)++ = operation | flag | (width * pixel_width - skip);
2708 if (operation != OP_SKIP )
2709 *(*dma_prog)++ = (uintptr_t) (volatile void *) *target_buffer;
2711 *target_buffer += width * pixel_width;
2712 bktr->current_col += width;
2716 if (bktr->current_col == 0 && width == cols) {
2719 } else if (bktr->current_col == 0 ) {
2722 } else if (bktr->current_col >= cols) {
2731 if (( flag & OP_SOL ) && ( start_skip > 0 )) {
2732 *(*dma_prog)++ = OP_SKIP | OP_SOL | start_skip;
2737 *(*dma_prog)++ = operation | flag |
2738 (width * pixel_width / 2 - skip);
2739 if (operation != OP_SKIP )
2740 *(*dma_prog)++ = (uintptr_t) (volatile void *) *target_buffer ;
2741 *target_buffer += (width * pixel_width / 2) ;
2743 if ( operation == OP_WRITE )
2744 operation = OP_WRITEC;
2745 *(*dma_prog)++ = operation | flag2 |
2746 (width * pixel_width / 2);
2747 *target_buffer += (width * pixel_width / 2) ;
2748 bktr->current_col += width;
2756 * Generate the RISC instructions to capture both VBI and video images
2759 rgb_vbi_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace )
2762 volatile uint32_t target_buffer, buffer, target,width;
2763 volatile uint32_t pitch;
2764 volatile uint32_t *dma_prog; /* DMA prog is an array of
2765 32 bit RISC instructions */
2766 volatile uint32_t *loop_point;
2767 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ];
2768 u_int Bpp = pf_int->public.Bpp;
2769 unsigned int vbisamples; /* VBI samples per line */
2770 unsigned int vbilines; /* VBI lines per field */
2771 unsigned int num_dwords; /* DWORDS per line */
2773 vbisamples = format_params[bktr->format_params].vbi_num_samples;
2774 vbilines = format_params[bktr->format_params].vbi_num_lines;
2775 num_dwords = vbisamples/4;
2777 OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt);
2778 OUTB(bktr, BKTR_ADC, SYNC_LEVEL);
2779 OUTB(bktr, BKTR_VBI_PACK_SIZE, ((num_dwords)) & 0xff);
2780 OUTB(bktr, BKTR_VBI_PACK_DEL, ((num_dwords)>> 8) & 0x01); /* no hdelay */
2783 OUTB(bktr, BKTR_OFORM, 0x00);
2785 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | 0x40); /* set chroma comb */
2786 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | 0x40);
2787 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x80); /* clear Ycomb */
2788 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x80);
2790 /* disable gamma correction removal */
2791 OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_GAMMA);
2794 OUTB(bktr, BKTR_E_VTC, 0);
2795 OUTB(bktr, BKTR_O_VTC, 0);
2797 OUTB(bktr, BKTR_E_VTC, 1);
2798 OUTB(bktr, BKTR_O_VTC, 1);
2800 bktr->capcontrol = 3 << 2 | 3;
2802 dma_prog = (uint32_t *) bktr->dma_prog;
2804 /* Construct Write */
2806 if (bktr->video.addr) {
2807 target_buffer = (u_long) bktr->video.addr;
2808 pitch = bktr->video.width;
2811 target_buffer = (u_long) vtophys(bktr->bigbuf);
2815 buffer = target_buffer;
2817 /* Wait for the VRE sync marking the end of the Even and
2818 * the start of the Odd field. Resync here.
2820 *dma_prog++ = OP_SYNC | BKTR_RESYNC |BKTR_VRE;
2823 loop_point = dma_prog;
2825 /* store the VBI data */
2826 /* look for sync with packed data */
2827 *dma_prog++ = OP_SYNC | BKTR_FM1;
2829 for(i = 0; i < vbilines; i++) {
2830 *dma_prog++ = OP_WRITE | OP_SOL | OP_EOL | vbisamples;
2831 *dma_prog++ = (u_long) vtophys((caddr_t)bktr->vbidata +
2832 (i * VBI_LINE_SIZE));
2835 if ( (i_flag == 2/*Odd*/) || (i_flag==3) /*interlaced*/ ) {
2836 /* store the Odd field video image */
2837 /* look for sync with packed data */
2838 *dma_prog++ = OP_SYNC | BKTR_FM1;
2839 *dma_prog++ = 0; /* NULL WORD */
2841 for (i = 0; i < (rows/interlace); i++) {
2842 target = target_buffer;
2843 if ( notclipped(bktr, i, width)) {
2844 split(bktr, (volatile uint32_t **) &dma_prog,
2845 bktr->y2 - bktr->y, OP_WRITE,
2846 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
2849 while(getline(bktr, i)) {
2850 if (bktr->y != bktr->y2 ) {
2851 split(bktr, (volatile uint32_t **) &dma_prog,
2852 bktr->y2 - bktr->y, OP_WRITE,
2853 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
2855 if (bktr->yclip != bktr->yclip2 ) {
2856 split(bktr,(volatile uint32_t **) &dma_prog,
2857 bktr->yclip2 - bktr->yclip,
2859 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
2865 target_buffer += interlace * pitch;
2871 /* Grab the Even field */
2872 /* Look for the VRO, end of Odd field, marker */
2873 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_RESYNC | BKTR_VRO;
2874 *dma_prog++ = 0; /* NULL WORD */
2876 /* store the VBI data */
2877 /* look for sync with packed data */
2878 *dma_prog++ = OP_SYNC | BKTR_FM1;
2880 for(i = 0; i < vbilines; i++) {
2881 *dma_prog++ = OP_WRITE | OP_SOL | OP_EOL | vbisamples;
2882 *dma_prog++ = (u_long) vtophys((caddr_t)bktr->vbidata +
2883 ((i+MAX_VBI_LINES) * VBI_LINE_SIZE));
2886 /* store the video image */
2887 if (i_flag == 1) /*Even Only*/
2888 target_buffer = buffer;
2889 if (i_flag == 3) /*interlaced*/
2890 target_buffer = buffer+pitch;
2893 if ((i_flag == 1) /*Even Only*/ || (i_flag==3) /*interlaced*/) {
2894 /* look for sync with packed data */
2895 *dma_prog++ = OP_SYNC | BKTR_FM1;
2896 *dma_prog++ = 0; /* NULL WORD */
2898 for (i = 0; i < (rows/interlace); i++) {
2899 target = target_buffer;
2900 if ( notclipped(bktr, i, width)) {
2901 split(bktr, (volatile uint32_t **) &dma_prog,
2902 bktr->y2 - bktr->y, OP_WRITE,
2903 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
2905 while(getline(bktr, i)) {
2906 if (bktr->y != bktr->y2 ) {
2907 split(bktr, (volatile uint32_t **) &dma_prog,
2908 bktr->y2 - bktr->y, OP_WRITE,
2909 Bpp, (volatile u_char **)(uintptr_t)&target,
2912 if (bktr->yclip != bktr->yclip2 ) {
2913 split(bktr, (volatile uint32_t **) &dma_prog,
2914 bktr->yclip2 - bktr->yclip, OP_SKIP,
2915 Bpp, (volatile u_char **)(uintptr_t) &target, cols);
2922 target_buffer += interlace * pitch;
2927 /* Look for end of 'Even Field' */
2928 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_RESYNC | BKTR_VRE;
2929 *dma_prog++ = 0; /* NULL WORD */
2931 *dma_prog++ = OP_JUMP ;
2932 *dma_prog++ = (u_long ) vtophys(loop_point) ;
2933 *dma_prog++ = 0; /* NULL WORD */
2941 rgb_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace )
2944 volatile uint32_t target_buffer, buffer, target,width;
2945 volatile uint32_t pitch;
2946 volatile uint32_t *dma_prog;
2947 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ];
2948 u_int Bpp = pf_int->public.Bpp;
2950 OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt);
2951 OUTB(bktr, BKTR_VBI_PACK_SIZE, 0);
2952 OUTB(bktr, BKTR_VBI_PACK_DEL, 0);
2953 OUTB(bktr, BKTR_ADC, SYNC_LEVEL);
2955 OUTB(bktr, BKTR_OFORM, 0x00);
2957 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | 0x40); /* set chroma comb */
2958 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | 0x40);
2959 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x80); /* clear Ycomb */
2960 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x80);
2962 /* disable gamma correction removal */
2963 OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_GAMMA);
2966 OUTB(bktr, BKTR_E_VTC, 0);
2967 OUTB(bktr, BKTR_O_VTC, 0);
2969 OUTB(bktr, BKTR_E_VTC, 1);
2970 OUTB(bktr, BKTR_O_VTC, 1);
2972 bktr->capcontrol = 3 << 2 | 3;
2974 dma_prog = (uint32_t *) bktr->dma_prog;
2976 /* Construct Write */
2978 if (bktr->video.addr) {
2979 target_buffer = (uint32_t) bktr->video.addr;
2980 pitch = bktr->video.width;
2983 target_buffer = (uint32_t) vtophys(bktr->bigbuf);
2987 buffer = target_buffer;
2989 /* contruct sync : for video packet format */
2990 *dma_prog++ = OP_SYNC | BKTR_RESYNC | BKTR_FM1;
2992 /* sync, mode indicator packed data */
2993 *dma_prog++ = 0; /* NULL WORD */
2995 for (i = 0; i < (rows/interlace); i++) {
2996 target = target_buffer;
2997 if ( notclipped(bktr, i, width)) {
2998 split(bktr, (volatile uint32_t **) &dma_prog,
2999 bktr->y2 - bktr->y, OP_WRITE,
3000 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
3003 while(getline(bktr, i)) {
3004 if (bktr->y != bktr->y2 ) {
3005 split(bktr, (volatile uint32_t **) &dma_prog,
3006 bktr->y2 - bktr->y, OP_WRITE,
3007 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
3009 if (bktr->yclip != bktr->yclip2 ) {
3010 split(bktr,(volatile uint32_t **) &dma_prog,
3011 bktr->yclip2 - bktr->yclip,
3013 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
3019 target_buffer += interlace * pitch;
3026 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_VRO;
3027 *dma_prog++ = 0; /* NULL WORD */
3029 *dma_prog++ = OP_JUMP;
3030 *dma_prog++ = (uint32_t ) vtophys(bktr->dma_prog);
3035 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_VRE;
3036 *dma_prog++ = 0; /* NULL WORD */
3038 *dma_prog++ = OP_JUMP;
3039 *dma_prog++ = (uint32_t ) vtophys(bktr->dma_prog);
3044 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_RESYNC | BKTR_VRO;
3045 *dma_prog++ = 0; /* NULL WORD */
3046 *dma_prog++ = OP_JUMP; ;
3047 *dma_prog = (uint32_t ) vtophys(bktr->odd_dma_prog);
3051 if (interlace == 2) {
3053 target_buffer = buffer + pitch;
3055 dma_prog = (uint32_t *) bktr->odd_dma_prog;
3057 /* sync vre IRQ bit */
3058 *dma_prog++ = OP_SYNC | BKTR_RESYNC | BKTR_FM1;
3059 *dma_prog++ = 0; /* NULL WORD */
3061 for (i = 0; i < (rows/interlace); i++) {
3062 target = target_buffer;
3063 if ( notclipped(bktr, i, width)) {
3064 split(bktr, (volatile uint32_t **) &dma_prog,
3065 bktr->y2 - bktr->y, OP_WRITE,
3066 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
3068 while(getline(bktr, i)) {
3069 if (bktr->y != bktr->y2 ) {
3070 split(bktr, (volatile uint32_t **) &dma_prog,
3071 bktr->y2 - bktr->y, OP_WRITE,
3072 Bpp, (volatile u_char **)(uintptr_t)&target,
3075 if (bktr->yclip != bktr->yclip2 ) {
3076 split(bktr, (volatile uint32_t **) &dma_prog,
3077 bktr->yclip2 - bktr->yclip, OP_SKIP,
3078 Bpp, (volatile u_char **)(uintptr_t)&target, cols);
3085 target_buffer += interlace * pitch;
3090 /* sync vre IRQ bit */
3091 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_RESYNC | BKTR_VRE;
3092 *dma_prog++ = 0; /* NULL WORD */
3093 *dma_prog++ = OP_JUMP ;
3094 *dma_prog++ = (uint32_t ) vtophys(bktr->dma_prog) ;
3095 *dma_prog++ = 0; /* NULL WORD */
3103 yuvpack_prog( bktr_ptr_t bktr, char i_flag,
3104 int cols, int rows, int interlace )
3107 volatile unsigned int inst;
3108 volatile unsigned int inst3;
3109 volatile uint32_t target_buffer, buffer;
3110 volatile uint32_t *dma_prog;
3111 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ];
3114 OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt);
3116 OUTB(bktr, BKTR_E_SCLOOP, INB(bktr, BKTR_E_SCLOOP) | BT848_E_SCLOOP_CAGC); /* enable chroma comb */
3117 OUTB(bktr, BKTR_O_SCLOOP, INB(bktr, BKTR_O_SCLOOP) | BT848_O_SCLOOP_CAGC);
3119 OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_RGB_DED | BT848_COLOR_CTL_GAMMA);
3120 OUTB(bktr, BKTR_ADC, SYNC_LEVEL);
3122 bktr->capcontrol = 1 << 6 | 1 << 4 | 1 << 2 | 3;
3123 bktr->capcontrol = 3 << 2 | 3;
3125 dma_prog = (uint32_t *) bktr->dma_prog;
3127 /* Construct Write */
3129 /* write , sol, eol */
3130 inst = OP_WRITE | OP_SOL | (cols);
3131 /* write , sol, eol */
3132 inst3 = OP_WRITE | OP_EOL | (cols);
3134 if (bktr->video.addr)
3135 target_buffer = (uint32_t) bktr->video.addr;
3137 target_buffer = (uint32_t) vtophys(bktr->bigbuf);
3139 buffer = target_buffer;
3141 /* contruct sync : for video packet format */
3142 /* sync, mode indicator packed data */
3143 *dma_prog++ = OP_SYNC | BKTR_RESYNC | BKTR_FM1;
3144 *dma_prog++ = 0; /* NULL WORD */
3148 for (i = 0; i < (rows/interlace); i++) {
3150 *dma_prog++ = target_buffer;
3151 *dma_prog++ = inst3;
3152 *dma_prog++ = target_buffer + b;
3153 target_buffer += interlace*(cols * 2);
3159 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_VRE;
3160 *dma_prog++ = 0; /* NULL WORD */
3162 *dma_prog++ = OP_JUMP;
3163 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3168 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_VRO;
3169 *dma_prog++ = 0; /* NULL WORD */
3170 *dma_prog++ = OP_JUMP;
3171 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3176 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_RESYNC | BKTR_VRO;
3177 *dma_prog++ = 0; /* NULL WORD */
3178 *dma_prog++ = OP_JUMP ;
3179 *dma_prog = (uint32_t) vtophys(bktr->odd_dma_prog);
3183 if (interlace == 2) {
3185 target_buffer = (uint32_t) buffer + cols*2;
3187 dma_prog = (uint32_t *) bktr->odd_dma_prog;
3190 *dma_prog++ = OP_SYNC | BKTR_RESYNC | BKTR_FM1;
3191 *dma_prog++ = 0; /* NULL WORD */
3193 for (i = 0; i < (rows/interlace) ; i++) {
3195 *dma_prog++ = target_buffer;
3196 *dma_prog++ = inst3;
3197 *dma_prog++ = target_buffer + b;
3198 target_buffer += interlace * ( cols*2);
3202 /* sync vro IRQ bit */
3203 *dma_prog++ = OP_SYNC | BKTR_GEN_IRQ | BKTR_RESYNC | BKTR_VRE;
3204 *dma_prog++ = 0; /* NULL WORD */
3205 *dma_prog++ = OP_JUMP ;
3206 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3208 *dma_prog++ = OP_JUMP;
3209 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3210 *dma_prog++ = 0; /* NULL WORD */
3218 yuv422_prog( bktr_ptr_t bktr, char i_flag,
3219 int cols, int rows, int interlace ){
3222 volatile unsigned int inst;
3223 volatile uint32_t target_buffer, t1, buffer;
3224 volatile uint32_t *dma_prog;
3225 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ];
3227 OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt);
3229 dma_prog = (uint32_t*) bktr->dma_prog;
3231 bktr->capcontrol = 1 << 6 | 1 << 4 | 3;
3233 OUTB(bktr, BKTR_ADC, SYNC_LEVEL);
3234 OUTB(bktr, BKTR_OFORM, 0x00);
3236 OUTB(bktr, BKTR_E_CONTROL, INB(bktr, BKTR_E_CONTROL) | BT848_E_CONTROL_LDEC); /* disable luma decimation */
3237 OUTB(bktr, BKTR_O_CONTROL, INB(bktr, BKTR_O_CONTROL) | BT848_O_CONTROL_LDEC);
3239 OUTB(bktr, BKTR_E_SCLOOP, INB(bktr, BKTR_E_SCLOOP) | BT848_E_SCLOOP_CAGC); /* chroma agc enable */
3240 OUTB(bktr, BKTR_O_SCLOOP, INB(bktr, BKTR_O_SCLOOP) | BT848_O_SCLOOP_CAGC);
3242 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x80); /* clear Ycomb */
3243 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x80);
3244 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | 0x40); /* set chroma comb */
3245 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | 0x40);
3247 /* disable gamma correction removal */
3248 OUTB(bktr, BKTR_COLOR_CTL, INB(bktr, BKTR_COLOR_CTL) | BT848_COLOR_CTL_GAMMA);
3250 /* Construct Write */
3251 inst = OP_WRITE123 | OP_SOL | OP_EOL | (cols);
3252 if (bktr->video.addr)
3253 target_buffer = (uint32_t) bktr->video.addr;
3255 target_buffer = (uint32_t) vtophys(bktr->bigbuf);
3257 buffer = target_buffer;
3261 /* contruct sync : for video packet format */
3262 *dma_prog++ = OP_SYNC | 1 << 15 | BKTR_FM3; /*sync, mode indicator packed data*/
3263 *dma_prog++ = 0; /* NULL WORD */
3265 for (i = 0; i < (rows/interlace ) ; i++) {
3267 *dma_prog++ = cols/2 | cols/2 << 16;
3268 *dma_prog++ = target_buffer;
3269 *dma_prog++ = t1 + (cols*rows) + i*cols/2 * interlace;
3270 *dma_prog++ = t1 + (cols*rows) + (cols*rows/2) + i*cols/2 * interlace;
3271 target_buffer += interlace*cols;
3276 *dma_prog++ = OP_SYNC | 1 << 24 | BKTR_VRE; /*sync vre*/
3277 *dma_prog++ = 0; /* NULL WORD */
3279 *dma_prog++ = OP_JUMP ;
3280 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3284 *dma_prog++ = OP_SYNC | 1 << 24 | BKTR_VRO; /*sync vre*/
3285 *dma_prog++ = 0; /* NULL WORD */
3287 *dma_prog++ = OP_JUMP;
3288 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3292 *dma_prog++ = OP_SYNC | 1 << 24 | 1 << 15 | BKTR_VRO;
3293 *dma_prog++ = 0; /* NULL WORD */
3295 *dma_prog++ = OP_JUMP ;
3296 *dma_prog = (uint32_t) vtophys(bktr->odd_dma_prog);
3300 if (interlace == 2) {
3302 dma_prog = (uint32_t *) bktr->odd_dma_prog;
3304 target_buffer = (uint32_t) buffer + cols;
3305 t1 = buffer + cols/2;
3306 *dma_prog++ = OP_SYNC | 1 << 15 | BKTR_FM3;
3307 *dma_prog++ = 0; /* NULL WORD */
3309 for (i = 0; i < (rows/interlace ) ; i++) {
3311 *dma_prog++ = cols/2 | cols/2 << 16;
3312 *dma_prog++ = target_buffer;
3313 *dma_prog++ = t1 + (cols*rows) + i*cols/2 * interlace;
3314 *dma_prog++ = t1 + (cols*rows) + (cols*rows/2) + i*cols/2 * interlace;
3315 target_buffer += interlace*cols;
3319 *dma_prog++ = OP_SYNC | 1 << 24 | 1 << 15 | BKTR_VRE;
3320 *dma_prog++ = 0; /* NULL WORD */
3321 *dma_prog++ = OP_JUMP ;
3322 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog) ;
3323 *dma_prog++ = 0; /* NULL WORD */
3331 yuv12_prog( bktr_ptr_t bktr, char i_flag,
3332 int cols, int rows, int interlace ){
3335 volatile unsigned int inst;
3336 volatile unsigned int inst1;
3337 volatile uint32_t target_buffer, t1, buffer;
3338 volatile uint32_t *dma_prog;
3339 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ];
3341 OUTB(bktr, BKTR_COLOR_FMT, pf_int->color_fmt);
3343 dma_prog = (uint32_t *) bktr->dma_prog;
3345 bktr->capcontrol = 1 << 6 | 1 << 4 | 3;
3347 OUTB(bktr, BKTR_ADC, SYNC_LEVEL);
3348 OUTB(bktr, BKTR_OFORM, 0x0);
3350 /* Construct Write */
3351 inst = OP_WRITE123 | OP_SOL | OP_EOL | (cols);
3352 inst1 = OP_WRITES123 | OP_SOL | OP_EOL | (cols);
3353 if (bktr->video.addr)
3354 target_buffer = (uint32_t) bktr->video.addr;
3356 target_buffer = (uint32_t) vtophys(bktr->bigbuf);
3358 buffer = target_buffer;
3361 *dma_prog++ = OP_SYNC | 1 << 15 | BKTR_FM3; /*sync, mode indicator packed data*/
3362 *dma_prog++ = 0; /* NULL WORD */
3364 for (i = 0; i < (rows/interlace )/2 ; i++) {
3366 *dma_prog++ = cols/2 | (cols/2 << 16);
3367 *dma_prog++ = target_buffer;
3368 *dma_prog++ = t1 + (cols*rows) + i*cols/2 * interlace;
3369 *dma_prog++ = t1 + (cols*rows) + (cols*rows/4) + i*cols/2 * interlace;
3370 target_buffer += interlace*cols;
3371 *dma_prog++ = inst1;
3372 *dma_prog++ = cols/2 | (cols/2 << 16);
3373 *dma_prog++ = target_buffer;
3374 target_buffer += interlace*cols;
3380 *dma_prog++ = OP_SYNC | 1 << 24 | BKTR_VRE; /*sync vre*/
3381 *dma_prog++ = 0; /* NULL WORD */
3383 *dma_prog++ = OP_JUMP;
3384 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3388 *dma_prog++ = OP_SYNC | 1 << 24 | BKTR_VRO; /*sync vro*/
3389 *dma_prog++ = 0; /* NULL WORD */
3391 *dma_prog++ = OP_JUMP;
3392 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3396 *dma_prog++ = OP_SYNC | 1 << 24 | 1 << 15 | BKTR_VRO;
3397 *dma_prog++ = 0; /* NULL WORD */
3398 *dma_prog++ = OP_JUMP ;
3399 *dma_prog = (uint32_t) vtophys(bktr->odd_dma_prog);
3403 if (interlace == 2) {
3405 dma_prog = (uint32_t *) bktr->odd_dma_prog;
3407 target_buffer = (uint32_t) buffer + cols;
3408 t1 = buffer + cols/2;
3409 *dma_prog++ = OP_SYNC | 1 << 15 | BKTR_FM3;
3410 *dma_prog++ = 0; /* NULL WORD */
3412 for (i = 0; i < ((rows/interlace )/2 ) ; i++) {
3414 *dma_prog++ = cols/2 | (cols/2 << 16);
3415 *dma_prog++ = target_buffer;
3416 *dma_prog++ = t1 + (cols*rows) + i*cols/2 * interlace;
3417 *dma_prog++ = t1 + (cols*rows) + (cols*rows/4) + i*cols/2 * interlace;
3418 target_buffer += interlace*cols;
3419 *dma_prog++ = inst1;
3420 *dma_prog++ = cols/2 | (cols/2 << 16);
3421 *dma_prog++ = target_buffer;
3422 target_buffer += interlace*cols;
3429 *dma_prog++ = OP_SYNC | 1 << 24 | 1 << 15 | BKTR_VRE;
3430 *dma_prog++ = 0; /* NULL WORD */
3431 *dma_prog++ = OP_JUMP;
3432 *dma_prog++ = (uint32_t) vtophys(bktr->dma_prog);
3433 *dma_prog++ = 0; /* NULL WORD */
3442 build_dma_prog( bktr_ptr_t bktr, char i_flag )
3444 int rows, cols, interlace;
3447 struct format_params *fp;
3448 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ];
3451 fp = &format_params[bktr->format_params];
3453 OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
3455 /* disable FIFO & RISC, leave other bits alone */
3456 OUTW(bktr, BKTR_GPIO_DMA_CTL, INW(bktr, BKTR_GPIO_DMA_CTL) & ~FIFO_RISC_ENABLED);
3458 /* set video parameters */
3459 if (bktr->capture_area_enabled)
3460 temp = ((quad_t ) fp->htotal* (quad_t) bktr->capture_area_x_size * 4096
3461 / fp->scaled_htotal / bktr->cols) - 4096;
3463 temp = ((quad_t ) fp->htotal* (quad_t) fp->scaled_hactive * 4096
3464 / fp->scaled_htotal / bktr->cols) - 4096;
3466 /* printf("%s: HSCALE value is %d\n", bktr_name(bktr), temp); */
3467 OUTB(bktr, BKTR_E_HSCALE_LO, temp & 0xff);
3468 OUTB(bktr, BKTR_O_HSCALE_LO, temp & 0xff);
3469 OUTB(bktr, BKTR_E_HSCALE_HI, (temp >> 8) & 0xff);
3470 OUTB(bktr, BKTR_O_HSCALE_HI, (temp >> 8) & 0xff);
3472 /* horizontal active */
3474 /* printf("%s: HACTIVE value is %d\n", bktr_name(bktr), temp); */
3475 OUTB(bktr, BKTR_E_HACTIVE_LO, temp & 0xff);
3476 OUTB(bktr, BKTR_O_HACTIVE_LO, temp & 0xff);
3477 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0x3);
3478 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0x3);
3479 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 8) & 0x3));
3480 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 8) & 0x3));
3482 /* horizontal delay */
3483 if (bktr->capture_area_enabled)
3484 temp = ( (fp->hdelay* fp->scaled_hactive + bktr->capture_area_x_offset* fp->scaled_htotal)
3485 * bktr->cols) / (bktr->capture_area_x_size * fp->hactive);
3487 temp = (fp->hdelay * bktr->cols) / fp->hactive;
3489 temp = temp & 0x3fe;
3491 /* printf("%s: HDELAY value is %d\n", bktr_name(bktr), temp); */
3492 OUTB(bktr, BKTR_E_DELAY_LO, temp & 0xff);
3493 OUTB(bktr, BKTR_O_DELAY_LO, temp & 0xff);
3494 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0xc);
3495 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0xc);
3496 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 6) & 0xc));
3497 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 6) & 0xc));
3499 /* vertical scale */
3501 if (bktr->capture_area_enabled) {
3502 if (bktr->flags & METEOR_ONLY_ODD_FIELDS ||
3503 bktr->flags & METEOR_ONLY_EVEN_FIELDS)
3505 (((bktr->capture_area_y_size * 256 + (bktr->rows/2)) / bktr->rows) - 512);
3508 (((bktr->capture_area_y_size * 512 + (bktr->rows / 2)) / bktr->rows) - 512);
3511 if (bktr->flags & METEOR_ONLY_ODD_FIELDS ||
3512 bktr->flags & METEOR_ONLY_EVEN_FIELDS)
3514 (((fp->vactive * 256 + (bktr->rows/2)) / bktr->rows) - 512);
3517 (((fp->vactive * 512 + (bktr->rows / 2)) / bktr->rows) - 512);
3522 /* printf("%s: VSCALE value is %d\n", bktr_name(bktr), tmp_int); */
3523 OUTB(bktr, BKTR_E_VSCALE_LO, tmp_int & 0xff);
3524 OUTB(bktr, BKTR_O_VSCALE_LO, tmp_int & 0xff);
3525 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x1f);
3526 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x1f);
3527 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | ((tmp_int >> 8) & 0x1f));
3528 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | ((tmp_int >> 8) & 0x1f));
3531 /* vertical active */
3532 if (bktr->capture_area_enabled)
3533 temp = bktr->capture_area_y_size;
3536 /* printf("%s: VACTIVE is %d\n", bktr_name(bktr), temp); */
3537 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0x30);
3538 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 4) & 0x30));
3539 OUTB(bktr, BKTR_E_VACTIVE_LO, temp & 0xff);
3540 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0x30);
3541 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 4) & 0x30));
3542 OUTB(bktr, BKTR_O_VACTIVE_LO, temp & 0xff);
3544 /* vertical delay */
3545 if (bktr->capture_area_enabled)
3546 temp = fp->vdelay + (bktr->capture_area_y_offset);
3549 /* printf("%s: VDELAY is %d\n", bktr_name(bktr), temp); */
3550 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) & ~0xC0);
3551 OUTB(bktr, BKTR_E_CROP, INB(bktr, BKTR_E_CROP) | ((temp >> 2) & 0xC0));
3552 OUTB(bktr, BKTR_E_VDELAY_LO, temp & 0xff);
3553 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) & ~0xC0);
3554 OUTB(bktr, BKTR_O_CROP, INB(bktr, BKTR_O_CROP) | ((temp >> 2) & 0xC0));
3555 OUTB(bktr, BKTR_O_VDELAY_LO, temp & 0xff);
3557 /* end of video params */
3559 if ((bktr->xtal_pll_mode == BT848_USE_PLL)
3560 && (fp->iform_xtsel==BT848_IFORM_X_XT1)) {
3561 OUTB(bktr, BKTR_TGCTRL, BT848_TGCTRL_TGCKI_PLL); /* Select PLL mode */
3563 OUTB(bktr, BKTR_TGCTRL, BT848_TGCTRL_TGCKI_XTAL); /* Select Normal xtal 0/xtal 1 mode */
3566 /* capture control */
3569 bktr->bktr_cap_ctl =
3570 (BT848_CAP_CTL_DITH_FRAME | BT848_CAP_CTL_EVEN);
3571 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x20);
3572 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x20);
3576 bktr->bktr_cap_ctl =
3577 (BT848_CAP_CTL_DITH_FRAME | BT848_CAP_CTL_ODD);
3578 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) & ~0x20);
3579 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) & ~0x20);
3583 bktr->bktr_cap_ctl =
3584 (BT848_CAP_CTL_DITH_FRAME |
3585 BT848_CAP_CTL_EVEN | BT848_CAP_CTL_ODD);
3586 OUTB(bktr, BKTR_E_VSCALE_HI, INB(bktr, BKTR_E_VSCALE_HI) | 0x20);
3587 OUTB(bktr, BKTR_O_VSCALE_HI, INB(bktr, BKTR_O_VSCALE_HI) | 0x20);
3592 OUTL(bktr, BKTR_RISC_STRT_ADD, vtophys(bktr->dma_prog));
3597 bktr->vbiflags &= ~VBI_CAPTURE; /* default - no vbi capture */
3599 /* RGB Grabs. If /dev/vbi is already open, or we are a PAL/SECAM */
3600 /* user, then use the rgb_vbi RISC program. */
3601 /* Otherwise, use the normal rgb RISC program */
3602 if (pf_int->public.type == METEOR_PIXTYPE_RGB) {
3603 if ( (bktr->vbiflags & VBI_OPEN)
3604 ||(bktr->format_params == BT848_IFORM_F_PALBDGHI)
3605 ||(bktr->format_params == BT848_IFORM_F_SECAM)
3607 bktr->bktr_cap_ctl |=
3608 BT848_CAP_CTL_VBI_EVEN | BT848_CAP_CTL_VBI_ODD;
3609 bktr->vbiflags |= VBI_CAPTURE;
3610 rgb_vbi_prog(bktr, i_flag, cols, rows, interlace);
3613 rgb_prog(bktr, i_flag, cols, rows, interlace);
3618 if ( pf_int->public.type == METEOR_PIXTYPE_YUV ) {
3619 yuv422_prog(bktr, i_flag, cols, rows, interlace);
3620 OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0)
3621 | pixfmt_swap_flags( bktr->pixfmt ));
3625 if ( pf_int->public.type == METEOR_PIXTYPE_YUV_PACKED ) {
3626 yuvpack_prog(bktr, i_flag, cols, rows, interlace);
3627 OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0)
3628 | pixfmt_swap_flags( bktr->pixfmt ));
3632 if ( pf_int->public.type == METEOR_PIXTYPE_YUV_12 ) {
3633 yuv12_prog(bktr, i_flag, cols, rows, interlace);
3634 OUTB(bktr, BKTR_COLOR_CTL, (INB(bktr, BKTR_COLOR_CTL) & 0xf0)
3635 | pixfmt_swap_flags( bktr->pixfmt ));
3642 /******************************************************************************
3643 * video & video capture specific routines:
3651 start_capture( bktr_ptr_t bktr, unsigned type )
3654 struct format_params *fp;
3656 fp = &format_params[bktr->format_params];
3658 /* If requested, clear out capture buf first */
3659 if (bktr->clr_on_start && (bktr->video.addr == 0)) {
3660 bzero((caddr_t)bktr->bigbuf,
3661 (size_t)bktr->rows * bktr->cols * bktr->frames *
3662 pixfmt_table[ bktr->pixfmt ].public.Bpp);
3665 OUTB(bktr, BKTR_DSTATUS, 0);
3666 OUTL(bktr, BKTR_INT_STAT, INL(bktr, BKTR_INT_STAT));
3668 bktr->flags |= type;
3669 bktr->flags &= ~METEOR_WANT_MASK;
3670 switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
3671 case METEOR_ONLY_EVEN_FIELDS:
3672 bktr->flags |= METEOR_WANT_EVEN;
3675 case METEOR_ONLY_ODD_FIELDS:
3676 bktr->flags |= METEOR_WANT_ODD;
3680 bktr->flags |= METEOR_WANT_MASK;
3685 /* TDEC is only valid for continuous captures */
3686 if ( type == METEOR_SINGLE ) {
3687 u_short fps_save = bktr->fps;
3689 set_fps(bktr, fp->frame_rate);
3690 bktr->fps = fps_save;
3693 set_fps(bktr, bktr->fps);
3695 if (bktr->dma_prog_loaded == FALSE) {
3696 build_dma_prog(bktr, i_flag);
3697 bktr->dma_prog_loaded = TRUE;
3701 OUTL(bktr, BKTR_RISC_STRT_ADD, vtophys(bktr->dma_prog));
3710 set_fps( bktr_ptr_t bktr, u_short fps )
3712 struct format_params *fp;
3715 fp = &format_params[bktr->format_params];
3717 switch(bktr->flags & METEOR_ONLY_FIELDS_MASK) {
3718 case METEOR_ONLY_EVEN_FIELDS:
3719 bktr->flags |= METEOR_WANT_EVEN;
3722 case METEOR_ONLY_ODD_FIELDS:
3723 bktr->flags |= METEOR_WANT_ODD;
3727 bktr->flags |= METEOR_WANT_MASK;
3732 OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
3733 OUTL(bktr, BKTR_INT_STAT, ALL_INTS_CLEARED);
3736 OUTB(bktr, BKTR_TDEC, 0);
3738 if (fps < fp->frame_rate)
3739 OUTB(bktr, BKTR_TDEC, i_flag*(fp->frame_rate - fps) & 0x3f);
3741 OUTB(bktr, BKTR_TDEC, 0);
3751 * Given a pixfmt index, compute the bt848 swap_flags necessary to
3752 * achieve the specified swapping.
3753 * Note that without bt swapping, 2Bpp and 3Bpp modes are written
3754 * byte-swapped, and 4Bpp modes are byte and word swapped (see Table 6
3756 * Note also that for 3Bpp, we may additionally need to do some creative
3757 * SKIPing to align the FIFO bytelines with the target buffer (see split()).
3758 * This is abstracted here: e.g. no swaps = RGBA; byte & short swap = ABGR
3759 * as one would expect.
3762 static u_int pixfmt_swap_flags( int pixfmt )
3764 struct meteor_pixfmt *pf = &pixfmt_table[ pixfmt ].public;
3767 switch ( pf->Bpp ) {
3768 case 2 : swapf = ( pf->swap_bytes ? 0 : BSWAP );
3771 case 3 : /* no swaps supported for 3bpp - makes no sense w/ bt848 */
3774 case 4 : if ( pf->swap_bytes )
3775 swapf = pf->swap_shorts ? 0 : WSWAP;
3777 swapf = pf->swap_shorts ? BSWAP : (BSWAP | WSWAP);
3786 * Converts meteor-defined pixel formats (e.g. METEOR_GEO_RGB16) into
3787 * our pixfmt_table indices.
3790 static int oformat_meteor_to_bt( u_long format )
3793 struct meteor_pixfmt *pf1, *pf2;
3795 /* Find format in compatibility table */
3796 for ( i = 0; i < METEOR_PIXFMT_TABLE_SIZE; i++ )
3797 if ( meteor_pixfmt_table[i].meteor_format == format )
3800 if ( i >= METEOR_PIXFMT_TABLE_SIZE )
3802 pf1 = &meteor_pixfmt_table[i].public;
3804 /* Match it with an entry in master pixel format table */
3805 for ( i = 0; i < PIXFMT_TABLE_SIZE; i++ ) {
3806 pf2 = &pixfmt_table[i].public;
3808 if (( pf1->type == pf2->type ) &&
3809 ( pf1->Bpp == pf2->Bpp ) &&
3810 !bcmp( pf1->masks, pf2->masks, sizeof( pf1->masks )) &&
3811 ( pf1->swap_bytes == pf2->swap_bytes ) &&
3812 ( pf1->swap_shorts == pf2->swap_shorts ))
3815 if ( i >= PIXFMT_TABLE_SIZE )
3821 /******************************************************************************
3826 #define I2CBITTIME (0x5<<4) /* 5 * 0.48uS */
3827 #define I2CBITTIME_878 (1 << 7)
3828 #define I2C_READ 0x01
3829 #define I2C_COMMAND (I2CBITTIME | \
3830 BT848_DATA_CTL_I2CSCL | \
3831 BT848_DATA_CTL_I2CSDA)
3833 #define I2C_COMMAND_878 (I2CBITTIME_878 | \
3834 BT848_DATA_CTL_I2CSCL | \
3835 BT848_DATA_CTL_I2CSDA)
3837 /* Select between old i2c code and new iicbus / smbus code */
3838 #if defined(BKTR_USE_FREEBSD_SMBUS)
3841 * The hardware interface is actually SMB commands
3844 i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 )
3848 if (bktr->id == BROOKTREE_848 ||
3849 bktr->id == BROOKTREE_848A ||
3850 bktr->id == BROOKTREE_849A)
3853 cmd = I2C_COMMAND_878;
3856 if (smbus_writew(bktr->i2c_sc.smbus, addr, cmd,
3857 (short)(((byte2 & 0xff) << 8) | (byte1 & 0xff))))
3860 if (smbus_writeb(bktr->i2c_sc.smbus, addr, cmd,
3861 (char)(byte1 & 0xff)))
3870 i2cRead( bktr_ptr_t bktr, int addr )
3875 if (bktr->id == BROOKTREE_848 ||
3876 bktr->id == BROOKTREE_848A ||
3877 bktr->id == BROOKTREE_849A)
3880 cmd = I2C_COMMAND_878;
3882 if (smbus_readb(bktr->i2c_sc.smbus, addr, cmd, &result))
3885 return ((int)((unsigned char)result));
3888 #define IICBUS(bktr) ((bktr)->i2c_sc.iicbb)
3890 /* The MSP34xx and DPL35xx Audio chip require i2c bus writes of up */
3891 /* to 5 bytes which the bt848 automated i2c bus controller cannot handle */
3892 /* Therefore we need low level control of the i2c bus hardware */
3894 /* Write to the MSP or DPL registers */
3896 msp_dpl_write(bktr_ptr_t bktr, int i2c_addr, unsigned char dev, unsigned int addr, unsigned int data)
3898 unsigned char addr_l, addr_h, data_h, data_l ;
3900 addr_h = (addr >>8) & 0xff;
3901 addr_l = addr & 0xff;
3902 data_h = (data >>8) & 0xff;
3903 data_l = data & 0xff;
3905 iicbus_start(IICBUS(bktr), i2c_addr, 0 /* no timeout? */);
3907 iicbus_write_byte(IICBUS(bktr), dev, 0);
3908 iicbus_write_byte(IICBUS(bktr), addr_h, 0);
3909 iicbus_write_byte(IICBUS(bktr), addr_l, 0);
3910 iicbus_write_byte(IICBUS(bktr), data_h, 0);
3911 iicbus_write_byte(IICBUS(bktr), data_l, 0);
3913 iicbus_stop(IICBUS(bktr));
3918 /* Read from the MSP or DPL registers */
3920 msp_dpl_read(bktr_ptr_t bktr, int i2c_addr, unsigned char dev, unsigned int addr)
3923 unsigned char addr_l, addr_h, dev_r;
3925 u_char data_read[2];
3927 addr_h = (addr >>8) & 0xff;
3928 addr_l = addr & 0xff;
3931 /* XXX errors ignored */
3932 iicbus_start(IICBUS(bktr), i2c_addr, 0 /* no timeout? */);
3934 iicbus_write_byte(IICBUS(bktr), dev_r, 0);
3935 iicbus_write_byte(IICBUS(bktr), addr_h, 0);
3936 iicbus_write_byte(IICBUS(bktr), addr_l, 0);
3938 iicbus_repeated_start(IICBUS(bktr), i2c_addr +1, 0 /* no timeout? */);
3939 iicbus_read(IICBUS(bktr), data_read, 2, &read, IIC_LAST_READ, 0);
3940 iicbus_stop(IICBUS(bktr));
3942 data = (data_read[0]<<8) | data_read[1];
3947 /* Reset the MSP or DPL chip */
3948 /* The user can block the reset (which is handy if you initialise the
3949 * MSP and/or DPL audio in another operating system first (eg in Windows)
3952 msp_dpl_reset( bktr_ptr_t bktr, int i2c_addr )
3955 #ifndef BKTR_NO_MSP_RESET
3956 /* put into reset mode */
3957 iicbus_start(IICBUS(bktr), i2c_addr, 0 /* no timeout? */);
3958 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3959 iicbus_write_byte(IICBUS(bktr), 0x80, 0);
3960 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3961 iicbus_stop(IICBUS(bktr));
3963 /* put back to operational mode */
3964 iicbus_start(IICBUS(bktr), i2c_addr, 0 /* no timeout? */);
3965 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3966 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3967 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3968 iicbus_stop(IICBUS(bktr));
3973 static void remote_read(bktr_ptr_t bktr, struct bktr_remote *remote) {
3976 /* XXX errors ignored */
3977 iicbus_start(IICBUS(bktr), bktr->remote_control_addr, 0 /* no timeout? */);
3978 iicbus_read(IICBUS(bktr), remote->data, 3, &read, IIC_LAST_READ, 0);
3979 iicbus_stop(IICBUS(bktr));
3984 #else /* defined(BKTR_USE_FREEBSD_SMBUS) */
3987 * Program the i2c bus directly
3990 i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 )
3995 /* clear status bits */
3996 OUTL(bktr, BKTR_INT_STAT, BT848_INT_RACK | BT848_INT_I2CDONE);
3998 /* build the command datum */
3999 if (bktr->id == BROOKTREE_848 ||
4000 bktr->id == BROOKTREE_848A ||
4001 bktr->id == BROOKTREE_849A) {
4002 data = ((addr & 0xff) << 24) | ((byte1 & 0xff) << 16) | I2C_COMMAND;
4004 data = ((addr & 0xff) << 24) | ((byte1 & 0xff) << 16) | I2C_COMMAND_878;
4006 if ( byte2 != -1 ) {
4007 data |= ((byte2 & 0xff) << 8);
4008 data |= BT848_DATA_CTL_I2CW3B;
4011 /* write the address and data */
4012 OUTL(bktr, BKTR_I2C_DATA_CTL, data);
4014 /* wait for completion */
4015 for ( x = 0x7fffffff; x; --x ) { /* safety valve */
4016 if ( INL(bktr, BKTR_INT_STAT) & BT848_INT_I2CDONE )
4021 if ( !x || !(INL(bktr, BKTR_INT_STAT) & BT848_INT_RACK) )
4033 i2cRead( bktr_ptr_t bktr, int addr )
4037 /* clear status bits */
4038 OUTL(bktr, BKTR_INT_STAT, BT848_INT_RACK | BT848_INT_I2CDONE);
4040 /* write the READ address */
4041 /* The Bt878 and Bt879 differed on the treatment of i2c commands */
4043 if (bktr->id == BROOKTREE_848 ||
4044 bktr->id == BROOKTREE_848A ||
4045 bktr->id == BROOKTREE_849A) {
4046 OUTL(bktr, BKTR_I2C_DATA_CTL, ((addr & 0xff) << 24) | I2C_COMMAND);
4048 OUTL(bktr, BKTR_I2C_DATA_CTL, ((addr & 0xff) << 24) | I2C_COMMAND_878);
4051 /* wait for completion */
4052 for ( x = 0x7fffffff; x; --x ) { /* safety valve */
4053 if ( INL(bktr, BKTR_INT_STAT) & BT848_INT_I2CDONE )
4058 if ( !x || !(INL(bktr, BKTR_INT_STAT) & BT848_INT_RACK) )
4062 return( (INL(bktr, BKTR_I2C_DATA_CTL) >> 8) & 0xff );
4065 /* The MSP34xx Audio chip require i2c bus writes of up to 5 bytes which the */
4066 /* bt848 automated i2c bus controller cannot handle */
4067 /* Therefore we need low level control of the i2c bus hardware */
4068 /* Idea for the following functions are from elsewhere in this driver and */
4069 /* from the Linux BTTV i2c driver by Gerd Knorr <kraxel@cs.tu-berlin.de> */
4072 static void i2c_start( bktr_ptr_t bktr) {
4073 OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release data */
4074 OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release clock */
4075 OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* lower data */
4076 OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock */
4079 static void i2c_stop( bktr_ptr_t bktr) {
4080 OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock & data */
4081 OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* release clock */
4082 OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release data */
4085 static int i2c_write_byte( bktr_ptr_t bktr, unsigned char data) {
4089 /* write out the byte */
4090 for ( x = 7; x >= 0; --x ) {
4091 if ( data & (1<<x) ) {
4092 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4093 DELAY( BITD ); /* assert HI data */
4094 OUTL(bktr, BKTR_I2C_DATA_CTL, 3);
4095 DELAY( BITD ); /* strobe clock */
4096 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4097 DELAY( BITD ); /* release clock */
4100 OUTL(bktr, BKTR_I2C_DATA_CTL, 0);
4101 DELAY( BITD ); /* assert LO data */
4102 OUTL(bktr, BKTR_I2C_DATA_CTL, 2);
4103 DELAY( BITD ); /* strobe clock */
4104 OUTL(bktr, BKTR_I2C_DATA_CTL, 0);
4105 DELAY( BITD ); /* release clock */
4109 /* look for an ACK */
4110 OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* float data */
4111 OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */
4112 status = INL(bktr, BKTR_I2C_DATA_CTL) & 1; /* read the ACK bit */
4113 OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */
4118 static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last ) {
4123 /* read in the byte */
4124 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4125 DELAY( BITD ); /* float data */
4126 for ( x = 7; x >= 0; --x ) {
4127 OUTL(bktr, BKTR_I2C_DATA_CTL, 3);
4128 DELAY( BITD ); /* strobe clock */
4129 bit = INL(bktr, BKTR_I2C_DATA_CTL) & 1; /* read the data bit */
4130 if ( bit ) byte |= (1<<x);
4131 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4132 DELAY( BITD ); /* release clock */
4134 /* After reading the byte, send an ACK */
4135 /* (unless that was the last byte, for which we send a NAK */
4136 if (last) { /* send NAK - same a writing a 1 */
4137 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4138 DELAY( BITD ); /* set data bit */
4139 OUTL(bktr, BKTR_I2C_DATA_CTL, 3);
4140 DELAY( BITD ); /* strobe clock */
4141 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4142 DELAY( BITD ); /* release clock */
4143 } else { /* send ACK - same as writing a 0 */
4144 OUTL(bktr, BKTR_I2C_DATA_CTL, 0);
4145 DELAY( BITD ); /* set data bit */
4146 OUTL(bktr, BKTR_I2C_DATA_CTL, 2);
4147 DELAY( BITD ); /* strobe clock */
4148 OUTL(bktr, BKTR_I2C_DATA_CTL, 0);
4149 DELAY( BITD ); /* release clock */
4157 /* Write to the MSP or DPL registers */
4158 void msp_dpl_write( bktr_ptr_t bktr, int i2c_addr, unsigned char dev, unsigned int addr,
4160 unsigned int msp_w_addr = i2c_addr;
4161 unsigned char addr_l, addr_h, data_h, data_l ;
4162 addr_h = (addr >>8) & 0xff;
4163 addr_l = addr & 0xff;
4164 data_h = (data >>8) & 0xff;
4165 data_l = data & 0xff;
4168 i2c_write_byte(bktr, msp_w_addr);
4169 i2c_write_byte(bktr, dev);
4170 i2c_write_byte(bktr, addr_h);
4171 i2c_write_byte(bktr, addr_l);
4172 i2c_write_byte(bktr, data_h);
4173 i2c_write_byte(bktr, data_l);
4177 /* Read from the MSP or DPL registers */
4178 unsigned int msp_dpl_read(bktr_ptr_t bktr, int i2c_addr, unsigned char dev, unsigned int addr){
4180 unsigned char addr_l, addr_h, data_1, data_2, dev_r ;
4181 addr_h = (addr >>8) & 0xff;
4182 addr_l = addr & 0xff;
4186 i2c_write_byte(bktr,i2c_addr);
4187 i2c_write_byte(bktr,dev_r);
4188 i2c_write_byte(bktr,addr_h);
4189 i2c_write_byte(bktr,addr_l);
4192 i2c_write_byte(bktr,i2c_addr+1);
4193 i2c_read_byte(bktr,&data_1, 0);
4194 i2c_read_byte(bktr,&data_2, 1);
4196 data = (data_1<<8) | data_2;
4200 /* Reset the MSP or DPL chip */
4201 /* The user can block the reset (which is handy if you initialise the
4202 * MSP audio in another operating system first (eg in Windows)
4204 void msp_dpl_reset( bktr_ptr_t bktr, int i2c_addr ) {
4206 #ifndef BKTR_NO_MSP_RESET
4207 /* put into reset mode */
4209 i2c_write_byte(bktr, i2c_addr);
4210 i2c_write_byte(bktr, 0x00);
4211 i2c_write_byte(bktr, 0x80);
4212 i2c_write_byte(bktr, 0x00);
4215 /* put back to operational mode */
4217 i2c_write_byte(bktr, i2c_addr);
4218 i2c_write_byte(bktr, 0x00);
4219 i2c_write_byte(bktr, 0x00);
4220 i2c_write_byte(bktr, 0x00);
4227 static void remote_read(bktr_ptr_t bktr, struct bktr_remote *remote) {
4229 /* XXX errors ignored */
4231 i2c_write_byte(bktr,bktr->remote_control_addr);
4232 i2c_read_byte(bktr,&(remote->data[0]), 0);
4233 i2c_read_byte(bktr,&(remote->data[1]), 0);
4234 i2c_read_byte(bktr,&(remote->data[2]), 0);
4240 #endif /* defined(BKTR_USE_FREEBSD_SMBUS) */
4243 #if defined( I2C_SOFTWARE_PROBE )
4246 * we are keeping this around for any parts that we need to probe
4247 * but that CANNOT be probed via an i2c read.
4248 * this is necessary because the hardware i2c mechanism
4249 * cannot be programmed for 1 byte writes.
4250 * currently there are no known i2c parts that we need to probe
4251 * and that cannot be safely read.
4253 static int i2cProbe( bktr_ptr_t bktr, int addr );
4258 * probe for an I2C device at addr.
4261 i2cProbe( bktr_ptr_t bktr, int addr )
4266 #if defined( EXTRA_START )
4267 OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release data */
4268 OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release clock */
4269 #endif /* EXTRA_START */
4270 OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* lower data */
4271 OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock */
4274 for ( x = 7; x >= 0; --x ) {
4275 if ( addr & (1<<x) ) {
4276 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4277 DELAY( BITD ); /* assert HI data */
4278 OUTL(bktr, BKTR_I2C_DATA_CTL, 3);
4279 DELAY( BITD ); /* strobe clock */
4280 OUTL(bktr, BKTR_I2C_DATA_CTL, 1);
4281 DELAY( BITD ); /* release clock */
4284 OUTL(bktr, BKTR_I2C_DATA_CTL, 0);
4285 DELAY( BITD ); /* assert LO data */
4286 OUTL(bktr, BKTR_I2C_DATA_CTL, 2);
4287 DELAY( BITD ); /* strobe clock */
4288 OUTL(bktr, BKTR_I2C_DATA_CTL, 0);
4289 DELAY( BITD ); /* release clock */
4293 /* look for an ACK */
4294 OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* float data */
4295 OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* strobe clock */
4296 status = INL(bktr, BKTR_I2C_DATA_CTL) & 1; /* read the ACK bit */
4297 OUTL(bktr, BKTR_I2C_DATA_CTL, 1); DELAY( BITD ); /* release clock */
4300 OUTL(bktr, BKTR_I2C_DATA_CTL, 0); DELAY( BITD ); /* lower clock & data */
4301 OUTL(bktr, BKTR_I2C_DATA_CTL, 2); DELAY( BITD ); /* release clock */
4302 OUTL(bktr, BKTR_I2C_DATA_CTL, 3); DELAY( BITD ); /* release data */
4309 #endif /* I2C_SOFTWARE_PROBE */
4314 #endif /* FreeBSD, BSDI, NetBSD, OpenBSD */