29 #include <linux/list.h>
30 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/slab.h>
38 #include <asm/div64.h>
65 static unsigned int video_debug;
69 static unsigned int irq_debug;
77 #define dprintk(level,fmt, arg...) if (video_debug >= level) \
78 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
85 .name =
"8 bpp, gray",
91 .name =
"15 bpp RGB, le",
97 .name =
"15 bpp RGB, be",
103 .name =
"16 bpp RGB, le",
109 .name =
"16 bpp RGB, be",
115 .name =
"24 bpp RGB, le",
121 .name =
"32 bpp RGB, le",
127 .name =
"32 bpp RGB, be",
133 .name =
"4:2:2, packed, YUYV",
139 .name =
"4:2:2, packed, UYVY",
152 if (formats[i].fourcc == fourcc)
175 static const struct cx88_ctrl cx8800_vid_ctls[] = {
182 .default_value = 0x7f,
192 .default_value = 0x3f,
202 .default_value = 0x7f,
215 .default_value = 0x7f,
225 .default_value = 0x0,
236 .default_value = 0x1,
244 .default_value = 0x1,
253 .default_value = 0x0,
261 static const struct cx88_ctrl cx8800_aud_ctls[] = {
277 .default_value = 0x3f,
287 .default_value = 0x40,
320 dprintk(1,
"res: get %d\n",bit);
346 dprintk(1,
"res: put %d\n",bits);
356 dprintk(1,
"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
357 input,
INPUT(input).vmux,
384 if (
INPUT(input).audioroute) {
388 if (core->
board.audio_chip &&
391 INPUT(input).audioroute, 0, 0);
414 static int start_video_dma(
struct cx8800_dev *dev,
453 static int stop_video_dma(
struct cx8800_dev *dev)
470 static int restart_video_queue(
struct cx8800_dev *dev,
476 if (!list_empty(&q->
active)) {
478 dprintk(2,
"restart_queue [%p/%d]: restart dma\n",
480 start_video_dma(dev, q, buf);
489 if (list_empty(&q->
queued))
493 list_move_tail(&buf->
vb.queue, &q->
active);
494 start_video_dma(dev, q, buf);
498 dprintk(2,
"[%p/%d] restart_queue - first active\n",
501 }
else if (prev->
vb.width == buf->
vb.width &&
502 prev->
vb.height == buf->
vb.height &&
504 list_move_tail(&buf->
vb.queue, &q->
active);
508 dprintk(2,
"[%p/%d] restart_queue - move to active\n",
528 if (*size * *count > vid_limit * 1024 * 1024)
529 *count = (vid_limit * 1024 * 1024) / *size;
549 if (0 != buf->
vb.baddr && buf->
vb.bsize < buf->
vb.size)
552 if (buf->
fmt != dev->
fmt ||
555 buf->
vb.field != field) {
570 buf->
bpl = buf->
vb.width * buf->
fmt->depth >> 3;
571 switch (buf->
vb.field) {
575 buf->
bpl, 0, buf->
vb.height);
580 buf->
bpl, 0, buf->
vb.height);
586 buf->
vb.height >> 1);
591 0, buf->
bpl * (buf->
vb.height >> 1),
593 buf->
vb.height >> 1);
598 buf->
bpl * (buf->
vb.height >> 1), 0,
600 buf->
vb.height >> 1);
606 dprintk(2,
"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
609 (
unsigned long)buf->
risc.dma);
633 if (!list_empty(&q->
queued)) {
636 dprintk(2,
"[%p/%d] buffer_queue - append to queued\n",
639 }
else if (list_empty(&q->
active)) {
641 start_video_dma(dev, q, buf);
645 dprintk(2,
"[%p/%d] buffer_queue - first active\n",
650 if (prev->
vb.width == buf->
vb.width &&
651 prev->
vb.height == buf->
vb.height &&
657 dprintk(2,
"[%p/%d] buffer_queue - append to active\n",
663 dprintk(2,
"[%p/%d] buffer_queue - first queued\n",
677 .buf_setup = buffer_setup,
678 .buf_prepare = buffer_prepare,
679 .buf_queue = buffer_queue,
680 .buf_release = buffer_release,
704 static int get_resource(
struct file *file)
719 static int video_open(
struct file *file)
740 dprintk(1,
"open dev=%s radio=%d type=%s\n",
768 dprintk(1,
"video_open: setting radio device\n");
773 if (core->
board.radio.audioroute) {
774 if(core->
board.audio_chip &&
777 core->
board.radio.audioroute, 0, 0);
799 video_read(
struct file *file,
char __user *
data,
size_t count, loff_t *ppos)
837 if (list_empty(&fh->
vidq.stream))
846 poll_wait(file, &buf->
vb.done, wait);
855 static int video_release(
struct file *file)
871 if (fh->
vidq.read_buf) {
872 buffer_release(&fh->
vidq,fh->
vidq.read_buf);
892 if (!dev->
core->users)
924 value = value << 8 |
value;
927 value = (value * 0x5a) / 0x7f << 8 | value;
933 value = (ctrl->
val < 1 ? 0 : ((ctrl->
val + 3) << 7));
944 dprintk(1,
"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
946 mask, cc->
sreg ?
" [shadowed]" :
"");
954 static int cx8800_s_aud_ctrl(
struct v4l2_ctrl *ctrl)
969 (0x90 + ctrl->
val) << 8 : 0);
982 value = (ctrl->
val < 0x40) ? (0x7f - ctrl->
val) : (ctrl->
val - 0x40);
985 value = 0x3f - (ctrl->
val & 0x3f);
991 dprintk(1,
"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
993 mask, cc->
sreg ?
" [shadowed]" :
"");
1004 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *
priv,
1013 f->
fmt.
pix.pixelformat = dev->
fmt->fourcc;
1014 f->
fmt.
pix.bytesperline =
1015 (f->
fmt.
pix.width * dev->
fmt->depth) >> 3;
1022 static int vidioc_try_fmt_vid_cap(
struct file *file,
void *
priv,
1028 unsigned int maxw, maxh;
1034 field = f->
fmt.
pix.field;
1039 field = (f->
fmt.
pix.height > maxh/2)
1057 &f->
fmt.
pix.height, 32, maxh, 0, 0);
1058 f->
fmt.
pix.bytesperline =
1066 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *priv,
1071 int err = vidioc_try_fmt_vid_cap (file,priv,f);
1109 static int vidioc_querycap(
struct file *file,
void *priv,
1121 static int vidioc_enum_fmt_vid_cap (
struct file *file,
void *priv,
1138 static int vidioc_querybuf (
struct file *file,
void *priv,
struct v4l2_buffer *p)
1143 static int vidioc_qbuf (
struct file *file,
void *priv,
struct v4l2_buffer *p)
1148 static int vidioc_dqbuf (
struct file *file,
void *priv,
struct v4l2_buffer *p)
1154 static int vidioc_streamon(
struct file *file,
void *priv,
enum v4l2_buf_type i)
1164 if (
unlikely(!res_get(dev, fh, get_resource(file))))
1169 static int vidioc_streamoff(
struct file *file,
void *priv,
enum v4l2_buf_type i)
1180 res = get_resource(file);
1184 res_free(dev,fh,res);
1196 static int vidioc_s_std (
struct file *file,
void *priv,
v4l2_std_id *tvnorms)
1210 static const char *
const iname[] = {
1221 unsigned int n = i->
index;
1225 if (0 ==
INPUT(n).type)
1238 static int vidioc_enum_input (
struct file *file,
void *priv,
1245 static int vidioc_g_input (
struct file *file,
void *priv,
unsigned int *i)
1253 static int vidioc_s_input (
struct file *file,
void *priv,
unsigned int i)
1259 if (0 ==
INPUT(i).type)
1269 static int vidioc_g_tuner (
struct file *file,
void *priv,
1287 t->
signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1291 static int vidioc_s_tuner (
struct file *file,
void *priv,
1305 static int vidioc_g_frequency (
struct file *file,
void *priv,
1347 static int vidioc_s_frequency (
struct file *file,
void *priv,
1356 static int vidioc_g_chip_ident(
struct file *file,
void *priv,
1366 #ifdef CONFIG_VIDEO_ADV_DEBUG
1367 static int vidioc_g_register (
struct file *file,
void *fh,
1380 static int vidioc_s_register (
struct file *file,
void *fh,
1396 static int radio_g_tuner (
struct file *file,
void *priv,
1412 static int radio_s_tuner (
struct file *file,
void *priv,
1429 static void cx8800_vid_timeout(
unsigned long data)
1435 unsigned long flags;
1443 while (!list_empty(&q->
active)) {
1448 printk(
"%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->
name,
1449 buf, buf->
vb.i, (
unsigned long)buf->
risc.dma);
1451 restart_video_queue(dev,q);
1452 spin_unlock_irqrestore(&dev->
slock,flags);
1455 static const char *cx88_vid_irqs[32] = {
1456 "y_risci1",
"u_risci1",
"v_risci1",
"vbi_risc1",
1457 "y_risci2",
"u_risci2",
"v_risci2",
"vbi_risc2",
1458 "y_oflow",
"u_oflow",
"v_oflow",
"vbi_oflow",
1459 "y_sync",
"u_sync",
"v_sync",
"vbi_sync",
1460 "opc_err",
"par_err",
"rip_err",
"pci_abort",
1463 static void cx8800_vid_irq(
struct cx8800_dev *dev)
1470 if (0 == (status & mask))
1473 if (irq_debug || (status & mask & ~0xff))
1479 if (status & (1 << 16)) {
1487 if (status & 0x01) {
1488 spin_lock(&dev->
slock);
1491 spin_unlock(&dev->
slock);
1495 if (status & 0x08) {
1496 spin_lock(&dev->
slock);
1499 spin_unlock(&dev->
slock);
1503 if (status & 0x10) {
1505 spin_lock(&dev->
slock);
1506 restart_video_queue(dev,&dev->
vidq);
1507 spin_unlock(&dev->
slock);
1511 if (status & 0x80) {
1513 spin_lock(&dev->
slock);
1515 spin_unlock(&dev->
slock);
1524 int loop, handled = 0;
1526 for (loop = 0; loop < 10; loop++) {
1537 cx8800_vid_irq(dev);
1556 .release = video_release,
1587 #ifdef CONFIG_VIDEO_ADV_DEBUG
1588 .vidioc_g_register = vidioc_g_register,
1589 .vidioc_s_register = vidioc_s_register,
1593 static const struct video_device cx8800_video_template = {
1594 .name =
"cx8800-video",
1595 .fops = &video_fops,
1596 .ioctl_ops = &video_ioctl_ops,
1621 #ifdef CONFIG_VIDEO_ADV_DEBUG
1622 .vidioc_g_register = vidioc_g_register,
1623 .vidioc_s_register = vidioc_s_register,
1627 static const struct video_device cx8800_vbi_template = {
1628 .name =
"cx8800-vbi",
1629 .fops = &video_fops,
1630 .ioctl_ops = &vbi_ioctl_ops,
1639 .release = video_release,
1645 .vidioc_g_tuner = radio_g_tuner,
1646 .vidioc_s_tuner = radio_s_tuner,
1652 #ifdef CONFIG_VIDEO_ADV_DEBUG
1653 .vidioc_g_register = vidioc_g_register,
1654 .vidioc_s_register = vidioc_s_register,
1658 static const struct video_device cx8800_radio_template = {
1659 .name =
"cx8800-radio",
1660 .fops = &radio_fops,
1661 .ioctl_ops = &radio_ioctl_ops,
1665 .s_ctrl = cx8800_s_vid_ctrl,
1669 .s_ctrl = cx8800_s_aud_ctrl,
1674 static void cx8800_unregister_video(
struct cx8800_dev *dev)
1677 if (video_is_registered(dev->
radio_dev))
1684 if (video_is_registered(dev->
vbi_dev))
1691 if (video_is_registered(dev->
video_dev))
1728 "latency: %d, mmio: 0x%llx\n", core->
name,
1729 pci_name(pci_dev), dev->
pci_rev, pci_dev->
irq,
1734 printk(
"%s/0: Oops: no 32bit PCI DMA ???\n",core->
name);
1744 INIT_LIST_HEAD(&dev->
vidq.active);
1745 INIT_LIST_HEAD(&dev->
vidq.queued);
1746 dev->
vidq.timeout.function = cx8800_vid_timeout;
1747 dev->
vidq.timeout.data = (
unsigned long)dev;
1753 INIT_LIST_HEAD(&dev->
vbiq.active);
1754 INIT_LIST_HEAD(&dev->
vbiq.queued);
1756 dev->
vbiq.timeout.data = (
unsigned long)dev;
1772 const struct cx88_ctrl *cc = &cx8800_aud_ctls[
i];
1781 vc->
priv = (
void *)cc;
1785 const struct cx88_ctrl *cc = &cx8800_vid_ctls[
i];
1794 vc->
priv = (
void *)cc;
1816 &wm8775_info, NULL);
1837 request_module(
"rtc-isl1208");
1842 request_module(
"ir-kbd-i2c");
1846 pci_set_drvdata(pci_dev, dev);
1861 &cx8800_video_template,
"video");
1865 video_nr[core->
nr]);
1875 video_set_drvdata(dev->
vbi_dev, dev);
1884 core->
name, video_device_node_name(dev->
vbi_dev));
1888 &cx8800_radio_template,
"radio");
1892 radio_nr[core->
nr]);
1903 if (core->
board.tuner_type != TUNER_ABSENT) {
1907 printk(
KERN_ERR "%s/0: failed to create cx88 audio thread, err=%d\n",
1916 cx8800_unregister_video(dev);
1926 static void __devexit cx8800_finidev(
struct pci_dev *pci_dev)
1928 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1946 cx8800_unregister_video(dev);
1947 pci_set_drvdata(pci_dev, NULL);
1958 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1962 spin_lock(&dev->
slock);
1963 if (!list_empty(&dev->
vidq.active)) {
1965 stop_video_dma(dev);
1968 if (!list_empty(&dev->
vbiq.active)) {
1973 spin_unlock(&dev->
slock);
1983 dev->
state.disabled = 1;
1988 static int cx8800_resume(
struct pci_dev *pci_dev)
1990 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1994 if (dev->
state.disabled) {
2002 dev->
state.disabled = 0;
2008 dev->
state.disabled = 1;
2022 spin_lock(&dev->
slock);
2023 if (!list_empty(&dev->
vidq.active)) {
2025 restart_video_queue(dev,&dev->
vidq);
2027 if (!list_empty(&dev->
vbiq.active)) {
2031 spin_unlock(&dev->
slock);
2051 static struct pci_driver cx8800_pci_driver = {
2053 .id_table = cx8800_pci_tbl,
2054 .probe = cx8800_initdev,
2057 .suspend = cx8800_suspend,
2058 .resume = cx8800_resume,
2062 static int __init cx8800_init(
void)
2066 return pci_register_driver(&cx8800_pci_driver);
2069 static void __exit cx8800_fini(
void)