3 * device driver for Conexant 2388x based TV cards
4 * video4linux video interface
6 * (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
8 * (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
10 * - video_ioctl2 conversion
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <linux/init.h>
29 #include <linux/list.h>
30 #include <linux/module.h>
31 #include <linux/kmod.h>
32 #include <linux/kernel.h>
33 #include <linux/slab.h>
34 #include <linux/interrupt.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
37 #include <linux/kthread.h>
38 #include <asm/div64.h>
41 #include <media/v4l2-common.h>
42 #include <media/v4l2-ioctl.h>
44 #ifdef CONFIG_VIDEO_V4L1_COMPAT
45 /* Include V4L1 specific functions. Should be removed soon */
46 #include <linux/videodev.h>
49 MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
50 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
51 MODULE_LICENSE("GPL");
53 /* ------------------------------------------------------------------ */
55 static unsigned int video_nr
[] = {[0 ... (CX88_MAXBOARDS
- 1)] = UNSET
};
56 static unsigned int vbi_nr
[] = {[0 ... (CX88_MAXBOARDS
- 1)] = UNSET
};
57 static unsigned int radio_nr
[] = {[0 ... (CX88_MAXBOARDS
- 1)] = UNSET
};
59 module_param_array(video_nr
, int, NULL
, 0444);
60 module_param_array(vbi_nr
, int, NULL
, 0444);
61 module_param_array(radio_nr
, int, NULL
, 0444);
63 MODULE_PARM_DESC(video_nr
,"video device numbers");
64 MODULE_PARM_DESC(vbi_nr
,"vbi device numbers");
65 MODULE_PARM_DESC(radio_nr
,"radio device numbers");
67 static unsigned int video_debug
;
68 module_param(video_debug
,int,0644);
69 MODULE_PARM_DESC(video_debug
,"enable debug messages [video]");
71 static unsigned int irq_debug
;
72 module_param(irq_debug
,int,0644);
73 MODULE_PARM_DESC(irq_debug
,"enable debug messages [IRQ handler]");
75 static unsigned int vid_limit
= 16;
76 module_param(vid_limit
,int,0644);
77 MODULE_PARM_DESC(vid_limit
,"capture memory limit in megabytes");
79 #define dprintk(level,fmt, arg...) if (video_debug >= level) \
80 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
82 /* ------------------------------------------------------------------ */
84 static LIST_HEAD(cx8800_devlist
);
86 /* ------------------------------------------------------------------- */
89 static struct cx8800_fmt formats
[] = {
91 .name
= "8 bpp, gray",
92 .fourcc
= V4L2_PIX_FMT_GREY
,
93 .cxformat
= ColorFormatY8
,
95 .flags
= FORMAT_FLAGS_PACKED
,
97 .name
= "15 bpp RGB, le",
98 .fourcc
= V4L2_PIX_FMT_RGB555
,
99 .cxformat
= ColorFormatRGB15
,
101 .flags
= FORMAT_FLAGS_PACKED
,
103 .name
= "15 bpp RGB, be",
104 .fourcc
= V4L2_PIX_FMT_RGB555X
,
105 .cxformat
= ColorFormatRGB15
| ColorFormatBSWAP
,
107 .flags
= FORMAT_FLAGS_PACKED
,
109 .name
= "16 bpp RGB, le",
110 .fourcc
= V4L2_PIX_FMT_RGB565
,
111 .cxformat
= ColorFormatRGB16
,
113 .flags
= FORMAT_FLAGS_PACKED
,
115 .name
= "16 bpp RGB, be",
116 .fourcc
= V4L2_PIX_FMT_RGB565X
,
117 .cxformat
= ColorFormatRGB16
| ColorFormatBSWAP
,
119 .flags
= FORMAT_FLAGS_PACKED
,
121 .name
= "24 bpp RGB, le",
122 .fourcc
= V4L2_PIX_FMT_BGR24
,
123 .cxformat
= ColorFormatRGB24
,
125 .flags
= FORMAT_FLAGS_PACKED
,
127 .name
= "32 bpp RGB, le",
128 .fourcc
= V4L2_PIX_FMT_BGR32
,
129 .cxformat
= ColorFormatRGB32
,
131 .flags
= FORMAT_FLAGS_PACKED
,
133 .name
= "32 bpp RGB, be",
134 .fourcc
= V4L2_PIX_FMT_RGB32
,
135 .cxformat
= ColorFormatRGB32
| ColorFormatBSWAP
| ColorFormatWSWAP
,
137 .flags
= FORMAT_FLAGS_PACKED
,
139 .name
= "4:2:2, packed, YUYV",
140 .fourcc
= V4L2_PIX_FMT_YUYV
,
141 .cxformat
= ColorFormatYUY2
,
143 .flags
= FORMAT_FLAGS_PACKED
,
145 .name
= "4:2:2, packed, UYVY",
146 .fourcc
= V4L2_PIX_FMT_UYVY
,
147 .cxformat
= ColorFormatYUY2
| ColorFormatBSWAP
,
149 .flags
= FORMAT_FLAGS_PACKED
,
153 static struct cx8800_fmt
* format_by_fourcc(unsigned int fourcc
)
157 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++)
158 if (formats
[i
].fourcc
== fourcc
)
163 /* ------------------------------------------------------------------- */
165 static const struct v4l2_queryctrl no_ctl
= {
167 .flags
= V4L2_CTRL_FLAG_DISABLED
,
170 static struct cx88_ctrl cx8800_ctls
[] = {
174 .id
= V4L2_CID_BRIGHTNESS
,
175 .name
= "Brightness",
179 .default_value
= 0x7f,
180 .type
= V4L2_CTRL_TYPE_INTEGER
,
183 .reg
= MO_CONTR_BRIGHT
,
188 .id
= V4L2_CID_CONTRAST
,
193 .default_value
= 0x3f,
194 .type
= V4L2_CTRL_TYPE_INTEGER
,
197 .reg
= MO_CONTR_BRIGHT
,
207 .default_value
= 0x7f,
208 .type
= V4L2_CTRL_TYPE_INTEGER
,
215 /* strictly, this only describes only U saturation.
216 * V saturation is handled specially through code.
219 .id
= V4L2_CID_SATURATION
,
220 .name
= "Saturation",
224 .default_value
= 0x7f,
225 .type
= V4L2_CTRL_TYPE_INTEGER
,
228 .reg
= MO_UV_SATURATION
,
233 .id
= V4L2_CID_CHROMA_AGC
,
234 .name
= "Chroma AGC",
237 .default_value
= 0x1,
238 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
240 .reg
= MO_INPUT_FORMAT
,
245 .id
= V4L2_CID_COLOR_KILLER
,
246 .name
= "Color killer",
249 .default_value
= 0x1,
250 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
252 .reg
= MO_INPUT_FORMAT
,
258 .id
= V4L2_CID_AUDIO_MUTE
,
263 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
266 .sreg
= SHADOW_AUD_VOL_CTL
,
271 .id
= V4L2_CID_AUDIO_VOLUME
,
276 .default_value
= 0x3f,
277 .type
= V4L2_CTRL_TYPE_INTEGER
,
280 .sreg
= SHADOW_AUD_VOL_CTL
,
285 .id
= V4L2_CID_AUDIO_BALANCE
,
290 .default_value
= 0x40,
291 .type
= V4L2_CTRL_TYPE_INTEGER
,
294 .sreg
= SHADOW_AUD_BAL_CTL
,
299 static const int CX8800_CTLS
= ARRAY_SIZE(cx8800_ctls
);
301 /* Must be sorted from low to high control ID! */
302 const u32 cx88_user_ctrls
[] = {
308 V4L2_CID_AUDIO_VOLUME
,
309 V4L2_CID_AUDIO_BALANCE
,
312 V4L2_CID_COLOR_KILLER
,
315 EXPORT_SYMBOL(cx88_user_ctrls
);
317 static const u32
*ctrl_classes
[] = {
322 int cx8800_ctrl_query(struct cx88_core
*core
, struct v4l2_queryctrl
*qctrl
)
326 if (qctrl
->id
< V4L2_CID_BASE
||
327 qctrl
->id
>= V4L2_CID_LASTP1
)
329 for (i
= 0; i
< CX8800_CTLS
; i
++)
330 if (cx8800_ctls
[i
].v
.id
== qctrl
->id
)
332 if (i
== CX8800_CTLS
) {
336 *qctrl
= cx8800_ctls
[i
].v
;
337 /* Report chroma AGC as inactive when SECAM is selected */
338 if (cx8800_ctls
[i
].v
.id
== V4L2_CID_CHROMA_AGC
&&
339 core
->tvnorm
& V4L2_STD_SECAM
)
340 qctrl
->flags
|= V4L2_CTRL_FLAG_INACTIVE
;
344 EXPORT_SYMBOL(cx8800_ctrl_query
);
346 /* ------------------------------------------------------------------- */
347 /* resource management */
349 static int res_get(struct cx8800_dev
*dev
, struct cx8800_fh
*fh
, unsigned int bit
)
351 struct cx88_core
*core
= dev
->core
;
352 if (fh
->resources
& bit
)
353 /* have it already allocated */
357 mutex_lock(&core
->lock
);
358 if (dev
->resources
& bit
) {
359 /* no, someone else uses it */
360 mutex_unlock(&core
->lock
);
363 /* it's free, grab it */
364 fh
->resources
|= bit
;
365 dev
->resources
|= bit
;
366 dprintk(1,"res: get %d\n",bit
);
367 mutex_unlock(&core
->lock
);
372 int res_check(struct cx8800_fh
*fh
, unsigned int bit
)
374 return (fh
->resources
& bit
);
378 int res_locked(struct cx8800_dev
*dev
, unsigned int bit
)
380 return (dev
->resources
& bit
);
384 void res_free(struct cx8800_dev
*dev
, struct cx8800_fh
*fh
, unsigned int bits
)
386 struct cx88_core
*core
= dev
->core
;
387 BUG_ON((fh
->resources
& bits
) != bits
);
389 mutex_lock(&core
->lock
);
390 fh
->resources
&= ~bits
;
391 dev
->resources
&= ~bits
;
392 dprintk(1,"res: put %d\n",bits
);
393 mutex_unlock(&core
->lock
);
396 /* ------------------------------------------------------------------ */
398 int cx88_video_mux(struct cx88_core
*core
, unsigned int input
)
400 /* struct cx88_core *core = dev->core; */
402 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
403 input
, INPUT(input
).vmux
,
404 INPUT(input
).gpio0
,INPUT(input
).gpio1
,
405 INPUT(input
).gpio2
,INPUT(input
).gpio3
);
407 cx_andor(MO_INPUT_FORMAT
, 0x03 << 14, INPUT(input
).vmux
<< 14);
408 cx_write(MO_GP3_IO
, INPUT(input
).gpio3
);
409 cx_write(MO_GP0_IO
, INPUT(input
).gpio0
);
410 cx_write(MO_GP1_IO
, INPUT(input
).gpio1
);
411 cx_write(MO_GP2_IO
, INPUT(input
).gpio2
);
413 switch (INPUT(input
).type
) {
414 case CX88_VMUX_SVIDEO
:
415 cx_set(MO_AFECFG_IO
, 0x00000001);
416 cx_set(MO_INPUT_FORMAT
, 0x00010010);
417 cx_set(MO_FILTER_EVEN
, 0x00002020);
418 cx_set(MO_FILTER_ODD
, 0x00002020);
421 cx_clear(MO_AFECFG_IO
, 0x00000001);
422 cx_clear(MO_INPUT_FORMAT
, 0x00010010);
423 cx_clear(MO_FILTER_EVEN
, 0x00002020);
424 cx_clear(MO_FILTER_ODD
, 0x00002020);
428 /* if there are audioroutes defined, we have an external
429 ADC to deal with audio */
430 if (INPUT(input
).audioroute
) {
431 /* The wm8775 module has the "2" route hardwired into
432 the initialization. Some boards may use different
433 routes for different inputs. HVR-1300 surely does */
434 if (core
->board
.audio_chip
&&
435 core
->board
.audio_chip
== V4L2_IDENT_WM8775
) {
436 struct v4l2_routing route
;
438 route
.input
= INPUT(input
).audioroute
;
439 cx88_call_i2c_clients(core
,
440 VIDIOC_INT_S_AUDIO_ROUTING
, &route
);
442 /* cx2388's C-ADC is connected to the tuner only.
443 When used with S-Video, that ADC is busy dealing with
444 chroma, so an external must be used for baseband audio */
445 if (INPUT(input
).type
!= CX88_VMUX_TELEVISION
) {
447 core
->tvaudio
= WW_I2SADC
;
448 cx88_set_tvaudio(core
);
451 cx_write(AUD_I2SCNTL
, 0x0);
452 cx_clear(AUD_CTL
, EN_I2SIN_ENABLE
);
458 EXPORT_SYMBOL(cx88_video_mux
);
460 /* ------------------------------------------------------------------ */
462 static int start_video_dma(struct cx8800_dev
*dev
,
463 struct cx88_dmaqueue
*q
,
464 struct cx88_buffer
*buf
)
466 struct cx88_core
*core
= dev
->core
;
468 /* setup fifo + format */
469 cx88_sram_channel_setup(core
, &cx88_sram_channels
[SRAM_CH21
],
470 buf
->bpl
, buf
->risc
.dma
);
471 cx88_set_scale(core
, buf
->vb
.width
, buf
->vb
.height
, buf
->vb
.field
);
472 cx_write(MO_COLOR_CTRL
, buf
->fmt
->cxformat
| ColorFormatGamma
);
475 cx_write(MO_VIDY_GPCNTRL
,GP_COUNT_CONTROL_RESET
);
479 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
| PCI_INT_VIDINT
);
481 /* Enables corresponding bits at PCI_INT_STAT:
482 bits 0 to 4: video, audio, transport stream, VIP, Host
484 bits 8 and 9: DMA complete for: SRC, DST
485 bits 10 and 11: BERR signal asserted for RISC: RD, WR
486 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
488 cx_set(MO_VID_INTMSK
, 0x0f0011);
491 cx_set(VID_CAPTURE_CONTROL
,0x06);
494 cx_set(MO_DEV_CNTRL2
, (1<<5));
495 cx_set(MO_VID_DMACNTRL
, 0x11); /* Planar Y and packed FIFO and RISC enable */
501 static int stop_video_dma(struct cx8800_dev
*dev
)
503 struct cx88_core
*core
= dev
->core
;
506 cx_clear(MO_VID_DMACNTRL
, 0x11);
508 /* disable capture */
509 cx_clear(VID_CAPTURE_CONTROL
,0x06);
512 cx_clear(MO_PCI_INTMSK
, PCI_INT_VIDINT
);
513 cx_clear(MO_VID_INTMSK
, 0x0f0011);
518 static int restart_video_queue(struct cx8800_dev
*dev
,
519 struct cx88_dmaqueue
*q
)
521 struct cx88_core
*core
= dev
->core
;
522 struct cx88_buffer
*buf
, *prev
;
524 if (!list_empty(&q
->active
)) {
525 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, vb
.queue
);
526 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
528 start_video_dma(dev
, q
, buf
);
529 list_for_each_entry(buf
, &q
->active
, vb
.queue
)
530 buf
->count
= q
->count
++;
531 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
537 if (list_empty(&q
->queued
))
539 buf
= list_entry(q
->queued
.next
, struct cx88_buffer
, vb
.queue
);
541 list_move_tail(&buf
->vb
.queue
, &q
->active
);
542 start_video_dma(dev
, q
, buf
);
543 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
544 buf
->count
= q
->count
++;
545 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
546 dprintk(2,"[%p/%d] restart_queue - first active\n",
549 } else if (prev
->vb
.width
== buf
->vb
.width
&&
550 prev
->vb
.height
== buf
->vb
.height
&&
551 prev
->fmt
== buf
->fmt
) {
552 list_move_tail(&buf
->vb
.queue
, &q
->active
);
553 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
554 buf
->count
= q
->count
++;
555 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
556 dprintk(2,"[%p/%d] restart_queue - move to active\n",
565 /* ------------------------------------------------------------------ */
568 buffer_setup(struct videobuf_queue
*q
, unsigned int *count
, unsigned int *size
)
570 struct cx8800_fh
*fh
= q
->priv_data
;
572 *size
= fh
->fmt
->depth
*fh
->width
*fh
->height
>> 3;
575 while (*size
* *count
> vid_limit
* 1024 * 1024)
581 buffer_prepare(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
,
582 enum v4l2_field field
)
584 struct cx8800_fh
*fh
= q
->priv_data
;
585 struct cx8800_dev
*dev
= fh
->dev
;
586 struct cx88_core
*core
= dev
->core
;
587 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
588 struct videobuf_dmabuf
*dma
=videobuf_to_dma(&buf
->vb
);
589 int rc
, init_buffer
= 0;
591 BUG_ON(NULL
== fh
->fmt
);
592 if (fh
->width
< 48 || fh
->width
> norm_maxw(core
->tvnorm
) ||
593 fh
->height
< 32 || fh
->height
> norm_maxh(core
->tvnorm
))
595 buf
->vb
.size
= (fh
->width
* fh
->height
* fh
->fmt
->depth
) >> 3;
596 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
599 if (buf
->fmt
!= fh
->fmt
||
600 buf
->vb
.width
!= fh
->width
||
601 buf
->vb
.height
!= fh
->height
||
602 buf
->vb
.field
!= field
) {
604 buf
->vb
.width
= fh
->width
;
605 buf
->vb
.height
= fh
->height
;
606 buf
->vb
.field
= field
;
610 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
612 if (0 != (rc
= videobuf_iolock(q
,&buf
->vb
,NULL
)))
617 buf
->bpl
= buf
->vb
.width
* buf
->fmt
->depth
>> 3;
618 switch (buf
->vb
.field
) {
620 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
621 dma
->sglist
, 0, UNSET
,
622 buf
->bpl
, 0, buf
->vb
.height
);
624 case V4L2_FIELD_BOTTOM
:
625 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
626 dma
->sglist
, UNSET
, 0,
627 buf
->bpl
, 0, buf
->vb
.height
);
629 case V4L2_FIELD_INTERLACED
:
630 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
631 dma
->sglist
, 0, buf
->bpl
,
633 buf
->vb
.height
>> 1);
635 case V4L2_FIELD_SEQ_TB
:
636 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
638 0, buf
->bpl
* (buf
->vb
.height
>> 1),
640 buf
->vb
.height
>> 1);
642 case V4L2_FIELD_SEQ_BT
:
643 cx88_risc_buffer(dev
->pci
, &buf
->risc
,
645 buf
->bpl
* (buf
->vb
.height
>> 1), 0,
647 buf
->vb
.height
>> 1);
653 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
655 fh
->width
, fh
->height
, fh
->fmt
->depth
, fh
->fmt
->name
,
656 (unsigned long)buf
->risc
.dma
);
658 buf
->vb
.state
= VIDEOBUF_PREPARED
;
662 cx88_free_buffer(q
,buf
);
667 buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
669 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
670 struct cx88_buffer
*prev
;
671 struct cx8800_fh
*fh
= vq
->priv_data
;
672 struct cx8800_dev
*dev
= fh
->dev
;
673 struct cx88_core
*core
= dev
->core
;
674 struct cx88_dmaqueue
*q
= &dev
->vidq
;
676 /* add jump to stopper */
677 buf
->risc
.jmp
[0] = cpu_to_le32(RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
678 buf
->risc
.jmp
[1] = cpu_to_le32(q
->stopper
.dma
);
680 if (!list_empty(&q
->queued
)) {
681 list_add_tail(&buf
->vb
.queue
,&q
->queued
);
682 buf
->vb
.state
= VIDEOBUF_QUEUED
;
683 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
686 } else if (list_empty(&q
->active
)) {
687 list_add_tail(&buf
->vb
.queue
,&q
->active
);
688 start_video_dma(dev
, q
, buf
);
689 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
690 buf
->count
= q
->count
++;
691 mod_timer(&q
->timeout
, jiffies
+BUFFER_TIMEOUT
);
692 dprintk(2,"[%p/%d] buffer_queue - first active\n",
696 prev
= list_entry(q
->active
.prev
, struct cx88_buffer
, vb
.queue
);
697 if (prev
->vb
.width
== buf
->vb
.width
&&
698 prev
->vb
.height
== buf
->vb
.height
&&
699 prev
->fmt
== buf
->fmt
) {
700 list_add_tail(&buf
->vb
.queue
,&q
->active
);
701 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
702 buf
->count
= q
->count
++;
703 prev
->risc
.jmp
[1] = cpu_to_le32(buf
->risc
.dma
);
704 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
708 list_add_tail(&buf
->vb
.queue
,&q
->queued
);
709 buf
->vb
.state
= VIDEOBUF_QUEUED
;
710 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
716 static void buffer_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
718 struct cx88_buffer
*buf
= container_of(vb
,struct cx88_buffer
,vb
);
720 cx88_free_buffer(q
,buf
);
723 static struct videobuf_queue_ops cx8800_video_qops
= {
724 .buf_setup
= buffer_setup
,
725 .buf_prepare
= buffer_prepare
,
726 .buf_queue
= buffer_queue
,
727 .buf_release
= buffer_release
,
730 /* ------------------------------------------------------------------ */
733 /* ------------------------------------------------------------------ */
735 static struct videobuf_queue
* get_queue(struct cx8800_fh
*fh
)
738 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
740 case V4L2_BUF_TYPE_VBI_CAPTURE
:
748 static int get_ressource(struct cx8800_fh
*fh
)
751 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
752 return RESOURCE_VIDEO
;
753 case V4L2_BUF_TYPE_VBI_CAPTURE
:
761 static int video_open(struct file
*file
)
763 int minor
= video_devdata(file
)->minor
;
764 struct cx8800_dev
*h
,*dev
= NULL
;
765 struct cx88_core
*core
;
766 struct cx8800_fh
*fh
;
767 enum v4l2_buf_type type
= 0;
771 list_for_each_entry(h
, &cx8800_devlist
, devlist
) {
772 if (h
->video_dev
->minor
== minor
) {
774 type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
776 if (h
->vbi_dev
->minor
== minor
) {
778 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
781 h
->radio_dev
->minor
== minor
) {
793 dprintk(1,"open minor=%d radio=%d type=%s\n",
794 minor
,radio
,v4l2_type_names
[type
]);
796 /* allocate + initialize per filehandle data */
797 fh
= kzalloc(sizeof(*fh
),GFP_KERNEL
);
802 file
->private_data
= fh
;
808 fh
->fmt
= format_by_fourcc(V4L2_PIX_FMT_BGR24
);
810 videobuf_queue_sg_init(&fh
->vidq
, &cx8800_video_qops
,
811 &dev
->pci
->dev
, &dev
->slock
,
812 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
813 V4L2_FIELD_INTERLACED
,
814 sizeof(struct cx88_buffer
),
816 videobuf_queue_sg_init(&fh
->vbiq
, &cx8800_vbi_qops
,
817 &dev
->pci
->dev
, &dev
->slock
,
818 V4L2_BUF_TYPE_VBI_CAPTURE
,
820 sizeof(struct cx88_buffer
),
824 dprintk(1,"video_open: setting radio device\n");
825 cx_write(MO_GP3_IO
, core
->board
.radio
.gpio3
);
826 cx_write(MO_GP0_IO
, core
->board
.radio
.gpio0
);
827 cx_write(MO_GP1_IO
, core
->board
.radio
.gpio1
);
828 cx_write(MO_GP2_IO
, core
->board
.radio
.gpio2
);
829 if (core
->board
.radio
.audioroute
) {
830 if(core
->board
.audio_chip
&&
831 core
->board
.audio_chip
== V4L2_IDENT_WM8775
) {
832 struct v4l2_routing route
;
834 route
.input
= core
->board
.radio
.audioroute
;
835 cx88_call_i2c_clients(core
,
836 VIDIOC_INT_S_AUDIO_ROUTING
, &route
);
839 core
->tvaudio
= WW_I2SADC
;
840 cx88_set_tvaudio(core
);
843 core
->tvaudio
= WW_FM
;
844 cx88_set_tvaudio(core
);
845 cx88_set_stereo(core
,V4L2_TUNER_MODE_STEREO
,1);
847 cx88_call_i2c_clients(core
,AUDC_SET_RADIO
,NULL
);
851 atomic_inc(&core
->users
);
857 video_read(struct file
*file
, char __user
*data
, size_t count
, loff_t
*ppos
)
859 struct cx8800_fh
*fh
= file
->private_data
;
862 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
863 if (res_locked(fh
->dev
,RESOURCE_VIDEO
))
865 return videobuf_read_one(&fh
->vidq
, data
, count
, ppos
,
866 file
->f_flags
& O_NONBLOCK
);
867 case V4L2_BUF_TYPE_VBI_CAPTURE
:
868 if (!res_get(fh
->dev
,fh
,RESOURCE_VBI
))
870 return videobuf_read_stream(&fh
->vbiq
, data
, count
, ppos
, 1,
871 file
->f_flags
& O_NONBLOCK
);
879 video_poll(struct file
*file
, struct poll_table_struct
*wait
)
881 struct cx8800_fh
*fh
= file
->private_data
;
882 struct cx88_buffer
*buf
;
884 if (V4L2_BUF_TYPE_VBI_CAPTURE
== fh
->type
) {
885 if (!res_get(fh
->dev
,fh
,RESOURCE_VBI
))
887 return videobuf_poll_stream(file
, &fh
->vbiq
, wait
);
890 if (res_check(fh
,RESOURCE_VIDEO
)) {
891 /* streaming capture */
892 if (list_empty(&fh
->vidq
.stream
))
894 buf
= list_entry(fh
->vidq
.stream
.next
,struct cx88_buffer
,vb
.stream
);
897 buf
= (struct cx88_buffer
*)fh
->vidq
.read_buf
;
901 poll_wait(file
, &buf
->vb
.done
, wait
);
902 if (buf
->vb
.state
== VIDEOBUF_DONE
||
903 buf
->vb
.state
== VIDEOBUF_ERROR
)
904 return POLLIN
|POLLRDNORM
;
908 static int video_release(struct file
*file
)
910 struct cx8800_fh
*fh
= file
->private_data
;
911 struct cx8800_dev
*dev
= fh
->dev
;
913 /* turn off overlay */
914 if (res_check(fh
, RESOURCE_OVERLAY
)) {
916 res_free(dev
,fh
,RESOURCE_OVERLAY
);
919 /* stop video capture */
920 if (res_check(fh
, RESOURCE_VIDEO
)) {
921 videobuf_queue_cancel(&fh
->vidq
);
922 res_free(dev
,fh
,RESOURCE_VIDEO
);
924 if (fh
->vidq
.read_buf
) {
925 buffer_release(&fh
->vidq
,fh
->vidq
.read_buf
);
926 kfree(fh
->vidq
.read_buf
);
929 /* stop vbi capture */
930 if (res_check(fh
, RESOURCE_VBI
)) {
931 videobuf_stop(&fh
->vbiq
);
932 res_free(dev
,fh
,RESOURCE_VBI
);
935 videobuf_mmap_free(&fh
->vidq
);
936 videobuf_mmap_free(&fh
->vbiq
);
937 file
->private_data
= NULL
;
940 if(atomic_dec_and_test(&dev
->core
->users
))
941 cx88_call_i2c_clients (dev
->core
, TUNER_SET_STANDBY
, NULL
);
947 video_mmap(struct file
*file
, struct vm_area_struct
* vma
)
949 struct cx8800_fh
*fh
= file
->private_data
;
951 return videobuf_mmap_mapper(get_queue(fh
), vma
);
954 /* ------------------------------------------------------------------ */
955 /* VIDEO CTRL IOCTLS */
957 int cx88_get_control (struct cx88_core
*core
, struct v4l2_control
*ctl
)
959 struct cx88_ctrl
*c
= NULL
;
963 for (i
= 0; i
< CX8800_CTLS
; i
++)
964 if (cx8800_ctls
[i
].v
.id
== ctl
->id
)
966 if (unlikely(NULL
== c
))
969 value
= c
->sreg
? cx_sread(c
->sreg
) : cx_read(c
->reg
);
971 case V4L2_CID_AUDIO_BALANCE
:
972 ctl
->value
= ((value
& 0x7f) < 0x40) ? ((value
& 0x7f) + 0x40)
973 : (0x7f - (value
& 0x7f));
975 case V4L2_CID_AUDIO_VOLUME
:
976 ctl
->value
= 0x3f - (value
& 0x3f);
979 ctl
->value
= ((value
+ (c
->off
<< c
->shift
)) & c
->mask
) >> c
->shift
;
982 dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
983 ctl
->id
, c
->v
.name
, ctl
->value
, c
->reg
,
984 value
,c
->mask
, c
->sreg
? " [shadowed]" : "");
987 EXPORT_SYMBOL(cx88_get_control
);
989 int cx88_set_control(struct cx88_core
*core
, struct v4l2_control
*ctl
)
991 struct cx88_ctrl
*c
= NULL
;
995 for (i
= 0; i
< CX8800_CTLS
; i
++) {
996 if (cx8800_ctls
[i
].v
.id
== ctl
->id
) {
1000 if (unlikely(NULL
== c
))
1003 if (ctl
->value
< c
->v
.minimum
)
1004 ctl
->value
= c
->v
.minimum
;
1005 if (ctl
->value
> c
->v
.maximum
)
1006 ctl
->value
= c
->v
.maximum
;
1009 case V4L2_CID_AUDIO_BALANCE
:
1010 value
= (ctl
->value
< 0x40) ? (0x7f - ctl
->value
) : (ctl
->value
- 0x40);
1012 case V4L2_CID_AUDIO_VOLUME
:
1013 value
= 0x3f - (ctl
->value
& 0x3f);
1015 case V4L2_CID_SATURATION
:
1016 /* special v_sat handling */
1018 value
= ((ctl
->value
- c
->off
) << c
->shift
) & c
->mask
;
1020 if (core
->tvnorm
& V4L2_STD_SECAM
) {
1021 /* For SECAM, both U and V sat should be equal */
1022 value
=value
<<8|value
;
1024 /* Keeps U Saturation proportional to V Sat */
1025 value
=(value
*0x5a)/0x7f<<8|value
;
1029 case V4L2_CID_CHROMA_AGC
:
1030 /* Do not allow chroma AGC to be enabled for SECAM */
1031 value
= ((ctl
->value
- c
->off
) << c
->shift
) & c
->mask
;
1032 if (core
->tvnorm
& V4L2_STD_SECAM
&& value
)
1036 value
= ((ctl
->value
- c
->off
) << c
->shift
) & c
->mask
;
1039 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
1040 ctl
->id
, c
->v
.name
, ctl
->value
, c
->reg
, value
,
1041 mask
, c
->sreg
? " [shadowed]" : "");
1043 cx_sandor(c
->sreg
, c
->reg
, mask
, value
);
1045 cx_andor(c
->reg
, mask
, value
);
1049 EXPORT_SYMBOL(cx88_set_control
);
1051 static void init_controls(struct cx88_core
*core
)
1053 struct v4l2_control ctrl
;
1056 for (i
= 0; i
< CX8800_CTLS
; i
++) {
1057 ctrl
.id
=cx8800_ctls
[i
].v
.id
;
1058 ctrl
.value
=cx8800_ctls
[i
].v
.default_value
;
1060 cx88_set_control(core
, &ctrl
);
1064 /* ------------------------------------------------------------------ */
1067 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
1068 struct v4l2_format
*f
)
1070 struct cx8800_fh
*fh
= priv
;
1072 f
->fmt
.pix
.width
= fh
->width
;
1073 f
->fmt
.pix
.height
= fh
->height
;
1074 f
->fmt
.pix
.field
= fh
->vidq
.field
;
1075 f
->fmt
.pix
.pixelformat
= fh
->fmt
->fourcc
;
1076 f
->fmt
.pix
.bytesperline
=
1077 (f
->fmt
.pix
.width
* fh
->fmt
->depth
) >> 3;
1078 f
->fmt
.pix
.sizeimage
=
1079 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
1083 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
1084 struct v4l2_format
*f
)
1086 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1087 struct cx8800_fmt
*fmt
;
1088 enum v4l2_field field
;
1089 unsigned int maxw
, maxh
;
1091 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
1095 field
= f
->fmt
.pix
.field
;
1096 maxw
= norm_maxw(core
->tvnorm
);
1097 maxh
= norm_maxh(core
->tvnorm
);
1099 if (V4L2_FIELD_ANY
== field
) {
1100 field
= (f
->fmt
.pix
.height
> maxh
/2)
1101 ? V4L2_FIELD_INTERLACED
1102 : V4L2_FIELD_BOTTOM
;
1106 case V4L2_FIELD_TOP
:
1107 case V4L2_FIELD_BOTTOM
:
1110 case V4L2_FIELD_INTERLACED
:
1116 f
->fmt
.pix
.field
= field
;
1117 if (f
->fmt
.pix
.height
< 32)
1118 f
->fmt
.pix
.height
= 32;
1119 if (f
->fmt
.pix
.height
> maxh
)
1120 f
->fmt
.pix
.height
= maxh
;
1121 if (f
->fmt
.pix
.width
< 48)
1122 f
->fmt
.pix
.width
= 48;
1123 if (f
->fmt
.pix
.width
> maxw
)
1124 f
->fmt
.pix
.width
= maxw
;
1125 f
->fmt
.pix
.width
&= ~0x03;
1126 f
->fmt
.pix
.bytesperline
=
1127 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
1128 f
->fmt
.pix
.sizeimage
=
1129 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
1134 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
1135 struct v4l2_format
*f
)
1137 struct cx8800_fh
*fh
= priv
;
1138 int err
= vidioc_try_fmt_vid_cap (file
,priv
,f
);
1142 fh
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
1143 fh
->width
= f
->fmt
.pix
.width
;
1144 fh
->height
= f
->fmt
.pix
.height
;
1145 fh
->vidq
.field
= f
->fmt
.pix
.field
;
1149 static int vidioc_querycap (struct file
*file
, void *priv
,
1150 struct v4l2_capability
*cap
)
1152 struct cx8800_dev
*dev
= ((struct cx8800_fh
*)priv
)->dev
;
1153 struct cx88_core
*core
= dev
->core
;
1155 strcpy(cap
->driver
, "cx8800");
1156 strlcpy(cap
->card
, core
->board
.name
, sizeof(cap
->card
));
1157 sprintf(cap
->bus_info
,"PCI:%s",pci_name(dev
->pci
));
1158 cap
->version
= CX88_VERSION_CODE
;
1160 V4L2_CAP_VIDEO_CAPTURE
|
1161 V4L2_CAP_READWRITE
|
1162 V4L2_CAP_STREAMING
|
1163 V4L2_CAP_VBI_CAPTURE
;
1164 if (UNSET
!= core
->board
.tuner_type
)
1165 cap
->capabilities
|= V4L2_CAP_TUNER
;
1169 static int vidioc_enum_fmt_vid_cap (struct file
*file
, void *priv
,
1170 struct v4l2_fmtdesc
*f
)
1172 if (unlikely(f
->index
>= ARRAY_SIZE(formats
)))
1175 strlcpy(f
->description
,formats
[f
->index
].name
,sizeof(f
->description
));
1176 f
->pixelformat
= formats
[f
->index
].fourcc
;
1181 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1182 static int vidiocgmbuf (struct file
*file
, void *priv
, struct video_mbuf
*mbuf
)
1184 struct cx8800_fh
*fh
= priv
;
1186 return videobuf_cgmbuf (get_queue(fh
), mbuf
, 8);
1190 static int vidioc_reqbufs (struct file
*file
, void *priv
, struct v4l2_requestbuffers
*p
)
1192 struct cx8800_fh
*fh
= priv
;
1193 return (videobuf_reqbufs(get_queue(fh
), p
));
1196 static int vidioc_querybuf (struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
1198 struct cx8800_fh
*fh
= priv
;
1199 return (videobuf_querybuf(get_queue(fh
), p
));
1202 static int vidioc_qbuf (struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
1204 struct cx8800_fh
*fh
= priv
;
1205 return (videobuf_qbuf(get_queue(fh
), p
));
1208 static int vidioc_dqbuf (struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
1210 struct cx8800_fh
*fh
= priv
;
1211 return (videobuf_dqbuf(get_queue(fh
), p
,
1212 file
->f_flags
& O_NONBLOCK
));
1215 static int vidioc_streamon(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1217 struct cx8800_fh
*fh
= priv
;
1218 struct cx8800_dev
*dev
= fh
->dev
;
1220 /* We should remember that this driver also supports teletext, */
1221 /* so we have to test if the v4l2_buf_type is VBI capture data. */
1222 if (unlikely((fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) &&
1223 (fh
->type
!= V4L2_BUF_TYPE_VBI_CAPTURE
)))
1226 if (unlikely(i
!= fh
->type
))
1229 if (unlikely(!res_get(dev
,fh
,get_ressource(fh
))))
1231 return videobuf_streamon(get_queue(fh
));
1234 static int vidioc_streamoff(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1236 struct cx8800_fh
*fh
= priv
;
1237 struct cx8800_dev
*dev
= fh
->dev
;
1240 if ((fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) &&
1241 (fh
->type
!= V4L2_BUF_TYPE_VBI_CAPTURE
))
1247 res
= get_ressource(fh
);
1248 err
= videobuf_streamoff(get_queue(fh
));
1251 res_free(dev
,fh
,res
);
1255 static int vidioc_s_std (struct file
*file
, void *priv
, v4l2_std_id
*tvnorms
)
1257 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1259 mutex_lock(&core
->lock
);
1260 cx88_set_tvnorm(core
,*tvnorms
);
1261 mutex_unlock(&core
->lock
);
1266 /* only one input in this sample driver */
1267 int cx88_enum_input (struct cx88_core
*core
,struct v4l2_input
*i
)
1269 static const char *iname
[] = {
1270 [ CX88_VMUX_COMPOSITE1
] = "Composite1",
1271 [ CX88_VMUX_COMPOSITE2
] = "Composite2",
1272 [ CX88_VMUX_COMPOSITE3
] = "Composite3",
1273 [ CX88_VMUX_COMPOSITE4
] = "Composite4",
1274 [ CX88_VMUX_SVIDEO
] = "S-Video",
1275 [ CX88_VMUX_TELEVISION
] = "Television",
1276 [ CX88_VMUX_CABLE
] = "Cable TV",
1277 [ CX88_VMUX_DVB
] = "DVB",
1278 [ CX88_VMUX_DEBUG
] = "for debug only",
1280 unsigned int n
= i
->index
;
1284 if (0 == INPUT(n
).type
)
1286 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1287 strcpy(i
->name
,iname
[INPUT(n
).type
]);
1288 if ((CX88_VMUX_TELEVISION
== INPUT(n
).type
) ||
1289 (CX88_VMUX_CABLE
== INPUT(n
).type
))
1290 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1291 i
->std
= CX88_NORMS
;
1294 EXPORT_SYMBOL(cx88_enum_input
);
1296 static int vidioc_enum_input (struct file
*file
, void *priv
,
1297 struct v4l2_input
*i
)
1299 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1300 return cx88_enum_input (core
,i
);
1303 static int vidioc_g_input (struct file
*file
, void *priv
, unsigned int *i
)
1305 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1311 static int vidioc_s_input (struct file
*file
, void *priv
, unsigned int i
)
1313 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1318 mutex_lock(&core
->lock
);
1319 cx88_newstation(core
);
1320 cx88_video_mux(core
,i
);
1321 mutex_unlock(&core
->lock
);
1327 static int vidioc_queryctrl (struct file
*file
, void *priv
,
1328 struct v4l2_queryctrl
*qctrl
)
1330 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1332 qctrl
->id
= v4l2_ctrl_next(ctrl_classes
, qctrl
->id
);
1333 if (unlikely(qctrl
->id
== 0))
1335 return cx8800_ctrl_query(core
, qctrl
);
1338 static int vidioc_g_ctrl (struct file
*file
, void *priv
,
1339 struct v4l2_control
*ctl
)
1341 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1343 cx88_get_control(core
,ctl
);
1346 static int vidioc_s_ctrl (struct file
*file
, void *priv
,
1347 struct v4l2_control
*ctl
)
1349 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1351 cx88_set_control(core
,ctl
);
1354 static int vidioc_g_tuner (struct file
*file
, void *priv
,
1355 struct v4l2_tuner
*t
)
1357 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1360 if (unlikely(UNSET
== core
->board
.tuner_type
))
1365 strcpy(t
->name
, "Television");
1366 t
->type
= V4L2_TUNER_ANALOG_TV
;
1367 t
->capability
= V4L2_TUNER_CAP_NORM
;
1368 t
->rangehigh
= 0xffffffffUL
;
1370 cx88_get_stereo(core
,t
);
1371 reg
= cx_read(MO_DEVICE_STATUS
);
1372 t
->signal
= (reg
& (1<<5)) ? 0xffff : 0x0000;
1376 static int vidioc_s_tuner (struct file
*file
, void *priv
,
1377 struct v4l2_tuner
*t
)
1379 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1381 if (UNSET
== core
->board
.tuner_type
)
1386 cx88_set_stereo(core
, t
->audmode
, 1);
1390 static int vidioc_g_frequency (struct file
*file
, void *priv
,
1391 struct v4l2_frequency
*f
)
1393 struct cx8800_fh
*fh
= priv
;
1394 struct cx88_core
*core
= fh
->dev
->core
;
1396 if (unlikely(UNSET
== core
->board
.tuner_type
))
1399 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1400 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1401 f
->frequency
= core
->freq
;
1403 cx88_call_i2c_clients(core
,VIDIOC_G_FREQUENCY
,f
);
1408 int cx88_set_freq (struct cx88_core
*core
,
1409 struct v4l2_frequency
*f
)
1411 if (unlikely(UNSET
== core
->board
.tuner_type
))
1413 if (unlikely(f
->tuner
!= 0))
1416 mutex_lock(&core
->lock
);
1417 core
->freq
= f
->frequency
;
1418 cx88_newstation(core
);
1419 cx88_call_i2c_clients(core
,VIDIOC_S_FREQUENCY
,f
);
1421 /* When changing channels it is required to reset TVAUDIO */
1423 cx88_set_tvaudio(core
);
1425 mutex_unlock(&core
->lock
);
1429 EXPORT_SYMBOL(cx88_set_freq
);
1431 static int vidioc_s_frequency (struct file
*file
, void *priv
,
1432 struct v4l2_frequency
*f
)
1434 struct cx8800_fh
*fh
= priv
;
1435 struct cx88_core
*core
= fh
->dev
->core
;
1437 if (unlikely(0 == fh
->radio
&& f
->type
!= V4L2_TUNER_ANALOG_TV
))
1439 if (unlikely(1 == fh
->radio
&& f
->type
!= V4L2_TUNER_RADIO
))
1443 cx88_set_freq (core
,f
);
1446 #ifdef CONFIG_VIDEO_ADV_DEBUG
1447 static int vidioc_g_register (struct file
*file
, void *fh
,
1448 struct v4l2_dbg_register
*reg
)
1450 struct cx88_core
*core
= ((struct cx8800_fh
*)fh
)->dev
->core
;
1452 if (!v4l2_chip_match_host(®
->match
))
1454 /* cx2388x has a 24-bit register space */
1455 reg
->val
= cx_read(reg
->reg
& 0xffffff);
1460 static int vidioc_s_register (struct file
*file
, void *fh
,
1461 struct v4l2_dbg_register
*reg
)
1463 struct cx88_core
*core
= ((struct cx8800_fh
*)fh
)->dev
->core
;
1465 if (!v4l2_chip_match_host(®
->match
))
1467 cx_write(reg
->reg
& 0xffffff, reg
->val
);
1472 /* ----------------------------------------------------------- */
1473 /* RADIO ESPECIFIC IOCTLS */
1474 /* ----------------------------------------------------------- */
1476 static int radio_querycap (struct file
*file
, void *priv
,
1477 struct v4l2_capability
*cap
)
1479 struct cx8800_dev
*dev
= ((struct cx8800_fh
*)priv
)->dev
;
1480 struct cx88_core
*core
= dev
->core
;
1482 strcpy(cap
->driver
, "cx8800");
1483 strlcpy(cap
->card
, core
->board
.name
, sizeof(cap
->card
));
1484 sprintf(cap
->bus_info
,"PCI:%s", pci_name(dev
->pci
));
1485 cap
->version
= CX88_VERSION_CODE
;
1486 cap
->capabilities
= V4L2_CAP_TUNER
;
1490 static int radio_g_tuner (struct file
*file
, void *priv
,
1491 struct v4l2_tuner
*t
)
1493 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1495 if (unlikely(t
->index
> 0))
1498 strcpy(t
->name
, "Radio");
1499 t
->type
= V4L2_TUNER_RADIO
;
1501 cx88_call_i2c_clients(core
,VIDIOC_G_TUNER
,t
);
1505 static int radio_enum_input (struct file
*file
, void *priv
,
1506 struct v4l2_input
*i
)
1510 strcpy(i
->name
,"Radio");
1511 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1516 static int radio_g_audio (struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1518 if (unlikely(a
->index
))
1521 strcpy(a
->name
,"Radio");
1525 /* FIXME: Should add a standard for radio */
1527 static int radio_s_tuner (struct file
*file
, void *priv
,
1528 struct v4l2_tuner
*t
)
1530 struct cx88_core
*core
= ((struct cx8800_fh
*)priv
)->dev
->core
;
1535 cx88_call_i2c_clients(core
,VIDIOC_S_TUNER
,t
);
1540 static int radio_s_audio (struct file
*file
, void *fh
,
1541 struct v4l2_audio
*a
)
1546 static int radio_s_input (struct file
*file
, void *fh
, unsigned int i
)
1551 static int radio_queryctrl (struct file
*file
, void *priv
,
1552 struct v4l2_queryctrl
*c
)
1556 if (c
->id
< V4L2_CID_BASE
||
1557 c
->id
>= V4L2_CID_LASTP1
)
1559 if (c
->id
== V4L2_CID_AUDIO_MUTE
) {
1560 for (i
= 0; i
< CX8800_CTLS
; i
++)
1561 if (cx8800_ctls
[i
].v
.id
== c
->id
)
1563 *c
= cx8800_ctls
[i
].v
;
1569 /* ----------------------------------------------------------- */
1571 static void cx8800_vid_timeout(unsigned long data
)
1573 struct cx8800_dev
*dev
= (struct cx8800_dev
*)data
;
1574 struct cx88_core
*core
= dev
->core
;
1575 struct cx88_dmaqueue
*q
= &dev
->vidq
;
1576 struct cx88_buffer
*buf
;
1577 unsigned long flags
;
1579 cx88_sram_channel_dump(core
, &cx88_sram_channels
[SRAM_CH21
]);
1581 cx_clear(MO_VID_DMACNTRL
, 0x11);
1582 cx_clear(VID_CAPTURE_CONTROL
, 0x06);
1584 spin_lock_irqsave(&dev
->slock
,flags
);
1585 while (!list_empty(&q
->active
)) {
1586 buf
= list_entry(q
->active
.next
, struct cx88_buffer
, vb
.queue
);
1587 list_del(&buf
->vb
.queue
);
1588 buf
->vb
.state
= VIDEOBUF_ERROR
;
1589 wake_up(&buf
->vb
.done
);
1590 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core
->name
,
1591 buf
, buf
->vb
.i
, (unsigned long)buf
->risc
.dma
);
1593 restart_video_queue(dev
,q
);
1594 spin_unlock_irqrestore(&dev
->slock
,flags
);
1597 static char *cx88_vid_irqs
[32] = {
1598 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1599 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1600 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1601 "y_sync", "u_sync", "v_sync", "vbi_sync",
1602 "opc_err", "par_err", "rip_err", "pci_abort",
1605 static void cx8800_vid_irq(struct cx8800_dev
*dev
)
1607 struct cx88_core
*core
= dev
->core
;
1608 u32 status
, mask
, count
;
1610 status
= cx_read(MO_VID_INTSTAT
);
1611 mask
= cx_read(MO_VID_INTMSK
);
1612 if (0 == (status
& mask
))
1614 cx_write(MO_VID_INTSTAT
, status
);
1615 if (irq_debug
|| (status
& mask
& ~0xff))
1616 cx88_print_irqbits(core
->name
, "irq vid",
1617 cx88_vid_irqs
, ARRAY_SIZE(cx88_vid_irqs
),
1620 /* risc op code error */
1621 if (status
& (1 << 16)) {
1622 printk(KERN_WARNING
"%s/0: video risc op code error\n",core
->name
);
1623 cx_clear(MO_VID_DMACNTRL
, 0x11);
1624 cx_clear(VID_CAPTURE_CONTROL
, 0x06);
1625 cx88_sram_channel_dump(core
, &cx88_sram_channels
[SRAM_CH21
]);
1629 if (status
& 0x01) {
1630 spin_lock(&dev
->slock
);
1631 count
= cx_read(MO_VIDY_GPCNT
);
1632 cx88_wakeup(core
, &dev
->vidq
, count
);
1633 spin_unlock(&dev
->slock
);
1637 if (status
& 0x08) {
1638 spin_lock(&dev
->slock
);
1639 count
= cx_read(MO_VBI_GPCNT
);
1640 cx88_wakeup(core
, &dev
->vbiq
, count
);
1641 spin_unlock(&dev
->slock
);
1645 if (status
& 0x10) {
1646 dprintk(2,"stopper video\n");
1647 spin_lock(&dev
->slock
);
1648 restart_video_queue(dev
,&dev
->vidq
);
1649 spin_unlock(&dev
->slock
);
1653 if (status
& 0x80) {
1654 dprintk(2,"stopper vbi\n");
1655 spin_lock(&dev
->slock
);
1656 cx8800_restart_vbi_queue(dev
,&dev
->vbiq
);
1657 spin_unlock(&dev
->slock
);
1661 static irqreturn_t
cx8800_irq(int irq
, void *dev_id
)
1663 struct cx8800_dev
*dev
= dev_id
;
1664 struct cx88_core
*core
= dev
->core
;
1666 int loop
, handled
= 0;
1668 for (loop
= 0; loop
< 10; loop
++) {
1669 status
= cx_read(MO_PCI_INTSTAT
) &
1670 (core
->pci_irqmask
| PCI_INT_VIDINT
);
1673 cx_write(MO_PCI_INTSTAT
, status
);
1676 if (status
& core
->pci_irqmask
)
1677 cx88_core_irq(core
,status
);
1678 if (status
& PCI_INT_VIDINT
)
1679 cx8800_vid_irq(dev
);
1682 printk(KERN_WARNING
"%s/0: irq loop -- clearing mask\n",
1684 cx_write(MO_PCI_INTMSK
,0);
1688 return IRQ_RETVAL(handled
);
1691 /* ----------------------------------------------------------- */
1692 /* exported stuff */
1694 static const struct v4l2_file_operations video_fops
=
1696 .owner
= THIS_MODULE
,
1698 .release
= video_release
,
1702 .ioctl
= video_ioctl2
,
1705 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1706 .vidioc_querycap
= vidioc_querycap
,
1707 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1708 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1709 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1710 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1711 .vidioc_g_fmt_vbi_cap
= cx8800_vbi_fmt
,
1712 .vidioc_try_fmt_vbi_cap
= cx8800_vbi_fmt
,
1713 .vidioc_s_fmt_vbi_cap
= cx8800_vbi_fmt
,
1714 .vidioc_reqbufs
= vidioc_reqbufs
,
1715 .vidioc_querybuf
= vidioc_querybuf
,
1716 .vidioc_qbuf
= vidioc_qbuf
,
1717 .vidioc_dqbuf
= vidioc_dqbuf
,
1718 .vidioc_s_std
= vidioc_s_std
,
1719 .vidioc_enum_input
= vidioc_enum_input
,
1720 .vidioc_g_input
= vidioc_g_input
,
1721 .vidioc_s_input
= vidioc_s_input
,
1722 .vidioc_queryctrl
= vidioc_queryctrl
,
1723 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1724 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1725 .vidioc_streamon
= vidioc_streamon
,
1726 .vidioc_streamoff
= vidioc_streamoff
,
1727 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1728 .vidiocgmbuf
= vidiocgmbuf
,
1730 .vidioc_g_tuner
= vidioc_g_tuner
,
1731 .vidioc_s_tuner
= vidioc_s_tuner
,
1732 .vidioc_g_frequency
= vidioc_g_frequency
,
1733 .vidioc_s_frequency
= vidioc_s_frequency
,
1734 #ifdef CONFIG_VIDEO_ADV_DEBUG
1735 .vidioc_g_register
= vidioc_g_register
,
1736 .vidioc_s_register
= vidioc_s_register
,
1740 static struct video_device cx8800_vbi_template
;
1742 static struct video_device cx8800_video_template
= {
1743 .name
= "cx8800-video",
1744 .fops
= &video_fops
,
1746 .ioctl_ops
= &video_ioctl_ops
,
1747 .tvnorms
= CX88_NORMS
,
1748 .current_norm
= V4L2_STD_NTSC_M
,
1751 static const struct v4l2_file_operations radio_fops
=
1753 .owner
= THIS_MODULE
,
1755 .release
= video_release
,
1756 .ioctl
= video_ioctl2
,
1759 static const struct v4l2_ioctl_ops radio_ioctl_ops
= {
1760 .vidioc_querycap
= radio_querycap
,
1761 .vidioc_g_tuner
= radio_g_tuner
,
1762 .vidioc_enum_input
= radio_enum_input
,
1763 .vidioc_g_audio
= radio_g_audio
,
1764 .vidioc_s_tuner
= radio_s_tuner
,
1765 .vidioc_s_audio
= radio_s_audio
,
1766 .vidioc_s_input
= radio_s_input
,
1767 .vidioc_queryctrl
= radio_queryctrl
,
1768 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1769 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1770 .vidioc_g_frequency
= vidioc_g_frequency
,
1771 .vidioc_s_frequency
= vidioc_s_frequency
,
1772 #ifdef CONFIG_VIDEO_ADV_DEBUG
1773 .vidioc_g_register
= vidioc_g_register
,
1774 .vidioc_s_register
= vidioc_s_register
,
1778 static struct video_device cx8800_radio_template
= {
1779 .name
= "cx8800-radio",
1780 .fops
= &radio_fops
,
1782 .ioctl_ops
= &radio_ioctl_ops
,
1785 /* ----------------------------------------------------------- */
1787 static void cx8800_unregister_video(struct cx8800_dev
*dev
)
1789 if (dev
->radio_dev
) {
1790 if (-1 != dev
->radio_dev
->minor
)
1791 video_unregister_device(dev
->radio_dev
);
1793 video_device_release(dev
->radio_dev
);
1794 dev
->radio_dev
= NULL
;
1797 if (-1 != dev
->vbi_dev
->minor
)
1798 video_unregister_device(dev
->vbi_dev
);
1800 video_device_release(dev
->vbi_dev
);
1801 dev
->vbi_dev
= NULL
;
1803 if (dev
->video_dev
) {
1804 if (-1 != dev
->video_dev
->minor
)
1805 video_unregister_device(dev
->video_dev
);
1807 video_device_release(dev
->video_dev
);
1808 dev
->video_dev
= NULL
;
1812 static int __devinit
cx8800_initdev(struct pci_dev
*pci_dev
,
1813 const struct pci_device_id
*pci_id
)
1815 struct cx8800_dev
*dev
;
1816 struct cx88_core
*core
;
1820 dev
= kzalloc(sizeof(*dev
),GFP_KERNEL
);
1826 if (pci_enable_device(pci_dev
)) {
1830 core
= cx88_core_get(dev
->pci
);
1837 /* print pci info */
1838 pci_read_config_byte(pci_dev
, PCI_CLASS_REVISION
, &dev
->pci_rev
);
1839 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &dev
->pci_lat
);
1840 printk(KERN_INFO
"%s/0: found at %s, rev: %d, irq: %d, "
1841 "latency: %d, mmio: 0x%llx\n", core
->name
,
1842 pci_name(pci_dev
), dev
->pci_rev
, pci_dev
->irq
,
1843 dev
->pci_lat
,(unsigned long long)pci_resource_start(pci_dev
,0));
1845 pci_set_master(pci_dev
);
1846 if (!pci_dma_supported(pci_dev
,DMA_32BIT_MASK
)) {
1847 printk("%s/0: Oops: no 32bit PCI DMA ???\n",core
->name
);
1852 /* Initialize VBI template */
1853 memcpy( &cx8800_vbi_template
, &cx8800_video_template
,
1854 sizeof(cx8800_vbi_template
) );
1855 strcpy(cx8800_vbi_template
.name
,"cx8800-vbi");
1857 /* initialize driver struct */
1858 spin_lock_init(&dev
->slock
);
1859 core
->tvnorm
= cx8800_video_template
.current_norm
;
1861 /* init video dma queues */
1862 INIT_LIST_HEAD(&dev
->vidq
.active
);
1863 INIT_LIST_HEAD(&dev
->vidq
.queued
);
1864 dev
->vidq
.timeout
.function
= cx8800_vid_timeout
;
1865 dev
->vidq
.timeout
.data
= (unsigned long)dev
;
1866 init_timer(&dev
->vidq
.timeout
);
1867 cx88_risc_stopper(dev
->pci
,&dev
->vidq
.stopper
,
1868 MO_VID_DMACNTRL
,0x11,0x00);
1870 /* init vbi dma queues */
1871 INIT_LIST_HEAD(&dev
->vbiq
.active
);
1872 INIT_LIST_HEAD(&dev
->vbiq
.queued
);
1873 dev
->vbiq
.timeout
.function
= cx8800_vbi_timeout
;
1874 dev
->vbiq
.timeout
.data
= (unsigned long)dev
;
1875 init_timer(&dev
->vbiq
.timeout
);
1876 cx88_risc_stopper(dev
->pci
,&dev
->vbiq
.stopper
,
1877 MO_VID_DMACNTRL
,0x88,0x00);
1880 err
= request_irq(pci_dev
->irq
, cx8800_irq
,
1881 IRQF_SHARED
| IRQF_DISABLED
, core
->name
, dev
);
1883 printk(KERN_ERR
"%s/0: can't get IRQ %d\n",
1884 core
->name
,pci_dev
->irq
);
1887 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
);
1889 /* load and configure helper modules */
1891 if (core
->board
.audio_chip
== V4L2_IDENT_WM8775
)
1892 request_module("wm8775");
1894 switch (core
->boardnr
) {
1895 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD
:
1896 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD
:
1897 request_module("rtc-isl1208");
1898 /* break intentionally omitted */
1899 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO
:
1900 request_module("ir-kbd-i2c");
1903 /* register v4l devices */
1904 dev
->video_dev
= cx88_vdev_init(core
,dev
->pci
,
1905 &cx8800_video_template
,"video");
1906 err
= video_register_device(dev
->video_dev
,VFL_TYPE_GRABBER
,
1907 video_nr
[core
->nr
]);
1909 printk(KERN_ERR
"%s/0: can't register video device\n",
1913 printk(KERN_INFO
"%s/0: registered device video%d [v4l2]\n",
1914 core
->name
, dev
->video_dev
->num
);
1916 dev
->vbi_dev
= cx88_vdev_init(core
,dev
->pci
,&cx8800_vbi_template
,"vbi");
1917 err
= video_register_device(dev
->vbi_dev
,VFL_TYPE_VBI
,
1920 printk(KERN_ERR
"%s/0: can't register vbi device\n",
1924 printk(KERN_INFO
"%s/0: registered device vbi%d\n",
1925 core
->name
, dev
->vbi_dev
->num
);
1927 if (core
->board
.radio
.type
== CX88_RADIO
) {
1928 dev
->radio_dev
= cx88_vdev_init(core
,dev
->pci
,
1929 &cx8800_radio_template
,"radio");
1930 err
= video_register_device(dev
->radio_dev
,VFL_TYPE_RADIO
,
1931 radio_nr
[core
->nr
]);
1933 printk(KERN_ERR
"%s/0: can't register radio device\n",
1937 printk(KERN_INFO
"%s/0: registered device radio%d\n",
1938 core
->name
, dev
->radio_dev
->num
);
1941 /* everything worked */
1942 list_add_tail(&dev
->devlist
,&cx8800_devlist
);
1943 pci_set_drvdata(pci_dev
,dev
);
1945 /* initial device configuration */
1946 mutex_lock(&core
->lock
);
1947 cx88_set_tvnorm(core
,core
->tvnorm
);
1948 init_controls(core
);
1949 cx88_video_mux(core
,0);
1950 mutex_unlock(&core
->lock
);
1952 /* start tvaudio thread */
1953 if (core
->board
.tuner_type
!= TUNER_ABSENT
) {
1954 core
->kthread
= kthread_run(cx88_audio_thread
, core
, "cx88 tvaudio");
1955 if (IS_ERR(core
->kthread
)) {
1956 err
= PTR_ERR(core
->kthread
);
1957 printk(KERN_ERR
"%s/0: failed to create cx88 audio thread, err=%d\n",
1964 cx8800_unregister_video(dev
);
1965 free_irq(pci_dev
->irq
, dev
);
1967 cx88_core_put(core
,dev
->pci
);
1973 static void __devexit
cx8800_finidev(struct pci_dev
*pci_dev
)
1975 struct cx8800_dev
*dev
= pci_get_drvdata(pci_dev
);
1976 struct cx88_core
*core
= dev
->core
;
1979 if (core
->kthread
) {
1980 kthread_stop(core
->kthread
);
1981 core
->kthread
= NULL
;
1985 cx88_ir_stop(core
, core
->ir
);
1987 cx88_shutdown(core
); /* FIXME */
1988 pci_disable_device(pci_dev
);
1990 /* unregister stuff */
1992 free_irq(pci_dev
->irq
, dev
);
1993 cx8800_unregister_video(dev
);
1994 pci_set_drvdata(pci_dev
, NULL
);
1997 btcx_riscmem_free(dev
->pci
,&dev
->vidq
.stopper
);
1998 list_del(&dev
->devlist
);
1999 cx88_core_put(core
,dev
->pci
);
2004 static int cx8800_suspend(struct pci_dev
*pci_dev
, pm_message_t state
)
2006 struct cx8800_dev
*dev
= pci_get_drvdata(pci_dev
);
2007 struct cx88_core
*core
= dev
->core
;
2009 /* stop video+vbi capture */
2010 spin_lock(&dev
->slock
);
2011 if (!list_empty(&dev
->vidq
.active
)) {
2012 printk("%s/0: suspend video\n", core
->name
);
2013 stop_video_dma(dev
);
2014 del_timer(&dev
->vidq
.timeout
);
2016 if (!list_empty(&dev
->vbiq
.active
)) {
2017 printk("%s/0: suspend vbi\n", core
->name
);
2018 cx8800_stop_vbi_dma(dev
);
2019 del_timer(&dev
->vbiq
.timeout
);
2021 spin_unlock(&dev
->slock
);
2024 cx88_ir_stop(core
, core
->ir
);
2025 /* FIXME -- shutdown device */
2026 cx88_shutdown(core
);
2028 pci_save_state(pci_dev
);
2029 if (0 != pci_set_power_state(pci_dev
, pci_choose_state(pci_dev
, state
))) {
2030 pci_disable_device(pci_dev
);
2031 dev
->state
.disabled
= 1;
2036 static int cx8800_resume(struct pci_dev
*pci_dev
)
2038 struct cx8800_dev
*dev
= pci_get_drvdata(pci_dev
);
2039 struct cx88_core
*core
= dev
->core
;
2042 if (dev
->state
.disabled
) {
2043 err
=pci_enable_device(pci_dev
);
2045 printk(KERN_ERR
"%s/0: can't enable device\n",
2050 dev
->state
.disabled
= 0;
2052 err
= pci_set_power_state(pci_dev
, PCI_D0
);
2054 printk(KERN_ERR
"%s/0: can't set power state\n", core
->name
);
2055 pci_disable_device(pci_dev
);
2056 dev
->state
.disabled
= 1;
2060 pci_restore_state(pci_dev
);
2062 /* FIXME: re-initialize hardware */
2065 cx88_ir_start(core
, core
->ir
);
2067 cx_set(MO_PCI_INTMSK
, core
->pci_irqmask
);
2069 /* restart video+vbi capture */
2070 spin_lock(&dev
->slock
);
2071 if (!list_empty(&dev
->vidq
.active
)) {
2072 printk("%s/0: resume video\n", core
->name
);
2073 restart_video_queue(dev
,&dev
->vidq
);
2075 if (!list_empty(&dev
->vbiq
.active
)) {
2076 printk("%s/0: resume vbi\n", core
->name
);
2077 cx8800_restart_vbi_queue(dev
,&dev
->vbiq
);
2079 spin_unlock(&dev
->slock
);
2085 /* ----------------------------------------------------------- */
2087 static struct pci_device_id cx8800_pci_tbl
[] = {
2091 .subvendor
= PCI_ANY_ID
,
2092 .subdevice
= PCI_ANY_ID
,
2094 /* --- end of list --- */
2097 MODULE_DEVICE_TABLE(pci
, cx8800_pci_tbl
);
2099 static struct pci_driver cx8800_pci_driver
= {
2101 .id_table
= cx8800_pci_tbl
,
2102 .probe
= cx8800_initdev
,
2103 .remove
= __devexit_p(cx8800_finidev
),
2105 .suspend
= cx8800_suspend
,
2106 .resume
= cx8800_resume
,
2110 static int cx8800_init(void)
2112 printk(KERN_INFO
"cx88/0: cx2388x v4l2 driver version %d.%d.%d loaded\n",
2113 (CX88_VERSION_CODE
>> 16) & 0xff,
2114 (CX88_VERSION_CODE
>> 8) & 0xff,
2115 CX88_VERSION_CODE
& 0xff);
2117 printk(KERN_INFO
"cx2388x: snapshot date %04d-%02d-%02d\n",
2118 SNAPSHOT
/10000, (SNAPSHOT
/100)%100, SNAPSHOT
%100);
2120 return pci_register_driver(&cx8800_pci_driver
);
2123 static void cx8800_fini(void)
2125 pci_unregister_driver(&cx8800_pci_driver
);
2128 module_init(cx8800_init
);
2129 module_exit(cx8800_fini
);
2131 /* ----------------------------------------------------------- */
2136 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off