From patchwork Fri May 18 06:26:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 136243 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp840582lji; Thu, 17 May 2018 23:27:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZon7rL8GGSNlGHR/dpRqixGfLPpx60C84A2Ir7xlO/URs5Kxhnh1KYVHFE+BdyHRjsmtLwA X-Received: by 2002:a17:902:1c7:: with SMTP id b65-v6mr8180332plb.298.1526624824335; Thu, 17 May 2018 23:27:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526624824; cv=none; d=google.com; s=arc-20160816; b=KE+cfpCPMObshDvzbrPMYYtwerMYFXXiFPMdYGcUgGq8AFhKe/ZR7bywnBvDxUvr+B Zm0GDv5zTgpwbiGdhfLD2KNZl3Zo1YAhQzxUrSZGTAwrBQM7yjnnyAL6dqrFBTCp8e6J 4AMEIY7Ez1Vw7k+xdHr4svh/Thh9nnu/GRikQjbdnjgUqi21bvXgtsxQL0ahqYi+ZCfr H4OYrdSxwkx6QBacHWa7qqereZJF08Q0bJqGo5TzVTxWO01J2Lu+xDYYzDxT3tfl/29X tS2BPWjaXxS8OMY19DmJzDmndEIdGQjH9sSG6lKAzY3bBK0SnE/Xf6v988dAeBPMVjQf w33Q== 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=rd/wYb0fKLDWtNN5WpdnRqomOv92nDDNdcoMM14LY98=; b=eBZEqDDOOcxCv7BYZ5tZolL3N37xuWhHcazDlE9rj/yzfR9VMMPDE7yVI6mZ2XdiE1 DUKhiu7eAvsqre6FNecSj3fkRsZKwLGKxwjWtzjoEPKit1e3kHlJOMfaSg/jEoi27WFU Z/rGUnK0ZjT2mp5fx/Rk8WDV1UtdbxrHtETypLzmWHSZBmwy5xkNffhtbCwBx9pypzGz VkuZlJxxSWdayVGnDuUJj4GT/KX7r1i95Y8rd6OlozXUibeluvE7s7bmOafUzoEyJKuq GYYu9D6QwKSIqbkJQo/XYc6hVFHrkvuMaKxuWxdZYqFmHndG5rV/nlRqY3PQ7371TOA/ /Qng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XVikWJkq; spf=pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-scsi-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 x28-v6si7002650pfa.37.2018.05.17.23.27.04; Thu, 17 May 2018 23:27:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-scsi-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=XVikWJkq; spf=pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-scsi-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 S1752204AbeERG1C (ORCPT + 1 other); Fri, 18 May 2018 02:27:02 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:37052 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752135AbeERG0o (ORCPT ); Fri, 18 May 2018 02:26:44 -0400 Received: by mail-pl0-f66.google.com with SMTP id w19-v6so3982879plq.4 for ; Thu, 17 May 2018 23:26:44 -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=rd/wYb0fKLDWtNN5WpdnRqomOv92nDDNdcoMM14LY98=; b=XVikWJkqDvsGEunCAEgndF46Mb9B9dBTy2O+xB0cnZP/+1WiwlTc5s27gGUnBfhE95 NcmcAIhKLp8YG5oDOdK5bfrub/ZGjZhLZwFDmCSKWTg6YaynFWjRnY3dtj3oCPAR57BE k0zW8erORdQIJ1dl8VRe3cPUc2ssF+1Tykxbw= 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=rd/wYb0fKLDWtNN5WpdnRqomOv92nDDNdcoMM14LY98=; b=CC4h8l2uqhjQTbr/UWkHbeyWAQDs/vco/Y3XeGrsYlj+pyYQAH6DARi95dWSUd7nAY m1pw+glnQcN67vYLIeXUWERrXSy/ypOfgslZqxDXKpInx3cCvliymyZE5JrpBgRPYxqC 6hC8NCfpP9pXYAs5CIrjtURIFJ6zeOAnssVXBRslPjaVdGZxvps5nYy6XHkyQrQOjl6C zZNo7MKh1XZKY7h7EABFtE6XoG00AXicQVBzT7R/VCHHBhMnErERBYeHlBqXXH5Ex/bO 6O3TrBKBzK3px5xef3mCUh1RD/pqWSm+Vg8t/l9b/ZcWXKPiqPEsuTOhgrmcwmqrz+2i 4f4A== X-Gm-Message-State: ALKqPwe24Trb4WxwL20XIpHBFMsxHgISTvW+1Pg1LpWQJrl7jS1NyrSf IH/y0FZRbfUMaEroQNG7Ez82BA== X-Received: by 2002:a17:902:1023:: with SMTP id b32-v6mr8199895pla.145.1526624803988; Thu, 17 May 2018 23:26:43 -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 b72-v6sm14157432pfm.69.2018.05.17.23.26.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 23:26:43 -0700 (PDT) From: Bjorn Andersson To: Vinayak Holikatti , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Andy Gross , 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 v3 2/3] scsi: ufs: Use freq table with devfreq Date: Thu, 17 May 2018 23:26:37 -0700 Message-Id: <20180518062638.31777-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518062638.31777-1-bjorn.andersson@linaro.org> References: <20180518062638.31777-1-bjorn.andersson@linaro.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 with devfreq and use these to determine if we're trying to step up or down. Reviewed-by: Chanwoo Choi [for devfreq & OPP part] Reviewed-by: Subhash Jadavani Signed-off-by: Bjorn Andersson --- Changes since v2: - Picked up R-b from Chanwoo and Subhash 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 f04902a066cb..3d46a70ed41d 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1200,16 +1200,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); @@ -1219,7 +1216,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(&hba->clk_list_head, 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; @@ -1289,16 +1292,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, DEVFREQ_GOV_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; } @@ -1307,6 +1323,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; @@ -7005,6 +7037,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);