From patchwork Mon Apr 10 08:02:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 9672063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 724C860231 for ; Mon, 10 Apr 2017 08:03:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6371E26E81 for ; Mon, 10 Apr 2017 08:03:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57C4828178; Mon, 10 Apr 2017 08:03:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E0F626E81 for ; Mon, 10 Apr 2017 08:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751968AbdDJIC4 (ORCPT ); Mon, 10 Apr 2017 04:02:56 -0400 Received: from mga06.intel.com ([134.134.136.31]:41252 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751801AbdDJICz (ORCPT ); Mon, 10 Apr 2017 04:02:55 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP; 10 Apr 2017 01:02:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,181,1488873600"; d="asc'?scan'208";a="954177255" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.68.37]) by orsmga003.jf.intel.com with ESMTP; 10 Apr 2017 01:02:36 -0700 From: Felipe Balbi To: Roger Quadros , Randy Dunlap , kbuild test robot Cc: kbuild-all@01.org, linux-usb@vger.kernel.org, linux-omap@vger.kernel.org Subject: Re: [balbi-usb:testing/next 46/49] undefined reference to `extcon_get_edev_by_phandle' In-Reply-To: <4d902467-2939-797c-0350-ee99aee07d49@ti.com> References: <201704090005.8IRIdzVM%fengguang.wu@intel.com> <4d902467-2939-797c-0350-ee99aee07d49@ti.com> Date: Mon, 10 Apr 2017 11:02:10 +0300 Message-ID: <87zifoelml.fsf@linux.intel.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, Roger Quadros writes: >>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git testing/next >>> head: 9653f750a746d5abc4bc054d818eb32d1351eae9 >>> commit: d5a80bad699c94703a0306edd250f65cfd050580 [46/49] usb: dwc3: Add dual-role support >>> config: x86_64-randconfig-h0-04081918 (attached as .config) >>> compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 >>> reproduce: >>> git checkout d5a80bad699c94703a0306edd250f65cfd050580 >>> # save the attached .config to linux build tree >>> make ARCH=x86_64 >>> >>> All errors (new ones prefixed by >>): >>> >>> drivers/built-in.o: In function `dwc3_drd_init': >>>>> (.text+0x2aff13): undefined reference to `extcon_get_edev_by_phandle' >>> drivers/built-in.o: In function `dwc3_drd_init': >>>>> (.text+0x2affb1): undefined reference to `extcon_register_notifier' >>> drivers/built-in.o: In function `dwc3_drd_init': >>>>> (.text+0x2b0029): undefined reference to `extcon_get_state' >>> drivers/built-in.o: In function `dwc3_drd_exit': >>>>> (.text+0x2b00e1): undefined reference to `extcon_unregister_notifier' >> >> EXTCON=m in this config. >> >> DWC3_DUAL_ROLE needs to depend on EXTCON... >> >> > Thanks for the analysis Randy. > > Felipe, let me know if you want me to resend the patch or you'll fix it locally. > Thanks. :) 8<--------------------------------- cut here ----------------------------------------- From 28ea6be01e2cf244c461a40c8e9593816f894412 Mon Sep 17 00:00:00 2001 From: Roger Quadros Date: Wed, 5 Apr 2017 13:39:31 +0300 Subject: [PATCH v2] usb: dwc3: Add dual-role support If dr_mode is "otg" then support dual role mode of operation. Currently this mode is only supported when an extcon handle is present in the dwc3 device tree node. This is needed to get the ID status events of the port. We're using a workqueue to manage the dual-role state transitions as the extcon notifier (dwc3_drd_notifier) is called in an atomic context by extcon_sync() and this doesn't go well with usb_del_gadget_udc() causing a lockdep and softirq warning. Signed-off-by: Roger Quadros Signed-off-by: Felipe Balbi --- Add EXTCON dependency drivers/usb/dwc3/Kconfig | 1 + drivers/usb/dwc3/Makefile | 4 +++ drivers/usb/dwc3/core.c | 11 +++--- drivers/usb/dwc3/core.h | 14 ++++++++ drivers/usb/dwc3/drd.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 drivers/usb/dwc3/drd.c diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index c5aa235863e8..aee55114d269 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -41,6 +41,7 @@ config USB_DWC3_GADGET config USB_DWC3_DUAL_ROLE bool "Dual Role mode" depends on ((USB=y || USB=USB_DWC3) && (USB_GADGET=y || USB_GADGET=USB_DWC3)) + depends on (EXTCON=y || EXTCON=USB_DWC3) help This is the default mode of working of DWC3 controller where both host and gadget features are enabled. diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile index ffca34029b21..f15fabbd1e59 100644 --- a/drivers/usb/dwc3/Makefile +++ b/drivers/usb/dwc3/Makefile @@ -17,6 +17,10 @@ ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE)),) dwc3-y += gadget.o ep0.o endif +ifneq ($(CONFIG_USB_DWC3_DUAL_ROLE),) + dwc3-y += drd.o +endif + ifneq ($(CONFIG_USB_DWC3_ULPI),) dwc3-y += ulpi.o endif diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 458e7c6cc002..455d89a1cd6d 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -921,7 +921,12 @@ static int dwc3_core_init_mode(struct dwc3 *dwc) break; case USB_DR_MODE_OTG: INIT_WORK(&dwc->drd_work, __dwc3_set_mode); - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + ret = dwc3_drd_init(dwc); + if (ret) { + if (ret != -EPROBE_DEFER) + dev_err(dev, "failed to initialize dual-role\n"); + return ret; + } break; default: dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); @@ -941,9 +946,7 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc) dwc3_host_exit(dwc); break; case USB_DR_MODE_OTG: - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); - dwc3_gadget_exit(dwc); - flush_work(&dwc->drd_work); + dwc3_drd_exit(dwc); break; default: /* do nothing */ diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 1fe23e36485f..981c77f5628e 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -785,6 +785,8 @@ struct dwc3_scratchpad_array { * @dr_mode: requested mode of operation * @current_dr_role: current role of operation when in dual-role mode * @desired_dr_role: desired role of operation when in dual-role mode + * @edev: extcon handle + * @edev_nb: extcon notifier * @hsphy_mode: UTMI phy mode, one of following: * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW @@ -898,6 +900,8 @@ struct dwc3 { enum usb_dr_mode dr_mode; u32 current_dr_role; u32 desired_dr_role; + struct extcon_dev *edev; + struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; u32 fladj; @@ -1218,6 +1222,16 @@ static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc, { return 0; } #endif +#if IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) +int dwc3_drd_init(struct dwc3 *dwc); +void dwc3_drd_exit(struct dwc3 *dwc); +#else +static inline int dwc3_drd_init(struct dwc3 *dwc) +{ return 0; } +static inline void dwc3_drd_exit(struct dwc3 *dwc) +{ } +#endif + /* power management interface */ #if !IS_ENABLED(CONFIG_USB_DWC3_HOST) int dwc3_gadget_suspend(struct dwc3 *dwc); diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c new file mode 100644 index 000000000000..2765c51c7ef5 --- /dev/null +++ b/drivers/usb/dwc3/drd.c @@ -0,0 +1,85 @@ +/** + * drd.c - DesignWare USB3 DRD Controller Dual-role support + * + * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com + * + * Authors: Roger Quadros + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 of + * the License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "debug.h" +#include "core.h" +#include "gadget.h" + +static void dwc3_drd_update(struct dwc3 *dwc) +{ + int id; + + id = extcon_get_state(dwc->edev, EXTCON_USB_HOST); + if (id < 0) + id = 0; + + dwc3_set_mode(dwc, id ? + DWC3_GCTL_PRTCAP_HOST : + DWC3_GCTL_PRTCAP_DEVICE); +} + +static int dwc3_drd_notifier(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct dwc3 *dwc = container_of(nb, struct dwc3, edev_nb); + + dwc3_set_mode(dwc, event ? + DWC3_GCTL_PRTCAP_HOST : + DWC3_GCTL_PRTCAP_DEVICE); + + return NOTIFY_DONE; +} + +int dwc3_drd_init(struct dwc3 *dwc) +{ + int ret; + + if (dwc->dev->of_node) { + if (of_property_read_bool(dwc->dev->of_node, "extcon")) + dwc->edev = extcon_get_edev_by_phandle(dwc->dev, 0); + + if (IS_ERR(dwc->edev)) + return PTR_ERR(dwc->edev); + + dwc->edev_nb.notifier_call = dwc3_drd_notifier; + ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST, + &dwc->edev_nb); + if (ret < 0) { + dev_err(dwc->dev, "couldn't register cable notifier\n"); + return ret; + } + } + + dwc3_drd_update(dwc); + + return 0; +} + +void dwc3_drd_exit(struct dwc3 *dwc) +{ + extcon_unregister_notifier(dwc->edev, EXTCON_USB_HOST, + &dwc->edev_nb); + + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + flush_work(&dwc->drd_work); + dwc3_gadget_exit(dwc); +}