Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3471694ybv; Mon, 10 Feb 2020 00:13:27 -0800 (PST) X-Google-Smtp-Source: APXvYqzVy00nZsbvafcS8dImLjBIVQYQhAGxa2i8Bgox3+SJ8DdooTCX+TJFDhvmOjwkiQOXipyZ X-Received: by 2002:a05:6808:b13:: with SMTP id s19mr104959oij.119.1581322407459; Mon, 10 Feb 2020 00:13:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581322407; cv=none; d=google.com; s=arc-20160816; b=niM5RnaFZynda9Dk0HhBWinvaK7QHio3FN6Pbb2iaD3YvcLvixMnrKt61nxn0WfDBa WBTES25M26zXOwLEIqyAhE9gtAU6VckO1Wcj/fAO2mFBLoMYWT1Lu7iLTqxIDCI53PaK 9GoUBAgrsHZMg2vmBjgQLUoqmUEJrD00qX3o4Ft5BLGAbsWcmlKm4M6emCtrnSGUsI8X r4yeoKMab7GvamwP9af2SX96Ngtqk7Uym/7iLOKpy8K6/aRF3ab2UnlMQ4UzPHHb8oJ7 U5XF/IxmP7jklFZE0oYMaVVOR3lyLkBVb2ZU9p1kE44zmg3YioxkeeoG0/2mLgB141L8 391Q== 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=Y389Vbo0qSoZ7bEjswVj6WBVgDKXBxnfWfVQytx9TXQ=; b=x1GkkfLuz5CnLZbHA1XAiHm0HgcapuJQRfkU0bviTiYt4RoRfe9BOASgdlpc92Bpuj DWXZJg9AvC7fHL9Qap9mQBVb4/V5nI9mZ+w5NXvUBeCLWUJ2GMr2+l472LyekXYzTNuL 4IJ6qspu7FUtD6VFj8pMk0DcHkO0t3v+E/BrQbFiBa1G7HZJeOcK7+RKOknw4gPeQ1Lt Js7hm+4KHFZYEvxrd/k2nq3fy99280uO6JUodMdycCR9/KJnbb/nErwJ4nS06NF/ODDs M/QnAsBV3ON6chcbtvxDicmDspLW9NmBKsB4PEM3AO0yFDCZhkJZE5TmEH/WsWmGVn2p SYIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=fmB8vTIV; 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 q9si8105134oif.92.2020.02.10.00.13.15; Mon, 10 Feb 2020 00:13:27 -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=fmB8vTIV; 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 S1727732AbgBJIMv (ORCPT + 99 others); Mon, 10 Feb 2020 03:12:51 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:18218 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727707AbgBJIMu (ORCPT ); Mon, 10 Feb 2020 03:12:50 -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:34 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 10 Feb 2020 00:12:48 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 10 Feb 2020 00:12:48 -0800 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 10 Feb 2020 08:12:47 +0000 Received: from hqnvemgw03.nvidia.com (10.124.88.68) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Mon, 10 Feb 2020 08:12:47 +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:47 -0800 From: Nagarjuna Kristam To: , , , , , , CC: , , , , Nagarjuna Kristam Subject: [Patch V5 07/21] phy: tegra: xusb: Add set_mode support for UTMI phy on Tegra186 Date: Mon, 10 Feb 2020 13:41:33 +0530 Message-ID: <1581322307-11140-8-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=1581322354; bh=Y389Vbo0qSoZ7bEjswVj6WBVgDKXBxnfWfVQytx9TXQ=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=fmB8vTIV47+KexiFUE1IeSs6EU1t97acpRtjWo2P4aej61nVuGGnicbbC2YoompI0 TZCr9Y4Z381rx4X3u11EYZ6NcWAwZEXN06AsckYrDOCf0Dy+WPD3e5spXEt50bQsf0 msxRoBqijJSi8ze58GVIwAacinr+TDueVOg3COFkLiPOIFWO4C3nxAuLvRfpj8NT6A btP6afPG6EBcJBZDeOFaHrWe8xbDyPuuZ2KwSMBkAhwWItB0+GoOrjHlfAoOHuc2vO LeG+ouGH9i9SNTvsrlok68JMhjKGo02UrjGlYGo98Z4syC+hVbOSRtXDT8AioXPVC2 XduJNL+wKPD1A== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for set_mode on UTMI phy. This allow XUSB host/device mode drivers to configure the hardware to corresponding modes. Signed-off-by: Nagarjuna Kristam Acked-by: Thierry Reding --- V5: - No changes. --- V4: - Added comment for conditional regulator disable. - Added Acked-by info. --- V2-V3: - No changes in this version --- drivers/phy/tegra/xusb-tegra186.c | 114 ++++++++++++++++++++++++++++++-------- 1 file changed, 92 insertions(+), 22 deletions(-) diff --git a/drivers/phy/tegra/xusb-tegra186.c b/drivers/phy/tegra/xusb-tegra186.c index 84c2739..ea62251 100644 --- a/drivers/phy/tegra/xusb-tegra186.c +++ b/drivers/phy/tegra/xusb-tegra186.c @@ -301,6 +301,97 @@ static void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy) tegra186_utmi_bias_pad_power_off(padctl); } +static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl, + bool status) +{ + u32 value; + + dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear"); + + value = padctl_readl(padctl, USB2_VBUS_ID); + + if (status) { + value |= VBUS_OVERRIDE; + value &= ~ID_OVERRIDE(~0); + value |= ID_OVERRIDE_FLOATING; + } else { + value &= ~VBUS_OVERRIDE; + } + + padctl_writel(padctl, value, USB2_VBUS_ID); + + return 0; +} + +static int tegra186_xusb_padctl_id_override(struct tegra_xusb_padctl *padctl, + bool status) +{ + u32 value; + + dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear"); + + value = padctl_readl(padctl, USB2_VBUS_ID); + + if (status) { + if (value & VBUS_OVERRIDE) { + value &= ~VBUS_OVERRIDE; + padctl_writel(padctl, value, USB2_VBUS_ID); + usleep_range(1000, 2000); + + value = padctl_readl(padctl, USB2_VBUS_ID); + } + + value &= ~ID_OVERRIDE(~0); + value |= ID_OVERRIDE_GROUNDED; + } else { + value &= ~ID_OVERRIDE(~0); + value |= ID_OVERRIDE_FLOATING; + } + + padctl_writel(padctl, value, USB2_VBUS_ID); + + return 0; +} + +static int tegra186_utmi_phy_set_mode(struct phy *phy, enum phy_mode mode, + int submode) +{ + struct tegra_xusb_lane *lane = phy_get_drvdata(phy); + struct tegra_xusb_padctl *padctl = lane->pad->padctl; + struct tegra_xusb_usb2_port *port = tegra_xusb_find_usb2_port(padctl, + lane->index); + int err = 0; + + mutex_lock(&padctl->lock); + + dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode); + + if (mode == PHY_MODE_USB_OTG) { + if (submode == USB_ROLE_HOST) { + tegra186_xusb_padctl_id_override(padctl, true); + + err = regulator_enable(port->supply); + } else if (submode == USB_ROLE_DEVICE) { + tegra186_xusb_padctl_vbus_override(padctl, true); + } else if (submode == USB_ROLE_NONE) { + /* + * When port is peripheral only or role transitions to + * USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not + * enabled. + */ + if (regulator_is_enabled(port->supply)) + regulator_disable(port->supply); + + tegra186_xusb_padctl_id_override(padctl, false); + tegra186_xusb_padctl_vbus_override(padctl, false); + } + } + + mutex_unlock(&padctl->lock); + + return err; +} + static int tegra186_utmi_phy_power_on(struct phy *phy) { struct tegra_xusb_lane *lane = phy_get_drvdata(phy); @@ -439,6 +530,7 @@ static const struct phy_ops utmi_phy_ops = { .exit = tegra186_utmi_phy_exit, .power_on = tegra186_utmi_phy_power_on, .power_off = tegra186_utmi_phy_power_off, + .set_mode = tegra186_utmi_phy_set_mode, .owner = THIS_MODULE, }; @@ -857,28 +949,6 @@ static void tegra186_xusb_padctl_remove(struct tegra_xusb_padctl *padctl) { } -static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl, - bool status) -{ - u32 value; - - dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear"); - - value = padctl_readl(padctl, USB2_VBUS_ID); - - if (status) { - value |= VBUS_OVERRIDE; - value &= ~ID_OVERRIDE(~0); - value |= ID_OVERRIDE_FLOATING; - } else { - value &= ~VBUS_OVERRIDE; - } - - padctl_writel(padctl, value, USB2_VBUS_ID); - - return 0; -} - static const struct tegra_xusb_padctl_ops tegra186_xusb_padctl_ops = { .probe = tegra186_xusb_padctl_probe, .remove = tegra186_xusb_padctl_remove, -- 2.7.4