From patchwork Wed Apr 16 21:26:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 28504 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C3161206A6 for ; Wed, 16 Apr 2014 21:29:19 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id p10sf39057781pdj.11 for ; Wed, 16 Apr 2014 14:29:18 -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=mnfnztCrf//ohCN7KLoN+4be7Kucsh2Qesk4wOIqlCM=; b=KKEEHcYR38gsQWJ8qKv6YoQlHIllKjWsNnCHfHA5THrv21j8bhVGDStzM1ISnfonL0 lPL3pg8sutibfYBciH0I36/R8jCu6qStjJaSjeSROdxqyBuWngLKm9Vx/fgTCIPZrars P/O/e3EypX3YpMqy0MyPrZrDY4I7QNWUrUcIvQcKMgGKXwWo8XbeAbmIy5uFGcEi6dqC FNL22pM6SecmGBB9hjcGUlMu35VyNB/KFysZ219G2o/4xjr0DpPdbTWry0oIqgCdTz18 Fbj51Ldg7sBl9M3jLvArJLlMRW0zxIim0xwNYrk3HZsPH3pJ0Ot+ZO7ahIjNz/tnpWLN zUPA== X-Gm-Message-State: ALoCoQm0kGueEo75CEDu1Fo2zchBJ1XaW4esccxdaIJdLfN++pX44XRR+WTMOUhIIiTIf0Z/vF0p X-Received: by 10.66.65.109 with SMTP id w13mr5050183pas.21.1397683758763; Wed, 16 Apr 2014 14:29:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.107 with SMTP id b98ls769982qgd.64.gmail; Wed, 16 Apr 2014 14:29:18 -0700 (PDT) X-Received: by 10.52.119.178 with SMTP id kv18mr1753461vdb.39.1397683758605; Wed, 16 Apr 2014 14:29:18 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id u5si4073035vdo.76.2014.04.16.14.29.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 16 Apr 2014 14:29:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id oz11so11220710veb.5 for ; Wed, 16 Apr 2014 14:29:18 -0700 (PDT) X-Received: by 10.52.183.228 with SMTP id ep4mr3195951vdc.30.1397683758516; Wed, 16 Apr 2014 14:29:18 -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.220.221.72 with SMTP id ib8csp343907vcb; Wed, 16 Apr 2014 14:29:18 -0700 (PDT) X-Received: by 10.68.99.194 with SMTP id es2mr11243773pbb.100.1397683757724; Wed, 16 Apr 2014 14:29:17 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cq4si7607364pbc.184.2014.04.16.14.29.16; Wed, 16 Apr 2014 14:29:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756602AbaDPV3Q (ORCPT + 5 others); Wed, 16 Apr 2014 17:29:16 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:55901 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755156AbaDPV3P (ORCPT ); Wed, 16 Apr 2014 17:29:15 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s3GLSssd027736; Wed, 16 Apr 2014 16:28:54 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3GLSs3O021111; Wed, 16 Apr 2014 16:28:54 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Wed, 16 Apr 2014 16:28:54 -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 s3GLSr7h024280; Wed, 16 Apr 2014 16:28:53 -0500 From: Felipe Balbi To: Linux USB Mailing List CC: Greg KH , , Linux OMAP Mailing List , Kishon Vijay Abraham I , Roger Quadros , George Cherian , , , , , David Cohen , Felipe Balbi Subject: [PATCH 3/8] usb: dwc3: core: refactor mode initialization to its own function Date: Wed, 16 Apr 2014 16:26:30 -0500 Message-ID: <1397683595-3606-4-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.9.2.459.g68773ac In-Reply-To: <1397683595-3606-1-git-send-email-balbi@ti.com> References: <1397683595-3606-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-omap@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=neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , Move mode (Host, Peripheral, OTG) initialization to its own function in order to decrease the size of our probe() routine. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/core.c | 133 ++++++++++++++++++++++++------------------------ 1 file changed, 67 insertions(+), 66 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 38976f3..2a68aea 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -553,6 +553,69 @@ static int dwc3_core_get_phy(struct dwc3 *dwc) return 0; } +static int dwc3_core_init_mode(struct dwc3 *dwc) +{ + struct device *dev = dwc->dev; + int ret; + + switch (dwc->dr_mode) { + case USB_DR_MODE_PERIPHERAL: + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + ret = dwc3_gadget_init(dwc); + if (ret) { + dev_err(dev, "failed to initialize gadget\n"); + return ret; + } + break; + case USB_DR_MODE_HOST: + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); + ret = dwc3_host_init(dwc); + if (ret) { + dev_err(dev, "failed to initialize host\n"); + return ret; + } + break; + case USB_DR_MODE_OTG: + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); + ret = dwc3_host_init(dwc); + if (ret) { + dev_err(dev, "failed to initialize host\n"); + return ret; + } + + ret = dwc3_gadget_init(dwc); + if (ret) { + dev_err(dev, "failed to initialize gadget\n"); + return ret; + } + break; + default: + dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); + return ret; + } + + return 0; +} + +static void dwc3_core_exit_mode(struct dwc3 *dwc) +{ + switch (dwc->dr_mode) { + case USB_DR_MODE_PERIPHERAL: + dwc3_gadget_exit(dwc); + break; + case USB_DR_MODE_HOST: + dwc3_host_exit(dwc); + break; + case USB_DR_MODE_OTG: + dwc3_host_exit(dwc); + dwc3_gadget_exit(dwc); + break; + default: + /* do nothing */ + break; + } +} + #define DWC3_ALIGN_MASK (16 - 1) static int dwc3_probe(struct platform_device *pdev) @@ -682,41 +745,9 @@ static int dwc3_probe(struct platform_device *pdev) goto err_usb3phy_power; } - switch (dwc->dr_mode) { - case USB_DR_MODE_PERIPHERAL: - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); - ret = dwc3_gadget_init(dwc); - if (ret) { - dev_err(dev, "failed to initialize gadget\n"); - goto err2; - } - break; - case USB_DR_MODE_HOST: - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); - ret = dwc3_host_init(dwc); - if (ret) { - dev_err(dev, "failed to initialize host\n"); - goto err2; - } - break; - case USB_DR_MODE_OTG: - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); - ret = dwc3_host_init(dwc); - if (ret) { - dev_err(dev, "failed to initialize host\n"); - goto err2; - } - - ret = dwc3_gadget_init(dwc); - if (ret) { - dev_err(dev, "failed to initialize gadget\n"); - goto err2; - } - break; - default: - dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); + ret = dwc3_core_init_mode(dwc); + if (ret) goto err2; - } ret = dwc3_debugfs_init(dwc); if (ret) { @@ -729,21 +760,7 @@ static int dwc3_probe(struct platform_device *pdev) return 0; err3: - switch (dwc->dr_mode) { - case USB_DR_MODE_PERIPHERAL: - dwc3_gadget_exit(dwc); - break; - case USB_DR_MODE_HOST: - dwc3_host_exit(dwc); - break; - case USB_DR_MODE_OTG: - dwc3_host_exit(dwc); - dwc3_gadget_exit(dwc); - break; - default: - /* do nothing */ - break; - } + dwc3_core_exit_mode(dwc); err2: dwc3_event_buffers_cleanup(dwc); @@ -778,23 +795,7 @@ static int dwc3_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); dwc3_debugfs_exit(dwc); - - switch (dwc->dr_mode) { - case USB_DR_MODE_PERIPHERAL: - dwc3_gadget_exit(dwc); - break; - case USB_DR_MODE_HOST: - dwc3_host_exit(dwc); - break; - case USB_DR_MODE_OTG: - dwc3_host_exit(dwc); - dwc3_gadget_exit(dwc); - break; - default: - /* do nothing */ - break; - } - + dwc3_core_exit_mode(dwc); dwc3_event_buffers_cleanup(dwc); dwc3_free_event_buffers(dwc); dwc3_core_exit(dwc);