From patchwork Tue Apr 24 00:20:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 134035 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1607303lji; Mon, 23 Apr 2018 17:20:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Hi31GypOqRSSzw7Di6M386N8TyXamRjw0QLrbalOOVwXI/H+6UcguW1WsJl6a17gTi0t+ X-Received: by 2002:a17:902:30a3:: with SMTP id v32-v6mr22891973plb.123.1524529248222; Mon, 23 Apr 2018 17:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524529248; cv=none; d=google.com; s=arc-20160816; b=gwOKPceU+JFlSQWZc2T5vLdvKKphnZymLf7xdmrxvS7RWinQOVV5Dzr9OnTortOF5u aPyHZtp6B8zlzIvw1Dlb8LB7IJNRM0p90kI5AGwBU/71jqX+OpQelEbQAOeGkGGdOZB4 Q8vOgYB3PsGktDk48a1aNiUB3x06Re/xNHIhbhBCFzcOA6yzfrZckwo2IHI5abHF147i 1YzqLQ3VtUKOk8a/XWiz/zR74//byViTT/pCTlOiL7Bt2LcbHWmGTg97EZCR5cfHRAVQ HLfzWZ9rsd9McPcM9UgpRfTR4Nh5thXiU+gZyf/Akihfo8HXxgyj4wqBgaSxnHDsgc0w mJ3A== 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=DSTbjfoz0kdQ/9LRJEh/g5udoe4jmqRYzjyUp1Wr9s4=; b=jP1r4bjU1EHI6OY7nZYcc8WkpaC4n9PzjK2wXjBfjwLBcWi1L20GDfxQyfo+zxBgMi KZhyHZXYhhmiNy96vNL86bMSx6Vkrgf40CW5z4S0/PAFUX41ey6yVuTOvAWzaP50Ju8S Pw+pCbbEj7qATtA4rxXI3Qfdd0xDphpsD/v8JtJAkkMMXYY/6+wupEjCcdpuwgmbGbjn Uy/ZKerYHy2wq/0VufFLheUva1J0+Tfp/6uUyAuuKPFyXJLYTlHYcF6wR6iySww4hFJf uUYr64IQvmd7H7Domp1nWObMrQ29+Zvpsej9Nd/uIy7eF3bI1Au4kweebJAB1FCqOZ8Q LbgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SwCP9z+t; 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 o13-v6si9543481pli.76.2018.04.23.17.20.47; Mon, 23 Apr 2018 17:20:48 -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=SwCP9z+t; 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 S932726AbeDXAUp (ORCPT + 29 others); Mon, 23 Apr 2018 20:20:45 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:46623 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932696AbeDXAUX (ORCPT ); Mon, 23 Apr 2018 20:20:23 -0400 Received: by mail-pf0-f196.google.com with SMTP id h69so10685370pfe.13 for ; Mon, 23 Apr 2018 17:20:23 -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=DSTbjfoz0kdQ/9LRJEh/g5udoe4jmqRYzjyUp1Wr9s4=; b=SwCP9z+tzdy9lk/cKHgYaYVujerGgji5mO8bIu2azCWgU+jUU4Y/Y91TSE1cZJttkW MzexYFLlQr6jcD5Fg64kmobYlUQVJX2lUV0pMXhKNny86y//a3kfYrIKaG9A1lI0xN1a Xy3kWBLOTW/dClIDUP72593eJxUl5v5cs2bbg= 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=DSTbjfoz0kdQ/9LRJEh/g5udoe4jmqRYzjyUp1Wr9s4=; b=qVbZ2qj1WvU0+/2AQhQzdZP62xZd6Fr01z6WNY0wnqT7eYwrJjP7MtomgV6gpPTBA0 JUBYYNDlptclAkJccAScW4yctpU6QByOmuRZ/FfBjz7SofY6LE106YOqmZE1JKvozffy CbmO/ks6PsbN6ERQoFCA34E6mR9EP+rSKd8kHGCLcILBh2U9/eaezhGSB+Cejeh1bXZK KE7ucl+0T+Z879oU5oMakvw4ZhvUE0TT5v+eBN8qM8+Kt8fnwh+WrBKRIsLG7bk32W7R LJjFM6+Cja0styzJV/ne4hbyjnW1wN4zeq7lUzZmaIVW+LJ4300+smE+CfaPjZaChydt V7+Q== X-Gm-Message-State: ALQs6tCGjDiA77WQZwVasFMHsRdzrNWuipC30kiow6LDIL8z8LPg5fT/ 17yytbtOEda42nGZ8E/eJBZNeg== X-Received: by 2002:a17:902:8342:: with SMTP id z2-v6mr22323951pln.311.1524529223164; Mon, 23 Apr 2018 17:20:23 -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 p6sm26669845pfk.104.2018.04.23.17.20.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 17:20:22 -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 3/3] scsi: ufs: Use freq table with devfreq Date: Mon, 23 Apr 2018 17:20:16 -0700 Message-Id: <20180424002016.9205-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180424002016.9205-1-bjorn.andersson@linaro.org> References: <20180424002016.9205-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 with devfreq and use these to determine if we're trying to step up or down. Signed-off-by: Bjorn Andersson --- drivers/scsi/ufs/ufshcd.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) -- 2.16.2 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 2253f24309ec..07b1f3c7bd2d 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(&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; @@ -1257,11 +1260,33 @@ static struct devfreq_dev_profile ufs_devfreq_profile = { static int ufshcd_devfreq_init(struct ufs_hba *hba) { + struct devfreq_dev_profile *profile; + struct list_head *clk_list = &hba->clk_list_head; + struct ufs_clk_info *clki; struct devfreq *devfreq; int ret; + /* Skip devfreq if we don't have any clocks in the list */ + if (list_empty(clk_list)) + return 0; + + profile = devm_kmemdup(hba->dev, &ufs_devfreq_profile, + sizeof(ufs_devfreq_profile), GFP_KERNEL); + if (!profile) + return -ENOMEM; + + profile->max_state = 2; + profile->freq_table = devm_kcalloc(hba->dev, profile->max_state, + sizeof(unsigned long), GFP_KERNEL); + if (!profile->freq_table) + return -ENOMEM; + + clki = list_first_entry(&hba->clk_list_head, struct ufs_clk_info, list); + profile->freq_table[0] = clki->min_freq; + profile->freq_table[1] = clki->max_freq; + devfreq = devm_devfreq_add_device(hba->dev, - &ufs_devfreq_profile, + profile, "simple_ondemand", NULL); if (IS_ERR(devfreq)) {