Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp654840pxx; Wed, 28 Oct 2020 13:32:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwOdMvAIxDkytwIeY0DAqs9iqgjgaFUA1JwgmF+25UZ7XiUa6RHIYXW30/DZEwbJoOtug1 X-Received: by 2002:a05:6402:1c8f:: with SMTP id cy15mr684153edb.335.1603917171045; Wed, 28 Oct 2020 13:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603917171; cv=none; d=google.com; s=arc-20160816; b=vLa1SmGpTDFtxN7ucBRJrP3U8qRVQ1uuItMHHLx3LuNS7ZLtMjst4sexY7viYWcjwi 9zjRS+htc0/pVmLXAzNACDvQJv3iNAnGLBXzc90Ac5oUFzU/ejX2jzBe4RQThQBBlJPH BmjWLGQX/0OOXSWefI3Ygtajxwt29WXhEFT1k+U6Rnl5VzFAOBGweEa6Ll021km12Wvp cD8rASOxLCC2bRhBfc2WvWJqYSn+xZdeMMoYMDhCyoVYGskDS58mGstwpuvAXKyY3NaI mQp5WB0x8D9AvmDu+VL8kTRgrz/Qf2CcSVwX2zoSOdwd3QpRAflGdeJ4oUzK21l9CCS6 FqUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=AJJPApGRLl1aqJk3VNH+KDsW7hD7J9x5e+cdGgRz554=; b=gK0NRr3jI1IPbMXCe4Uyym0OO+FvF6ZCEws6X51k9gicX3BCSzrn1RuIH3M6FmgfcL YgRtXUnL7OzRolTHK1KnqiDjY7xnE6w7E5t27d016h3L9E/O+nRs0/gmLGSAazPwUjZt I6XNH9jJ5cr7x2DkJLWfPqgR7zzf/nnZfC9qvrr/arkxqw+CAAyaG24OkKPYc4JE+mpY L9gJmA8zDUhlO7CluaP/l2Hvg2JM8lJM6ajHU3Pt1bCnQpiiUb24lvXHJ3FyLBGQDgfI IFRr8MrinEUqEXOVuS7+CqXm1fauis0zaus13V4muel4qK6aTBkck2MOKGbm580fS4/+ k2Rg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y6si18713edm.295.2020.10.28.13.32.28; Wed, 28 Oct 2020 13:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1829450AbgJ0TLD (ORCPT + 99 others); Tue, 27 Oct 2020 15:11:03 -0400 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]:2072 "EHLO alexa-out-sd-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S371908AbgJ0TKw (ORCPT ); Tue, 27 Oct 2020 15:10:52 -0400 Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-01.qualcomm.com with ESMTP; 27 Oct 2020 12:10:48 -0700 X-QCInternal: smtphost Received: from asutoshd-linux1.qualcomm.com ([10.46.160.39]) by ironmsg01-sd.qualcomm.com with ESMTP; 27 Oct 2020 12:10:47 -0700 Received: by asutoshd-linux1.qualcomm.com (Postfix, from userid 92687) id B146220F57; Tue, 27 Oct 2020 12:10:47 -0700 (PDT) From: Asutosh Das To: cang@codeaurora.org, martin.petersen@oracle.com, linux-scsi@vger.kernel.org Cc: linux-arm-msm@vger.kernel.org, Asutosh Das , Alim Akhtar , Avri Altman , "James E.J. Bottomley" , Matthias Brugger , Stanley Chu , Bean Huo , Bart Van Assche , Satya Tangirala , linux-kernel@vger.kernel.org (open list), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek SoC support) Subject: [PATCH v2 1/2] scsi: ufs: Put hba into LPM during clk gating Date: Tue, 27 Oct 2020 12:10:36 -0700 Message-Id: <52198e70bff750632740d78678a815256d697e43.1603825776.git.asutoshd@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Can Guo During clock gating, after clocks are disabled, put hba into LPM to save more power. Acked-by: Stanley Chu Signed-off-by: Can Guo Signed-off-by: Asutosh Das --- drivers/scsi/ufs/ufshcd.c | 9 +++++++-- drivers/scsi/ufs/ufshcd.h | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 47c544d..9fc1bac 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -245,6 +245,8 @@ static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba); static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable); static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set); static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable); +static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba); +static void ufshcd_hba_vreg_set_hpm(struct ufs_hba *hba); static inline bool ufshcd_valid_tag(struct ufs_hba *hba, int tag) { @@ -1548,6 +1550,7 @@ static void ufshcd_ungate_work(struct work_struct *work) } spin_unlock_irqrestore(hba->host->host_lock, flags); + ufshcd_hba_vreg_set_hpm(hba); ufshcd_setup_clocks(hba, true); ufshcd_enable_irq(hba); @@ -1713,6 +1716,8 @@ static void ufshcd_gate_work(struct work_struct *work) /* If link is active, device ref_clk can't be switched off */ __ufshcd_setup_clocks(hba, false, true); + /* Put the host controller in low power mode if possible */ + ufshcd_hba_vreg_set_lpm(hba); /* * In case you are here to cancel this work the gating state * would be marked as REQ_CLKS_ON. In this case keep the state @@ -8405,13 +8410,13 @@ static int ufshcd_vreg_set_hpm(struct ufs_hba *hba) static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba) { - if (ufshcd_is_link_off(hba)) + if (ufshcd_is_link_off(hba) || ufshcd_can_aggressive_pc(hba)) ufshcd_setup_hba_vreg(hba, false); } static void ufshcd_hba_vreg_set_hpm(struct ufs_hba *hba) { - if (ufshcd_is_link_off(hba)) + if (ufshcd_is_link_off(hba) || ufshcd_can_aggressive_pc(hba)) ufshcd_setup_hba_vreg(hba, true); } diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 47eb143..0fbb735 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -592,6 +592,13 @@ enum ufshcd_caps { * inline crypto engine, if it is present */ UFSHCD_CAP_CRYPTO = 1 << 8, + + /* + * This capability allows the controller regulators to be put into + * lpm mode aggressively during clock gating. + * This would increase power savings. + */ + UFSHCD_CAP_AGGR_POWER_COLLAPSE = 1 << 9, }; struct ufs_hba_variant_params { @@ -829,6 +836,12 @@ return true; #endif } +static inline bool ufshcd_can_aggressive_pc(struct ufs_hba *hba) +{ + return !!(ufshcd_is_link_hibern8(hba) && + (hba->caps & UFSHCD_CAP_AGGR_POWER_COLLAPSE)); +} + static inline bool ufshcd_is_auto_hibern8_supported(struct ufs_hba *hba) { return (hba->capabilities & MASK_AUTO_HIBERN8_SUPPORT) && -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.