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: 10381763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7474D60353 for ; Fri, 4 May 2018 22:44:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E81F295A8 for ; Fri, 4 May 2018 22:44:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53263295AA; Fri, 4 May 2018 22:44:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B330D295A8 for ; Fri, 4 May 2018 22:44:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751809AbeEDWoi (ORCPT ); Fri, 4 May 2018 18:44:38 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39753 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751785AbeEDWoe (ORCPT ); Fri, 4 May 2018 18:44:34 -0400 Received: by mail-pf0-f193.google.com with SMTP id a22so4391679pfn.6 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=YT576O5aLbY7QANeBCryFP+IjhuIxz8GGNcQz3av3rYuiyeyBzT7jwwaW+MDVlLLwK Z/BDu0bfuS/iFJcvaZhHG0zTu4CxKa0eyEtGgtS68idU2m5RaxHeAJqHEg/RXrPzQ69N LoRay6TTs3VP049WifAI7BQ8aY0p/njU+sBwhCDU/GCU2v2XVs33CBAo5WIL6Ojt0vPY p9DXteLBwQrirSS0gwgoR/ieejFyRpWoLV8pZnLmrPOxAAbycZyFeH51DrNnczAqf2Rc tlK2+lRbzQmrigoTgWVLwOYy0qj93+2ZRGjYVuVwQhTKMEyp3UDd9YHgqA7DRlPZtVMF Zwig== X-Gm-Message-State: ALQs6tBy2Ri9FjXjSd6STHLVjCahJZxLLZUhb3a62m3HeXJfLzuCi9I+ nZ/CSv3RFt2E6mVaQikyONHSyQ== X-Google-Smtp-Source: AB8JxZoEJt480UNQ8nJEM25AyF+PXF0V1SpopZaMteCM1zzKVDLzozZ5xNIVoB7Cpl2g0wsWAXHEOA== 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-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Chanwoo Choi Reviewed-by: Subhash Jadavani --- 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);