From patchwork Wed Jul 12 01:02:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9835689 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 DACE660393 for ; Wed, 12 Jul 2017 01:03:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE5CF285B6 for ; Wed, 12 Jul 2017 01:03:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2AB7285D4; Wed, 12 Jul 2017 01:03:52 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 16781285B6 for ; Wed, 12 Jul 2017 01:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xBYbjaPZQmVkJCGqQeR9a9bMLIty88MLciHUDR4lFyA=; b=CfY8lARVglR4sJmWKjKqGiJKup M1cuRgJh/lKFK9ywLxeTUUMmCjf4t9Kz454Bm9KmOAzjdgOz/o7bvWyQbETQfQHYoiGcfWsaafMf9 it5scaqNpeCsRBK+UubUMNcDqQ1v7Nv8qdm14YH8uKP2S6nYI8IZGN1YX5HEEjMBwmAtKjxHQ/WZt aC1ySvUExIIHe87OLkHPE7c1Tsl437ewcoR18B5YnHotkgNuZLl85bO+pudxXn2OPU1LrdF9ENpEQ h1zMYg+rQJx2R1iw5jsiX9CHqLWj5WbglzpkV5K+YAFK5Tod0S5UUtHwCkP1VEOpmCgOBdDjfPUVn jGcu5dnw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dV64D-0008Sf-RG; Wed, 12 Jul 2017 01:03:49 +0000 Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dV63l-0007uR-SH for linux-arm-kernel@lists.infradead.org; Wed, 12 Jul 2017 01:03:23 +0000 Received: by mail-pg0-x22e.google.com with SMTP id k14so4351854pgr.0 for ; Tue, 11 Jul 2017 18:03:01 -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=SnVLsasyuKSlr94shIPM/o9Y2VoqEPL8Y6hVX5D6WpE=; b=kO19SFbXnoruiQOyaLmQiWqTvmeiLi9skbDBhlRGyg/fZaZod/iRS9V27SsUZWy17+ Q8a5fRNbKOG25KNqc/bNk/4MUvzEl8tL6n+8L8Nck/JRfz09L1M6kISAu0YLWs1ExAjJ lHkTevo6o1SMJC/CCQEtl/M1XNPqWZxOQvI4E= 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=SnVLsasyuKSlr94shIPM/o9Y2VoqEPL8Y6hVX5D6WpE=; b=ASwk75tkERToaL4ywENLONUcY3Ng+C04AyXNyCUrpRxIqT4anrYCL2OgnprUMA6EXL w97gf9dbI2meRL46FkuYXx1WnN5Cwo4npmisRKn37QngLkDPSO1/UsbwBFplrf2aRlmi 5umTpCauCcgmceAq1GoGxgkqVJMiRNKMu25LCiRrAenYVCNB4v40gqMIG8n67KSsdYQB mNnuKb1fbiqfx9/AuiELCjKDd5O7Lg1Sz1+cwOflDojAAoBMT4VVS3CeZ+Btx4rmj78C zFsaLhe/NMPsQUcqVePacXCvdVT+qJc4TTThGlpYEN/arhwqV38pr4it/Mg5ujSKBosf 6eMA== X-Gm-Message-State: AIVw110qq97UhdihmBiigigOseTvYUYBxOFaEFpkc8es/cU8HjI3M8vS 6gNQjyql/LwKn6fp X-Received: by 10.98.33.132 with SMTP id o4mr52779006pfj.11.1499821381013; Tue, 11 Jul 2017 18:03:01 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id o8sm839571pgn.52.2017.07.11.18.02.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Jul 2017 18:03:00 -0700 (PDT) From: Stephen Boyd To: Peter Chen Subject: [PATCH 2/3] usb: chipidea: Hook into mux framework to toggle usb switch Date: Tue, 11 Jul 2017 18:02:54 -0700 Message-Id: <20170712010255.26855-3-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170712010255.26855-1-stephen.boyd@linaro.org> References: <20170712010255.26855-1-stephen.boyd@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170711_180321_969199_122F890F X-CRM114-Status: GOOD ( 18.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Peter Chen , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Clark , Rob Herring , Greg Kroah-Hartman , Andy Gross , Peter Rosin , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 8 ++++++++ drivers/usb/chipidea/core.c | 17 +++++++++++++++++ drivers/usb/chipidea/host.c | 10 ++++++++++ drivers/usb/chipidea/udc.c | 11 +++++++++++ include/linux/usb/chipidea.h | 14 ++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt index 0e03344e2e8b..96ce81d975d5 100644 --- a/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +++ b/Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt @@ -76,6 +76,11 @@ 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. +- mux-control-names: Shall be "usb_switch" if mux-controls is specified. +- usb-switch-states: Two u32's defining the state to set on the mux for the + host mode and device modes respectively. i.mx specific properties - fsl,usbmisc: phandler of non-core register device, with one @@ -102,4 +107,7 @@ Example: rx-burst-size-dword = <0x10>; extcon = <0>, <&usb_id>; phy-clkgate-delay-us = <400>; + mux-controls = <&usb_switch>; + mux-control-names = "usb_switch"; + usb-switch-states = <0>, <1>; }; diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index b17ed3a9a304..6531d771f296 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" @@ -606,6 +607,7 @@ static int ci_get_platdata(struct device *dev, { struct extcon_dev *ext_vbus, *ext_id; struct ci_hdrc_cable *cable; + struct ci_hdrc_switch *usb_switch; int ret; if (!platdata->phy_mode) @@ -690,6 +692,21 @@ 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; + if (IS_ENABLED(CONFIG_MULTIPLEXER)) { + usb_switch = &platdata->usb_switch; + usb_switch->mux = devm_mux_control_get(dev, "usb_switch"); + if (!IS_ERR(usb_switch->mux)) { + if (of_property_read_u32_index(dev->of_node, + "usb-switch-states", + 0, &usb_switch->device)) + return -EINVAL; + if (of_property_read_u32_index(dev->of_node, + "usb-switch-states", + 1, &usb_switch->host)) + return -EINVAL; + } + } + 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..9fd23ecc2da3 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" @@ -123,6 +124,13 @@ static int host_start(struct ci_hdrc *ci) if (usb_disabled()) return -ENODEV; + if (!IS_ERR(ci->platdata->usb_switch.mux)) { + ret = mux_control_select(ci->platdata->usb_switch.mux, + ci->platdata->usb_switch.host); + if (ret) + return ret; + } + hcd = __usb_create_hcd(&ci_ehci_hc_driver, ci->dev->parent, ci->dev, dev_name(ci->dev), NULL); if (!hcd) @@ -205,6 +213,8 @@ static void host_stop(struct ci_hdrc *ci) if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) && (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON)) regulator_disable(ci->platdata->reg_vbus); + if (!IS_ERR(ci->platdata->usb_switch.mux)) + mux_control_deselect(ci->platdata->usb_switch.mux); } ci->hcd = NULL; ci->otg.host = NULL; diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index d68b125796f9..ab3355905740 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" @@ -1899,6 +1900,13 @@ static int udc_start(struct ci_hdrc *ci) ci->gadget.name = ci->platdata->name; ci->gadget.otg_caps = otg_caps; + if (!IS_ERR(ci->platdata->usb_switch.mux)) { + retval = mux_control_select(ci->platdata->usb_switch.mux, + ci->platdata->usb_switch.device); + if (retval) + return retval; + } + if (ci->is_otg && (otg_caps->hnp_support || otg_caps->srp_support || otg_caps->adp_support)) ci->gadget.is_otg = 1; @@ -1982,6 +1990,9 @@ static void udc_id_switch_for_host(struct ci_hdrc *ci) hw_write_otgsc(ci, OTGSC_BSVIE | OTGSC_BSVIS, OTGSC_BSVIS); ci->vbus_active = 0; + + if (!IS_ERR(ci->platdata->usb_switch.mux)) + mux_control_deselect(ci->platdata->usb_switch.mux); } /** diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index c5fdfcf99828..559bd470b8c0 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 @@ -29,6 +30,18 @@ struct ci_hdrc_cable { struct notifier_block nb; }; +/** + * struct ci_hdrc_switch - structure for usb mux control + * @mux: mux to set @host state or @device state on during role switch + * @host: Value to set for mux to connect D+/D- to host D+/D- lines + * @device: Value to set for mux to connect D+/D- to device D+/D- lines + */ +struct ci_hdrc_switch { + struct mux_control *mux; + int host; + int device; +}; + struct ci_hdrc_platform_data { const char *name; /* offset of the capability registers */ @@ -74,6 +87,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 ci_hdrc_switch usb_switch; u32 phy_clkgate_delay_us; };