From patchwork Fri Jul 14 21:40:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 107826 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1445171qge; Fri, 14 Jul 2017 14:40:19 -0700 (PDT) X-Received: by 10.98.68.156 with SMTP id m28mr7388288pfi.159.1500068419214; Fri, 14 Jul 2017 14:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500068419; cv=none; d=google.com; s=arc-20160816; b=ISqM9NUnxgqIF5geG8cOhrRfevNeZoxmmJam0o2zJ7r4/ezFAqW4aC8mO1WQqiSONj gNK2a9yIwvpjE5F71/3Cjp7eatvp4/tqFN4JQQz+R8qusOs/JGH5hfmaxM3RhpxTdf3k OBwDO1JJlhOhCoI6mUcmI0kLzJW3NHJ3GvpOkeezrbFgIo0hLZo1Iq+i1EvQWa0ESiEB v46LtT1eIV8hfdqkly/fuMiCj1S9NdVnL3/E3WFPIpfp8yJ2rdnOAL+QEZ9ivBYFHLU5 eNBYmSZ7I6GH/UVxG1dw/R7ErNfJZC3RMUprEAuwGBaCQqHLtyH7+LvG4Q6Ddg52MIvl 2vNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=B33/6Mb2jqMX7VKidcxV/DrGnwIRnUvo0JF72S6mTQY=; b=ARatMsu+0bsTPmU2qvrJ7nUsoM41XUDrO28c0fVxQRPnZeNteysiG7MimUDErJI78Z jkwrGahnthN//4hLPRTlqduMz0KQhluDgYWJHePxOtTBYJCe2Tir3rL5IS2+BZqPCeT0 Ikbjgx6auH1kjyXC1yYQYjqp9nhaqR6SB5dEX3xlXM79JkAvlUaHhZAGP1c/Kkl3l017 85+SaQU23b/RzmAthY9r3zYYfCcCMD1C4TXHaK4mjwk/3hX8571eNchUCtWLBuYoEBex tHmUPcJxG9FNeI7/F5p6OYBGVoxHRLQu+0RlS0bbohqwkV4oHf5klspBgyM5BAo5x5Oz XxBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=csXU6IjH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si7654193plj.365.2017.07.14.14.40.18; Fri, 14 Jul 2017 14:40:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=csXU6IjH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751197AbdGNVkP (ORCPT + 25 others); Fri, 14 Jul 2017 17:40:15 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:35270 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751146AbdGNVkK (ORCPT ); Fri, 14 Jul 2017 17:40:10 -0400 Received: by mail-pf0-f171.google.com with SMTP id c73so51009912pfk.2 for ; Fri, 14 Jul 2017 14:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B33/6Mb2jqMX7VKidcxV/DrGnwIRnUvo0JF72S6mTQY=; b=csXU6IjHGCHSQoy6SwCsFWvqi/F2yCbXDs4q4U25AsvtGM0M+/vZgiWOP0RB3PIuHH qOBcemNTb3H/PB6/bLcXUzTGr5jdCS7VUZsRL5QBXtgZUhbKDyNK8CKeVV/hDfMXYj/Z KhJamwh+6/PMkAWmmGlmCOxNqhBZuczdBjG/8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B33/6Mb2jqMX7VKidcxV/DrGnwIRnUvo0JF72S6mTQY=; b=LicSDjHH6QllOc55vCR6YIb5znsNX5ZbRZqOMMlY0YsyZC4xGMXkYGIJDx+0k/+P4j NTe+lvEU7HQRV8V1b4G3soAL/yB9J41n0lmNUfYLYw1TjEmk5jYX3v7soqVhdBmdRK7i hetHS+Xm2+5ECtP6R3mTsRKZXyJq4n5k5KiqMELuMsshZ8yme5xBuY7KHoBv/6pfaIHP eJmzgspkDy359CY7HtvMRDNCDVzM5T1vXo7LwKjDk+k3w12g+PsnT2DtA3w/X06yIDVx PnoXiN7ccqDv2SYeAMWTNY2bPTj4R4mPR1nF4GAN5aXefofXuS8+vh31PBAR0mrAz9O4 IJUw== X-Gm-Message-State: AIVw1122KSBLnxJKWdyto/Nc7AARK9Gs8hqplGDZosyPmUWPoSMMSem/ 2c4ZrtamyY6InXq+ X-Received: by 10.98.220.218 with SMTP id c87mr7359244pfl.73.1500068410240; Fri, 14 Jul 2017 14:40:10 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id e13sm17795271pfh.96.2017.07.14.14.40.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jul 2017 14:40:09 -0700 (PDT) From: Stephen Boyd To: Peter Chen Cc: linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.infradead.org, Rob Herring , Rob Clark , Andy Gross , Peter Rosin , Peter Chen , Greg Kroah-Hartman , devicetree@vger.kernel.org Subject: [PATCH v2 2/3] usb: chipidea: Hook into mux framework to toggle usb switch Date: Fri, 14 Jul 2017 14:40:04 -0700 Message-Id: <20170714214005.14967-3-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170714214005.14967-1-stephen.boyd@linaro.org> References: <20170714214005.14967-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the db410c 96boards platform we have a TC7USB40MU on the board to mux the D+/D- lines coming from the controller between a micro usb "device" port and a USB hub for "host" roles[1]. During a role switch, we need to toggle this mux to forward the D+/D- lines to either the port or the hub. Add the necessary code to do the role switch in chipidea core via the generic mux framework. Board configurations like on db410c are expected to change roles via the sysfs API described in Documentation/ABI/testing/sysfs-platform-chipidea-usb2. [1] https://github.com/96boards/documentation/raw/master/ConsumerEdition/DragonBoard-410c/HardwareDocs/Schematics_DragonBoard.pdf Cc: Peter Rosin Cc: Peter Chen Cc: Greg Kroah-Hartman Cc: Signed-off-by: Stephen Boyd --- Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 6 ++++++ drivers/usb/chipidea/Kconfig | 1 + drivers/usb/chipidea/core.c | 5 +++++ drivers/usb/chipidea/host.c | 7 +++++++ drivers/usb/chipidea/udc.c | 13 ++++++++++++- include/linux/usb/chipidea.h | 2 ++ 6 files changed, 33 insertions(+), 1 deletion(-) -- 2.10.0.297.gf6727b0 diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt index 0e03344e2e8b..2e9318151df7 100644 --- a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt @@ -76,6 +76,10 @@ Optional properties: needs to make sure it does not send more than 90% maximum_periodic_data_per_frame. The use case is multiple transactions, but less frame rate. +- mux-controls: The mux control for toggling host/device output of this + controller. It's expected that a mux state of 0 indicates device mode and a + mux state of 1 indicates host mode. +- mux-control-names: Shall be "usb_switch" if mux-controls is specified. i.mx specific properties - fsl,usbmisc: phandler of non-core register device, with one @@ -102,4 +106,6 @@ Example: rx-burst-size-dword = <0x10>; extcon = <0>, <&usb_id>; phy-clkgate-delay-us = <400>; + mux-controls = <&usb_switch>; + mux-control-names = "usb_switch"; }; diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig index 51f4157bbecf..3798e0e69d57 100644 --- a/drivers/usb/chipidea/Kconfig +++ b/drivers/usb/chipidea/Kconfig @@ -3,6 +3,7 @@ config USB_CHIPIDEA depends on ((USB_EHCI_HCD && USB_GADGET) || (USB_EHCI_HCD && !USB_GADGET) || (!USB_EHCI_HCD && USB_GADGET)) && HAS_DMA select EXTCON select RESET_CONTROLLER + select MULTIPLEXER help Say Y here if your system has a dual role high speed USB controller based on ChipIdea silicon IP. It supports: diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index b17ed3a9a304..d088c262ebb8 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -64,6 +64,7 @@ #include #include #include +#include #include "ci.h" #include "udc.h" @@ -690,6 +691,10 @@ static int ci_get_platdata(struct device *dev, if (of_find_property(dev->of_node, "non-zero-ttctrl-ttha", NULL)) platdata->flags |= CI_HDRC_SET_NON_ZERO_TTHA; + platdata->usb_switch = devm_mux_control_get_optional(dev, "usb_switch"); + if (IS_ERR(platdata->usb_switch)) + return PTR_ERR(platdata->usb_switch); + ext_id = ERR_PTR(-ENODEV); ext_vbus = ERR_PTR(-ENODEV); if (of_property_read_bool(dev->of_node, "extcon")) { diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index 18cb8e46262d..9ef3ecf27ad3 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "../host/ehci.h" @@ -175,6 +176,10 @@ static int host_start(struct ci_hdrc *ci) if (ci_otg_is_fsm_mode(ci)) { otg->host = &hcd->self; hcd->self.otg_port = 1; + } else { + ret = mux_control_select(ci->platdata->usb_switch, 1); + if (ret) + goto disable_reg; } } @@ -195,6 +200,8 @@ static void host_stop(struct ci_hdrc *ci) struct usb_hcd *hcd = ci->hcd; if (hcd) { + if (!ci_otg_is_fsm_mode(ci)) + mux_control_deselect(ci->platdata->usb_switch); if (ci->platdata->notify_event) ci->platdata->notify_event(ci, CI_HDRC_CONTROLLER_STOPPED_EVENT); diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index d68b125796f9..deb18099e168 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "ci.h" #include "udc.h" @@ -1964,16 +1965,26 @@ void ci_hdrc_gadget_destroy(struct ci_hdrc *ci) static int udc_id_switch_for_device(struct ci_hdrc *ci) { + int ret = 0; + if (ci->is_otg) /* Clear and enable BSV irq */ hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, OTGSC_BSVIS | OTGSC_BSVIE); - return 0; + if (!ci_otg_is_fsm_mode(ci)) + ret = mux_control_select(ci->platdata->usb_switch, 0); + + if (ci->is_otg && ret) + hw_write_otgsc(ci, OTGSC_BSVIE | OTGSC_BSVIS, OTGSC_BSVIS); + + return ret; } static void udc_id_switch_for_host(struct ci_hdrc *ci) { + mux_control_deselect(ci->platdata->usb_switch); + /* * host doesn't care B_SESSION_VALID event * so clear and disbale BSV irq diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index c5fdfcf99828..3b27e333de1d 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -9,6 +9,7 @@ #include struct ci_hdrc; +struct mux_control; /** * struct ci_hdrc_cable - structure for external connector cable state tracking @@ -74,6 +75,7 @@ struct ci_hdrc_platform_data { /* VBUS and ID signal state tracking, using extcon framework */ struct ci_hdrc_cable vbus_extcon; struct ci_hdrc_cable id_extcon; + struct mux_control *usb_switch; u32 phy_clkgate_delay_us; };