Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp85586ybb; Tue, 24 Mar 2020 17:08:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtldzXrF7HdynEvvLuz4Y42shyJ2Uz3bPsAVO3yufzGV6gjyT9sF9wS7pzPllFGMqS6/MAn X-Received: by 2002:a9d:548:: with SMTP id 66mr472759otw.227.1585094898117; Tue, 24 Mar 2020 17:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585094898; cv=none; d=google.com; s=arc-20160816; b=ADj4mU2jTS9DFxeJyssu3M5qZ6+fe+m4l9yz/qaH1fk+mnaYEjncHF3J+Q+bMztL8A XaEAl5K+poLfqSOFO/EW0D4WoejflKIvPZI8uraEHimYjFazNBD+E4GLvFUEhnjR+EhE SEMo3mezJ8mg+i7U/EH6QS36I/hnInp5bCOefafkxcLSMwbL6iR+r/JnEooGqdkfTftS K7mdXO/8mQd6YEGp/6+BIzUe8wSuWg7U+FFU7T/ug0YybdGzf5kM1d0/uqJPHFsbOvpG PeKg9LaL6lvuDl2GAbtv7CYzve3oF00bc3L6xs5Ee4U73royOXq/0AWxuJKCZphqs2Ho c6eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=5k1B6hYGK2MBsFUIcanfMLoLPaBYSo/SYx2sRUZ4gVE=; b=VSuxQf9A+34GDzJeiDnArecTQFeZlFPSTvreqlNWrZZt0ECaIdvjFLp8xkQG1dEzl8 j+TTTxL4I7/AKOtEW6nBrkVj6NKoKFZVBvdnTBN8U/BUn+Nif2oaN0eBiY+2gAjPSihr E0NZ3e7Ohs2LdZlMnpen0grDHXVSqtEeqqyGxTzBJWZk+Lo7x02wM1UbRs6YJIZ4Hxpy XBry6Y3wjXlf9pHWwRW05tgHKMJJNqy7acfwIrxSRzjgTSxHwq5nNdSypu4JJ8JTz+wE wvJVdOFigdbVh7+HWy1z7YCZ0tHP5ZzlA83YXLkM8w4+yEq7X/rdbsy7MFWdVYBO64Pb oFug== ARC-Authentication-Results: i=1; mx.google.com; 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 x2si9334793oix.42.2020.03.24.17.07.35; Tue, 24 Mar 2020 17:08:18 -0700 (PDT) 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; 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 S1727190AbgCYAHN (ORCPT + 99 others); Tue, 24 Mar 2020 20:07:13 -0400 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]:11963 "EHLO alexa-out-sd-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbgCYAHN (ORCPT ); Tue, 24 Mar 2020 20:07:13 -0400 Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-01.qualcomm.com with ESMTP; 24 Mar 2020 17:07:12 -0700 Received: from asutoshd-linux1.qualcomm.com ([10.46.160.39]) by ironmsg03-sd.qualcomm.com with ESMTP; 24 Mar 2020 17:07:11 -0700 Received: by asutoshd-linux1.qualcomm.com (Postfix, from userid 92687) id DF6991F79D; Tue, 24 Mar 2020 17:07:11 -0700 (PDT) From: Asutosh Das To: cang@codeaurora.org, martin.petersen@oracle.com, linux-scsi@vger.kernel.org Cc: Asutosh Das , linux-arm-msm@vger.kernel.org, Alim Akhtar , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Bean Huo , Bart Van Assche , Venkat Gopalakrishnan , Tomas Winkler , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v1 1/3] scsi: ufshcd: Update the set frequency to devfreq Date: Tue, 24 Mar 2020 17:07:03 -0700 Message-Id: X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the frequency that devfreq provides the driver to set always leads the clocks to be scaled up. Hence, round the clock-rate to the nearest frequency before deciding to scale. Also update the devfreq statistics of current frequency. Signed-off-by: Asutosh Das --- drivers/scsi/ufs/ufshcd.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 2a2a63b..4607bc6 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1187,6 +1187,9 @@ static int ufshcd_devfreq_target(struct device *dev, if (!ufshcd_is_clkscaling_supported(hba)) return -EINVAL; + clki = list_first_entry(&hba->clk_list_head, struct ufs_clk_info, list); + /* Override with the closest supported frequency */ + *freq = (unsigned long) clk_round_rate(clki->clk, *freq); spin_lock_irqsave(hba->host->host_lock, irq_flags); if (ufshcd_eh_in_progress(hba)) { spin_unlock_irqrestore(hba->host->host_lock, irq_flags); @@ -1201,8 +1204,13 @@ static int ufshcd_devfreq_target(struct device *dev, goto out; } - clki = list_first_entry(&hba->clk_list_head, struct ufs_clk_info, list); + /* Decide based on the rounded-off frequency and update */ scale_up = (*freq == clki->max_freq) ? true : false; + if (scale_up) + *freq = clki->max_freq; + else + *freq = clki->min_freq; + /* Update the frequency */ if (!ufshcd_is_devfreq_scaling_required(hba, scale_up)) { spin_unlock_irqrestore(hba->host->host_lock, irq_flags); ret = 0; @@ -1250,6 +1258,8 @@ static int ufshcd_devfreq_get_dev_status(struct device *dev, struct ufs_hba *hba = dev_get_drvdata(dev); struct ufs_clk_scaling *scaling = &hba->clk_scaling; unsigned long flags; + struct list_head *clk_list = &hba->clk_list_head; + struct ufs_clk_info *clki; if (!ufshcd_is_clkscaling_supported(hba)) return -EINVAL; @@ -1260,6 +1270,8 @@ static int ufshcd_devfreq_get_dev_status(struct device *dev, if (!scaling->window_start_t) goto start_window; + clki = list_first_entry(clk_list, struct ufs_clk_info, list); + stat->current_frequency = clki->curr_freq; if (scaling->is_busy_started) scaling->tot_busy_t += ktime_to_us(ktime_sub(ktime_get(), scaling->busy_start_t)); -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.