Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6629524yba; Wed, 1 May 2019 16:42:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwA0jLptUsnDt/5IDvFB6sAHWlCUXB4yyILNFZ/oV6OXJVhtGt0WfRu87biftvCi9rsFKAm X-Received: by 2002:a17:902:42:: with SMTP id 60mr367402pla.79.1556754174158; Wed, 01 May 2019 16:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556754174; cv=none; d=google.com; s=arc-20160816; b=cuog+D0T83o6zRm5LXVgCLXf3eBmRHk2DutTCDL4be2SY7v3uDTcLdHUwAfpD1wMqv 6j8XSjPDC+8Noo+QGKA6DcBkCv5/gNQC8J0hrxdjb3g0gC5gRvPwguD6YuHNJzjdg4+3 RPy6rr/HH8c7xxWDx011YKhDk7DCpG0mt9bE/1EnbXNgQHjDBfNaHumEGL79m5nF+ZSO 6d69xbZ8eLENLtAnoZ/JCP/R2T4I+rnWjzSoCprhcbtieTi3I3Zo2MpR0nGQXtDllegf nIPNPBrNrQXwDtJrya8BpL4hRAbMOdlkzLgRYtyw7iodquqW/uXAIQ+MangK4aOKHz60 e9EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7gSgxpoZvck6q57Fc1Ag09/Sll6e8T2kyeInAsQ6ito=; b=tfNm+02wFo92HE0rMUmNScbO//8X9A89VjNOy5BeaN3n48flrqvVdWJhhpSuJvXANm Mqceo7fQF8tKepnWxwG7AP7wjoB59Ri528HfkmS3sGlbxOH6qCNm3T0K5y28gwYUOE3e 9LzM5x03r6EeLXLAWaoE9Y4V4tbE5DF/5gf6Uu2oPXvgcS5955zgt17pQj6PmLroONF0 d4FwdYqhj+SctWflQ3v0HQd8fT5VyTnYUX4Ve3R9bdOaKGFhSi8BhDkIQRQ0qrVN4r2F HydmY2U3orRv4TsUcJsWsQIFIKvjV4mtCFl/pmiTCRWa7r+p0HK310g9q+QA30C7lqWN a0LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="h3c3i0/P"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d5si40237971pgh.516.2019.05.01.16.42.36; Wed, 01 May 2019 16:42:54 -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=@gmail.com header.s=20161025 header.b="h3c3i0/P"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726267AbfEAXlp (ORCPT + 99 others); Wed, 1 May 2019 19:41:45 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:54911 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbfEAXlo (ORCPT ); Wed, 1 May 2019 19:41:44 -0400 Received: by mail-it1-f196.google.com with SMTP id a190so334774ite.4; Wed, 01 May 2019 16:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7gSgxpoZvck6q57Fc1Ag09/Sll6e8T2kyeInAsQ6ito=; b=h3c3i0/PG7S5kJddW/4dh1PGYpgqEVZKJWglATzbSfonpzmU3wqRVpdyMWEZKatQex NKMLaXr5z6PpNWO0ktRb1hat8l6drP2anxDENEIpeK2QdBbmRLmWlDfCMOK1+Yxdnnap sxSlGHt0bNVct19YqoZ5J7Ha7HCo3f6eC0S0d2PpmXFn+komkoBhoPK63Q5qPQQkDYD2 JIOFlvzr75sWMV3wPYeSdgLzgO91KjSdHIMIfAtgbOv0r1WaQdw2ChJck+jsRlC2GF3Z EbRad8m7Mz9La4NEzjsajg8JTuMw/Op3wjIJ3DkZdSyoYIO7yH6tKctZzvFt7khoIq+d ZRsQ== 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:mime-version:content-transfer-encoding; bh=7gSgxpoZvck6q57Fc1Ag09/Sll6e8T2kyeInAsQ6ito=; b=pl5CzYr512bbNOqYT+TQ+KoyQrrPMlTy6nY6o9f0goQ7tTNxcpEToIrbiVns3V5+bR Nu/RMrBLqu3tysA8m3psOTmQvSCTbW6AhxK8FG61RQIhiaswCQKELfP//ojK5M8dH8Nr Ay5MiA3znpM8KM8tGld85qIv9VDDBHFStX18YvxkJ0f3ftEpX1638E6BYzFra3hRVGYr IP3CSCdpM0CiD0HH7ig1nUuc0Fq+22Vnf7TyFaoX9DIQ/+L7w2FsLR1zTp6jSTsPRv8o QTx/nywF1Lxgje2xI9SQV80VP07YmIyFbu6Td09zqgaq48y+NEmmogjfGC9Bkmr+WTEU qh3w== X-Gm-Message-State: APjAAAXwruNGyjUt+/MJF9LypOOPKiaxxzzUni1iee5izUNiYtYh9ujf hgeE59pSDYdgssnJZBZChVw= X-Received: by 2002:a24:1f50:: with SMTP id d77mr207848itd.25.1556754103751; Wed, 01 May 2019 16:41:43 -0700 (PDT) Received: from localhost.localdomain (ppp94-29-35-107.pppoe.spdop.ru. [94.29.35.107]) by smtp.gmail.com with ESMTPSA id m3sm2392507ion.69.2019.05.01.16.41.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 May 2019 16:41:43 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Tomeu Vizoso Cc: linux-pm@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 01/16] PM / devfreq: tegra: Fix kHz to Hz conversion Date: Thu, 2 May 2019 02:38:00 +0300 Message-Id: <20190501233815.32643-2-digetx@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190501233815.32643-1-digetx@gmail.com> References: <20190501233815.32643-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kHz to Hz is incorrectly converted in a few places in the code, this results in a wrong frequency being calculated because devfreq core uses OPP frequencies that are given in Hz to clamp the rate, while tegra-devfreq gives to the core value in kHz and then it also expects to receive value in kHz from the core. In a result memory freq is always set to a value which is close to ULONG_MAX because of the bug. Hence the EMC frequency is always capped to the maximum and the driver doesn't do anything useful. This patch was tested on Tegra30 and Tegra124 SoC's, EMC frequency scaling works properly now. Cc: # 4.14+ Tested-by: Steev Klimaszewski Reviewed-by: Chanwoo Choi Signed-off-by: Dmitry Osipenko --- drivers/devfreq/tegra-devfreq.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/devfreq/tegra-devfreq.c b/drivers/devfreq/tegra-devfreq.c index c89ba7b834ff..43cd1233f87b 100644 --- a/drivers/devfreq/tegra-devfreq.c +++ b/drivers/devfreq/tegra-devfreq.c @@ -486,11 +486,11 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq, { struct tegra_devfreq *tegra = dev_get_drvdata(dev); struct dev_pm_opp *opp; - unsigned long rate = *freq * KHZ; + unsigned long rate; - opp = devfreq_recommended_opp(dev, &rate, flags); + opp = devfreq_recommended_opp(dev, freq, flags); if (IS_ERR(opp)) { - dev_err(dev, "Failed to find opp for %lu KHz\n", *freq); + dev_err(dev, "Failed to find opp for %lu Hz\n", *freq); return PTR_ERR(opp); } rate = dev_pm_opp_get_freq(opp); @@ -499,8 +499,6 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq, clk_set_min_rate(tegra->emc_clock, rate); clk_set_rate(tegra->emc_clock, 0); - *freq = rate; - return 0; } @@ -510,7 +508,7 @@ static int tegra_devfreq_get_dev_status(struct device *dev, struct tegra_devfreq *tegra = dev_get_drvdata(dev); struct tegra_devfreq_device *actmon_dev; - stat->current_frequency = tegra->cur_freq; + stat->current_frequency = tegra->cur_freq * KHZ; /* To be used by the tegra governor */ stat->private_data = tegra; @@ -565,7 +563,7 @@ static int tegra_governor_get_target(struct devfreq *devfreq, target_freq = max(target_freq, dev->target_freq); } - *freq = target_freq; + *freq = target_freq * KHZ; return 0; } -- 2.21.0