From patchwork Thu Mar 13 12:38:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Manley X-Patchwork-Id: 23047 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1WO4ur-0003rR-T0; Thu, 13 Mar 2014 13:39:18 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-5) with esmtp id 1WO4up-0003jh-8a; Thu, 13 Mar 2014 13:39:17 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752419AbaCMMjL (ORCPT + 1 other); Thu, 13 Mar 2014 08:39:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:57589 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752373AbaCMMjK (ORCPT ); Thu, 13 Mar 2014 08:39:10 -0400 Received: from compute1.internal (compute1.nyi.mail.srv.osa [10.202.2.41]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 6879B207E8 for ; Thu, 13 Mar 2014 08:39:09 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Thu, 13 Mar 2014 08:39:09 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=williammanley.net; h=from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=q9U193hvpAsRFObpgy6Hx9j/83Q=; b=AIJBmSzoLy1xqA3kgWsoE qcFDgBBE/JIMjZXIBZSJgnqj43s/Gx0zrKhk0lVuE1cnPW5OE+XwGH7tYgdnMCky RDsEGCbyZPC2DCfzUYWfKfWB2x0DzfigG57h7olk2kOCX1c/PS9xvu6xW0JLPJDb to4wVRpAG7uZdN/wjLZQnI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:date:message-id :in-reply-to:references; s=smtpout; bh=q9U193hvpAsRFObpgy6Hx9j/8 3Q=; b=I3yBiMhliTk/lnnpD6FpokF0kProwlEk0ej7ZFVyQFMcJ3Q42OXWjj8gi SX1fAV++M/RMMLtskKoTtInqr11nDYJqnBNNms3I3v5R76SQhnXBbC61nJERQgpa LFX+GmsfP1Kc5hI7R9w7QztrEeR7wc59dxw1YdQRONE0+zqeeY= X-Sasl-enc: kksnWeXv26iDzaIHHrXqBCSVOe2XFiG/FFF0KvujXnDn 1394714349 Received: from localhost.localdomain (unknown [86.26.230.106]) by mail.messagingengine.com (Postfix) with ESMTPA id A4B04C007AC; Thu, 13 Mar 2014 08:39:08 -0400 (EDT) From: William Manley To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, William Manley Subject: [PATCH v2] uvcvideo: Work around buggy Logitech C920 firmware Date: Thu, 13 Mar 2014 12:38:48 +0000 Message-Id: <1394714328-29969-1-git-send-email-will@williammanley.net> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394647711-25291-1-git-send-email-will@williammanley.net> References: <1394647711-25291-1-git-send-email-will@williammanley.net> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2014.3.13.122717 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_4000_4999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DKIM_SIGNATURE 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_MEDIA_BODY 0, __CP_URI_IN_BODY 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SXL_RIP_ERROR_SERVFAIL , __SXL_SIG_ERROR_SERVFAIL , __SXL_URI_ERROR_SERVFAIL , __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' The uvcvideo webcam driver exposes the v4l2 control "Exposure (Absolute)" which allows the user to control the exposure time of the webcam, essentially controlling the brightness of the received image. By default the webcam automatically adjusts the exposure time automatically but the if you set the control "Exposure, Auto"="Manual Mode" the user can fix the exposure time. Unfortunately it seems that the Logitech C920 has a firmware bug where it will forget that it's in manual mode temporarily during initialisation. This means that the camera doesn't respect the exposure time that the user requested if they request it before starting to stream video. They end up with a video stream which is either too bright or too dark and must reset the controls after video starts streaming. This patch introduces the quirk UVC_QUIRK_RESTORE_CTRLS_ON_INIT which causes the cached controls to be re-uploaded to the camera immediately after initialising the camera. This quirk is applied to the C920 to work around this camera bug. Changes since patch v1: * Introduce quirk so workaround is only applied to the C920. Signed-off-by: William Manley --- drivers/media/usb/uvc/uvc_ctrl.c | 2 +- drivers/media/usb/uvc/uvc_driver.c | 11 ++++++++++- drivers/media/usb/uvc/uvc_video.c | 6 ++++++ drivers/media/usb/uvc/uvcvideo.h | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index a2f4501..f72d7eb 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1795,7 +1795,7 @@ done: * - Handle restore order (Auto-Exposure Mode should be restored before * Exposure Time). */ -int uvc_ctrl_resume_device(struct uvc_device *dev) +int uvc_ctrl_restore_values(struct uvc_device *dev) { struct uvc_control *ctrl; struct uvc_entity *entity; diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c3bb250..d3a9c3b 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1981,7 +1981,7 @@ static int __uvc_resume(struct usb_interface *intf, int reset) int ret = 0; if (reset) { - ret = uvc_ctrl_resume_device(dev); + ret = uvc_ctrl_restore_values(dev); if (ret < 0) return ret; } @@ -2156,6 +2156,15 @@ static struct usb_device_id uvc_ids[] = { .bInterfaceClass = USB_CLASS_VENDOR_SPEC, .bInterfaceSubClass = 1, .bInterfaceProtocol = 0 }, + /* Logitech HD Pro Webcam C920 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x046d, + .idProduct = 0x082d, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_QUIRK_RESTORE_CTRLS_ON_INIT }, /* Chicony CNF7129 (Asus EEE 100HE) */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 3394c34..85ff6b8 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1660,6 +1660,12 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) } } + /* The Logitech C920 temporarily forgets that it should not be + adjusting Exposure Absolute during init so restore controls to + stored values. */ + if (stream->dev->quirks & UVC_QUIRK_RESTORE_CTRLS_ON_INIT) + uvc_ctrl_restore_values(stream->dev); + return 0; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 9e35982..0f54376 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -137,6 +137,7 @@ #define UVC_QUIRK_FIX_BANDWIDTH 0x00000080 #define UVC_QUIRK_PROBE_DEF 0x00000100 #define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200 +#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 @@ -676,7 +677,7 @@ extern int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, const struct uvc_control_mapping *mapping); extern int uvc_ctrl_init_device(struct uvc_device *dev); extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); -extern int uvc_ctrl_resume_device(struct uvc_device *dev); +extern int uvc_ctrl_restore_values(struct uvc_device *dev); extern int uvc_ctrl_begin(struct uvc_video_chain *chain); extern int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,