Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14057348ybl; Mon, 30 Dec 2019 03:15:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxVBwqcjfC8STSwJatnXZQ60Ve729qu8+eoY7nAkW8QOybE+kI4EJAlUYSzReTbQi+9TWua X-Received: by 2002:aca:3141:: with SMTP id x62mr4693160oix.108.1577704559312; Mon, 30 Dec 2019 03:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577704559; cv=none; d=google.com; s=arc-20160816; b=bu1OUNJMZpB/v/RYofj84jA8x44kOyxbjQlQ1zE0Y4nreCMJA98TdFe2qYAlkSCpHG QdMw+dfMS3cCKP2M5X6w/KRE3TAScxcQJcuKzCZr11wfQ1PiL55Jxvi152PykGtFMubq tlXVECNf3vHyNadRkhoD1B7onuur0CFuOYUmrbPTQ36Cd9YGdhnO3esUZvY0VMedYls7 8GNF17hrWpqErGUk8veSptDubVB3Zhdbvwj4R//92lPASvauDxnvRKUJy/wE4FnNVRn2 RVkrj8ycXpPMP9Fw5VqVST71Cti0Yk0MGSwCrVm+tvophlOxfudCk7Qe+vlHfb40S87Z xwKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=K+oEbyvzG/P+nHK8o49dn5j4HhavBLATleGdnDrniAE=; b=U7trxU0EzI4YWhZOleq0CL1m7O4OQARLMrlkAz9tMWMt1IsUTuv29iFNlgUguT1b+T 4bjXGkpOQ/ZBCnvuRLCpcEyExNX11sirYXe16pt8ZB/mnYD1s4SSZFxqKOVtem/VfA5A Dn5B8QdEiyZUSwypl1ez51bATCAchIXFON75BkhbMr+NdrI/O0WPOJbXjebzd2erTI7x 2YxwO1JTWJrt1K7oSwX2Zaid2rIzskoJMz0g3NdoFEWUNKubolVRHbanvxn5sD+mGmKB KNe3WTrvk2qsB6wuFtfSShP+c8JvHLAcH/iAdDdUYP2AU8FtHgFvdmiONwrlnrbZeSAh zcLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=OySnadAS; 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si20767705oip.248.2019.12.30.03.15.25; Mon, 30 Dec 2019 03:15:59 -0800 (PST) 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=@nvidia.com header.s=n1 header.b=OySnadAS; 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727561AbfL3LOR (ORCPT + 99 others); Mon, 30 Dec 2019 06:14:17 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:19428 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727528AbfL3LOQ (ORCPT ); Mon, 30 Dec 2019 06:14:16 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 30 Dec 2019 03:14:01 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 30 Dec 2019 03:14:15 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 30 Dec 2019 03:14:15 -0800 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 30 Dec 2019 11:14:14 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 30 Dec 2019 11:14:14 +0000 Received: from nkristam-ubuntu.nvidia.com (Not Verified[10.19.64.167]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 30 Dec 2019 03:14:13 -0800 From: Nagarjuna Kristam To: , , , , , , CC: , , , , Nagarjuna Kristam Subject: [Patch V3 10/18] usb: gadget: tegra-xudc: Add usb-phy support Date: Mon, 30 Dec 2019 16:39:47 +0530 Message-ID: <1577704195-2535-11-git-send-email-nkristam@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1577704195-2535-1-git-send-email-nkristam@nvidia.com> References: <1577704195-2535-1-git-send-email-nkristam@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1577704441; bh=K+oEbyvzG/P+nHK8o49dn5j4HhavBLATleGdnDrniAE=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=OySnadASZDujVt68SmLf/IirSw6CImMFl56H89ELpdQwfYcQt8Wr7SL8u+Wr4FtpT +KeDqkvzC3LTfSILAeUhfQ8hvwJbmNeCP7MSPh6T2iXrA/gVpIhiQYNsSLkqOXE3aO p+CotTwMPl+p5dHZP+kKkSI+m/pZiR/r1XFSUKOM1AhizS1vMHob8RMSrYdWXFnzZo A7fYv+YachlxMg6yYH1pifC6c84jp7noAcQl0BPHOryEASPeF/zWgy6SMt/gKuthT5 F1CXQV7SXBkqWs6g3FHdwWd7ZPn/meDpapHS//Jr/80fXAxMzCpzWiU7cZ/0+GYdmJ Co48UVaZGNHcw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org usb-phy is used to get notified on the USB role changes. Get usb-phy from the utmi phy. Signed-off-by: Nagarjuna Kristam --- V2-V3: - No changes in this version --- drivers/usb/gadget/udc/tegra-xudc.c | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index 6ddb974..0f27d57 100644 --- a/drivers/usb/gadget/udc/tegra-xudc.c +++ b/drivers/usb/gadget/udc/tegra-xudc.c @@ -26,7 +26,9 @@ #include #include #include +#include #include +#include #include /* XUSB_DEV registers */ @@ -488,6 +490,9 @@ struct tegra_xudc { bool suspended; bool powergated; + struct usb_phy *usbphy; + struct notifier_block vbus_nb; + struct completion disconnect_complete; bool selfpowered; @@ -678,7 +683,22 @@ static void tegra_xudc_usb_role_sw_work(struct work_struct *work) tegra_xudc_device_mode_on(xudc); else tegra_xudc_device_mode_off(xudc); +} + +static int tegra_xudc_vbus_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct tegra_xudc *xudc = container_of(nb, struct tegra_xudc, + vbus_nb); + + dev_dbg(xudc->dev, "%s action is %ld\n", __func__, action); + + xudc->role = (enum usb_role)action; + if (!xudc->suspended) + schedule_work(&xudc->usb_role_sw_work); + + return NOTIFY_OK; } static void tegra_xudc_plc_reset_work(struct work_struct *work) @@ -1949,6 +1969,9 @@ static int tegra_xudc_gadget_start(struct usb_gadget *gadget, xudc_writel(xudc, val, CTRL); } + if (xudc->usbphy) + otg_set_peripheral(xudc->usbphy->otg, gadget); + xudc->driver = driver; unlock: dev_dbg(xudc->dev, "%s: ret value is %d", __func__, ret); @@ -1969,6 +1992,9 @@ static int tegra_xudc_gadget_stop(struct usb_gadget *gadget) spin_lock_irqsave(&xudc->lock, flags); + if (xudc->usbphy) + otg_set_peripheral(xudc->usbphy->otg, NULL); + val = xudc_readl(xudc, CTRL); val &= ~(CTRL_IE | CTRL_ENABLE); xudc_writel(xudc, val, CTRL); @@ -3573,10 +3599,15 @@ static int tegra_xudc_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&xudc->port_reset_war_work, tegra_xudc_port_reset_war_work); - /* Set the mode as device mode and this keeps phy always ON */ - dev_info(xudc->dev, "Set usb role to device mode always"); - xudc->role = USB_ROLE_DEVICE; - schedule_work(&xudc->usb_role_sw_work); + xudc->vbus_nb.notifier_call = tegra_xudc_vbus_notifier; + xudc->usbphy = devm_usb_get_phy_by_node(xudc->dev, + xudc->utmi_phy->dev.of_node, + &xudc->vbus_nb); + if (IS_ERR(xudc->usbphy)) { + err = PTR_ERR(xudc->usbphy); + dev_err(xudc->dev, "failed to get usbphy phy: %d\n", err); + goto free_eps; + } pm_runtime_enable(&pdev->dev); -- 2.7.4