diff options
Diffstat (limited to 'drivers/media/video/gspca/gspca.c')
-rw-r--r-- | drivers/media/video/gspca/gspca.c | 119 |
1 files changed, 80 insertions, 39 deletions
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c index 15d302b28b79..7be69284da03 100644 --- a/drivers/media/video/gspca/gspca.c +++ b/drivers/media/video/gspca/gspca.c | |||
@@ -114,7 +114,10 @@ static void fill_frame(struct gspca_dev *gspca_dev, | |||
114 | cam_pkt_op pkt_scan; | 114 | cam_pkt_op pkt_scan; |
115 | 115 | ||
116 | if (urb->status != 0) { | 116 | if (urb->status != 0) { |
117 | PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); | 117 | #ifdef CONFIG_PM |
118 | if (!gspca_dev->frozen) | ||
119 | #endif | ||
120 | PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); | ||
118 | return; /* disconnection ? */ | 121 | return; /* disconnection ? */ |
119 | } | 122 | } |
120 | pkt_scan = gspca_dev->sd_desc->pkt_scan; | 123 | pkt_scan = gspca_dev->sd_desc->pkt_scan; |
@@ -555,10 +558,12 @@ static void gspca_stream_off(struct gspca_dev *gspca_dev) | |||
555 | gspca_dev->streaming = 0; | 558 | gspca_dev->streaming = 0; |
556 | atomic_set(&gspca_dev->nevent, 0); | 559 | atomic_set(&gspca_dev->nevent, 0); |
557 | if (gspca_dev->present) { | 560 | if (gspca_dev->present) { |
558 | gspca_dev->sd_desc->stopN(gspca_dev); | 561 | if (gspca_dev->sd_desc->stopN) |
562 | gspca_dev->sd_desc->stopN(gspca_dev); | ||
559 | destroy_urbs(gspca_dev); | 563 | destroy_urbs(gspca_dev); |
560 | gspca_set_alt0(gspca_dev); | 564 | gspca_set_alt0(gspca_dev); |
561 | gspca_dev->sd_desc->stop0(gspca_dev); | 565 | if (gspca_dev->sd_desc->stop0) |
566 | gspca_dev->sd_desc->stop0(gspca_dev); | ||
562 | PDEBUG(D_STREAM, "stream off OK"); | 567 | PDEBUG(D_STREAM, "stream off OK"); |
563 | } | 568 | } |
564 | } | 569 | } |
@@ -767,19 +772,7 @@ static int dev_open(struct inode *inode, struct file *file) | |||
767 | goto out; | 772 | goto out; |
768 | } | 773 | } |
769 | 774 | ||
770 | /* if not done yet, initialize the sensor */ | 775 | if (gspca_dev->users > 4) { /* (arbitrary value) */ |
771 | if (gspca_dev->users == 0) { | ||
772 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) { | ||
773 | ret = -ERESTARTSYS; | ||
774 | goto out; | ||
775 | } | ||
776 | ret = gspca_dev->sd_desc->open(gspca_dev); | ||
777 | mutex_unlock(&gspca_dev->usb_lock); | ||
778 | if (ret != 0) { | ||
779 | PDEBUG(D_ERR|D_CONF, "init device failed %d", ret); | ||
780 | goto out; | ||
781 | } | ||
782 | } else if (gspca_dev->users > 4) { /* (arbitrary value) */ | ||
783 | ret = -EBUSY; | 776 | ret = -EBUSY; |
784 | goto out; | 777 | goto out; |
785 | } | 778 | } |
@@ -792,6 +785,7 @@ static int dev_open(struct inode *inode, struct file *file) | |||
792 | else | 785 | else |
793 | gspca_dev->vdev.debug &= ~3; | 786 | gspca_dev->vdev.debug &= ~3; |
794 | #endif | 787 | #endif |
788 | ret = 0; | ||
795 | out: | 789 | out: |
796 | mutex_unlock(&gspca_dev->queue_lock); | 790 | mutex_unlock(&gspca_dev->queue_lock); |
797 | if (ret != 0) | 791 | if (ret != 0) |
@@ -812,11 +806,11 @@ static int dev_close(struct inode *inode, struct file *file) | |||
812 | 806 | ||
813 | /* if the file did the capture, free the streaming resources */ | 807 | /* if the file did the capture, free the streaming resources */ |
814 | if (gspca_dev->capt_file == file) { | 808 | if (gspca_dev->capt_file == file) { |
815 | mutex_lock(&gspca_dev->usb_lock); | 809 | if (gspca_dev->streaming) { |
816 | if (gspca_dev->streaming) | 810 | mutex_lock(&gspca_dev->usb_lock); |
817 | gspca_stream_off(gspca_dev); | 811 | gspca_stream_off(gspca_dev); |
818 | gspca_dev->sd_desc->close(gspca_dev); | 812 | mutex_unlock(&gspca_dev->usb_lock); |
819 | mutex_unlock(&gspca_dev->usb_lock); | 813 | } |
820 | frame_free(gspca_dev); | 814 | frame_free(gspca_dev); |
821 | gspca_dev->capt_file = NULL; | 815 | gspca_dev->capt_file = NULL; |
822 | gspca_dev->memory = GSPCA_MEMORY_NO; | 816 | gspca_dev->memory = GSPCA_MEMORY_NO; |
@@ -853,42 +847,44 @@ static int vidioc_querycap(struct file *file, void *priv, | |||
853 | return 0; | 847 | return 0; |
854 | } | 848 | } |
855 | 849 | ||
856 | /* the use of V4L2_CTRL_FLAG_NEXT_CTRL asks for the controls to be sorted */ | ||
857 | static int vidioc_queryctrl(struct file *file, void *priv, | 850 | static int vidioc_queryctrl(struct file *file, void *priv, |
858 | struct v4l2_queryctrl *q_ctrl) | 851 | struct v4l2_queryctrl *q_ctrl) |
859 | { | 852 | { |
860 | struct gspca_dev *gspca_dev = priv; | 853 | struct gspca_dev *gspca_dev = priv; |
861 | int i; | 854 | int i, ix; |
862 | u32 id; | 855 | u32 id; |
863 | 856 | ||
857 | ix = -1; | ||
864 | id = q_ctrl->id; | 858 | id = q_ctrl->id; |
865 | if (id & V4L2_CTRL_FLAG_NEXT_CTRL) { | 859 | if (id & V4L2_CTRL_FLAG_NEXT_CTRL) { |
866 | id &= V4L2_CTRL_ID_MASK; | 860 | id &= V4L2_CTRL_ID_MASK; |
867 | id++; | 861 | id++; |
868 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { | 862 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { |
869 | if (id >= gspca_dev->sd_desc->ctrls[i].qctrl.id) { | 863 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id < id) |
870 | memcpy(q_ctrl, | 864 | continue; |
871 | &gspca_dev->sd_desc->ctrls[i].qctrl, | 865 | if (ix < 0) { |
872 | sizeof *q_ctrl); | 866 | ix = i; |
873 | return 0; | 867 | continue; |
874 | } | 868 | } |
869 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id | ||
870 | > gspca_dev->sd_desc->ctrls[ix].qctrl.id) | ||
871 | continue; | ||
872 | ix = i; | ||
875 | } | 873 | } |
876 | return -EINVAL; | ||
877 | } | 874 | } |
878 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { | 875 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { |
879 | if (id == gspca_dev->sd_desc->ctrls[i].qctrl.id) { | 876 | if (id == gspca_dev->sd_desc->ctrls[i].qctrl.id) { |
880 | memcpy(q_ctrl, | 877 | ix = i; |
881 | &gspca_dev->sd_desc->ctrls[i].qctrl, | 878 | break; |
882 | sizeof *q_ctrl); | ||
883 | return 0; | ||
884 | } | 879 | } |
885 | } | 880 | } |
886 | if (id >= V4L2_CID_BASE | 881 | if (ix < 0) |
887 | && id <= V4L2_CID_LASTP1) { | 882 | return -EINVAL; |
883 | memcpy(q_ctrl, &gspca_dev->sd_desc->ctrls[ix].qctrl, | ||
884 | sizeof *q_ctrl); | ||
885 | if (gspca_dev->ctrl_dis & (1 << ix)) | ||
888 | q_ctrl->flags |= V4L2_CTRL_FLAG_DISABLED; | 886 | q_ctrl->flags |= V4L2_CTRL_FLAG_DISABLED; |
889 | return 0; | 887 | return 0; |
890 | } | ||
891 | return -EINVAL; | ||
892 | } | 888 | } |
893 | 889 | ||
894 | static int vidioc_s_ctrl(struct file *file, void *priv, | 890 | static int vidioc_s_ctrl(struct file *file, void *priv, |
@@ -903,6 +899,8 @@ static int vidioc_s_ctrl(struct file *file, void *priv, | |||
903 | i++, ctrls++) { | 899 | i++, ctrls++) { |
904 | if (ctrl->id != ctrls->qctrl.id) | 900 | if (ctrl->id != ctrls->qctrl.id) |
905 | continue; | 901 | continue; |
902 | if (gspca_dev->ctrl_dis & (1 << i)) | ||
903 | return -EINVAL; | ||
906 | if (ctrl->value < ctrls->qctrl.minimum | 904 | if (ctrl->value < ctrls->qctrl.minimum |
907 | || ctrl->value > ctrls->qctrl.maximum) | 905 | || ctrl->value > ctrls->qctrl.maximum) |
908 | return -ERANGE; | 906 | return -ERANGE; |
@@ -929,6 +927,8 @@ static int vidioc_g_ctrl(struct file *file, void *priv, | |||
929 | i++, ctrls++) { | 927 | i++, ctrls++) { |
930 | if (ctrl->id != ctrls->qctrl.id) | 928 | if (ctrl->id != ctrls->qctrl.id) |
931 | continue; | 929 | continue; |
930 | if (gspca_dev->ctrl_dis & (1 << i)) | ||
931 | return -EINVAL; | ||
932 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) | 932 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
933 | return -ERESTARTSYS; | 933 | return -ERESTARTSYS; |
934 | ret = ctrls->get(gspca_dev, &ctrl->value); | 934 | ret = ctrls->get(gspca_dev, &ctrl->value); |
@@ -1403,7 +1403,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, | |||
1403 | i = ret; /* frame index */ | 1403 | i = ret; /* frame index */ |
1404 | frame = &gspca_dev->frame[i]; | 1404 | frame = &gspca_dev->frame[i]; |
1405 | if (gspca_dev->memory == V4L2_MEMORY_USERPTR) { | 1405 | if (gspca_dev->memory == V4L2_MEMORY_USERPTR) { |
1406 | if (copy_to_user((__u8 *) frame->v4l2_buf.m.userptr, | 1406 | if (copy_to_user((__u8 __user *) frame->v4l2_buf.m.userptr, |
1407 | frame->data, | 1407 | frame->data, |
1408 | frame->v4l2_buf.bytesused)) { | 1408 | frame->v4l2_buf.bytesused)) { |
1409 | PDEBUG(D_ERR|D_STREAM, | 1409 | PDEBUG(D_ERR|D_STREAM, |
@@ -1731,6 +1731,12 @@ int gspca_dev_probe(struct usb_interface *intf, | |||
1731 | err("couldn't kzalloc gspca struct"); | 1731 | err("couldn't kzalloc gspca struct"); |
1732 | return -EIO; | 1732 | return -EIO; |
1733 | } | 1733 | } |
1734 | gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL); | ||
1735 | if (!gspca_dev->usb_buf) { | ||
1736 | err("out of memory"); | ||
1737 | ret = -EIO; | ||
1738 | goto out; | ||
1739 | } | ||
1734 | gspca_dev->dev = dev; | 1740 | gspca_dev->dev = dev; |
1735 | gspca_dev->iface = interface->bInterfaceNumber; | 1741 | gspca_dev->iface = interface->bInterfaceNumber; |
1736 | gspca_dev->nbalt = intf->num_altsetting; | 1742 | gspca_dev->nbalt = intf->num_altsetting; |
@@ -1738,10 +1744,13 @@ int gspca_dev_probe(struct usb_interface *intf, | |||
1738 | /* gspca_dev->users = 0; (done by kzalloc) */ | 1744 | /* gspca_dev->users = 0; (done by kzalloc) */ |
1739 | gspca_dev->nbufread = 2; | 1745 | gspca_dev->nbufread = 2; |
1740 | 1746 | ||
1741 | /* configure the subdriver */ | 1747 | /* configure the subdriver and initialize the USB device */ |
1742 | ret = gspca_dev->sd_desc->config(gspca_dev, id); | 1748 | ret = gspca_dev->sd_desc->config(gspca_dev, id); |
1743 | if (ret < 0) | 1749 | if (ret < 0) |
1744 | goto out; | 1750 | goto out; |
1751 | ret = gspca_dev->sd_desc->init(gspca_dev); | ||
1752 | if (ret < 0) | ||
1753 | goto out; | ||
1745 | ret = gspca_set_alt0(gspca_dev); | 1754 | ret = gspca_set_alt0(gspca_dev); |
1746 | if (ret < 0) | 1755 | if (ret < 0) |
1747 | goto out; | 1756 | goto out; |
@@ -1771,6 +1780,7 @@ int gspca_dev_probe(struct usb_interface *intf, | |||
1771 | PDEBUG(D_PROBE, "probe ok"); | 1780 | PDEBUG(D_PROBE, "probe ok"); |
1772 | return 0; | 1781 | return 0; |
1773 | out: | 1782 | out: |
1783 | kfree(gspca_dev->usb_buf); | ||
1774 | kfree(gspca_dev); | 1784 | kfree(gspca_dev); |
1775 | return ret; | 1785 | return ret; |
1776 | } | 1786 | } |
@@ -1803,11 +1813,42 @@ void gspca_disconnect(struct usb_interface *intf) | |||
1803 | /* We don't want people trying to open up the device */ | 1813 | /* We don't want people trying to open up the device */ |
1804 | video_unregister_device(&gspca_dev->vdev); | 1814 | video_unregister_device(&gspca_dev->vdev); |
1805 | /* Free the memory */ | 1815 | /* Free the memory */ |
1816 | kfree(gspca_dev->usb_buf); | ||
1806 | kfree(gspca_dev); | 1817 | kfree(gspca_dev); |
1807 | PDEBUG(D_PROBE, "disconnect complete"); | 1818 | PDEBUG(D_PROBE, "disconnect complete"); |
1808 | } | 1819 | } |
1809 | EXPORT_SYMBOL(gspca_disconnect); | 1820 | EXPORT_SYMBOL(gspca_disconnect); |
1810 | 1821 | ||
1822 | #ifdef CONFIG_PM | ||
1823 | int gspca_suspend(struct usb_interface *intf, pm_message_t message) | ||
1824 | { | ||
1825 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); | ||
1826 | |||
1827 | if (!gspca_dev->streaming) | ||
1828 | return 0; | ||
1829 | gspca_dev->frozen = 1; /* avoid urb error messages */ | ||
1830 | if (gspca_dev->sd_desc->stopN) | ||
1831 | gspca_dev->sd_desc->stopN(gspca_dev); | ||
1832 | destroy_urbs(gspca_dev); | ||
1833 | gspca_set_alt0(gspca_dev); | ||
1834 | if (gspca_dev->sd_desc->stop0) | ||
1835 | gspca_dev->sd_desc->stop0(gspca_dev); | ||
1836 | return 0; | ||
1837 | } | ||
1838 | EXPORT_SYMBOL(gspca_suspend); | ||
1839 | |||
1840 | int gspca_resume(struct usb_interface *intf) | ||
1841 | { | ||
1842 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); | ||
1843 | |||
1844 | gspca_dev->frozen = 0; | ||
1845 | gspca_dev->sd_desc->init(gspca_dev); | ||
1846 | if (gspca_dev->streaming) | ||
1847 | return gspca_init_transfer(gspca_dev); | ||
1848 | return 0; | ||
1849 | } | ||
1850 | EXPORT_SYMBOL(gspca_resume); | ||
1851 | #endif | ||
1811 | /* -- cam driver utility functions -- */ | 1852 | /* -- cam driver utility functions -- */ |
1812 | 1853 | ||
1813 | /* auto gain and exposure algorithm based on the knee algorithm described here: | 1854 | /* auto gain and exposure algorithm based on the knee algorithm described here: |