Received: by 10.223.164.202 with SMTP id h10csp4904832wrb; Tue, 21 Nov 2017 01:26:42 -0800 (PST) X-Google-Smtp-Source: AGs4zMY0WywWg+sONBE9z+mwlPZhNo+F9z2UBOjD38XHJj8+UIGc5jbjqIN1gRTLsnkNetVlJfEg X-Received: by 10.159.216.141 with SMTP id s13mr16606190plp.125.1511256402278; Tue, 21 Nov 2017 01:26:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511256402; cv=none; d=google.com; s=arc-20160816; b=FJ/mdVb9tHDCpOeQ80Wb9qzEYT5IBejnCGdRGaqAGUe+0a7jad/soTHv7erYu0Zkmi 0k8lNZCkcELe/Pc7isclxe5YVcMMC6AbV7AJ45Av5+fByC1weyCt7DUXH4yjeEBA2x66 dBDSOHGMt2No71FQrsrVWidireI1WlnLj8GaAkyk6cK6rJ7M25APQIM58YZW4e6kvRKC h34a3lOdCNbB6qwLuc4IJOpFxWZRPi7Ear4YfMHAj4dTw4FFQmn/vDwE33fQUelUHvx8 8AGkIV7VnxJVjBnZXS99inzbkumiffSxonXzHYu0bDVMCTCiwssDos1um4P86o6/PLGE BtZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=EobzEHAHxX+/PGihniUDALNQpB8YCLsd87XuhnaiIv8=; b=NtDfbUSJ8PsB3fb2WyBGV7SOFVEV438STIXJ9EEjI0IKd/VHjoR/AgSyZeAXUrwMRj hq85V0pri1pyCaxZSV7kr+sI/c8rd9BwPoBzJNFZX+oUcea6PmZhtEpjnySnh2HRArcp sVUawzNg2F2sB4M+2/z8wBy3OHriUXQqYN9UiZHddAyYzlZI/DNY0r/Zk0WqlksqGm8q aBIyO1Ao2/EKrjjgBS0xqHyLR7zDqH5iv8mihf2d7AysP7mYbcihEhwIoMsFXgw7ORVu 5ieOZrdBkjRGSVpH6LT3Fmjd2zX1l/dI43yWBpEFXTWamRCkXl7ATwIquvB2+MOj5UCC VnQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=QeSIhffA; dkim=pass header.i=@codeaurora.org header.s=default header.b=QeSIhffA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si10390046pgn.364.2017.11.21.01.26.31; Tue, 21 Nov 2017 01:26:42 -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=@codeaurora.org header.s=default header.b=QeSIhffA; dkim=pass header.i=@codeaurora.org header.s=default header.b=QeSIhffA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752006AbdKUJZd (ORCPT + 72 others); Tue, 21 Nov 2017 04:25:33 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:42008 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751263AbdKUJZ0 (ORCPT ); Tue, 21 Nov 2017 04:25:26 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DD054607EA; Tue, 21 Nov 2017 09:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511256325; bh=0Uz+AqvETrdN6JFj7jUUOia15hVM02sfuQ5qlTx/M5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QeSIhffAGgndK/qm56TX0lBAcDUUS67U1dajzChUcLHbIdKb9Xwc5r5nH6fHUG8PA JTqpZVJgvDFyW/qIZDxSETrtE4a2pTs+eZgs3fdgF84oZ2buEpybTzktlPyChLSCqN +4J2BdCAi+hZp1v0W/Njbd0cbjTc2qo5ktbdBH3g= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 AD388606F8; Tue, 21 Nov 2017 09:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511256325; bh=0Uz+AqvETrdN6JFj7jUUOia15hVM02sfuQ5qlTx/M5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QeSIhffAGgndK/qm56TX0lBAcDUUS67U1dajzChUcLHbIdKb9Xwc5r5nH6fHUG8PA JTqpZVJgvDFyW/qIZDxSETrtE4a2pTs+eZgs3fdgF84oZ2buEpybTzktlPyChLSCqN +4J2BdCAi+hZp1v0W/Njbd0cbjTc2qo5ktbdBH3g= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org AD388606F8 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: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, Manu Gautam , Vivek Gautam , Heiko Stuebner , Jaehoon Chung , linux-kernel@vger.kernel.org (open list:GENERIC PHY FRAMEWORK) Subject: [PATCH v3 15/16] phy: qcom-qusb2: Add support for runtime PM Date: Tue, 21 Nov 2017 14:53:25 +0530 Message-Id: <1511256206-1587-16-git-send-email-mgautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1511256206-1587-1-git-send-email-mgautam@codeaurora.org> References: <1511256206-1587-1-git-send-email-mgautam@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Disable clocks and enable DP/DM wakeup interrupts when suspending PHY. Core driver should notify speed to PHY driver to enable appropriate DP/DM wakeup interrupts polarity in suspend state. Signed-off-by: Manu Gautam --- drivers/phy/qualcomm/phy-qcom-qusb2.c | 181 ++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) diff --git a/drivers/phy/qualcomm/phy-qcom-qusb2.c b/drivers/phy/qualcomm/phy-qcom-qusb2.c index bda1f4c..84cce0e 100644 --- a/drivers/phy/qualcomm/phy-qcom-qusb2.c +++ b/drivers/phy/qualcomm/phy-qcom-qusb2.c @@ -56,6 +56,18 @@ #define PHY_CLK_SCHEME_SEL BIT(0) +/* QUSB2PHY_INTR_CTRL register bits */ +#define DMSE_INTR_HIGH_SEL BIT(4) +#define DPSE_INTR_HIGH_SEL BIT(3) +#define CHG_DET_INTR_EN BIT(2) +#define DMSE_INTR_EN BIT(1) +#define DPSE_INTR_EN BIT(0) + +/* QUSB2PHY_PLL_CORE_INPUT_OVERRIDE register bits */ +#define CORE_PLL_EN_FROM_RESET BIT(4) +#define CORE_RESET BIT(5) +#define CORE_RESET_MUX BIT(6) + #define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO 0x04 #define QUSB2PHY_PLL_CLOCK_INVERTERS 0x18c #define QUSB2PHY_PLL_CMODE 0x2c @@ -93,6 +105,7 @@ struct qusb2_phy_init_tbl { /* set of registers with offsets different per-PHY */ enum qusb2phy_reg_layout { + QUSB2PHY_PLL_CORE_INPUT_OVERRIDE, QUSB2PHY_PLL_STATUS, QUSB2PHY_PORT_TUNE1, QUSB2PHY_PORT_TUNE2, @@ -112,8 +125,10 @@ enum qusb2phy_reg_layout { [QUSB2PHY_PORT_TUNE3] = 0x88, [QUSB2PHY_PORT_TUNE4] = 0x8c, [QUSB2PHY_PORT_TUNE5] = 0x90, + [QUSB2PHY_PORT_TEST1] = 0xb8, [QUSB2PHY_PORT_TEST2] = 0x9c, [QUSB2PHY_PORT_POWERDOWN] = 0xb4, + [QUSB2PHY_INTR_CTRL] = 0xbc, }; static const struct qusb2_phy_init_tbl msm8996_init_tbl[] = { @@ -133,14 +148,17 @@ enum qusb2phy_reg_layout { }; static const unsigned int qusb2_v2_regs_layout[] = { + [QUSB2PHY_PLL_CORE_INPUT_OVERRIDE] = 0xa8, [QUSB2PHY_PLL_STATUS] = 0x1a0, [QUSB2PHY_PORT_TUNE1] = 0x240, [QUSB2PHY_PORT_TUNE2] = 0x244, [QUSB2PHY_PORT_TUNE3] = 0x248, [QUSB2PHY_PORT_TUNE4] = 0x24c, [QUSB2PHY_PORT_TUNE5] = 0x250, + [QUSB2PHY_PORT_TEST1] = 0x254, [QUSB2PHY_PORT_TEST2] = 0x258, [QUSB2PHY_PORT_POWERDOWN] = 0x210, + [QUSB2PHY_INTR_CTRL] = 0x230, }; static const struct qusb2_phy_init_tbl qusb2_v2_init_tbl[] = { @@ -175,9 +193,13 @@ struct qusb2_phy_cfg { const unsigned int *regs; unsigned int mask_core_ready; unsigned int disable_ctrl; + unsigned int autoresume_en; /* true if PHY has PLL_TEST register to select clk_scheme */ bool has_pll_test; + + /* true if PHY has PLL_CORE_INPUT_OVERRIDE register to reset PLL */ + bool has_pll_override; }; static const struct qusb2_phy_cfg msm8996_phy_cfg = { @@ -188,6 +210,7 @@ struct qusb2_phy_cfg { .has_pll_test = true, .disable_ctrl = (CLAMP_N_EN | FREEZIO_N | POWER_DOWN), .mask_core_ready = PLL_LOCKED, + .autoresume_en = BIT(3), }; static const struct qusb2_phy_cfg qusb2_v2_phy_cfg = { @@ -198,6 +221,8 @@ struct qusb2_phy_cfg { .disable_ctrl = (PWR_CTRL1_VREF_SUPPLY_TRIM | PWR_CTRL1_CLAMP_N_EN | POWER_DOWN), .mask_core_ready = CORE_READY_STATUS, + .has_pll_override = true, + .autoresume_en = BIT(0), }; static const char * const qusb2_phy_vreg_names[] = { @@ -223,6 +248,8 @@ struct qusb2_phy_cfg { * * @cfg: phy config data * @has_se_clk_scheme: indicate if PHY has single-ended ref clock scheme + * @phy_initialized: indicate if PHY has been initialized + * @speed: current PHY speed */ struct qusb2_phy { struct phy *phy; @@ -239,6 +266,8 @@ struct qusb2_phy { const struct qusb2_phy_cfg *cfg; bool has_se_clk_scheme; + bool phy_initialized; + enum phy_speed speed; }; static inline void qusb2_setbits(void __iomem *base, u32 offset, u32 val) @@ -307,6 +336,137 @@ 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_notify_speed(struct phy *phy, enum phy_speed speed) +{ + struct qusb2_phy *qphy = phy_get_drvdata(phy); + + qphy->speed = speed; + + return 0; +} + +static enum phy_speed qusb2_phy_get_speed(struct phy *phy) +{ + struct qusb2_phy *qphy = phy_get_drvdata(phy); + + return qphy->speed; +} + +static int __maybe_unused qusb2_phy_runtime_suspend(struct device *dev) +{ + struct qusb2_phy *qphy = dev_get_drvdata(dev); + const struct qusb2_phy_cfg *cfg = qphy->cfg; + u32 intr_mask; + + dev_vdbg(dev, "Suspending QUSB2 Phy, speed:%d\n", qphy->speed); + + if (!qphy->phy_initialized) { + dev_vdbg(dev, "PHY not initialized, bailing out\n"); + return 0; + } + + /* + * Enable DP/DM interrupts to detect line state changes based on current + * speed. In other words, enable the triggers _opposite_ of what the + * current D+/D- levels are e.g. if currently D+ high, D- low + * (HS 'J'/Suspend), configure the mask to trigger on D+ low OR D- high + */ + intr_mask = DPSE_INTR_EN | DMSE_INTR_EN; + switch (qphy->speed) { + case PHY_SPEED_USB_HS: + case PHY_SPEED_USB_FS: + intr_mask |= DMSE_INTR_HIGH_SEL; + break; + case PHY_SPEED_USB_LS: + intr_mask |= DPSE_INTR_HIGH_SEL; + break; + default: + /* No device connected, enable both DP/DM high interrupt */ + intr_mask |= DMSE_INTR_HIGH_SEL; + intr_mask |= DPSE_INTR_HIGH_SEL; + break; + } + + writel(intr_mask, qphy->base + cfg->regs[QUSB2PHY_INTR_CTRL]); + + /* hold core PLL into reset */ + if (cfg->has_pll_override) { + qusb2_setbits(qphy->base, + cfg->regs[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE], + CORE_PLL_EN_FROM_RESET | CORE_RESET | + CORE_RESET_MUX); + } + + /* enable phy auto-resume only if device is connected on bus */ + if (qphy->speed != PHY_SPEED_UNKNOWN) { + qusb2_setbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TEST1], + cfg->autoresume_en); + /* Autoresume bit has to be toggled in order to enable it */ + qusb2_clrbits(qphy->base, cfg->regs[QUSB2PHY_PORT_TEST1], + cfg->autoresume_en); + } + + if (!qphy->has_se_clk_scheme) + clk_disable_unprepare(qphy->ref_clk); + + clk_disable_unprepare(qphy->cfg_ahb_clk); + clk_disable_unprepare(qphy->iface_clk); + + return 0; +} + +static int __maybe_unused qusb2_phy_runtime_resume(struct device *dev) +{ + struct qusb2_phy *qphy = dev_get_drvdata(dev); + const struct qusb2_phy_cfg *cfg = qphy->cfg; + int ret; + + dev_vdbg(dev, "Resuming QUSB2 phy, speed:%d\n", qphy->speed); + + if (!qphy->phy_initialized) { + dev_vdbg(dev, "PHY not initialized, bailing out\n"); + return 0; + } + + ret = clk_prepare_enable(qphy->iface_clk); + if (ret) { + dev_err(dev, "failed to enable iface_clk, %d\n", ret); + return ret; + } + + ret = clk_prepare_enable(qphy->cfg_ahb_clk); + if (ret) { + dev_err(dev, "failed to enable cfg ahb clock, %d\n", ret); + goto disable_iface_clk; + } + + if (!qphy->has_se_clk_scheme) { + clk_prepare_enable(qphy->ref_clk); + if (ret) { + dev_err(dev, "failed to enable ref clk, %d\n", ret); + goto disable_ahb_clk; + } + } + + writel(0x0, qphy->base + cfg->regs[QUSB2PHY_INTR_CTRL]); + + /* bring core PLL out of reset */ + if (cfg->has_pll_override) { + qusb2_clrbits(qphy->base, + cfg->regs[QUSB2PHY_PLL_CORE_INPUT_OVERRIDE], + CORE_RESET | CORE_RESET_MUX); + } + + return 0; + +disable_ahb_clk: + clk_disable_unprepare(qphy->cfg_ahb_clk); +disable_iface_clk: + clk_disable_unprepare(qphy->iface_clk); + + return ret; +} + static int qusb2_phy_init(struct phy *phy) { struct qusb2_phy *qphy = phy_get_drvdata(phy); @@ -431,6 +591,7 @@ static int qusb2_phy_init(struct phy *phy) ret = -EBUSY; goto disable_ref_clk; } + qphy->phy_initialized = true; return 0; @@ -467,12 +628,16 @@ static int qusb2_phy_exit(struct phy *phy) regulator_bulk_disable(ARRAY_SIZE(qphy->vregs), qphy->vregs); + qphy->phy_initialized = false; + return 0; } static const struct phy_ops qusb2_phy_gen_ops = { .init = qusb2_phy_init, .exit = qusb2_phy_exit, + .notify_speed = qusb2_phy_notify_speed, + .get_speed = qusb2_phy_get_speed, .owner = THIS_MODULE, }; @@ -488,6 +653,11 @@ static int qusb2_phy_exit(struct phy *phy) }; MODULE_DEVICE_TABLE(of, qusb2_phy_of_match_table); +static const struct dev_pm_ops qusb2_phy_pm_ops = { + SET_RUNTIME_PM_OPS(qusb2_phy_runtime_suspend, + qusb2_phy_runtime_resume, NULL) +}; + static int qusb2_phy_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -565,11 +735,19 @@ static int qusb2_phy_probe(struct platform_device *pdev) qphy->cell = NULL; dev_dbg(dev, "failed to lookup tune2 hstx trim value\n"); } + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + /* + * Prevent runtime pm from being ON by default. Users can enable + * it using power/control in sysfs. + */ + pm_runtime_forbid(dev); generic_phy = devm_phy_create(dev, NULL, &qusb2_phy_gen_ops); if (IS_ERR(generic_phy)) { ret = PTR_ERR(generic_phy); dev_err(dev, "failed to create phy, %d\n", ret); + pm_runtime_disable(dev); return ret; } qphy->phy = generic_phy; @@ -580,6 +758,8 @@ static int qusb2_phy_probe(struct platform_device *pdev) phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); if (!IS_ERR(phy_provider)) dev_info(dev, "Registered Qcom-QUSB2 phy\n"); + else + pm_runtime_disable(dev); return PTR_ERR_OR_ZERO(phy_provider); } @@ -588,6 +768,7 @@ static int qusb2_phy_probe(struct platform_device *pdev) .probe = qusb2_phy_probe, .driver = { .name = "qcom-qusb2-phy", + .pm = &qusb2_phy_pm_ops, .of_match_table = qusb2_phy_of_match_table, }, }; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project From 1586117239480186736@xxx Thu Dec 07 09:34:34 +0000 2017 X-GM-THRID: 1586117239480186736 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread