From patchwork Fri Oct 17 17:09:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 38923 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D1DCC202DB for ; Fri, 17 Oct 2014 17:11:14 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id b13sf712207wgh.8 for ; Fri, 17 Oct 2014 10:11:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=4oH3CPVAAmT5bYifTLsQDYxf3FKIXWiq11sj2orssbM=; b=Rub24PYyfpRXeOD/vzWdRLHOchZEN1vyqnhRlDMFo6MIMWVPwaFLGIp6Om06+JwDnE OmPzACZjDwlELzUgQnudXewLiWLVmazhDrvncW3IXi/41/ZJG7CME2+h2n832XCo/oxl udKgDUpdaJcSLQttov0E/KLVvslFvDJM5KsFn4ExPL7VBqkps08T6/3bSh7lQSsMdIUQ 1eEQ7F9YhN2xg6ncMVNyCHu+TnIJYW+pJHEixS75jNRT8HUPXBzpGVczqWgGSJ5uTB1+ boq56Hp1hicerXaovqUAKZAXfOLXUJeC+3qpZDzYpqLTxPep2t1l44t4GcNPZJMuFDBo 2BLw== X-Gm-Message-State: ALoCoQkyIpX1RNc8+d6QA7+hmcFIIWfW2oBkQ12CmjESE1djbCYn51oI+OZZXNZr7P1j26v+9pL5 X-Received: by 10.180.74.130 with SMTP id t2mr52426wiv.4.1413565874076; Fri, 17 Oct 2014 10:11:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.10 with SMTP id m10ls284669laj.72.gmail; Fri, 17 Oct 2014 10:11:13 -0700 (PDT) X-Received: by 10.112.148.231 with SMTP id tv7mr4489738lbb.94.1413565873921; Fri, 17 Oct 2014 10:11:13 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id w8si3022144law.7.2014.10.17.10.11.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Oct 2014 10:11:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id gi9so1043257lab.7 for ; Fri, 17 Oct 2014 10:11:13 -0700 (PDT) X-Received: by 10.152.202.135 with SMTP id ki7mr10287581lac.40.1413565873844; Fri, 17 Oct 2014 10:11:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp266854lbz; Fri, 17 Oct 2014 10:11:13 -0700 (PDT) X-Received: by 10.69.26.133 with SMTP id iy5mr9932303pbd.114.1413565872322; Fri, 17 Oct 2014 10:11:12 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si1689853pdo.55.2014.10.17.10.11.11 for ; Fri, 17 Oct 2014 10:11:12 -0700 (PDT) Received-SPF: none (google.com: linux-usb-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753644AbaJQRLI (ORCPT + 3 others); Fri, 17 Oct 2014 13:11:08 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:43993 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753474AbaJQRKX (ORCPT ); Fri, 17 Oct 2014 13:10:23 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9HHAMFX007454 for ; Fri, 17 Oct 2014 12:10:22 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9HHAMLY027754 for ; Fri, 17 Oct 2014 12:10:22 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Fri, 17 Oct 2014 12:10:22 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9HHALUC021651; Fri, 17 Oct 2014 12:10:22 -0500 From: Felipe Balbi To: Linux USB Mailing List CC: Felipe Balbi Subject: [PATCH 07/28] usb: gadget: function: uvc: make sure to balance ep enable/disable Date: Fri, 17 Oct 2014 12:09:43 -0500 Message-ID: <1413565804-13061-8-git-send-email-balbi@ti.com> X-Mailer: git-send-email 2.1.0.GIT In-Reply-To: <1413565804-13061-1-git-send-email-balbi@ti.com> References: <1413565804-13061-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If a set_alt() to the same alternate setting that's already selected is received, functions are required to reset the interface state, this means we must disable all endpoints and reenable them again. This is also documented on our kdoc for struct usb_function * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may * initialize usb_ep.driver data at this time (when it is used). * Note that setting an interface to its current altsetting resets * interface state, and that all interfaces have a disabled state. Signed-off-by: Felipe Balbi --- drivers/usb/gadget/function/f_uvc.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index e126439..e00e8b7 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c @@ -286,11 +286,12 @@ static int uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) { struct uvc_device *uvc = to_uvc(f); + struct usb_composite_dev *cdev = f->config->cdev; struct v4l2_event v4l2_event; struct uvc_event *uvc_event = (void *)&v4l2_event.u.data; int ret; - INFO(f->config->cdev, "uvc_function_set_alt(%u, %u)\n", interface, alt); + INFO(cdev, "uvc_function_set_alt(%u, %u)\n", interface, alt); if (interface == uvc->control_intf) { if (alt) @@ -299,7 +300,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) if (uvc->state == UVC_STATE_DISCONNECTED) { memset(&v4l2_event, 0, sizeof(v4l2_event)); v4l2_event.type = UVC_EVENT_CONNECT; - uvc_event->speed = f->config->cdev->gadget->speed; + uvc_event->speed = cdev->gadget->speed; v4l2_event_queue(uvc->vdev, &v4l2_event); uvc->state = UVC_STATE_CONNECTED; @@ -321,8 +322,10 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) if (uvc->state != UVC_STATE_STREAMING) return 0; - if (uvc->video.ep) + if (uvc->video.ep) { usb_ep_disable(uvc->video.ep); + uvc->video.ep->driver_data = NULL; + } memset(&v4l2_event, 0, sizeof(v4l2_event)); v4l2_event.type = UVC_EVENT_STREAMOFF; @@ -335,14 +338,22 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt) if (uvc->state != UVC_STATE_CONNECTED) return 0; - if (uvc->video.ep) { - ret = config_ep_by_speed(f->config->cdev->gadget, - &(uvc->func), uvc->video.ep); - if (ret) - return ret; - usb_ep_enable(uvc->video.ep); + if (!uvc->video.ep) + return -EINVAL; + + if (uvc->video.ep->driver_data) { + INFO(cdev, "reset UVC\n"); + usb_ep_disable(uvc->video.ep); + uvc->video.ep->driver_data = NULL; } + ret = config_ep_by_speed(f->config->cdev->gadget, + &(uvc->func), uvc->video.ep); + if (ret) + return ret; + usb_ep_enable(uvc->video.ep); + uvc->video.ep->driver_data = uvc; + memset(&v4l2_event, 0, sizeof(v4l2_event)); v4l2_event.type = UVC_EVENT_STREAMON; v4l2_event_queue(uvc->vdev, &v4l2_event);