From patchwork Mon Jun 1 10:46:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanley Chu X-Patchwork-Id: 213832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2FDAC433E0 for ; Mon, 1 Jun 2020 10:47:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D4EA20772 for ; Mon, 1 Jun 2020 10:47:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="qnN/SsqG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726265AbgFAKq6 (ORCPT ); Mon, 1 Jun 2020 06:46:58 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:19803 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725838AbgFAKqv (ORCPT ); Mon, 1 Jun 2020 06:46:51 -0400 X-UUID: 466e592f65ab4626a02a4b3263d9c3fe-20200601 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=ckHEM7GVI4e4nimxXTABhbmcvCORVQbBj1jfInkgoAg=; b=qnN/SsqGEXsZ18dqu2xVroL2VBVeEEMEczfG/pDyYCVrhvUl8L5hQh06i+noZP9ZEkh1JUF2WeYH/p2ivFVDzCCNvuUlaxL25TfZj5jJB/T0pZf24humDsJroV31H/4gQeIEuJTkDeLzYTY0SEMkiffNvIbjPxqMuXuloKATZyo=; X-UUID: 466e592f65ab4626a02a4b3263d9c3fe-20200601 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 571622865; Mon, 01 Jun 2020 18:46:48 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 1 Jun 2020 18:46:45 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 1 Jun 2020 18:46:46 +0800 From: Stanley Chu To: , , , , CC: , , , , , , , , , , , , , , Stanley Chu Subject: [PATCH v3 3/5] scsi: ufs-mediatek: Introduce low-power mode for device power supply Date: Mon, 1 Jun 2020 18:46:44 +0800 Message-ID: <20200601104646.15436-4-stanley.chu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200601104646.15436-1-stanley.chu@mediatek.com> References: <20200601104646.15436-1-stanley.chu@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Allow device power supply to enter low-power mode if device will do nothing to save more power. Signed-off-by: Stanley Chu Reviewed-by: Pengshun Zhao --- drivers/scsi/ufs/ufs-mediatek.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 2.18.0 diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c index 3c85f5e97dea..5f41b7b7db8f 100644 --- a/drivers/scsi/ufs/ufs-mediatek.c +++ b/drivers/scsi/ufs/ufs-mediatek.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "ufshcd.h" @@ -521,6 +522,19 @@ static int ufs_mtk_link_set_lpm(struct ufs_hba *hba) return 0; } +static void ufs_mtk_vreg_set_lpm(struct ufs_hba *hba, bool lpm) +{ + if (!hba->vreg_info.vccq2) + return; + + if (lpm & !hba->vreg_info.vcc->enabled) + regulator_set_mode(hba->vreg_info.vccq2->reg, + REGULATOR_MODE_IDLE); + else if (!lpm) + regulator_set_mode(hba->vreg_info.vccq2->reg, + REGULATOR_MODE_NORMAL); +} + static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) { int err; @@ -537,6 +551,12 @@ static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) ufshcd_set_link_off(hba); return -EAGAIN; } + /* + * Make sure no error will be returned to prevent + * ufshcd_suspend() re-enabling regulators while vreg is still + * in low-power mode. + */ + ufs_mtk_vreg_set_lpm(hba, true); } if (!ufshcd_is_link_active(hba)) @@ -554,6 +574,7 @@ static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) phy_power_on(host->mphy); if (ufshcd_is_link_hibern8(hba)) { + ufs_mtk_vreg_set_lpm(hba, false); err = ufs_mtk_link_set_hpm(hba); if (err) { err = ufshcd_link_recovery(hba);