Received: by 10.192.165.156 with SMTP id m28csp80967imm; Tue, 17 Apr 2018 06:54:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx48fYc1P9yBE0k1AqphOny7azd/P0zFqpLO+2gCVCg/BxNNoUo1uVxDmgGgq3lUKI5jUk8w0 X-Received: by 2002:a17:902:3265:: with SMTP id y92-v6mr2150334plb.16.1523973291584; Tue, 17 Apr 2018 06:54:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523973291; cv=none; d=google.com; s=arc-20160816; b=vErhinxvGuearldDgD6x+c1T8jZhvajKsA2NLTLiWIprRngP1GvGfeRpFwULxg7gmh D9G/g21teYz1HIC7yvJQqy1GRBtmIAp2F3fwlDHfYq6cThyBwPVhdZCItYAHMur0sGFz MPXRoWDPZ0tLE5SZbF3cphRNBSSG5ig2kEZBRPoXPIsxyVzDj7E/bZNPKgxOJBAeQxmf KPgbjn4/9KkdjL2Rh9k7rUYumlIQFrYIdpcNEWBvJRO85xMo6Dgxsf4Mxh36VEJ2XRkr N/j0Q1vTMacn8g1kbvHL/Pg1RfLmXGo3g0HNLnWRFRj4McfPyBtAh9GskroQATU21WXe q6jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=iPTwW6HBJBmmtT28LZEo7ABezLUlHGvrkCfpLlhK9Jg=; b=p3LjQLPmfUtxVyxvdYCP2nY45jUFF9FQIyVJRXV+a1SVGxbHhO6dzk8osWDS/kBR9e JRQYarUjysCjw4CC706GyyF79vvCRKej3SOytAW4lKNP4YYBO7v3vOjlJgbh9fyDxZpG 1W8lYxCrZls6wOZRBtPgk9Y3vcORMZJ8vOPFMoqlRG5Q3hGCn7UrhGm8WU+5Jl75+So0 ti8OzOULm4TwLvuqsWCw7P9ojM+Hw6m9SQxbOHGoQHmZGndhZahy+83poFlC4Pdh+Tfj sPPq4Y2MAJYneX3mp5RPXhTzBnxf7i+knSgEEiqOa7GIKcp0MPAk255itMuS8N+TrFSS 8TmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=dzWh5f36; dkim=pass header.i=@codeaurora.org header.s=default header.b=Jm0uhRQ2; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bj11-v6si14377900plb.480.2018.04.17.06.54.36; Tue, 17 Apr 2018 06:54:51 -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=@codeaurora.org header.s=default header.b=dzWh5f36; dkim=pass header.i=@codeaurora.org header.s=default header.b=Jm0uhRQ2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753584AbeDQNxV (ORCPT + 99 others); Tue, 17 Apr 2018 09:53:21 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:34478 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752672AbeDQNxT (ORCPT ); Tue, 17 Apr 2018 09:53:19 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 8B09460385; Tue, 17 Apr 2018 13:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523973198; bh=Y17WWSSqUbn3DaDSqyU+RqM7Dea8F9wRGzpCrGV4lRY=; h=From:To:Cc:Subject:Date:From; b=dzWh5f365jyY14nTUwliMaWRYzzc6O7vqF+qatLnMAOugE1zTo6bXDRQjkgpmxA15 Ol7TMAlaoeA+cw7bo0/phu4Z5sP4hOiVyme8i1fhusEyx/F5NqTqTfSa6ycITmHM1q fgfGjDwrKBOkYRLqxBN4h9Nq7kCsirXASELwxowc= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lx-platforms-5.mea.qualcomm.com (unknown [185.23.60.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: yossim@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D5A646071A; Tue, 17 Apr 2018 13:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523973184; bh=Y17WWSSqUbn3DaDSqyU+RqM7Dea8F9wRGzpCrGV4lRY=; h=From:To:Cc:Subject:Date:From; b=Jm0uhRQ2HDSKahuwP/9/ST8qWjWP+t2Oabel6x6fP3/xeLGrQojGgVhM1t9eVWbr/ wqLdDawOd5/DdIoHSTpTgIWwOJEEZGY+Eb6bHrwVkMf7xp+oRNcQbIgiqpE2+wCKeD GZFA8l8T/OS51Bq06ZHnb13ddmR2CNnGEOc/CKwY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D5A646071A Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=yossim@codeaurora.org From: Yossi Mansharoff To: Peter Chen , Greg Kroah-Hartman , linux-usb@vger.kernel.org (open list:CHIPIDEA USB HIGH SPEED DUAL ROLE CONTROLLER), linux-kernel@vger.kernel.org (open list) Cc: robh@kernel.org, swboyd@chromium.org, Yossi Mansharoff , Peter Rosin , Peter Chen , , Stephen Boyd Subject: [PATCH v2] usb: chipidea: Hook into mux framework to toggle usb switch Date: Tue, 17 Apr 2018 16:52:28 +0300 Message-Id: <1523973148-2094-1-git-send-email-yossim@codeaurora.org> X-Mailer: git-send-email 1.9.1 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 Signed-off-by: Yossi Mansharoff --- drivers/usb/chipidea/Kconfig | 2 ++ drivers/usb/chipidea/core.c | 5 +++++ drivers/usb/chipidea/host.c | 7 +++++++ drivers/usb/chipidea/udc.c | 13 ++++++++++++- include/linux/usb/chipidea.h | 2 ++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig index 785f0ed..6a8e635 100644 --- a/drivers/usb/chipidea/Kconfig +++ b/drivers/usb/chipidea/Kconfig @@ -3,6 +3,8 @@ 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 + select MUX_GPIO 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 33ae87f..8fa0991 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -61,6 +61,7 @@ #include #include #include +#include #include "ci.h" #include "udc.h" @@ -687,6 +688,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 af45aa32..d9d2d00 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "../host/ehci.h" @@ -161,6 +162,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; } } @@ -181,6 +186,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 9852ec5..209d3f6 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "ci.h" #include "udc.h" @@ -1965,16 +1966,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 07f9936..9ea55a1 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -10,6 +10,7 @@ #include struct ci_hdrc; +struct mux_control; /** * struct ci_hdrc_cable - structure for external connector cable state tracking @@ -76,6 +77,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; }; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project