Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2244905ybl; Thu, 19 Dec 2019 10:19:58 -0800 (PST) X-Google-Smtp-Source: APXvYqzzBU1uLQ6BfjpgDqfDK4UVcCkPX+FDEq3T1AFtMzaXq/WAusuj1tSOnymJXOutKfsDbXtw X-Received: by 2002:a05:6830:1e5a:: with SMTP id e26mr9572590otj.351.1576779597974; Thu, 19 Dec 2019 10:19:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576779597; cv=none; d=google.com; s=arc-20160816; b=XgAwMWkbVtkyZkAf2fbwKQDSQehrMZEMTCqqT4BFu7SSRvR2IeHI0qEKnktkRdsXxT jGVwrxI8NCX4bBYlcWpfdvXMa4xshJnPlbct9Stfuk8C3gGR6IiulzOLxPCpLuufnzVI EToA3Cv6wGQnzkxGW48b1mCiToXF5/wJsabZIxJJDsiMNmuTMl3cjt8vBgsDC45/r7pf fGplDnEcxPaLtBdTnVC5KJGQXGNIIp3+mjpsmiEYtVathWZQiPQj0BH/topz5cQ+vkQ6 zouhuhrZ8VY5rrE6b6yQlCDOWHiX6AspFLV3CU3TaJBtgqelZVATtKWGXLMStlGOQz58 LgBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=hdfl3j3PUu29KvhFJr+t8q9A7l1fLtUS6dfELY8PVLE=; b=avKDfNhUbl5wE1V00LWufUj/t6XnDnHa4W5uSav+BC9GBhSoMJkl5T15tH/pJQY3xx YUS15/JoA6dY2KP2N5IrSr6BqKrja/N7JoV1vSZzmlQfeYasjYbLkWE7Vs092TRSrx9t E1S+0m1wQH64EDCPcAvbnOy/+zMBLPxZ+2m1KjbEIW3utyrqynX3Obb+QslZz3jFTfr7 S9SUclD3y7dqKIv85aJBAhKkhZWPD+DwFALSNpx235rKNV5RtAgdWGxFWwcnif8kA1F1 h1LNJ5p0UJgHvSpNId0KvqbegK9+o6m9bDvK3i+lvpeqTVNX/5QXctTWtWqajFNiFT17 +00A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tCS54bJd; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g26si2815120otj.32.2019.12.19.10.19.45; Thu, 19 Dec 2019 10:19:57 -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=@gmail.com header.s=20161025 header.b=tCS54bJd; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726936AbfLSSSh (ORCPT + 99 others); Thu, 19 Dec 2019 13:18:37 -0500 Received: from mail-vs1-f66.google.com ([209.85.217.66]:46018 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726797AbfLSSSg (ORCPT ); Thu, 19 Dec 2019 13:18:36 -0500 Received: by mail-vs1-f66.google.com with SMTP id b4so3902857vsa.12; Thu, 19 Dec 2019 10:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hdfl3j3PUu29KvhFJr+t8q9A7l1fLtUS6dfELY8PVLE=; b=tCS54bJd6f3428WApblIOzLQvg9gXUk1ry2iLEcNoz5mn+Ev/It5H2F9ixzC8H3L7O gy0IKkXEef1q6L0ksBFGDnOsjR/d7EBCW93dzLdMYSzBycxQDu5ezgzhvuFSzH3C8Lm/ JlAmLHyjT024P+gfLHAh9AEPlaXfFD3YP4yLDycw9CpwqSePfClSIox4XVdEvj5Nr5Bn FjVC6LL8OR3gYVOQ86fmVwGRCASN1MYtioAty36QxsKkpWaLkkDWk5onwgp+d+6B+dOw +x6EdoeRB0BmdvaglW+aUzVAef6OztV1h6RgZVussRPpI7Udtcb9/edVA/g/XEvrPZnk C5rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hdfl3j3PUu29KvhFJr+t8q9A7l1fLtUS6dfELY8PVLE=; b=aY7Ka4mrPmCTOs/GoLBItS/dODCuFKyS+2DQoHImWqRC0mOavV4ZooPBlRfCKX97ZY LZqaV4nUMz1YGHZAZViyIAkvrM2m35TuJd4zrnj/kayC1QEZW0WYM/wZuBjsje5VkG1x QOcrG+Ik0/m35kELUrtdDl4e15VyYDvRYdw6NnAY7bha7vAIq5PbybuGqJJMURl9OM0T AbuU/Rgv3XSbTMUH6HRCRbHteXxbOeUg1i945sr593cudXiWEKVVEgtl+kkQhywILSL6 8LBvb5BWyxdSEkWlCzVOj5Pnh1SBphRHI+baoVtE9+wYqylPE3MZxFy/F3Ir8r3MhJlT XTNQ== X-Gm-Message-State: APjAAAW7Hkt8wcmRBdq11MQ4Sf/X3TJ00z5XcoLBTMtJ/HukAEJpUBpS PkkDRZRYU4mxedP5F51r3U0tle7YFDvhgzIehtdpe1SC X-Received: by 2002:a05:6102:204a:: with SMTP id q10mr6222578vsr.127.1576779515189; Thu, 19 Dec 2019 10:18:35 -0800 (PST) MIME-Version: 1.0 References: <1576224695-22657-1-git-send-email-stanley.chu@mediatek.com> <1576224695-22657-2-git-send-email-stanley.chu@mediatek.com> In-Reply-To: <1576224695-22657-2-git-send-email-stanley.chu@mediatek.com> From: Alim Akhtar Date: Thu, 19 Dec 2019 23:47:59 +0530 Message-ID: Subject: Re: [PATCH v1 1/4] scsi: ufs-mediatek: introduce reference clock control To: Stanley Chu Cc: linux-scsi@vger.kernel.org, "Martin K. Petersen" , Avri Altman , Alim Akhtar , Pedro Sousa , "James E.J. Bottomley" , Matthias Brugger , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, open list , "Bean Huo (beanhuo)" , Kuohong Wang , peter.wang@mediatek.com, chun-hung.wu@mediatek.com, andy.teng@mediatek.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 13, 2019 at 2:23 PM Stanley Chu wrote: > > Introduce reference clock control in MediaTek Chipset in order > to disable it if it is not necessary by UFS device to save system power. > > Currently reference clock can be disabled during system suspend, runtime > suspend and clock-gating after link enters hibernate state. > > Signed-off-by: Stanley Chu Reviewed-by: Alim Akhtar > --- > drivers/scsi/ufs/ufs-mediatek.c | 64 ++++++++++++++++++++++++++++++--- > drivers/scsi/ufs/ufs-mediatek.h | 20 +++++++++-- > 2 files changed, 78 insertions(+), 6 deletions(-) > > diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c > index 6a3ec11b16db..690483c78212 100644 > --- a/drivers/scsi/ufs/ufs-mediatek.c > +++ b/drivers/scsi/ufs/ufs-mediatek.c > @@ -18,6 +18,11 @@ > #include "unipro.h" > #include "ufs-mediatek.h" > > +#define ufs_mtk_ref_clk_notify(on, res) \ > + arm_smccc_smc(MTK_SIP_UFS_CONTROL, \ > + UFS_MTK_SIP_REF_CLK_NOTIFICATION, \ > + on, 0, 0, 0, 0, 0, &(res)) > + > static void ufs_mtk_cfg_unipro_cg(struct ufs_hba *hba, bool enable) > { > u32 tmp; > @@ -83,6 +88,49 @@ static int ufs_mtk_bind_mphy(struct ufs_hba *hba) > return err; > } > > +static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on) > +{ > + struct ufs_mtk_host *host = ufshcd_get_variant(hba); > + struct arm_smccc_res res; > + unsigned long timeout; > + u32 value; > + > + if (host->ref_clk_enabled == on) > + return 0; > + > + if (on) { > + ufs_mtk_ref_clk_notify(on, res); > + ufshcd_writel(hba, REFCLK_REQUEST, REG_UFS_REFCLK_CTRL); > + } else { > + ufshcd_writel(hba, REFCLK_RELEASE, REG_UFS_REFCLK_CTRL); > + } > + > + /* Wait for ack */ > + timeout = jiffies + msecs_to_jiffies(REFCLK_REQ_TIMEOUT_MS); > + do { > + value = ufshcd_readl(hba, REG_UFS_REFCLK_CTRL); > + > + /* Wait until ack bit equals to req bit */ > + if (((value & REFCLK_ACK) >> 1) == (value & REFCLK_REQUEST)) > + goto out; > + > + usleep_range(100, 200); > + } while (time_before(jiffies, timeout)); > + > + dev_err(hba->dev, "missing ack of refclk req, reg: 0x%x\n", value); > + > + ufs_mtk_ref_clk_notify(host->ref_clk_enabled, res); > + > + return -ETIMEDOUT; > + > +out: > + host->ref_clk_enabled = on; > + if (!on) > + ufs_mtk_ref_clk_notify(on, res); > + > + return 0; > +} > + > /** > * ufs_mtk_setup_clocks - enables/disable clocks > * @hba: host controller instance > @@ -107,12 +155,16 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on, > > switch (status) { > case PRE_CHANGE: > - if (!on) > + if (!on) { > + ufs_mtk_setup_ref_clk(hba, on); > ret = phy_power_off(host->mphy); > + } > break; > case POST_CHANGE: > - if (on) > + if (on) { > ret = phy_power_on(host->mphy); > + ufs_mtk_setup_ref_clk(hba, on); > + } > break; > } > > @@ -299,8 +351,10 @@ static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) > { > struct ufs_mtk_host *host = ufshcd_get_variant(hba); > > - if (ufshcd_is_link_hibern8(hba)) > + if (ufshcd_is_link_hibern8(hba)) { > phy_power_off(host->mphy); > + ufs_mtk_setup_ref_clk(hba, false); > + } > > return 0; > } > @@ -309,8 +363,10 @@ static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) > { > struct ufs_mtk_host *host = ufshcd_get_variant(hba); > > - if (ufshcd_is_link_hibern8(hba)) > + if (ufshcd_is_link_hibern8(hba)) { > + ufs_mtk_setup_ref_clk(hba, true); > phy_power_on(host->mphy); > + } > > return 0; > } > diff --git a/drivers/scsi/ufs/ufs-mediatek.h b/drivers/scsi/ufs/ufs-mediatek.h > index b03f601d3a9e..14f8a8357c09 100644 > --- a/drivers/scsi/ufs/ufs-mediatek.h > +++ b/drivers/scsi/ufs/ufs-mediatek.h > @@ -6,7 +6,21 @@ > #ifndef _UFS_MEDIATEK_H > #define _UFS_MEDIATEK_H > > -#include > +/* > + * Vendor specific UFSHCI Registers > + */ > +#define REG_UFS_REFCLK_CTRL 0x144 > + > +/* > + * Ref-clk control > + * > + * Values for register REG_UFS_REFCLK_CTRL > + */ > +#define REFCLK_RELEASE 0x0 > +#define REFCLK_REQUEST BIT(0) > +#define REFCLK_ACK BIT(1) > + > +#define REFCLK_REQ_TIMEOUT_MS 3 > > /* > * Vendor specific pre-defined parameters > @@ -34,7 +48,8 @@ > /* > * SiP commands > */ > -#define UFS_MTK_SIP_DEVICE_RESET BIT(1) > +#define UFS_MTK_SIP_DEVICE_RESET BIT(1) > +#define UFS_MTK_SIP_REF_CLK_NOTIFICATION BIT(3) > > /* > * VS_DEBUGCLOCKENABLE > @@ -55,6 +70,7 @@ enum { > struct ufs_mtk_host { > struct ufs_hba *hba; > struct phy *mphy; > + bool ref_clk_enabled; > }; > > #endif /* !_UFS_MEDIATEK_H */ > -- > 2.18.0 -- Regards, Alim