aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-01-29 11:18:09 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-03-05 12:26:04 -0500
commit88b6ffedd90158173eb74c8f9169208277520cbc (patch)
treeae6904dd0cad6b1b6abce4bad0df5fb75d10ef86 /drivers/media/usb
parentb86d15440b683f8634c0cb26fc0861a5bc4913ac (diff)
[media] cx231xx-417: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/usb')
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-417.c213
-rw-r--r--drivers/media/usb/cx231xx/cx231xx.h2
2 files changed, 86 insertions, 129 deletions
diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index 567d7ab1663d..49c842aa1f70 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -34,6 +34,7 @@
34#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
37#include <media/v4l2-event.h>
37#include <media/cx2341x.h> 38#include <media/cx2341x.h>
38#include <media/tuner.h> 39#include <media/tuner.h>
39#include <linux/usb.h> 40#include <linux/usb.h>
@@ -744,7 +745,7 @@ static int cx231xx_mbox_func(void *priv, u32 command, int in, int out,
744 if (value != 0x12345678) { 745 if (value != 0x12345678) {
745 dprintk(3, "Firmware and/or mailbox pointer not initialized or corrupted, signature = 0x%x, cmd = %s\n", 746 dprintk(3, "Firmware and/or mailbox pointer not initialized or corrupted, signature = 0x%x, cmd = %s\n",
746 value, cmd_to_str(command)); 747 value, cmd_to_str(command));
747 return -1; 748 return -EIO;
748 } 749 }
749 750
750 /* This read looks at 32 bits, but flag is only 8 bits. 751 /* This read looks at 32 bits, but flag is only 8 bits.
@@ -754,7 +755,7 @@ static int cx231xx_mbox_func(void *priv, u32 command, int in, int out,
754 if (flag) { 755 if (flag) {
755 dprintk(3, "ERROR: Mailbox appears to be in use (%x), cmd = %s\n", 756 dprintk(3, "ERROR: Mailbox appears to be in use (%x), cmd = %s\n",
756 flag, cmd_to_str(command)); 757 flag, cmd_to_str(command));
757 return -1; 758 return -EBUSY;
758 } 759 }
759 760
760 flag |= 1; /* tell 'em we're working on it */ 761 flag |= 1; /* tell 'em we're working on it */
@@ -783,7 +784,7 @@ static int cx231xx_mbox_func(void *priv, u32 command, int in, int out,
783 break; 784 break;
784 if (time_after(jiffies, timeout)) { 785 if (time_after(jiffies, timeout)) {
785 dprintk(3, "ERROR: API Mailbox timeout\n"); 786 dprintk(3, "ERROR: API Mailbox timeout\n");
786 return -1; 787 return -EIO;
787 } 788 }
788 udelay(10); 789 udelay(10);
789 } 790 }
@@ -800,7 +801,7 @@ static int cx231xx_mbox_func(void *priv, u32 command, int in, int out,
800 flag = 0; 801 flag = 0;
801 mc417_memory_write(dev, dev->cx23417_mailbox, flag); 802 mc417_memory_write(dev, dev->cx23417_mailbox, flag);
802 803
803 return retval; 804 return 0;
804} 805}
805 806
806/* We don't need to call the API often, so using just one 807/* We don't need to call the API often, so using just one
@@ -829,6 +830,7 @@ static int cx231xx_api_cmd(struct cx231xx *dev, u32 command,
829 return err; 830 return err;
830} 831}
831 832
833
832static int cx231xx_find_mailbox(struct cx231xx *dev) 834static int cx231xx_find_mailbox(struct cx231xx *dev)
833{ 835{
834 u32 signature[4] = { 836 u32 signature[4] = {
@@ -1092,10 +1094,10 @@ static void cx231xx_codec_settings(struct cx231xx *dev)
1092 cx231xx_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, 1094 cx231xx_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
1093 dev->ts1.height, dev->ts1.width); 1095 dev->ts1.height, dev->ts1.width);
1094 1096
1095 dev->mpeg_params.width = dev->ts1.width; 1097 dev->mpeg_ctrl_handler.width = dev->ts1.width;
1096 dev->mpeg_params.height = dev->ts1.height; 1098 dev->mpeg_ctrl_handler.height = dev->ts1.height;
1097 1099
1098 cx2341x_update(dev, cx231xx_mbox_func, NULL, &dev->mpeg_params); 1100 cx2341x_handler_setup(&dev->mpeg_ctrl_handler);
1099 1101
1100 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 3, 1); 1102 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 3, 1);
1101 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 4, 1); 1103 cx231xx_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 4, 1);
@@ -1481,36 +1483,6 @@ static struct videobuf_queue_ops cx231xx_qops = {
1481 1483
1482/* ------------------------------------------------------------------ */ 1484/* ------------------------------------------------------------------ */
1483 1485
1484static const u32 *ctrl_classes[] = {
1485 cx2341x_mpeg_ctrls,
1486 NULL
1487};
1488
1489static int cx231xx_queryctrl(struct cx231xx *dev,
1490 struct v4l2_queryctrl *qctrl)
1491{
1492 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1493 if (qctrl->id == 0)
1494 return -EINVAL;
1495
1496 /* MPEG V4L2 controls */
1497 if (cx2341x_ctrl_query(&dev->mpeg_params, qctrl))
1498 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
1499
1500 return 0;
1501}
1502
1503static int cx231xx_querymenu(struct cx231xx *dev,
1504 struct v4l2_querymenu *qmenu)
1505{
1506 struct v4l2_queryctrl qctrl;
1507
1508 qctrl.id = qmenu->id;
1509 cx231xx_queryctrl(dev, &qctrl);
1510 return v4l2_ctrl_query_menu(qmenu, &qctrl,
1511 cx2341x_ctrl_get_menu(&dev->mpeg_params, qmenu->id));
1512}
1513
1514static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm) 1486static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm)
1515{ 1487{
1516 struct cx231xx_fh *fh = file->private_data; 1488 struct cx231xx_fh *fh = file->private_data;
@@ -1537,12 +1509,12 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
1537 dprintk(3, "encodernorm set to NTSC\n"); 1509 dprintk(3, "encodernorm set to NTSC\n");
1538 dev->norm = V4L2_STD_NTSC; 1510 dev->norm = V4L2_STD_NTSC;
1539 dev->ts1.height = 480; 1511 dev->ts1.height = 480;
1540 dev->mpeg_params.is_50hz = 0; 1512 cx2341x_handler_set_50hz(&dev->mpeg_ctrl_handler, false);
1541 } else { 1513 } else {
1542 dprintk(3, "encodernorm set to PAL\n"); 1514 dprintk(3, "encodernorm set to PAL\n");
1543 dev->norm = V4L2_STD_PAL_B; 1515 dev->norm = V4L2_STD_PAL_B;
1544 dev->ts1.height = 576; 1516 dev->ts1.height = 576;
1545 dev->mpeg_params.is_50hz = 1; 1517 cx2341x_handler_set_50hz(&dev->mpeg_ctrl_handler, true);
1546 } 1518 }
1547 call_all(dev, core, s_std, dev->norm); 1519 call_all(dev, core, s_std, dev->norm);
1548 /* do mode control overrides */ 1520 /* do mode control overrides */
@@ -1680,92 +1652,13 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1680 return videobuf_streamoff(&fh->vidq); 1652 return videobuf_streamoff(&fh->vidq);
1681} 1653}
1682 1654
1683static int vidioc_g_ext_ctrls(struct file *file, void *priv,
1684 struct v4l2_ext_controls *f)
1685{
1686 struct cx231xx_fh *fh = priv;
1687 struct cx231xx *dev = fh->dev;
1688
1689 dprintk(3, "enter vidioc_g_ext_ctrls()\n");
1690 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1691 return -EINVAL;
1692 dprintk(3, "exit vidioc_g_ext_ctrls()\n");
1693 return cx2341x_ext_ctrls(&dev->mpeg_params, 0, f, VIDIOC_G_EXT_CTRLS);
1694}
1695
1696static int vidioc_s_ext_ctrls(struct file *file, void *priv,
1697 struct v4l2_ext_controls *f)
1698{
1699 struct cx231xx_fh *fh = priv;
1700 struct cx231xx *dev = fh->dev;
1701 struct cx2341x_mpeg_params p;
1702 int err;
1703
1704 dprintk(3, "enter vidioc_s_ext_ctrls()\n");
1705 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1706 return -EINVAL;
1707
1708 p = dev->mpeg_params;
1709 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_TRY_EXT_CTRLS);
1710 if (err == 0) {
1711 err = cx2341x_update(dev, cx231xx_mbox_func,
1712 &dev->mpeg_params, &p);
1713 dev->mpeg_params = p;
1714 }
1715
1716 return err;
1717}
1718
1719static int vidioc_try_ext_ctrls(struct file *file, void *priv,
1720 struct v4l2_ext_controls *f)
1721{
1722 struct cx231xx_fh *fh = priv;
1723 struct cx231xx *dev = fh->dev;
1724 struct cx2341x_mpeg_params p;
1725 int err;
1726
1727 dprintk(3, "enter vidioc_try_ext_ctrls()\n");
1728 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1729 return -EINVAL;
1730
1731 p = dev->mpeg_params;
1732 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_TRY_EXT_CTRLS);
1733 dprintk(3, "exit vidioc_try_ext_ctrls() err=%d\n", err);
1734 return err;
1735}
1736
1737static int vidioc_log_status(struct file *file, void *priv) 1655static int vidioc_log_status(struct file *file, void *priv)
1738{ 1656{
1739 struct cx231xx_fh *fh = priv; 1657 struct cx231xx_fh *fh = priv;
1740 struct cx231xx *dev = fh->dev; 1658 struct cx231xx *dev = fh->dev;
1741 char name[32 + 2];
1742 1659
1743 snprintf(name, sizeof(name), "%s/2", dev->name);
1744 call_all(dev, core, log_status); 1660 call_all(dev, core, log_status);
1745 cx2341x_log_status(&dev->mpeg_params, name); 1661 return v4l2_ctrl_log_status(file, priv);
1746 return 0;
1747}
1748
1749static int vidioc_querymenu(struct file *file, void *priv,
1750 struct v4l2_querymenu *a)
1751{
1752 struct cx231xx_fh *fh = priv;
1753 struct cx231xx *dev = fh->dev;
1754
1755 dprintk(3, "enter vidioc_querymenu()\n");
1756 dprintk(3, "exit vidioc_querymenu()\n");
1757 return cx231xx_querymenu(dev, a);
1758}
1759
1760static int vidioc_queryctrl(struct file *file, void *priv,
1761 struct v4l2_queryctrl *c)
1762{
1763 struct cx231xx_fh *fh = priv;
1764 struct cx231xx *dev = fh->dev;
1765
1766 dprintk(3, "enter vidioc_queryctrl()\n");
1767 dprintk(3, "exit vidioc_queryctrl()\n");
1768 return cx231xx_queryctrl(dev, c);
1769} 1662}
1770 1663
1771static int mpeg_open(struct file *file) 1664static int mpeg_open(struct file *file)
@@ -1885,9 +1778,23 @@ static ssize_t mpeg_read(struct file *file, char __user *data,
1885static unsigned int mpeg_poll(struct file *file, 1778static unsigned int mpeg_poll(struct file *file,
1886 struct poll_table_struct *wait) 1779 struct poll_table_struct *wait)
1887{ 1780{
1781 unsigned long req_events = poll_requested_events(wait);
1888 struct cx231xx_fh *fh = file->private_data; 1782 struct cx231xx_fh *fh = file->private_data;
1783 struct cx231xx *dev = fh->dev;
1784 unsigned int res = 0;
1889 1785
1890 return videobuf_poll_stream(file, &fh->vidq, wait); 1786 if (v4l2_event_pending(&fh->fh))
1787 res |= POLLPRI;
1788 else
1789 poll_wait(file, &fh->fh.wait, wait);
1790
1791 if (!(req_events & (POLLIN | POLLRDNORM)))
1792 return res;
1793
1794 mutex_lock(&dev->lock);
1795 res |= videobuf_poll_stream(file, &fh->vidq, wait);
1796 mutex_unlock(&dev->lock);
1797 return res;
1891} 1798}
1892 1799
1893static int mpeg_mmap(struct file *file, struct vm_area_struct *vma) 1800static int mpeg_mmap(struct file *file, struct vm_area_struct *vma)
@@ -1932,17 +1839,14 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1932 .vidioc_dqbuf = vidioc_dqbuf, 1839 .vidioc_dqbuf = vidioc_dqbuf,
1933 .vidioc_streamon = vidioc_streamon, 1840 .vidioc_streamon = vidioc_streamon,
1934 .vidioc_streamoff = vidioc_streamoff, 1841 .vidioc_streamoff = vidioc_streamoff,
1935 .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
1936 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1937 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1938 .vidioc_log_status = vidioc_log_status, 1842 .vidioc_log_status = vidioc_log_status,
1939 .vidioc_querymenu = vidioc_querymenu,
1940 .vidioc_queryctrl = vidioc_queryctrl,
1941 .vidioc_g_chip_ident = cx231xx_g_chip_ident, 1843 .vidioc_g_chip_ident = cx231xx_g_chip_ident,
1942#ifdef CONFIG_VIDEO_ADV_DEBUG 1844#ifdef CONFIG_VIDEO_ADV_DEBUG
1943 .vidioc_g_register = cx231xx_g_register, 1845 .vidioc_g_register = cx231xx_g_register,
1944 .vidioc_s_register = cx231xx_s_register, 1846 .vidioc_s_register = cx231xx_s_register,
1945#endif 1847#endif
1848 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1849 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1946}; 1850};
1947 1851
1948static struct video_device cx231xx_mpeg_template = { 1852static struct video_device cx231xx_mpeg_template = {
@@ -1950,7 +1854,7 @@ static struct video_device cx231xx_mpeg_template = {
1950 .fops = &mpeg_fops, 1854 .fops = &mpeg_fops,
1951 .ioctl_ops = &mpeg_ioctl_ops, 1855 .ioctl_ops = &mpeg_ioctl_ops,
1952 .minor = -1, 1856 .minor = -1,
1953 .tvnorms = CX231xx_NORMS, 1857 .tvnorms = V4L2_STD_ALL,
1954}; 1858};
1955 1859
1956void cx231xx_417_unregister(struct cx231xx *dev) 1860void cx231xx_417_unregister(struct cx231xx *dev)
@@ -1963,10 +1867,44 @@ void cx231xx_417_unregister(struct cx231xx *dev)
1963 video_unregister_device(dev->v4l_device); 1867 video_unregister_device(dev->v4l_device);
1964 else 1868 else
1965 video_device_release(dev->v4l_device); 1869 video_device_release(dev->v4l_device);
1870 v4l2_ctrl_handler_free(&dev->mpeg_ctrl_handler.hdl);
1966 dev->v4l_device = NULL; 1871 dev->v4l_device = NULL;
1967 } 1872 }
1968} 1873}
1969 1874
1875static int cx231xx_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
1876{
1877 struct cx231xx *dev = container_of(cxhdl, struct cx231xx, mpeg_ctrl_handler);
1878 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
1879 struct v4l2_mbus_framefmt fmt;
1880
1881 /* fix videodecoder resolution */
1882 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
1883 fmt.height = cxhdl->height;
1884 fmt.code = V4L2_MBUS_FMT_FIXED;
1885 v4l2_subdev_call(dev->sd_cx25840, video, s_mbus_fmt, &fmt);
1886 return 0;
1887}
1888
1889static int cx231xx_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
1890{
1891 static const u32 freqs[3] = { 44100, 48000, 32000 };
1892 struct cx231xx *dev = container_of(cxhdl, struct cx231xx, mpeg_ctrl_handler);
1893
1894 /* The audio clock of the digitizer must match the codec sample
1895 rate otherwise you get some very strange effects. */
1896 if (idx < ARRAY_SIZE(freqs))
1897 call_all(dev, audio, s_clock_freq, freqs[idx]);
1898 return 0;
1899}
1900
1901static struct cx2341x_handler_ops cx231xx_ops = {
1902 /* needed for the video clock freq */
1903 .s_audio_sampling_freq = cx231xx_s_audio_sampling_freq,
1904 /* needed for setting up the video resolution */
1905 .s_video_encoding = cx231xx_s_video_encoding,
1906};
1907
1970static struct video_device *cx231xx_video_dev_alloc( 1908static struct video_device *cx231xx_video_dev_alloc(
1971 struct cx231xx *dev, 1909 struct cx231xx *dev,
1972 struct usb_device *usbdev, 1910 struct usb_device *usbdev,
@@ -1987,6 +1925,7 @@ static struct video_device *cx231xx_video_dev_alloc(
1987 vfd->lock = &dev->lock; 1925 vfd->lock = &dev->lock;
1988 vfd->release = video_device_release; 1926 vfd->release = video_device_release;
1989 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags); 1927 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
1928 vfd->ctrl_handler = &dev->mpeg_ctrl_handler.hdl;
1990 video_set_drvdata(vfd, dev); 1929 video_set_drvdata(vfd, dev);
1991 if (dev->tuner_type == TUNER_ABSENT) { 1930 if (dev->tuner_type == TUNER_ABSENT) {
1992 v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY); 1931 v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY);
@@ -2016,10 +1955,27 @@ int cx231xx_417_register(struct cx231xx *dev)
2016 tsport->height = 576; 1955 tsport->height = 576;
2017 1956
2018 tsport->width = 720; 1957 tsport->width = 720;
2019 cx2341x_fill_defaults(&dev->mpeg_params); 1958 err = cx2341x_handler_init(&dev->mpeg_ctrl_handler, 50);
1959 if (err) {
1960 dprintk(3, "%s: can't init cx2341x controls\n", dev->name);
1961 return err;
1962 }
1963 dev->mpeg_ctrl_handler.func = cx231xx_mbox_func;
1964 dev->mpeg_ctrl_handler.priv = dev;
1965 dev->mpeg_ctrl_handler.ops = &cx231xx_ops;
1966 if (dev->sd_cx25840)
1967 v4l2_ctrl_add_handler(&dev->mpeg_ctrl_handler.hdl,
1968 dev->sd_cx25840->ctrl_handler, NULL);
1969 if (dev->mpeg_ctrl_handler.hdl.error) {
1970 err = dev->mpeg_ctrl_handler.hdl.error;
1971 dprintk(3, "%s: can't add cx25840 controls\n", dev->name);
1972 v4l2_ctrl_handler_free(&dev->mpeg_ctrl_handler.hdl);
1973 return err;
1974 }
2020 dev->norm = V4L2_STD_NTSC; 1975 dev->norm = V4L2_STD_NTSC;
2021 1976
2022 dev->mpeg_params.port = CX2341X_PORT_SERIAL; 1977 dev->mpeg_ctrl_handler.port = CX2341X_PORT_SERIAL;
1978 cx2341x_handler_set_50hz(&dev->mpeg_ctrl_handler, false);
2023 1979
2024 /* Allocate and initialize V4L video device */ 1980 /* Allocate and initialize V4L video device */
2025 dev->v4l_device = cx231xx_video_dev_alloc(dev, 1981 dev->v4l_device = cx231xx_video_dev_alloc(dev,
@@ -2028,6 +1984,7 @@ int cx231xx_417_register(struct cx231xx *dev)
2028 VFL_TYPE_GRABBER, -1); 1984 VFL_TYPE_GRABBER, -1);
2029 if (err < 0) { 1985 if (err < 0) {
2030 dprintk(3, "%s: can't register mpeg device\n", dev->name); 1986 dprintk(3, "%s: can't register mpeg device\n", dev->name);
1987 v4l2_ctrl_handler_free(&dev->mpeg_ctrl_handler.hdl);
2031 return err; 1988 return err;
2032 } 1989 }
2033 1990
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index 6130e4f5924d..0f92fd1ea794 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -612,6 +612,7 @@ struct cx231xx {
612 struct v4l2_subdev *sd_tuner; 612 struct v4l2_subdev *sd_tuner;
613 struct v4l2_ctrl_handler ctrl_handler; 613 struct v4l2_ctrl_handler ctrl_handler;
614 struct v4l2_ctrl_handler radio_ctrl_handler; 614 struct v4l2_ctrl_handler radio_ctrl_handler;
615 struct cx2341x_handler mpeg_ctrl_handler;
615 616
616 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */ 617 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
617 atomic_t stream_started; /* stream should be running if true */ 618 atomic_t stream_started; /* stream should be running if true */
@@ -715,7 +716,6 @@ struct cx231xx {
715 u8 USE_ISO; 716 u8 USE_ISO;
716 struct cx231xx_tvnorm encodernorm; 717 struct cx231xx_tvnorm encodernorm;
717 struct cx231xx_tsport ts1, ts2; 718 struct cx231xx_tsport ts1, ts2;
718 struct cx2341x_mpeg_params mpeg_params;
719 struct video_device *v4l_device; 719 struct video_device *v4l_device;
720 atomic_t v4l_reader_count; 720 atomic_t v4l_reader_count;
721 u32 freq; 721 u32 freq;