Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3472508ybv; Mon, 10 Feb 2020 00:14:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyML8gdYw+aDNQ1vQqVWpncQDRNptXTWX0kDHQOyhxsymxe90WZ0NF6VXdeAnnsC+9k5sSv X-Received: by 2002:a05:6830:95:: with SMTP id a21mr204019oto.171.1581322475685; Mon, 10 Feb 2020 00:14:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581322475; cv=none; d=google.com; s=arc-20160816; b=AsIw+CxC5YELVnKMvyW8Vz46miuwEMTISU+ZJqdKxP58tLSoR+YmwhtoYP2rS/orye Nq2vqU+T0QW5qCnQz/ZYjo0dr5gUbCcbh8pDsQlGN4TYQz4AuelFayVDRsvKr6Q/GApn PvcwFu1120zGNUtkWMN8ijTL012OZob1tQIL7Ggq8oJ7RqpgveZ9VjOSocCW/ir7nwJD v8Kflo7aV8B4qC5oYLSQv23rJVFpcN3jkedKYlYCui4H74R8YMQ+kfjZpgXdrl/ssy9m U8e1km9EVbQ0frL2SlLTG9ixotAO482kmYKqhKYIPGKzjxtqPlO/UsK9CV1wS1zHNfMF B3oQ== 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=fM3ZAjPUPkY9CGZ1xeMcfY9eoH1/576Ng/4psDfAtjk=; b=IHnN2WrBMZRPxmB7WqdPxMadrujh2ctcbkc/dxjLDJIeWemTnSZmnIgIgkSNLs3TKc 7hJXsOio+rItBgFyjSXaPlEUxIpMq3NQAdKSvqDv5DPmXtabyZykfGwDmkj5VomU3F5x KslHRoDMC6YjnPDB/s8P6T/WegYDkTQx++L3PAdO/fIDakwC6fkD0Chl2t74XmDbfPdr TvR9W+g/vrJTsfMDKa2FS0Z5KRUJ4564nfbNVu7QeKC/m98nvvVmXmbERUqadBY5F0ME x7V7dtmBsHfP6IY6V5F1R9EpS8upNCYqb0mDLyHo3ficWzpjjwZYHea4J+SCE83IhMQC 716A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=lAH+8G2c; 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 y23si4388254oti.65.2020.02.10.00.14.24; Mon, 10 Feb 2020 00:14:35 -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=lAH+8G2c; 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 S1727079AbgBJINB (ORCPT + 99 others); Mon, 10 Feb 2020 03:13:01 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:18259 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727764AbgBJINA (ORCPT ); Mon, 10 Feb 2020 03:13:00 -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, 10 Feb 2020 00:12:45 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 10 Feb 2020 00:12:59 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 10 Feb 2020 00:12:59 -0800 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 10 Feb 2020 08:12:59 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 10 Feb 2020 08:12:59 +0000 Received: from nkristam-ubuntu.nvidia.com (Not Verified[10.19.67.128]) by hqnvemgw03.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 10 Feb 2020 00:12:58 -0800 From: Nagarjuna Kristam To: , , , , , , CC: , , , , Nagarjuna Kristam Subject: [Patch V5 10/21] usb: gadget: tegra-xudc: Add usb-phy support Date: Mon, 10 Feb 2020 13:41:36 +0530 Message-ID: <1581322307-11140-11-git-send-email-nkristam@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1581322307-11140-1-git-send-email-nkristam@nvidia.com> References: <1581322307-11140-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=1581322365; bh=fM3ZAjPUPkY9CGZ1xeMcfY9eoH1/576Ng/4psDfAtjk=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=lAH+8G2cLInkZY2vGi41FsrbwhCtv57O8Jbx2lGWXMjWg5PfYsbFmEMXZYAtKpG6+ gB9R/8bac+UXihE1KyvfyKWXr1WiNs4J+lDf7pn+uGQ/xpZPsGD8HYepoPAQDMiiFX 48i8mGZ3P/DYw8aoqQOtzP5zXS8FhEUMhG45ca/Ydfx+05Al+JbwIj6H/xafomwh8Q hnk2abgpIVXF/a4sxD1cul0sraBMphYQ6Ju4Pg5sG894FGSs/A8JaEoTsaIPlsHo0G 9AoCKQ5PK/f0ikNo6eWS5SjehozLF6NsdV9eLsK/BvfJ9lgEk0GVjzIYF0jgrI0GC0 eNOm7Uwihxr6A== 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 --- V5: - No changes. --- V4: - Addressed nit comments from Thierry. - usb_phy_event is used to detect device mode instead of usb_role. --- V2-V3: - No changes in this version --- drivers/usb/gadget/udc/tegra-xudc.c | 48 ++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index acecdcf..7411dd15 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 */ @@ -487,6 +489,9 @@ struct tegra_xudc { bool suspended; bool powergated; + struct usb_phy *usbphy; + struct notifier_block vbus_nb; + struct completion disconnect_complete; bool selfpowered; @@ -669,6 +674,31 @@ static void tegra_xudc_usb_role_sw_work(struct work_struct *work) tegra_xudc_device_mode_off(xudc); } +static int tegra_xudc_vbus_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct tegra_xudc *xudc = container_of(nb, struct tegra_xudc, + vbus_nb); + struct usb_phy *usbphy = (struct usb_phy *)data; + + dev_dbg(xudc->dev, "%s(): event is %d\n", __func__, usbphy->last_event); + + if ((xudc->device_mode && usbphy->last_event == USB_EVENT_VBUS) || + (!xudc->device_mode && usbphy->last_event != USB_EVENT_VBUS)) { + dev_dbg(xudc->dev, "Same role(%d) received. Ignore", + xudc->device_mode); + return NOTIFY_OK; + } + + xudc->device_mode = (usbphy->last_event == USB_EVENT_VBUS) ? true : + false; + + if (!xudc->suspended) + schedule_work(&xudc->usb_role_sw_work); + + return NOTIFY_OK; +} + static void tegra_xudc_plc_reset_work(struct work_struct *work) { struct delayed_work *dwork = to_delayed_work(work); @@ -1937,6 +1967,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); @@ -1957,6 +1990,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); @@ -3561,9 +3597,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 */ - xudc->device_mode = true; - schedule_work(&xudc->usb_role_sw_work); + xudc->vbus_nb.notifier_call = tegra_xudc_vbus_notify; + 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 USB PHY: %d\n", err); + goto free_eps; + } pm_runtime_enable(&pdev->dev); -- 2.7.4