Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp14057349ybl; Mon, 30 Dec 2019 03:15:59 -0800 (PST) X-Google-Smtp-Source: APXvYqzBlnHxXclzDSlRq9Eld3pjlduxnwM3YaXIOSWjPu9Tx0ZwTZ9RwSh8BlrMia0snrJj8rSX X-Received: by 2002:a05:6830:1042:: with SMTP id b2mr73874705otp.306.1577704559328; 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=xieyIorwsbXohgfXU0elmb37cuuwgv6QmavfT/vcii9k1G/IV7ua5VR6zUyhGWwKW6 O4Vekxam8zopFE2wX5TXvmLsF6rM19NyjIlYca+0mdavdaQcRhAjmmDdVWrMv86CAtzA jOqvnDFt1dG0vJALUvOqOfDXugpvI9Y3C+rHpEK+m5qZ426SVZ4Z4YGZmgjvPRZoYByY EsQcnLEn6dzs2Qohb+3EJve+u40vECSMq2z6j4jo9IrAX5L0L35+qPVbyJsZe2TNfjo4 nnp3Zb7HpLWZVX/R3SXNysarwEu6/g+ruZxSzfe7h9AA0AT9jZgg1Uz2QR1mKcxbDyrB pkWw== 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=KV+RvZVcS5R2rrUVtJwt3OsWge2zRuD3fZVV5DbWXpE=; b=tORhRM6moosaCCs/oagRZVRtEEt6Z4imSn8Aqtd6oMdegodnhilxcsHo12+VlQa75y BgyB6xbp+oKrkZabg9sTPlLI1aYWc5HB+ou53r3PD7AMobqBxLlRI93acLMXQp0js86w FSDVv0+FgCovp3syAuLwYhjZ4gJTJ0TIshtpwlR7FvW5leA1FmWRUcxMel45TCWSQRRy 5fUZkVd2jTa1AlMzzhT+WXjiERusZ5552TJQPgg6mNjKqtjhu/8BGYW9WX/KA0maYj/G ByydOQ0dpHUkD8fRsljFxOqabp7Kgc3QqdavvjFl4c777uCCOgvdv9qpRcxT9T29rg8r /0ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=UIDDn1z8; 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 k13si20333253oij.118.2019.12.30.03.15.27; 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=UIDDn1z8; 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 S1727515AbfL3LOG (ORCPT + 99 others); Mon, 30 Dec 2019 06:14:06 -0500 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:1277 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727471AbfL3LOE (ORCPT ); Mon, 30 Dec 2019 06:14:04 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 30 Dec 2019 03:13:49 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 30 Dec 2019 03:14:03 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 30 Dec 2019 03:14:03 -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, 30 Dec 2019 11:14:03 +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, 30 Dec 2019 11:14:03 +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:02 -0800 From: Nagarjuna Kristam To: , , , , , , CC: , , , , Nagarjuna Kristam Subject: [Patch V3 07/18] phy: tegra: xusb: Add set_mode support for utmi phy on Tegra186 Date: Mon, 30 Dec 2019 16:39:44 +0530 Message-ID: <1577704195-2535-8-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=1577704429; bh=KV+RvZVcS5R2rrUVtJwt3OsWge2zRuD3fZVV5DbWXpE=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=UIDDn1z85Nq6LCqY6n96wPxQvvxsFAa23oiscbLIh0pnkd4GQKxIYS90gdZSTzMFe yWxucpNXU3D3Ai1E6PE5hzxwGuUwxZmykPxJxRwyXnNVUqHubfhN8lybIQ5sve7sVB MA9qblNXnc9CKh8raC14Y5zSfRdBz6aOdovYiGPzEQ6ulIFLAhrZQNWTNTCuC0/l6Y Cm4F7XPr80aaUs8JSFBOrBBPWH1ye50Z47+SzqEAoq6S7wOO4ib1uLkd3qip4R/PJL ds0cRsROvtrZwOF0r/545G9Bt0wKgvvI5wEW9WFV6jvu4d4EMiBNn7yXYrWFE2zy/2 EukDA6/nP43Ig== 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 --- V2-V3: - No changes in this version --- drivers/phy/tegra/xusb-tegra186.c | 109 ++++++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 22 deletions(-) diff --git a/drivers/phy/tegra/xusb-tegra186.c b/drivers/phy/tegra/xusb-tegra186.c index 84c2739..9a45160 100644 --- a/drivers/phy/tegra/xusb-tegra186.c +++ b/drivers/phy/tegra/xusb-tegra186.c @@ -301,6 +301,92 @@ 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) { + 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 +525,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 +944,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