Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2519129imm; Wed, 16 May 2018 14:21:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZryjlTevefe3s1gsxujqVD32skyoNUJR8v0BUaGYI+/9e80Fru5DA6qPRrfxI3D+EfwwX1J X-Received: by 2002:a65:408b:: with SMTP id t11-v6mr2025970pgp.222.1526505668805; Wed, 16 May 2018 14:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526505668; cv=none; d=google.com; s=arc-20160816; b=a+Qx9s6p1nPvG8PJpFDtKxu6eqRJwUV6QYazszoXFAcKd//GPYTPEZzgzRIl2xIXwP uRg1TZwAyG9gUj/1mT8qtphL9GKDY07f+uqBHChCPOuC1+c6Hux7nR1mrwnjk7vEotWo 9ObytpV03nQkFWTnV59aumFvnNiDHvPechN2wQY2t04e3omtj6Pf71wn+zS+HgrQk2fZ zJYCxEeZQ9P+sUFwkepKDExyZIBvIN2PmIk7hlyyGYTceqxULW+Um9X3OwZmJweBwEGI Cml1O/NaLS0+fkH4B1P/kC4rZ1XHR4EV1NZ/W8AV33h6eIj943a/OP70K22qZ01tk9FX XNrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=N1ViyCugtVHhLivL3dYV8eM2DxAmxS4R6L50/LRv90s=; b=A+jGghA5QZF3uAJtomD5LzpF3mxCaj1nDQeTx605yDjJjAVTC9cwB/FKARONLhaQwb GlGz6YGhyUe3M5W0g2VKSYXqnQx4XZqN2ZOcJm/TM2cQMHSgt7wrrwCMZywiu4+SNYl3 B78HMfRg3XZET9cU9PqnyU50bD6ozuOhz4PZ1IEwabDGfi3KOTIcKuh/qxx0/1qGC6C3 9LoeBMK0lh0XopCJA3tlzKtNdVkFMnF1M/ySzzZseSq+BGKVf7Glr+Zel4toaMejeUth MKan27euglzQPNHhL2YDYVhBGmd5tD6xSS1iB0NXNSBFG07MlCdXtg4mJfwNrrY0d5G9 W5EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=SFQAa7ST; dkim=pass header.i=@codeaurora.org header.s=default header.b=K+EowSbA; 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 o9-v6si2718609pgp.508.2018.05.16.14.20.53; Wed, 16 May 2018 14:21:08 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=SFQAa7ST; dkim=pass header.i=@codeaurora.org header.s=default header.b=K+EowSbA; 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 S1751315AbeEPVUh (ORCPT + 99 others); Wed, 16 May 2018 17:20:37 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:33240 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750953AbeEPVUf (ORCPT ); Wed, 16 May 2018 17:20:35 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id BF19A60AF9; Wed, 16 May 2018 21:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526505634; bh=Jz9DBB6ZcQM68gL5tidDXeQ+kwuA5f3tTZ8p4EUTnUo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SFQAa7SToBw+Th97ys1pgDec2X4p9ryriO313IUuUNd3/rL5IsFCkwiVIAk70Ryxr waIUIWCVCzuNBJghttqu36cpb/zGiOpfAl69GTh11omquxXFcwQ9YrbW8S7O9X2Ttt X6upg8KrVq11/UH+8cbfNIC5kQwiBfd66YVLUHz8= 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 mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 5B637601EA; Wed, 16 May 2018 21:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526505633; bh=Jz9DBB6ZcQM68gL5tidDXeQ+kwuA5f3tTZ8p4EUTnUo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=K+EowSbA35woaPSga/37SDOxAR59AJqAxUzyrki1EmgV0dCgbiOPRUhKeKBen19kH ZNEwSQBuiexsnfu5KAKPdU0oXW4MoVxXBxu7455hSy1Lclr8h63vBbiVaH4CvOv3cx RNj3cigegpjwOqc/psQJKP1TlzLLwBu1KQ8W4dvY= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 16 May 2018 14:20:33 -0700 From: Subhash Jadavani To: Bjorn Andersson Cc: Vinayak Holikatti , "James E.J. Bottomley" , "Martin K. Petersen" , MyungJoo Ham , Kyungmin Park , Chanwoo Choi , linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Vivek Gautam , linux-scsi-owner@vger.kernel.org Subject: Re: [PATCH v2 2/2] scsi: ufs: Use freq table with devfreq In-Reply-To: <20180504224427.32606-3-bjorn.andersson@linaro.org> References: <20180504224427.32606-1-bjorn.andersson@linaro.org> <20180504224427.32606-3-bjorn.andersson@linaro.org> Message-ID: <90f5df2414f26ed8c8c95b41d2f018c2@codeaurora.org> X-Sender: subhashj@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-05-04 15:44, Bjorn Andersson wrote: > devfreq requires that the client operates on actual frequencies, not > only 0 and UMAX_INT and as such UFS brok with the introduction of > f1d981eaecf8 ("PM / devfreq: Use the available min/max frequency"). > > This patch registers the frequencies of the first clock as opp levels > and use these to determine if we're trying to step up or down. > > Signed-off-by: Bjorn Andersson > --- > > Chances since v1: > - Register min_freq and max_freq as opp levels. > - Unregister opp levels on removal, to make e.g. probe defer working > > drivers/scsi/ufs/ufshcd.c | 47 +++++++++++++++++++++++++++++++++------ > 1 file changed, 40 insertions(+), 7 deletions(-) > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c > index 2253f24309ec..257614b889bd 100644 > --- a/drivers/scsi/ufs/ufshcd.c > +++ b/drivers/scsi/ufs/ufshcd.c > @@ -1168,16 +1168,13 @@ static int ufshcd_devfreq_target(struct device > *dev, > struct ufs_hba *hba = dev_get_drvdata(dev); > ktime_t start; > bool scale_up, sched_clk_scaling_suspend_work = false; > + struct list_head *clk_list = &hba->clk_list_head; > + struct ufs_clk_info *clki; > unsigned long irq_flags; > > if (!ufshcd_is_clkscaling_supported(hba)) > return -EINVAL; > > - if ((*freq > 0) && (*freq < UINT_MAX)) { > - dev_err(hba->dev, "%s: invalid freq = %lu\n", __func__, *freq); > - return -EINVAL; > - } > - > spin_lock_irqsave(hba->host->host_lock, irq_flags); > if (ufshcd_eh_in_progress(hba)) { > spin_unlock_irqrestore(hba->host->host_lock, irq_flags); > @@ -1187,7 +1184,13 @@ static int ufshcd_devfreq_target(struct device > *dev, > if (!hba->clk_scaling.active_reqs) > sched_clk_scaling_suspend_work = true; > > - scale_up = (*freq == UINT_MAX) ? true : false; > + if (list_empty(clk_list)) { > + spin_unlock_irqrestore(hba->host->host_lock, irq_flags); > + goto out; > + } > + > + clki = list_first_entry(clk_list, struct ufs_clk_info, list); > + scale_up = (*freq == clki->max_freq) ? true : false; > if (!ufshcd_is_devfreq_scaling_required(hba, scale_up)) { > spin_unlock_irqrestore(hba->host->host_lock, irq_flags); > ret = 0; > @@ -1257,16 +1260,29 @@ static struct devfreq_dev_profile > ufs_devfreq_profile = { > > static int ufshcd_devfreq_init(struct ufs_hba *hba) > { > + struct list_head *clk_list = &hba->clk_list_head; > + struct ufs_clk_info *clki; > struct devfreq *devfreq; > int ret; > > - devfreq = devm_devfreq_add_device(hba->dev, > + /* Skip devfreq if we don't have any clocks in the list */ > + if (list_empty(clk_list)) > + return 0; > + > + clki = list_first_entry(clk_list, struct ufs_clk_info, list); > + dev_pm_opp_add(hba->dev, clki->min_freq, 0); > + dev_pm_opp_add(hba->dev, clki->max_freq, 0); > + > + devfreq = devfreq_add_device(hba->dev, > &ufs_devfreq_profile, > "simple_ondemand", > NULL); > if (IS_ERR(devfreq)) { > ret = PTR_ERR(devfreq); > dev_err(hba->dev, "Unable to register with devfreq %d\n", ret); > + > + dev_pm_opp_remove(hba->dev, clki->min_freq); > + dev_pm_opp_remove(hba->dev, clki->max_freq); > return ret; > } > > @@ -1275,6 +1291,22 @@ static int ufshcd_devfreq_init(struct ufs_hba > *hba) > return 0; > } > > +static void ufshcd_devfreq_remove(struct ufs_hba *hba) > +{ > + struct list_head *clk_list = &hba->clk_list_head; > + struct ufs_clk_info *clki; > + > + if (!hba->devfreq) > + return; > + > + devfreq_remove_device(hba->devfreq); > + hba->devfreq = NULL; > + > + clki = list_first_entry(clk_list, struct ufs_clk_info, list); > + dev_pm_opp_remove(hba->dev, clki->min_freq); > + dev_pm_opp_remove(hba->dev, clki->max_freq); > +} > + > static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba) > { > unsigned long flags; > @@ -6966,6 +6998,7 @@ static void ufshcd_hba_exit(struct ufs_hba *hba) > if (hba->devfreq) > ufshcd_suspend_clkscaling(hba); > destroy_workqueue(hba->clk_scaling.workq); > + ufshcd_devfreq_remove(hba); > } > ufshcd_setup_clocks(hba, false); > ufshcd_setup_hba_vreg(hba, false); Looks good to me. Reviewed-by: Subhash Jadavani -- The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project