From patchwork Fri Jul 21 11:01:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manu Gautam X-Patchwork-Id: 9856575 X-Patchwork-Delegate: agross@codeaurora.org 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 19305601C0 for ; Fri, 21 Jul 2017 11:04:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 072AB28791 for ; Fri, 21 Jul 2017 11:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFA33287B2; Fri, 21 Jul 2017 11:04:07 +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 6557028791 for ; Fri, 21 Jul 2017 11:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752310AbdGULCi (ORCPT ); Fri, 21 Jul 2017 07:02:38 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58254 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752270AbdGULCg (ORCPT ); Fri, 21 Jul 2017 07:02:36 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 904CD61112; Fri, 21 Jul 2017 11:02:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500634955; bh=jK6JFKBsxbfh1umyCXV4DpJrmnuSM6bgsXvT44u6bi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UDIMoXcx/VEpSq0/14bb10xayAbk5F3kqFTxlpDBM1eE7Xt5r0ikUu6C/jowWuYOp Ln8epFUyE/ov0JuhWwMCoKuxDD30gpEXCpKR3uSHnRFrwNgLrXxWH36UTkl13I2olE Y+98CGLirBZNccAz0P5NhprMzdAlL/ivTXIlTVco= 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 9890660FF4; Fri, 21 Jul 2017 11:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1500634954; bh=jK6JFKBsxbfh1umyCXV4DpJrmnuSM6bgsXvT44u6bi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QM80awDkaYwy6ePNwDVqKVM/5w4x6BJetgZIxCY9lDE0igNlW9l//aBxaWM4s4SY/ 7+MrXamAiMEnBpNRbLvcUX0GHxCtITeGS4wUswUis3SnmYB9VaL1HAfp8LUwMBYrpO CdFwnl4cOlkdjuKKzuBOQFTndL/T+I6gvjEtV2D8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9890660FF4 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 , Felipe Balbi Cc: linux-arm-msm@vger.kernel.org, Manu Gautam , Vivek Gautam , Jaehoon Chung , Wei Yongjun , Fengguang Wu , linux-kernel@vger.kernel.org (open list:GENERIC PHY FRAMEWORK) Subject: [PATCH v1 2/6] phy: qcom-qmp: Power-on PHY before initialization Date: Fri, 21 Jul 2017 16:31:57 +0530 Message-Id: <1500634921-25914-3-git-send-email-mgautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500634921-25914-1-git-send-email-mgautam@codeaurora.org> References: <1500634921-25914-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 PHY must be powered on before turning ON clocks and attempting to initialize it. Driver is exposing separate init and power_on routines for this. Apparently USB dwc3 core driver performs power-on after init. Also, poweron and init for QMP PHY need to be executed together always, hence remove poweron callback from phy_ops and explicitly perform this from init, similar changes needed for poweroff. Signed-off-by: Manu Gautam diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c index a230c7b..aefb853 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -479,6 +479,8 @@ struct qcom_qmp { struct mutex phy_mutex; int init_count; + bool power_enabled; + bool clk_enabled; }; static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val) @@ -599,29 +601,69 @@ static void qcom_qmp_phy_configure(void __iomem *base, } } -static int qcom_qmp_phy_poweron(struct phy *phy) +static int qcom_qmp_phy_poweron(struct qcom_qmp *qmp) { - struct qmp_phy *qphy = phy_get_drvdata(phy); - struct qcom_qmp *qmp = qphy->qmp; int num = qmp->cfg->num_vregs; int ret; - dev_vdbg(&phy->dev, "Powering on QMP phy\n"); + dev_vdbg(qmp->dev, "Powering on QMP phy\n"); + + if (qmp->power_enabled) + return 0; /* turn on regulator supplies */ ret = regulator_bulk_enable(num, qmp->vregs); if (ret) dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret); + else + qmp->power_enabled = true; return ret; } -static int qcom_qmp_phy_poweroff(struct phy *phy) +static int qcom_qmp_phy_poweroff(struct qcom_qmp *qmp) { - struct qmp_phy *qphy = phy_get_drvdata(phy); - struct qcom_qmp *qmp = qphy->qmp; + if (!qmp->power_enabled) + return 0; regulator_bulk_disable(qmp->cfg->num_vregs, qmp->vregs); + qmp->power_enabled = false; + + return 0; +} + +static int qcom_qmp_phy_enable_clocks(struct qcom_qmp *qmp) +{ + int ret = 0, i; + + if (qmp->clk_enabled) + return 0; + + for (i = 0; i < qmp->cfg->num_clks; i++) { + ret = clk_prepare_enable(qmp->clks[i]); + if (ret) { + dev_err(qmp->dev, "failed to enable %s clk, err=%d\n", + qmp->cfg->clk_list[i], ret); + while (--i >= 0) + clk_disable_unprepare(qmp->clks[i]); + } + } + qmp->clk_enabled = true; + + return ret; +} + +static int qcom_qmp_phy_disable_clocks(struct qcom_qmp *qmp) +{ + int i = qmp->cfg->num_clks; + + if (!qmp->clk_enabled) + return 0; + + while (--i >= 0) + clk_disable_unprepare(qmp->clks[i]); + + qmp->clk_enabled = false; return 0; } @@ -729,19 +771,17 @@ static int qcom_qmp_phy_init(struct phy *phy) void __iomem *pcs = qphy->pcs; void __iomem *status; unsigned int mask, val; - int ret, i; + int ret; dev_vdbg(qmp->dev, "Initializing QMP phy\n"); - for (i = 0; i < qmp->cfg->num_clks; i++) { - ret = clk_prepare_enable(qmp->clks[i]); - if (ret) { - dev_err(qmp->dev, "failed to enable %s clk, err=%d\n", - qmp->cfg->clk_list[i], ret); - while (--i >= 0) - clk_disable_unprepare(qmp->clks[i]); - } - } + ret = qcom_qmp_phy_poweron(qmp); + if (ret) + return ret; + + ret = qcom_qmp_phy_enable_clocks(qmp); + if (ret) + goto err_clk_enable; ret = qcom_qmp_phy_com_init(qmp); if (ret) @@ -801,8 +841,9 @@ static int qcom_qmp_phy_init(struct phy *phy) err_lane_rst: qcom_qmp_phy_com_exit(qmp); err_com_init: - while (--i >= 0) - clk_disable_unprepare(qmp->clks[i]); + qcom_qmp_phy_disable_clocks(qmp); +err_clk_enable: + qcom_qmp_phy_poweroff(qmp); return ret; } @@ -812,7 +853,6 @@ static int qcom_qmp_phy_exit(struct phy *phy) struct qmp_phy *qphy = phy_get_drvdata(phy); struct qcom_qmp *qmp = qphy->qmp; const struct qmp_phy_cfg *cfg = qmp->cfg; - int i = cfg->num_clks; clk_disable_unprepare(qphy->pipe_clk); @@ -830,8 +870,9 @@ static int qcom_qmp_phy_exit(struct phy *phy) qcom_qmp_phy_com_exit(qmp); - while (--i >= 0) - clk_disable_unprepare(qmp->clks[i]); + qcom_qmp_phy_disable_clocks(qmp); + + qcom_qmp_phy_poweroff(qmp); return 0; } @@ -958,8 +999,6 @@ static int phy_pipe_clk_register(struct qcom_qmp *qmp, int id) static const struct phy_ops qcom_qmp_phy_gen_ops = { .init = qcom_qmp_phy_init, .exit = qcom_qmp_phy_exit, - .power_on = qcom_qmp_phy_poweron, - .power_off = qcom_qmp_phy_poweroff, .owner = THIS_MODULE, };