From patchwork Wed Dec 17 13:49:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 5507051 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2E188BEEA8 for ; Wed, 17 Dec 2014 13:50:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01D5720A25 for ; Wed, 17 Dec 2014 13:50:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97ED820A22 for ; Wed, 17 Dec 2014 13:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750979AbaLQNuM (ORCPT ); Wed, 17 Dec 2014 08:50:12 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:49975 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750946AbaLQNuL (ORCPT ); Wed, 17 Dec 2014 08:50:11 -0500 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NGQ007X7BYHWT20@mailout1.w1.samsung.com>; Wed, 17 Dec 2014 13:54:17 +0000 (GMT) X-AuditID: cbfec7f5-b7fc86d0000066b7-68-54918a10e76e Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 12.16.26295.01A81945; Wed, 17 Dec 2014 13:50:08 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NGQ00ECCBRFSN80@eusync2.samsung.com>; Wed, 17 Dec 2014 13:50:08 +0000 (GMT) From: Marek Szyprowski To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Kyungmin Park , Robert Baldyga , Paul Zimmerman , Felipe Balbi Subject: [PATCH] usb: dwc2: add support for initial state for dual-role mode Date: Wed, 17 Dec 2014 14:49:53 +0100 Message-id: <1418824193-19182-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOJMWRmVeSWpSXmKPExsVy+t/xK7oCXRNDDKb8N7Q4eL/e4mzTG3aL Gef3MVksWtbKbLH2yF12i+1TpjNZPDi8k92B3aNvyypGjy37PzN6HL+xncnj8ya5AJYoLpuU 1JzMstQifbsErowl12wKdipWnNw9jb2BsU26i5GTQ0LAROLP3r/MELaYxIV769m6GLk4hASW Mkq8+nmfCcLpY5JYtvsPO0gVm4ChRNfbLjYQW0TAQWLJ0jtgHcwCpxgl1l07wAqSEBbwkfja toali5GDg0VAVWL1Zn6QMK+Ah8SUbc/YILbJSfx/uYJpAiP3AkaGVYyiqaXJBcVJ6blGesWJ ucWleel6yfm5mxghgfF1B+PSY1aHGAU4GJV4eF9cnxAixJpYVlyZe4hRgoNZSYT3c+DEECHe lMTKqtSi/Pii0pzU4kOMTBycUg2MRVuuhLe01pyLvpxS5+Dgf1HQ7/uH4gLR+cWfyjyPvuQ+ f2ex9+mcHT17FsoZCnIeCtWtDWqK+KliYblIPzXSxO9F/NMTJh6y9y5NlxSWyU7+sL5G8e3d L1wfFhgcm7a04N7Sbb4cFyf+3Vrdsz2mvXhGgeitg2LbfjLprpR1zDDfyPl59aQWJZbijERD Leai4kQAqNODsuoBAAA= Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DWC2 module on Exynos SoCs is used only as peripheral controller (UDC), so add support for selecting default initial state for dual-role mode. The default init mode can be overridden by device tree 'dr_mode' property. This patch enables to use usb gadget on Exynos SoCs, when DWC2 driver has been compiled as 'dual-role driver'. Signed-off-by: Marek Szyprowski --- drivers/usb/dwc2/core.h | 3 +++ drivers/usb/dwc2/platform.c | 62 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 7a70a13..b0fed4e 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -354,6 +354,7 @@ struct dwc2_core_params { int reload_ctl; int ahbcfg; int uframe_sched; + int default_dr_mode; }; /** @@ -570,6 +571,8 @@ struct dwc2_hsotg { struct dwc2_core_params *core_params; enum usb_otg_state op_state; enum usb_dr_mode dr_mode; + unsigned int hcd_enabled:1; + unsigned int gadget_enabled:1; struct phy *phy; struct usb_phy *uphy; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 6a795aa..8abf437 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -76,6 +76,7 @@ static const struct dwc2_core_params params_bcm2835 = { .reload_ctl = 0, .ahbcfg = 0x10, .uframe_sched = 0, + .default_dr_mode = USB_DR_MODE_OTG, }; static const struct dwc2_core_params params_rk3066 = { @@ -104,6 +105,36 @@ static const struct dwc2_core_params params_rk3066 = { .reload_ctl = -1, .ahbcfg = 0x7, /* INCR16 */ .uframe_sched = -1, + .default_dr_mode = USB_DR_MODE_OTG, +}; + +static const struct dwc2_core_params params_s3c_hsotg = { + .otg_cap = -1, + .otg_ver = -1, + .dma_enable = 0, + .dma_desc_enable = 0, + .speed = -1, + .enable_dynamic_fifo = -1, + .en_multiple_tx_fifo = -1, + .host_rx_fifo_size = -1, + .host_nperio_tx_fifo_size = -1, + .host_perio_tx_fifo_size = -1, + .max_transfer_size = -1, + .max_packet_count = -1, + .host_channels = -1, + .phy_type = -1, + .phy_utmi_width = -1, + .phy_ulpi_ddr = -1, + .phy_ulpi_ext_vbus = -1, + .i2c_enable = -1, + .ulpi_fs_ls = -1, + .host_support_fs_ls_low_power = -1, + .host_ls_low_power_phy_clk = -1, + .ts_dline = -1, + .reload_ctl = -1, + .ahbcfg = -1, + .uframe_sched = -1, + .default_dr_mode = USB_DR_MODE_PERIPHERAL, }; /** @@ -121,8 +152,10 @@ static int dwc2_driver_remove(struct platform_device *dev) { struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); - dwc2_hcd_remove(hsotg); - s3c_hsotg_remove(hsotg); + if (hsotg->hcd_enabled) + dwc2_hcd_remove(hsotg); + if (hsotg->gadget_enabled) + s3c_hsotg_remove(hsotg); return 0; } @@ -131,7 +164,7 @@ static const struct of_device_id dwc2_of_match_table[] = { { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, { .compatible = "rockchip,rk3066-usb", .data = ¶ms_rk3066 }, { .compatible = "snps,dwc2", .data = NULL }, - { .compatible = "samsung,s3c6400-hsotg", .data = NULL}, + { .compatible = "samsung,s3c6400-hsotg", .data = ¶ms_s3c_hsotg }, {}, }; MODULE_DEVICE_TABLE(of, dwc2_of_match_table); @@ -211,15 +244,26 @@ static int dwc2_driver_probe(struct platform_device *dev) (unsigned long)res->start, hsotg->regs); hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node); + if (hsotg->dr_mode == USB_DR_MODE_UNKNOWN && + params->default_dr_mode > USB_DR_MODE_UNKNOWN) + hsotg->dr_mode = params->default_dr_mode; spin_lock_init(&hsotg->lock); mutex_init(&hsotg->init_mutex); - retval = dwc2_gadget_init(hsotg, irq); - if (retval) - return retval; - retval = dwc2_hcd_init(hsotg, irq, params); - if (retval) - return retval; + + if (hsotg->dr_mode != USB_DR_MODE_HOST) { + retval = dwc2_gadget_init(hsotg, irq); + if (retval) + return retval; + hsotg->gadget_enabled = 1; + } + + if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { + retval = dwc2_hcd_init(hsotg, irq, params); + if (retval) + return retval; + hsotg->hcd_enabled = 1; + } platform_set_drvdata(dev, hsotg);