From patchwork Tue Apr 24 00:20:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 134034 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1607107lji; Mon, 23 Apr 2018 17:20:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+QVPzvz78lgE2hTliXIIQO3wFVV7mioDQub6KK9fZHssNxfhGVxpmeYN5qAXdZYbYlBJ5a X-Received: by 2002:a17:902:6181:: with SMTP id u1-v6mr22507018plj.272.1524529229892; Mon, 23 Apr 2018 17:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524529229; cv=none; d=google.com; s=arc-20160816; b=qdo6X0rtSl/4m18QwekhUSLfKWN2GRAibZyxwcV+RqlrUHy7QUIe1rA8TjfmFCHIX8 GO7RoE2DJUx1PS0JjOv/CnWMD4DSdktAlMLPKeSNBp678wHXueBKFYOIWYsVJ92r3xDc HWIFFUavnMFoxPihrfOlyPe73c+R08UtQR9c8Y3bs9fNVH3Rlp6IFAsw6mL5mnIYdFlk iMeNNGHCR03SxaIxu4jO4F4CBp+AFqKbV63oyNYpP/xv7smbrnblmaAe1x5uVN8kDQTP qlMqSqX1CY/ePBX+579U/zxrlClPpB33GRmlzHhZPgkVz8bCSUXblIto0OVXKSdBX2JH 0niA== 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=oq/MiC8agxBZwYUIV0NGKzNJZJQo/yYIKvJRf6+gseI=; b=haTLN8E2uVGk8IZQBMsp8CRrwSEtGdr2Qa9H+DiYAIZAQeZRMHEFePWnB9q62WKURZ WFKj980i4hPZjHDK/Fnyiwnn0hZ0t4Poif0adAlIbCNxH+30tf9MBAe6YFESgF1PDT3i D0cZmWgaB2koWvngqUsMo7SbX+kgCJ+v1+E1N+3pJvv7uhngqP/Eb8xnZDe/7vXNtGp4 fW3zpJojbD8bG54q5ZxjQe2yzmrqt2ejRxhTHYsseO9kuYHCyT3rl8y1cz6+8bAYsO2U iQ8Zb/2rz/BU+gmFkAQZ7iZ8SfWhsah0TLnzoUv78Z03doPDwuroQ498bvBsuEIhbo4F mIRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CzwC5R4Q; 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 v8-v6si13603870plk.465.2018.04.23.17.20.29; Mon, 23 Apr 2018 17:20:29 -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=CzwC5R4Q; 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 S932712AbeDXAU0 (ORCPT + 29 others); Mon, 23 Apr 2018 20:20:26 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:41969 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932661AbeDXAUV (ORCPT ); Mon, 23 Apr 2018 20:20:21 -0400 Received: by mail-pf0-f193.google.com with SMTP id v63so1104897pfk.8 for ; Mon, 23 Apr 2018 17:20:21 -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=oq/MiC8agxBZwYUIV0NGKzNJZJQo/yYIKvJRf6+gseI=; b=CzwC5R4QKaMWmSZX+q1tv5MRTSmSySzeaRDACVS+SJGXRA97V589CwlXb/93McvfK0 GtwXT3wZSkLd6pS6ozytjICxe4hBDTRzHWwANEIyz5pLIE93DKDtdErUxP2nDF/P79fq HL4NWW33y9C51d/wMxu0ANidzbk0vhF5XArqk= 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=oq/MiC8agxBZwYUIV0NGKzNJZJQo/yYIKvJRf6+gseI=; b=PZIaGorEDHWKU3+l6SsQWlcQKYlFkaHf6VsKQ7rXkVFJ3bzbT/vBdFf7DxUCSi45qp k8IXv52Qb9zTU1qTwxPoPc0PI7+sdtUscN52QX72la9lFY1B+QHw4xxQLTvUuMQ5fmWT Bb7AZEjJLxKmU/H07aTh8C8iM628Z+bW4SNrp01vr+6IoM2Ya1cr50tibJQfr+tn/gob gSu33L4Yy7zIUMVZ0xp8/dKn81nxjKNaipiGLLma3KpMblGzTimSRkX7RLYsJKCKeskc skR0bpd032JC8m+f+iFeBRX8ONtfWssDGSVy2Zq5Hhv9l5hE5iymq51t1S7+OeDWCijW lhEg== X-Gm-Message-State: ALQs6tB3HnKxTDc2X29uqXffm9zisOHEXM3nTMV3PSq3G6pRee6O3Y5+ Qazp21Bmclc3+4SuaUD2eENELQ== X-Received: by 10.98.238.3 with SMTP id e3mr21753324pfi.232.1524529220991; Mon, 23 Apr 2018 17:20:20 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 17:20:20 -0700 (PDT) From: Bjorn Andersson To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi Cc: Vinayak Holikatti , "James E.J. Bottomley" , "Martin K. Petersen" , 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 1/3] PM / devfreq: Actually support providing freq_table Date: Mon, 23 Apr 2018 17:20:14 -0700 Message-Id: <20180424002016.9205-2-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 The code in devfreq_add_device() handles the case where a freq_table is passed by the client, but then requests min and max frequences from the, in this case absent, opp tables. Read the min and max frequencies from the frequency table, which has been built from the opp table if one exists, instead of querying the opp table. Signed-off-by: Bjorn Andersson --- An alternative approach is to clarify in the devfreq code that it's not possible to pass a freq_table and then in patch 3 create an opp table for the device in runtime; although the error handling of this becomes non-trivial. Transitioning the UFSHCD to use opp tables directly is hindered by the fact that the Qualcomm UFS hardware has two different clocks that needs to be running at different rates, so we would need a way to describe the two rates in the opp table. (And would force us to change the DT binding) drivers/devfreq/devfreq.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) -- 2.16.2 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index fe2af6aa88fc..086ced50a13d 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -74,30 +74,16 @@ static struct devfreq *find_device_devfreq(struct device *dev) static unsigned long find_available_min_freq(struct devfreq *devfreq) { - struct dev_pm_opp *opp; - unsigned long min_freq = 0; - - opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &min_freq); - if (IS_ERR(opp)) - min_freq = 0; - else - dev_pm_opp_put(opp); + struct devfreq_dev_profile *profile = devfreq->profile; - return min_freq; + return profile->freq_table[0]; } static unsigned long find_available_max_freq(struct devfreq *devfreq) { - struct dev_pm_opp *opp; - unsigned long max_freq = ULONG_MAX; - - opp = dev_pm_opp_find_freq_floor(devfreq->dev.parent, &max_freq); - if (IS_ERR(opp)) - max_freq = 0; - else - dev_pm_opp_put(opp); + struct devfreq_dev_profile *profile = devfreq->profile; - return max_freq; + return profile->freq_table[profile->max_state - 1]; } /** From patchwork Tue Apr 24 00:20:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 134036 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1607525lji; Mon, 23 Apr 2018 17:21:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx49IJVVrES/IatUoFvsJgoZzx8uIbiSj7X0lI/jS1E2T/EDmD7hkQT9W5SUpopekWHRJMULN X-Received: by 10.98.204.220 with SMTP id j89mr21741786pfk.182.1524529266777; Mon, 23 Apr 2018 17:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524529266; cv=none; d=google.com; s=arc-20160816; b=hUuJBxtJGz0ceMaZC1/Ptu2vcNJnuJ+gY6xKujNTMsDzSuQ4J0TL2t1GJ0lATn4/Ot MVhqtasI8CLmxtltDTxhqCcMpp47zXLDpd5Y4MVkUIt0tBJs5W7E+gWzKJ6iTdWCtzrP gBOAa249UPxDESly+/JtVcdUn03y9leUOWWUXeTX71174Qdk/pdLECsBpMQ/wxg5QtWc NgKi2A/2eBCMUFc4iLyGlmxWZiKOS8jfXlOGFZJSHJDBF2uUGMfQ7iLul9MsVv+IjuMN 1Lv/IUzGLJj2mVvGSdsbFXpnWcEwBpTnJlbnkhX4n0ps2ViRidMWr3MColO6M2+rExv7 8g2w== 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=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=dUYSBk+jexprAAlXcHp2CeC00dnIvRKdx+6dXrJ/jQ97LP/kopbDgOe55NQQEBqiGR eIPBnDcFeOn+2U8Zj75UVcl49RQBHideBKIBJHIP6J7osCSymDAaMNn9sGippF91jxgM wd2CFhcl9/Pl+cm7fmDnOZRWxyu4Z9CV6XghjbIMRLFH2uBzSNOCxGD3tndDt3EL3Pup QG+0vmasRljH0h8cIZOXOgjAvKBnuY+LG4AqYSyAtFSkdRSd/C44uR3VUwP06mcskPXa 02GXVTgkeZmVQdkaD4TnRvon0Wk+4dfkSdTSE9WbZv5IgxiHGKgVFzizsahTni7ApB7c b7HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J2s69Ubs; 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 h17si12369555pfj.178.2018.04.23.17.21.06; Mon, 23 Apr 2018 17:21:06 -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=J2s69Ubs; 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 S932739AbeDXAVE (ORCPT + 29 others); Mon, 23 Apr 2018 20:21:04 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:44519 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932674AbeDXAUW (ORCPT ); Mon, 23 Apr 2018 20:20:22 -0400 Received: by mail-pf0-f195.google.com with SMTP id p15so10681759pff.11 for ; Mon, 23 Apr 2018 17:20:22 -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=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=J2s69UbsahGMzxJIdQWi4bfO6OZ8ercD2J74i+LalmAZKU3tOwlIPdZBrzYQzoaJcN kkviA5WBDjS8yL333Gj/4GLx9MTFd0GByph3zAW6HYQNVDZJAICyQHGqEWIculhRMw3E xdBnUggCuw3Q4OkG0p50nxH9E26jGZ0c/zp2U= 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=w6Vzo0qvNj0fO9AWCxGt2xe6iPrgO7z9fIuhfDaX+6c=; b=oGi0veqlAv844ohc8ZzS1TEhUv9SIW0N1oRucRajVM/0+uR7+YU87idJvtCsJ/FpS1 Jy+UR4X96Io+rSTJPOAKQIUG5bGqX38JXhMD3Gu6sbDtgbtlBUkr4eNptDnfpT7rYu// Uj7Zuy5ws96tGUxAJFAhMbNzmunK3K12Xtxty8ymKZEgI15/DqUXXJemczKkyQMzZn3B bozurtlzYn2hdhOWW5eSCOxBxOzItXgaZtW6t5kaQ4wKD3ga5CcVF3A4D4iBcQc9QC5g HZeNW2kMH+e5oUxZjlIkJQBT9EtCU0WID1+QylMu/hrb6cU/jHcm9qKfQm/OCXESj0Ye FXPA== X-Gm-Message-State: ALQs6tDAZ1jMQU68ikIMQHvuN6AC42oVdWqaQ6NVeRn7AccP+K8Qbdjl 75MixMXy7nhLqXohnU9CWN2Fkw== X-Received: by 10.98.14.7 with SMTP id w7mr21747324pfi.50.1524529222072; Mon, 23 Apr 2018 17:20:22 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 17:20:21 -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 2/3] scsi: ufs: Extract devfreq registration Date: Mon, 23 Apr 2018 17:20:15 -0700 Message-Id: <20180424002016.9205-3-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 Failing to register with devfreq leaves hba->devfreq assigned, which causes the error path to dereference the ERR_PTR(). Rather than bolting on more conditionals, move the call of devm_devfreq_add_device() into it's own function and only update hba->devfreq once it's successfully registered. The subsequent patch builds upon this to make UFS actually work again, as it's been broken since f1d981eaecf8 ("PM / devfreq: Use the available min/max frequency") Signed-off-by: Bjorn Andersson --- drivers/scsi/ufs/ufshcd.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) -- 2.16.2 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8f22a980b1a7..2253f24309ec 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1255,6 +1255,26 @@ static struct devfreq_dev_profile ufs_devfreq_profile = { .get_dev_status = ufshcd_devfreq_get_dev_status, }; +static int ufshcd_devfreq_init(struct ufs_hba *hba) +{ + struct devfreq *devfreq; + int ret; + + devfreq = devm_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); + return ret; + } + + hba->devfreq = devfreq; + + return 0; +} + static void __ufshcd_suspend_clkscaling(struct ufs_hba *hba) { unsigned long flags; @@ -6399,16 +6419,9 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) sizeof(struct ufs_pa_layer_attr)); hba->clk_scaling.saved_pwr_info.is_valid = true; if (!hba->devfreq) { - hba->devfreq = devm_devfreq_add_device(hba->dev, - &ufs_devfreq_profile, - "simple_ondemand", - NULL); - if (IS_ERR(hba->devfreq)) { - ret = PTR_ERR(hba->devfreq); - dev_err(hba->dev, "Unable to register with devfreq %d\n", - ret); + ret = ufshcd_devfreq_init(hba); + if (ret) goto out; - } } hba->clk_scaling.is_allowed = true; } 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)) {