From patchwork Wed Sep 27 08:59:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manu Gautam X-Patchwork-Id: 9973505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 49E3760365 for ; Wed, 27 Sep 2017 09:05:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DFEC1FFB2 for ; Wed, 27 Sep 2017 09:05:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 326E0290E4; Wed, 27 Sep 2017 09:05:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B8561FFB2 for ; Wed, 27 Sep 2017 09:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753053AbdI0JEA (ORCPT ); Wed, 27 Sep 2017 05:04:00 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:51492 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752507AbdI0JBZ (ORCPT ); Wed, 27 Sep 2017 05:01:25 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 54C2D609D1; Wed, 27 Sep 2017 09:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1506502884; bh=WkfqKEDxFWt+BM7xVVCGvUnTxeW6PXiZKPKJ8eC37rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gsKmc1taE4/GH1BHZeDTGlHAOwVrVGX1iK02AdiyJ9LVGupsJTqk7uxyBxKywUvnB FkxJwAphs+d7HHos7d4QudKaQStgfQUSHnjPfSFRmrYtIUaVujI1w6791yXEOp1ehN CEHQsgFLMff1CLZ3KesW3jdHk7U32OkN64Exren4= Received: from mgautam-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 76E8F6071D; Wed, 27 Sep 2017 09:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1506502882; bh=WkfqKEDxFWt+BM7xVVCGvUnTxeW6PXiZKPKJ8eC37rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nGweno2KzXlZbGAxso0pv9t186eTTB5CFkBH1ZzYHlhZQG74v4Tyg1Atb6I7l0j4c M2uETPlpKpMCOh298JX2zKtQ81H8sKn3V/ndk50nTRb5PXFV10yCbs2iS9otjbg1Sw xsF0JbXILGnVVTbjh3sa89Y4wszUNXToVdi1BouY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 76E8F6071D 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=mgautam@codeaurora.org From: Manu Gautam To: Kishon Vijay Abraham I Cc: Felipe Balbi , linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, Manu Gautam , Vivek Gautam , Viresh Kumar , Krzysztof Kozlowski , linux-kernel@vger.kernel.org (open list:GENERIC PHY FRAMEWORK) Subject: [PATCH v2 14/17] phy: qcom-qusb2: Set vbus sw-override signal in device mode Date: Wed, 27 Sep 2017 14:29:10 +0530 Message-Id: <1506502753-27408-15-git-send-email-mgautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1506502753-27408-1-git-send-email-mgautam@codeaurora.org> References: <1506502753-27408-1-git-send-email-mgautam@codeaurora.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP VBUS signal coming from PHY must be asserted in device for controller to start operation or assert pull-up. For some platforms where VBUS line is not connected to PHY there is HS_PHY_CTRL register in QSCRATCH wrapper that can be used by software to override VBUS signal going to controller. Signed-off-by: Manu Gautam --- drivers/phy/qualcomm/phy-qcom-qusb2.c | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c index bda1f4c..0e9d88b 100644 --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c @@ -68,6 +68,11 @@ #define QUSB2PHY_IMP_CTRL2 0x224 #define QUSB2PHY_CHG_CTRL2 0x23c +/* QSCRATCH register bits */ +#define QSCRATCH_HS_PHY_CTRL 0x10 +#define UTMI_OTG_VBUS_VALID BIT(20) +#define SW_SESSVLD_SEL BIT(28) + struct qusb2_phy_init_tbl { unsigned int offset; unsigned int val; @@ -211,6 +216,7 @@ struct qusb2_phy_cfg { * * @phy: generic phy * @base: iomapped memory space for qubs2 phy + * @qscratch_base: iomapped memory space for qscratch region * * @cfg_ahb_clk: AHB2PHY interface clock * @ref_clk: phy reference clock @@ -223,10 +229,12 @@ struct qusb2_phy_cfg { * * @cfg: phy config data * @has_se_clk_scheme: indicate if PHY has single-ended ref clock scheme + * @mode: indicate current PHY mode of operation e.g. HOST or DEVICE */ struct qusb2_phy { struct phy *phy; void __iomem *base; + void __iomem *qscratch_base; struct clk *cfg_ahb_clk; struct clk *ref_clk; @@ -239,6 +247,7 @@ struct qusb2_phy { const struct qusb2_phy_cfg *cfg; bool has_se_clk_scheme; + enum phy_mode mode; }; static inline void qusb2_setbits(void __iomem *base, u32 offset, u32 val) @@ -307,6 +316,25 @@ static void qusb2_phy_set_tune2_param(struct qusb2_phy *qphy) qusb2_setbits(qphy->base, QUSB2PHY_PORT_TUNE2, val[0] << 0x4); } +static int qusb2_phy_set_mode(struct phy *phy, enum phy_mode mode) +{ + struct qusb2_phy *qphy = phy_get_drvdata(phy); + + qphy->mode = mode; + + /* Update VBUS override in qscratch register */ + if (qphy->qscratch_base) { + if (mode == PHY_MODE_USB_DEVICE) + qusb2_setbits(qphy->qscratch_base, QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + else + qusb2_clrbits(qphy->qscratch_base, QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + } + + return 0; +} + static int qusb2_phy_init(struct phy *phy) { struct qusb2_phy *qphy = phy_get_drvdata(phy); @@ -473,6 +501,7 @@ static int qusb2_phy_exit(struct phy *phy) static const struct phy_ops qusb2_phy_gen_ops = { .init = qusb2_phy_init, .exit = qusb2_phy_exit, + .set_mode = qusb2_phy_set_mode, .owner = THIS_MODULE, }; @@ -507,6 +536,16 @@ static int qusb2_phy_probe(struct platform_device *pdev) if (IS_ERR(qphy->base)) return PTR_ERR(qphy->base); + /* Check if platform uses qscratch wrapper */ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qscratch"); + if (res) { + /* Can't request region as used by other phy and glue drivers */ + qphy->qscratch_base = devm_ioremap(dev, res->start, + resource_size(res)); + if (IS_ERR(qphy->qscratch_base)) + return PTR_ERR(qphy->qscratch_base); + } + qphy->cfg_ahb_clk = devm_clk_get(dev, "cfg_ahb"); if (IS_ERR(qphy->cfg_ahb_clk)) { ret = PTR_ERR(qphy->cfg_ahb_clk);