From patchwork Fri May 4 22:44:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 135032 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp594960lji; Fri, 4 May 2018 15:44:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZols6Kln0SDq79Ra3WeMeypJbCWaaoeQD2+wrHtMrXkK1ewoF9FA0uZMz04xEdqyc/p9UB7 X-Received: by 2002:a17:902:683:: with SMTP id 3-v6mr29552142plh.206.1525473882626; Fri, 04 May 2018 15:44:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525473882; cv=none; d=google.com; s=arc-20160816; b=U5CgU9CMvlI5mhCBElVY2WRS2VKbTPblpXCOXL2XOFkKkUkRJpr33EbsZfSrPW+W/4 lOnLSihIQtXEKgyiGZ30nPnzWevtdWU9sCVGIkHmNu+uT0moAyTSETwixWC3SABAlT2f K1m9fHRO0d73OMQbNf886lGlK2Tm0oEpPLVSuNSpQ5TvHbravkSzTDztGqdu67AehkPT jgn07vHoLgR33ceZ3ZGSmohLo/zvHsmjnaFddU6GSFOvsKN6/Mi6jCFkeywZRasoBJle ptSGo9gYWlbYGuehZSig9gmzkAvqmguFzgo1SJehmv/Y/Sm24OsR+pCkbeXge5bG8yIn YKyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=81fRjY8PsQTpYjp/W4pda+uUyW6sEhdEi2TI5RCaNPc=; b=z+eKRi/0jP1e3CGGoKtejaicTxR4RhQocxQV6GlNr1aYPwyeh+fDYcf5WbUFJJaaNH KyV4act5U5zND6xHOdNy1XM6Ug/dVArkGCKyfi4lUqABkRlvrbtFGz4ivMEflBlzh/M4 vhMvV+nHwvOZUBbqbveQoi8sqopvFmlN3OXiB4vinDsFjtywJn2a0SWJ7r4bIv+n3ZWg 9/e2lEZOd41yUXeouV+MvsROrozkYbJqTcy2z/COiyA3YHZsnzxmCDywu5gA7pWtwMs/ PdB0ghm6Du+8u9rgQFRTYPgLdKxSZi+4fSRgdcHQrzPsCH7vsnlXx6O/MzHuK4R0jw9Q AbCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C/AoiLY5; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7-v6si16483197plt.149.2018.05.04.15.44.42; Fri, 04 May 2018 15:44:42 -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=@linaro.org header.s=google header.b=C/AoiLY5; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751826AbeEDWoi (ORCPT + 29 others); Fri, 4 May 2018 18:44:38 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33678 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751775AbeEDWoe (ORCPT ); Fri, 4 May 2018 18:44:34 -0400 Received: by mail-pf0-f196.google.com with SMTP id f20so9702264pfn.0 for ; Fri, 04 May 2018 15:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=81fRjY8PsQTpYjp/W4pda+uUyW6sEhdEi2TI5RCaNPc=; b=C/AoiLY5e5AALg50e3KWk4jqduRHiquMg6sZPAac7tulnRzZ2bf5K+sCWoJsKnkeww SELvm3oB37RXSoS2XeDeF1ewMupdfynD8AxNC7kb1Td40wvJFXIupJQ7FqO+vgzImV18 38Pizb+8/huzZunyT3/qPNxykgFV4x+6zCXdQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=81fRjY8PsQTpYjp/W4pda+uUyW6sEhdEi2TI5RCaNPc=; b=T2TfXMhFa5DMgBNVmGRLOByOZ4rbzMGUIMFDK7LNEJGYf65MXzs56qJvPAt0Le0uhF GuRBdedEu77aSzLqWra9Fx5E7mwC0AT3gjOGo61OVbXU1U/MXvT1OEzAzqRBCozjWBA2 Sh4GZ2zO+fLgiBRDQzMYUUR0ChziGAn45wVNNMMhEFIVBj3MinyckGyPngOpddSJ4JrM aWXAMOtOYTcKmQZ9t6sIkpX8uEDa+V7bbis9I70re8sHniW7XPLRM/hKQejwLTExTvi4 KaQgAbmCxok61GaDY3UD2IjKgvLDgfZIJR0tZvZd7RgyDPyUCM24s0qYCf8NFk86iadQ zF8Q== X-Gm-Message-State: ALQs6tAdnuISwHP9bGViLa9fZC5fnA5Eb/9d0y4iYSdcYUxsSbwSNVck cqUM4kS1b/kyNujwFzYplk6BkQ== X-Received: by 2002:a63:7344:: with SMTP id d4-v6mr23198150pgn.273.1525473873898; Fri, 04 May 2018 15:44:33 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id b29sm34793210pfh.155.2018.05.04.15.44.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 May 2018 15:44:33 -0700 (PDT) From: Bjorn Andersson To: Vinayak Holikatti , "James E.J. Bottomley" , "Martin K. Petersen" Cc: 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 Subject: [PATCH v2 2/2] scsi: ufs: Use freq table with devfreq Date: Fri, 4 May 2018 15:44:27 -0700 Message-Id: <20180504224427.32606-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180504224427.32606-1-bjorn.andersson@linaro.org> References: <20180504224427.32606-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.17.0 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);