1 // SPDX-License-Identifier: GPL-2.0-or-later
4 bttv-risc.c -- interfaces to other kernel modules
6 bttv risc code handling
10 (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org>
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/pci.h>
21 #include <linux/vmalloc.h>
22 #include <linux/interrupt.h>
24 #include <asm/pgtable.h>
25 #include <media/v4l2-ioctl.h>
29 #define VCR_HACK_LINES 4
31 /* ---------------------------------------------------------- */
32 /* risc code generators */
35 bttv_risc_packed(struct bttv
*btv
, struct btcx_riscmem
*risc
,
36 struct scatterlist
*sglist
,
37 unsigned int offset
, unsigned int bpl
,
38 unsigned int padding
, unsigned int skip_lines
,
39 unsigned int store_lines
)
41 u32 instructions
,line
,todo
;
42 struct scatterlist
*sg
;
46 /* estimate risc mem: worst case is one write per page border +
47 one write per scan line + sync + jump (all 2 dwords). padding
48 can cause next bpl to start close to a page border. First DMA
49 region may be smaller than PAGE_SIZE */
50 instructions
= skip_lines
* 4;
51 instructions
+= (1 + ((bpl
+ padding
) * store_lines
)
52 / PAGE_SIZE
+ store_lines
) * 8;
53 instructions
+= 2 * 8;
54 if ((rc
= btcx_riscmem_alloc(btv
->c
.pci
,risc
,instructions
)) < 0)
57 /* sync instruction */
59 *(rp
++) = cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
60 *(rp
++) = cpu_to_le32(0);
62 while (skip_lines
-- > 0) {
63 *(rp
++) = cpu_to_le32(BT848_RISC_SKIP
| BT848_RISC_SOL
|
64 BT848_RISC_EOL
| bpl
);
69 for (line
= 0; line
< store_lines
; line
++) {
70 if ((btv
->opt_vcr_hack
) &&
71 (line
>= (store_lines
- VCR_HACK_LINES
)))
73 while (offset
&& offset
>= sg_dma_len(sg
)) {
74 offset
-= sg_dma_len(sg
);
77 if (bpl
<= sg_dma_len(sg
)-offset
) {
78 /* fits into current chunk */
79 *(rp
++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_SOL
|
81 *(rp
++)=cpu_to_le32(sg_dma_address(sg
)+offset
);
84 /* scanline needs to be split */
86 *(rp
++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_SOL
|
87 (sg_dma_len(sg
)-offset
));
88 *(rp
++)=cpu_to_le32(sg_dma_address(sg
)+offset
);
89 todo
-= (sg_dma_len(sg
)-offset
);
92 while (todo
> sg_dma_len(sg
)) {
93 *(rp
++)=cpu_to_le32(BT848_RISC_WRITE
|
95 *(rp
++)=cpu_to_le32(sg_dma_address(sg
));
96 todo
-= sg_dma_len(sg
);
99 *(rp
++)=cpu_to_le32(BT848_RISC_WRITE
|BT848_RISC_EOL
|
101 *(rp
++)=cpu_to_le32(sg_dma_address(sg
));
107 /* save pointer to jmp instruction address */
109 BUG_ON((risc
->jmp
- risc
->cpu
+ 2) * sizeof(*risc
->cpu
) > risc
->size
);
114 bttv_risc_planar(struct bttv
*btv
, struct btcx_riscmem
*risc
,
115 struct scatterlist
*sglist
,
116 unsigned int yoffset
, unsigned int ybpl
,
117 unsigned int ypadding
, unsigned int ylines
,
118 unsigned int uoffset
, unsigned int voffset
,
119 unsigned int hshift
, unsigned int vshift
,
120 unsigned int cpadding
)
122 unsigned int instructions
,line
,todo
,ylen
,chroma
;
125 struct scatterlist
*ysg
;
126 struct scatterlist
*usg
;
127 struct scatterlist
*vsg
;
128 int topfield
= (0 == yoffset
);
131 /* estimate risc mem: worst case is one write per page border +
132 one write per scan line (5 dwords)
133 plus sync + jump (2 dwords) */
134 instructions
= ((3 + (ybpl
+ ypadding
) * ylines
* 2)
135 / PAGE_SIZE
) + ylines
;
137 if ((rc
= btcx_riscmem_alloc(btv
->c
.pci
,risc
,instructions
*4*5)) < 0)
140 /* sync instruction */
142 *(rp
++) = cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM3
);
143 *(rp
++) = cpu_to_le32(0);
149 for (line
= 0; line
< ylines
; line
++) {
150 if ((btv
->opt_vcr_hack
) &&
151 (line
>= (ylines
- VCR_HACK_LINES
)))
159 chroma
= ((line
& 1) == 0);
161 chroma
= ((line
& 1) == 1);
165 chroma
= ((line
& 3) == 0);
167 chroma
= ((line
& 3) == 2);
174 for (todo
= ybpl
; todo
> 0; todo
-= ylen
) {
175 /* go to next sg entry if needed */
176 while (yoffset
&& yoffset
>= sg_dma_len(ysg
)) {
177 yoffset
-= sg_dma_len(ysg
);
181 /* calculate max number of bytes we can write */
183 if (yoffset
+ ylen
> sg_dma_len(ysg
))
184 ylen
= sg_dma_len(ysg
) - yoffset
;
186 while (uoffset
&& uoffset
>= sg_dma_len(usg
)) {
187 uoffset
-= sg_dma_len(usg
);
190 while (voffset
&& voffset
>= sg_dma_len(vsg
)) {
191 voffset
-= sg_dma_len(vsg
);
195 if (uoffset
+ (ylen
>>hshift
) > sg_dma_len(usg
))
196 ylen
= (sg_dma_len(usg
) - uoffset
) << hshift
;
197 if (voffset
+ (ylen
>>hshift
) > sg_dma_len(vsg
))
198 ylen
= (sg_dma_len(vsg
) - voffset
) << hshift
;
199 ri
= BT848_RISC_WRITE123
;
201 ri
= BT848_RISC_WRITE1S23
;
204 ri
|= BT848_RISC_SOL
;
206 ri
|= BT848_RISC_EOL
;
208 /* write risc instruction */
209 *(rp
++)=cpu_to_le32(ri
| ylen
);
210 *(rp
++)=cpu_to_le32(((ylen
>> hshift
) << 16) |
212 *(rp
++)=cpu_to_le32(sg_dma_address(ysg
)+yoffset
);
215 *(rp
++)=cpu_to_le32(sg_dma_address(usg
)+uoffset
);
216 uoffset
+= ylen
>> hshift
;
217 *(rp
++)=cpu_to_le32(sg_dma_address(vsg
)+voffset
);
218 voffset
+= ylen
>> hshift
;
228 /* save pointer to jmp instruction address */
230 BUG_ON((risc
->jmp
- risc
->cpu
+ 2) * sizeof(*risc
->cpu
) > risc
->size
);
235 bttv_risc_overlay(struct bttv
*btv
, struct btcx_riscmem
*risc
,
236 const struct bttv_format
*fmt
, struct bttv_overlay
*ov
,
237 int skip_even
, int skip_odd
)
239 int dwords
, rc
, line
, maxy
, start
, end
;
240 unsigned skip
, nskips
;
241 struct btcx_skiplist
*skips
;
246 /* skip list for window clipping */
247 skips
= kmalloc_array(ov
->nclips
, sizeof(*skips
),GFP_KERNEL
);
251 /* estimate risc mem: worst case is (1.5*clip+1) * lines instructions
252 + sync + jump (all 2 dwords) */
253 dwords
= (3 * ov
->nclips
+ 2) *
254 ((skip_even
|| skip_odd
) ? (ov
->w
.height
+1)>>1 : ov
->w
.height
);
256 if ((rc
= btcx_riscmem_alloc(btv
->c
.pci
,risc
,dwords
*4)) < 0) {
261 /* sync instruction */
263 *(rp
++) = cpu_to_le32(BT848_RISC_SYNC
|BT848_FIFO_STATUS_FM1
);
264 *(rp
++) = cpu_to_le32(0);
266 addr
= (unsigned long)btv
->fbuf
.base
;
267 addr
+= btv
->fbuf
.fmt
.bytesperline
* ov
->w
.top
;
268 addr
+= (fmt
->depth
>> 3) * ov
->w
.left
;
271 for (maxy
= -1, line
= 0; line
< ov
->w
.height
;
272 line
++, addr
+= btv
->fbuf
.fmt
.bytesperline
) {
273 if ((btv
->opt_vcr_hack
) &&
274 (line
>= (ov
->w
.height
- VCR_HACK_LINES
)))
276 if ((line
%2) == 0 && skip_even
)
278 if ((line
%2) == 1 && skip_odd
)
281 /* calculate clipping */
283 btcx_calc_skips(line
, ov
->w
.width
, &maxy
,
284 skips
, &nskips
, ov
->clips
, ov
->nclips
);
286 /* write out risc code */
287 for (start
= 0, skip
= 0; start
< ov
->w
.width
; start
= end
) {
288 if (skip
>= nskips
) {
289 ri
= BT848_RISC_WRITE
;
291 } else if (start
< skips
[skip
].start
) {
292 ri
= BT848_RISC_WRITE
;
293 end
= skips
[skip
].start
;
295 ri
= BT848_RISC_SKIP
;
296 end
= skips
[skip
].end
;
299 if (BT848_RISC_WRITE
== ri
)
300 ra
= addr
+ (fmt
->depth
>>3)*start
;
305 ri
|= BT848_RISC_SOL
;
306 if (ov
->w
.width
== end
)
307 ri
|= BT848_RISC_EOL
;
308 ri
|= (fmt
->depth
>>3) * (end
-start
);
310 *(rp
++)=cpu_to_le32(ri
);
312 *(rp
++)=cpu_to_le32(ra
);
316 /* save pointer to jmp instruction address */
318 BUG_ON((risc
->jmp
- risc
->cpu
+ 2) * sizeof(*risc
->cpu
) > risc
->size
);
323 /* ---------------------------------------------------------- */
326 bttv_calc_geo_old(struct bttv
*btv
, struct bttv_geometry
*geo
,
327 int width
, int height
, int interleaved
,
328 const struct bttv_tvnorm
*tvnorm
)
333 int swidth
= tvnorm
->swidth
;
334 int totalwidth
= tvnorm
->totalwidth
;
335 int scaledtwidth
= tvnorm
->scaledtwidth
;
337 if (btv
->input
== btv
->dig
) {
343 vdelay
= tvnorm
->vdelay
;
345 xsf
= (width
*scaledtwidth
)/swidth
;
346 geo
->hscale
= ((totalwidth
*4096UL)/xsf
-4096);
347 geo
->hdelay
= tvnorm
->hdelayx1
;
348 geo
->hdelay
= (geo
->hdelay
*width
)/swidth
;
349 geo
->hdelay
&= 0x3fe;
350 sr
= ((tvnorm
->sheight
>> (interleaved
?0:1))*512)/height
- 512;
351 geo
->vscale
= (0x10000UL
-sr
) & 0x1fff;
352 geo
->crop
= ((width
>>8)&0x03) | ((geo
->hdelay
>>6)&0x0c) |
353 ((tvnorm
->sheight
>>4)&0x30) | ((vdelay
>>2)&0xc0);
354 geo
->vscale
|= interleaved
? (BT848_VSCALE_INT
<<8) : 0;
355 geo
->vdelay
= vdelay
;
357 geo
->sheight
= tvnorm
->sheight
;
358 geo
->vtotal
= tvnorm
->vtotal
;
360 if (btv
->opt_combfilter
) {
361 geo
->vtc
= (width
< 193) ? 2 : ((width
< 385) ? 1 : 0);
362 geo
->comb
= (width
< 769) ? 1 : 0;
370 bttv_calc_geo (struct bttv
* btv
,
371 struct bttv_geometry
* geo
,
375 const struct bttv_tvnorm
* tvnorm
,
376 const struct v4l2_rect
* crop
)
378 unsigned int c_width
;
379 unsigned int c_height
;
382 if ((crop
->left
== tvnorm
->cropcap
.defrect
.left
383 && crop
->top
== tvnorm
->cropcap
.defrect
.top
384 && crop
->width
== tvnorm
->cropcap
.defrect
.width
385 && crop
->height
== tvnorm
->cropcap
.defrect
.height
386 && width
<= tvnorm
->swidth
/* see PAL-Nc et al */)
387 || btv
->input
== btv
->dig
) {
388 bttv_calc_geo_old(btv
, geo
, width
, height
,
389 both_fields
, tvnorm
);
393 /* For bug compatibility the image size checks permit scale
394 factors > 16. See bttv_crop_calc_limits(). */
395 c_width
= min((unsigned int) crop
->width
, width
* 16);
396 c_height
= min((unsigned int) crop
->height
, height
* 16);
399 geo
->hscale
= (c_width
* 4096U + (width
>> 1)) / width
- 4096;
400 /* Even to store Cb first, odd for Cr. */
401 geo
->hdelay
= ((crop
->left
* width
+ c_width
) / c_width
) & ~1;
403 geo
->sheight
= c_height
;
404 geo
->vdelay
= crop
->top
- tvnorm
->cropcap
.bounds
.top
+ MIN_VDELAY
;
405 sr
= c_height
>> !both_fields
;
406 sr
= (sr
* 512U + (height
>> 1)) / height
- 512;
407 geo
->vscale
= (0x10000UL
- sr
) & 0x1fff;
408 geo
->vscale
|= both_fields
? (BT848_VSCALE_INT
<< 8) : 0;
409 geo
->vtotal
= tvnorm
->vtotal
;
411 geo
->crop
= (((geo
->width
>> 8) & 0x03) |
412 ((geo
->hdelay
>> 6) & 0x0c) |
413 ((geo
->sheight
>> 4) & 0x30) |
414 ((geo
->vdelay
>> 2) & 0xc0));
416 if (btv
->opt_combfilter
) {
417 geo
->vtc
= (width
< 193) ? 2 : ((width
< 385) ? 1 : 0);
418 geo
->comb
= (width
< 769) ? 1 : 0;
426 bttv_apply_geo(struct bttv
*btv
, struct bttv_geometry
*geo
, int odd
)
428 int off
= odd
? 0x80 : 0x00;
431 btor(BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
433 btand(~BT848_VSCALE_COMB
, BT848_E_VSCALE_HI
+off
);
435 btwrite(geo
->vtc
, BT848_E_VTC
+off
);
436 btwrite(geo
->hscale
>> 8, BT848_E_HSCALE_HI
+off
);
437 btwrite(geo
->hscale
& 0xff, BT848_E_HSCALE_LO
+off
);
438 btaor((geo
->vscale
>>8), 0xe0, BT848_E_VSCALE_HI
+off
);
439 btwrite(geo
->vscale
& 0xff, BT848_E_VSCALE_LO
+off
);
440 btwrite(geo
->width
& 0xff, BT848_E_HACTIVE_LO
+off
);
441 btwrite(geo
->hdelay
& 0xff, BT848_E_HDELAY_LO
+off
);
442 btwrite(geo
->sheight
& 0xff, BT848_E_VACTIVE_LO
+off
);
443 btwrite(geo
->vdelay
& 0xff, BT848_E_VDELAY_LO
+off
);
444 btwrite(geo
->crop
, BT848_E_CROP
+off
);
445 btwrite(geo
->vtotal
>>8, BT848_VTOTAL_HI
);
446 btwrite(geo
->vtotal
& 0xff, BT848_VTOTAL_LO
);
449 /* ---------------------------------------------------------- */
450 /* risc group / risc main loop / dma management */
453 bttv_set_dma(struct bttv
*btv
, int override
)
459 if (NULL
!= btv
->curr
.top
) btv
->cap_ctl
|= 0x02;
460 if (NULL
!= btv
->curr
.bottom
) btv
->cap_ctl
|= 0x01;
461 if (NULL
!= btv
->cvbi
) btv
->cap_ctl
|= 0x0c;
464 capctl
|= (btv
->cap_ctl
& 0x03) ? 0x03 : 0x00; /* capture */
465 capctl
|= (btv
->cap_ctl
& 0x0c) ? 0x0c : 0x00; /* vbi data */
468 d2printk("%d: capctl=%x lirq=%d top=%08llx/%08llx even=%08llx/%08llx\n",
469 btv
->c
.nr
,capctl
,btv
->loop_irq
,
470 btv
->cvbi
? (unsigned long long)btv
->cvbi
->top
.dma
: 0,
471 btv
->curr
.top
? (unsigned long long)btv
->curr
.top
->top
.dma
: 0,
472 btv
->cvbi
? (unsigned long long)btv
->cvbi
->bottom
.dma
: 0,
473 btv
->curr
.bottom
? (unsigned long long)btv
->curr
.bottom
->bottom
.dma
: 0);
475 cmd
= BT848_RISC_JUMP
;
477 cmd
|= BT848_RISC_IRQ
;
478 cmd
|= (btv
->loop_irq
& 0x0f) << 16;
479 cmd
|= (~btv
->loop_irq
& 0x0f) << 20;
481 if (btv
->curr
.frame_irq
|| btv
->loop_irq
|| btv
->cvbi
) {
482 mod_timer(&btv
->timeout
, jiffies
+BTTV_TIMEOUT
);
484 del_timer(&btv
->timeout
);
486 btv
->main
.cpu
[RISC_SLOT_LOOP
] = cpu_to_le32(cmd
);
488 btaor(capctl
, ~0x0f, BT848_CAP_CTL
);
492 btwrite(btv
->main
.dma
, BT848_RISC_STRT_ADD
);
493 btor(3, BT848_GPIO_DMA_CTL
);
498 btand(~3, BT848_GPIO_DMA_CTL
);
505 bttv_risc_init_main(struct bttv
*btv
)
509 if ((rc
= btcx_riscmem_alloc(btv
->c
.pci
,&btv
->main
,PAGE_SIZE
)) < 0)
511 dprintk("%d: risc main @ %08llx\n",
512 btv
->c
.nr
, (unsigned long long)btv
->main
.dma
);
514 btv
->main
.cpu
[0] = cpu_to_le32(BT848_RISC_SYNC
| BT848_RISC_RESYNC
|
515 BT848_FIFO_STATUS_VRE
);
516 btv
->main
.cpu
[1] = cpu_to_le32(0);
517 btv
->main
.cpu
[2] = cpu_to_le32(BT848_RISC_JUMP
);
518 btv
->main
.cpu
[3] = cpu_to_le32(btv
->main
.dma
+ (4<<2));
521 btv
->main
.cpu
[4] = cpu_to_le32(BT848_RISC_JUMP
);
522 btv
->main
.cpu
[5] = cpu_to_le32(btv
->main
.dma
+ (6<<2));
523 btv
->main
.cpu
[6] = cpu_to_le32(BT848_RISC_JUMP
);
524 btv
->main
.cpu
[7] = cpu_to_le32(btv
->main
.dma
+ (8<<2));
526 btv
->main
.cpu
[8] = cpu_to_le32(BT848_RISC_SYNC
| BT848_RISC_RESYNC
|
527 BT848_FIFO_STATUS_VRO
);
528 btv
->main
.cpu
[9] = cpu_to_le32(0);
531 btv
->main
.cpu
[10] = cpu_to_le32(BT848_RISC_JUMP
);
532 btv
->main
.cpu
[11] = cpu_to_le32(btv
->main
.dma
+ (12<<2));
533 btv
->main
.cpu
[12] = cpu_to_le32(BT848_RISC_JUMP
);
534 btv
->main
.cpu
[13] = cpu_to_le32(btv
->main
.dma
+ (14<<2));
536 /* jump back to top field */
537 btv
->main
.cpu
[14] = cpu_to_le32(BT848_RISC_JUMP
);
538 btv
->main
.cpu
[15] = cpu_to_le32(btv
->main
.dma
+ (0<<2));
544 bttv_risc_hook(struct bttv
*btv
, int slot
, struct btcx_riscmem
*risc
,
548 unsigned long next
= btv
->main
.dma
+ ((slot
+2) << 2);
551 d2printk("%d: risc=%p slot[%d]=NULL\n", btv
->c
.nr
, risc
, slot
);
552 btv
->main
.cpu
[slot
+1] = cpu_to_le32(next
);
554 d2printk("%d: risc=%p slot[%d]=%08llx irq=%d\n",
555 btv
->c
.nr
, risc
, slot
,
556 (unsigned long long)risc
->dma
, irqflags
);
557 cmd
= BT848_RISC_JUMP
;
559 cmd
|= BT848_RISC_IRQ
;
560 cmd
|= (irqflags
& 0x0f) << 16;
561 cmd
|= (~irqflags
& 0x0f) << 20;
563 risc
->jmp
[0] = cpu_to_le32(cmd
);
564 risc
->jmp
[1] = cpu_to_le32(next
);
565 btv
->main
.cpu
[slot
+1] = cpu_to_le32(risc
->dma
);
571 bttv_dma_free(struct videobuf_queue
*q
,struct bttv
*btv
, struct bttv_buffer
*buf
)
573 struct videobuf_dmabuf
*dma
=videobuf_to_dma(&buf
->vb
);
575 BUG_ON(in_interrupt());
576 videobuf_waiton(q
, &buf
->vb
, 0, 0);
577 videobuf_dma_unmap(q
->dev
, dma
);
578 videobuf_dma_free(dma
);
579 btcx_riscmem_free(btv
->c
.pci
,&buf
->bottom
);
580 btcx_riscmem_free(btv
->c
.pci
,&buf
->top
);
581 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
585 bttv_buffer_activate_vbi(struct bttv
*btv
,
586 struct bttv_buffer
*vbi
)
588 struct btcx_riscmem
*top
;
589 struct btcx_riscmem
*bottom
;
591 int bottom_irq_flags
;
596 bottom_irq_flags
= 0;
599 unsigned int crop
, vdelay
;
601 vbi
->vb
.state
= VIDEOBUF_ACTIVE
;
602 list_del(&vbi
->vb
.queue
);
604 /* VDELAY is start of video, end of VBI capturing. */
605 crop
= btread(BT848_E_CROP
);
606 vdelay
= btread(BT848_E_VDELAY_LO
) + ((crop
& 0xc0) << 2);
608 if (vbi
->geo
.vdelay
> vdelay
) {
609 vdelay
= vbi
->geo
.vdelay
& 0xfe;
610 crop
= (crop
& 0x3f) | ((vbi
->geo
.vdelay
>> 2) & 0xc0);
612 btwrite(vdelay
, BT848_E_VDELAY_LO
);
613 btwrite(crop
, BT848_E_CROP
);
614 btwrite(vdelay
, BT848_O_VDELAY_LO
);
615 btwrite(crop
, BT848_O_CROP
);
618 if (vbi
->vbi_count
[0] > 0) {
623 if (vbi
->vbi_count
[1] > 0) {
625 bottom
= &vbi
->bottom
;
626 bottom_irq_flags
= 4;
630 bttv_risc_hook(btv
, RISC_SLOT_O_VBI
, top
, top_irq_flags
);
631 bttv_risc_hook(btv
, RISC_SLOT_E_VBI
, bottom
, bottom_irq_flags
);
637 bttv_buffer_activate_video(struct bttv
*btv
,
638 struct bttv_buffer_set
*set
)
641 if (NULL
!= set
->top
&& NULL
!= set
->bottom
) {
642 if (set
->top
== set
->bottom
) {
643 set
->top
->vb
.state
= VIDEOBUF_ACTIVE
;
644 if (set
->top
->vb
.queue
.next
)
645 list_del(&set
->top
->vb
.queue
);
647 set
->top
->vb
.state
= VIDEOBUF_ACTIVE
;
648 set
->bottom
->vb
.state
= VIDEOBUF_ACTIVE
;
649 if (set
->top
->vb
.queue
.next
)
650 list_del(&set
->top
->vb
.queue
);
651 if (set
->bottom
->vb
.queue
.next
)
652 list_del(&set
->bottom
->vb
.queue
);
654 bttv_apply_geo(btv
, &set
->top
->geo
, 1);
655 bttv_apply_geo(btv
, &set
->bottom
->geo
,0);
656 bttv_risc_hook(btv
, RISC_SLOT_O_FIELD
, &set
->top
->top
,
658 bttv_risc_hook(btv
, RISC_SLOT_E_FIELD
, &set
->bottom
->bottom
,
660 btaor((set
->top
->btformat
& 0xf0) | (set
->bottom
->btformat
& 0x0f),
661 ~0xff, BT848_COLOR_FMT
);
662 btaor((set
->top
->btswap
& 0x0a) | (set
->bottom
->btswap
& 0x05),
663 ~0x0f, BT848_COLOR_CTL
);
664 } else if (NULL
!= set
->top
) {
665 set
->top
->vb
.state
= VIDEOBUF_ACTIVE
;
666 if (set
->top
->vb
.queue
.next
)
667 list_del(&set
->top
->vb
.queue
);
668 bttv_apply_geo(btv
, &set
->top
->geo
,1);
669 bttv_apply_geo(btv
, &set
->top
->geo
,0);
670 bttv_risc_hook(btv
, RISC_SLOT_O_FIELD
, &set
->top
->top
,
672 bttv_risc_hook(btv
, RISC_SLOT_E_FIELD
, NULL
, 0);
673 btaor(set
->top
->btformat
& 0xff, ~0xff, BT848_COLOR_FMT
);
674 btaor(set
->top
->btswap
& 0x0f, ~0x0f, BT848_COLOR_CTL
);
675 } else if (NULL
!= set
->bottom
) {
676 set
->bottom
->vb
.state
= VIDEOBUF_ACTIVE
;
677 if (set
->bottom
->vb
.queue
.next
)
678 list_del(&set
->bottom
->vb
.queue
);
679 bttv_apply_geo(btv
, &set
->bottom
->geo
,1);
680 bttv_apply_geo(btv
, &set
->bottom
->geo
,0);
681 bttv_risc_hook(btv
, RISC_SLOT_O_FIELD
, NULL
, 0);
682 bttv_risc_hook(btv
, RISC_SLOT_E_FIELD
, &set
->bottom
->bottom
,
684 btaor(set
->bottom
->btformat
& 0xff, ~0xff, BT848_COLOR_FMT
);
685 btaor(set
->bottom
->btswap
& 0x0f, ~0x0f, BT848_COLOR_CTL
);
687 bttv_risc_hook(btv
, RISC_SLOT_O_FIELD
, NULL
, 0);
688 bttv_risc_hook(btv
, RISC_SLOT_E_FIELD
, NULL
, 0);
693 /* ---------------------------------------------------------- */
695 /* calculate geometry, build risc code */
697 bttv_buffer_risc(struct bttv
*btv
, struct bttv_buffer
*buf
)
699 const struct bttv_tvnorm
*tvnorm
= bttv_tvnorms
+ buf
->tvnorm
;
700 struct videobuf_dmabuf
*dma
=videobuf_to_dma(&buf
->vb
);
702 dprintk("%d: buffer field: %s format: 0x%08x size: %dx%d\n",
703 btv
->c
.nr
, v4l2_field_names
[buf
->vb
.field
],
704 buf
->fmt
->fourcc
, buf
->vb
.width
, buf
->vb
.height
);
706 /* packed pixel modes */
707 if (buf
->fmt
->flags
& FORMAT_FLAGS_PACKED
) {
708 int bpl
= (buf
->fmt
->depth
>> 3) * buf
->vb
.width
;
709 int bpf
= bpl
* (buf
->vb
.height
>> 1);
711 bttv_calc_geo(btv
,&buf
->geo
,buf
->vb
.width
,buf
->vb
.height
,
712 V4L2_FIELD_HAS_BOTH(buf
->vb
.field
),
715 switch (buf
->vb
.field
) {
717 bttv_risc_packed(btv
,&buf
->top
,dma
->sglist
,
719 /* padding */ 0,/* skip_lines */ 0,
722 case V4L2_FIELD_BOTTOM
:
723 bttv_risc_packed(btv
,&buf
->bottom
,dma
->sglist
,
724 0,bpl
,0,0,buf
->vb
.height
);
726 case V4L2_FIELD_INTERLACED
:
727 bttv_risc_packed(btv
,&buf
->top
,dma
->sglist
,
728 0,bpl
,bpl
,0,buf
->vb
.height
>> 1);
729 bttv_risc_packed(btv
,&buf
->bottom
,dma
->sglist
,
730 bpl
,bpl
,bpl
,0,buf
->vb
.height
>> 1);
732 case V4L2_FIELD_SEQ_TB
:
733 bttv_risc_packed(btv
,&buf
->top
,dma
->sglist
,
734 0,bpl
,0,0,buf
->vb
.height
>> 1);
735 bttv_risc_packed(btv
,&buf
->bottom
,dma
->sglist
,
736 bpf
,bpl
,0,0,buf
->vb
.height
>> 1);
744 if (buf
->fmt
->flags
& FORMAT_FLAGS_PLANAR
) {
745 int uoffset
, voffset
;
746 int ypadding
, cpadding
, lines
;
748 /* calculate chroma offsets */
749 uoffset
= buf
->vb
.width
* buf
->vb
.height
;
750 voffset
= buf
->vb
.width
* buf
->vb
.height
;
751 if (buf
->fmt
->flags
& FORMAT_FLAGS_CrCb
) {
752 /* Y-Cr-Cb plane order */
753 uoffset
>>= buf
->fmt
->hshift
;
754 uoffset
>>= buf
->fmt
->vshift
;
757 /* Y-Cb-Cr plane order */
758 voffset
>>= buf
->fmt
->hshift
;
759 voffset
>>= buf
->fmt
->vshift
;
763 switch (buf
->vb
.field
) {
765 bttv_calc_geo(btv
,&buf
->geo
,buf
->vb
.width
,
766 buf
->vb
.height
,/* both_fields */ 0,
768 bttv_risc_planar(btv
, &buf
->top
, dma
->sglist
,
769 0,buf
->vb
.width
,0,buf
->vb
.height
,
770 uoffset
,voffset
,buf
->fmt
->hshift
,
773 case V4L2_FIELD_BOTTOM
:
774 bttv_calc_geo(btv
,&buf
->geo
,buf
->vb
.width
,
777 bttv_risc_planar(btv
, &buf
->bottom
, dma
->sglist
,
778 0,buf
->vb
.width
,0,buf
->vb
.height
,
779 uoffset
,voffset
,buf
->fmt
->hshift
,
782 case V4L2_FIELD_INTERLACED
:
783 bttv_calc_geo(btv
,&buf
->geo
,buf
->vb
.width
,
786 lines
= buf
->vb
.height
>> 1;
787 ypadding
= buf
->vb
.width
;
788 cpadding
= buf
->vb
.width
>> buf
->fmt
->hshift
;
789 bttv_risc_planar(btv
,&buf
->top
,
791 0,buf
->vb
.width
,ypadding
,lines
,
796 bttv_risc_planar(btv
,&buf
->bottom
,
798 ypadding
,buf
->vb
.width
,ypadding
,lines
,
805 case V4L2_FIELD_SEQ_TB
:
806 bttv_calc_geo(btv
,&buf
->geo
,buf
->vb
.width
,
809 lines
= buf
->vb
.height
>> 1;
810 ypadding
= buf
->vb
.width
;
811 cpadding
= buf
->vb
.width
>> buf
->fmt
->hshift
;
812 bttv_risc_planar(btv
,&buf
->top
,
814 0,buf
->vb
.width
,0,lines
,
820 bttv_risc_planar(btv
,&buf
->bottom
,
822 lines
* ypadding
,buf
->vb
.width
,0,lines
,
823 lines
* ypadding
+ (uoffset
>> 1),
824 lines
* ypadding
+ (voffset
>> 1),
835 if (buf
->fmt
->flags
& FORMAT_FLAGS_RAW
) {
836 /* build risc code */
837 buf
->vb
.field
= V4L2_FIELD_SEQ_TB
;
838 bttv_calc_geo(btv
,&buf
->geo
,tvnorm
->swidth
,tvnorm
->sheight
,
839 1,tvnorm
,&buf
->crop
);
840 bttv_risc_packed(btv
, &buf
->top
, dma
->sglist
,
841 /* offset */ 0, RAW_BPL
, /* padding */ 0,
842 /* skip_lines */ 0, RAW_LINES
);
843 bttv_risc_packed(btv
, &buf
->bottom
, dma
->sglist
,
844 buf
->vb
.size
/2 , RAW_BPL
, 0, 0, RAW_LINES
);
847 /* copy format info */
848 buf
->btformat
= buf
->fmt
->btformat
;
849 buf
->btswap
= buf
->fmt
->btswap
;
853 /* ---------------------------------------------------------- */
855 /* calculate geometry, build risc code */
857 bttv_overlay_risc(struct bttv
*btv
,
858 struct bttv_overlay
*ov
,
859 const struct bttv_format
*fmt
,
860 struct bttv_buffer
*buf
)
862 /* check interleave, bottom+top fields */
863 dprintk("%d: overlay fields: %s format: 0x%08x size: %dx%d\n",
864 btv
->c
.nr
, v4l2_field_names
[buf
->vb
.field
],
865 fmt
->fourcc
, ov
->w
.width
, ov
->w
.height
);
867 /* calculate geometry */
868 bttv_calc_geo(btv
,&buf
->geo
,ov
->w
.width
,ov
->w
.height
,
869 V4L2_FIELD_HAS_BOTH(ov
->field
),
870 &bttv_tvnorms
[ov
->tvnorm
],&buf
->crop
);
872 /* build risc code */
875 bttv_risc_overlay(btv
, &buf
->top
, fmt
, ov
, 0, 0);
877 case V4L2_FIELD_BOTTOM
:
878 bttv_risc_overlay(btv
, &buf
->bottom
, fmt
, ov
, 0, 0);
880 case V4L2_FIELD_INTERLACED
:
881 bttv_risc_overlay(btv
, &buf
->top
, fmt
, ov
, 0, 1);
882 bttv_risc_overlay(btv
, &buf
->bottom
, fmt
, ov
, 1, 0);
888 /* copy format info */
889 buf
->btformat
= fmt
->btformat
;
890 buf
->btswap
= fmt
->btswap
;
891 buf
->vb
.field
= ov
->field
;