From patchwork Fri Jul 13 09:53:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sayali Lokhande X-Patchwork-Id: 10522953 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 94D6F602B3 for ; Fri, 13 Jul 2018 09:54:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 845082978B for ; Fri, 13 Jul 2018 09:54:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 755E92978C; Fri, 13 Jul 2018 09:54:26 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 20E5A2978C for ; Fri, 13 Jul 2018 09:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727389AbeGMKIU (ORCPT ); Fri, 13 Jul 2018 06:08:20 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:50416 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726817AbeGMKIU (ORCPT ); Fri, 13 Jul 2018 06:08:20 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 354B360B74; Fri, 13 Jul 2018 09:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1531475664; bh=A4vqSNmkJ6M0okyY7xZNgzUoUCkAhEFtwShfK4XsboI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jvB8i4HAB3+QRkHmV7IDRm4360PVYfz+4Ki4j4X9a4epP/aXoBzNMFMcGYw1nov6b wo/645ercFD9sgUh6FZ3PzT20AjHzvnQ77c5Fly6wVm4fUENvB3A7VGIIz+I+Awnz9 ZSQCXaZOCOUxhpq7cK9BxxIghHIZ/mU8WdqnpJS0= Received: from sayalil-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sayalil@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 8D08D60B83; Fri, 13 Jul 2018 09:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1531475663; bh=A4vqSNmkJ6M0okyY7xZNgzUoUCkAhEFtwShfK4XsboI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AySif/FAXK3+401mNUGOlDoLHoVOingJqIeXV8ZSNsql79dQjDJJ/5rwJUxDbHU8z yqNGXNvyexjl9fIEHBEPK2A9HU5yTR+06T8myQ7tVg+eYxOdUGffaGf6lGt3xudeKn DVraAiDYTGHUnIZ7ySm76yccAFv8e5O4ZQQzUUZo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8D08D60B83 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sayalil@codeaurora.org From: Sayali Lokhande To: adrian.hunter@intel.com, ulf.hansson@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, shawn.lin@rock-chips.com, linux-arm-msm@vger.kernel.org, georgi.djakov@linaro.org, devicetree@vger.kernel.org, asutoshd@codeaurora.org, stummala@codeaurora.org, venkatg@codeaurora.org, vviswana@codeaurora.org, bjorn.andersson@linaro.org, riteshh@codeaurora.org, vbadigan@codeaurora.org, sayalil@codeaurora.org, Sujit Reddy Thumma Subject: [PATCH RFC 7/7] mmc: core: Add a debugfs entry to set max clock rate Date: Fri, 13 Jul 2018 15:23:03 +0530 Message-Id: <1531475583-7050-8-git-send-email-sayalil@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1531475583-7050-1-git-send-email-sayalil@codeaurora.org> References: <1531475583-7050-1-git-send-email-sayalil@codeaurora.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Limiting the max frequency supported by host controller to a certain value can be useful for testing power consumption at various frequencies that are supported by the host. Note: If the card supports less than desired value then the frequency of operation would be limited to that frequency. Usage: mount -t debugfs none /sys/kernel/debug echo > /sys/kernel/debug/mmcX/max_clock cat /sys/kernel/debug/mmcX/max_clock Signed-off-by: Sujit Reddy Thumma Signed-off-by: Sayali Lokhande --- drivers/mmc/core/debugfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c index 630ca8e..26499f7 100644 --- a/drivers/mmc/core/debugfs.c +++ b/drivers/mmc/core/debugfs.c @@ -262,6 +262,46 @@ static int mmc_scale_set(void *data, u64 val) DEFINE_SIMPLE_ATTRIBUTE(mmc_scale_fops, mmc_scale_get, mmc_scale_set, "%llu\n"); +static int mmc_max_clock_get(void *data, u64 *val) +{ + struct mmc_host *host = data; + + if (!host) + return -EINVAL; + + *val = host->f_max; + + return 0; +} + +static int mmc_max_clock_set(void *data, u64 val) +{ + struct mmc_host *host = data; + int err = -EINVAL; + unsigned long freq = val; + unsigned int old_freq; + + if (!host || (val < host->f_min)) + goto out; + + mmc_claim_host(host); + if (host->bus_ops && host->bus_ops->change_bus_speed) { + old_freq = host->f_max; + host->f_max = freq; + + err = host->bus_ops->change_bus_speed(host, &freq); + + if (err) + host->f_max = old_freq; + } + mmc_release_host(host); +out: + return err; +} + +DEFINE_SIMPLE_ATTRIBUTE(mmc_max_clock_fops, mmc_max_clock_get, + mmc_max_clock_set, "%llu\n"); + void mmc_add_host_debugfs(struct mmc_host *host) { struct dentry *root; @@ -290,6 +330,10 @@ void mmc_add_host_debugfs(struct mmc_host *host) &mmc_clock_fops)) goto err_node; + if (!debugfs_create_file("max_clock", 0600, root, host, + &mmc_max_clock_fops)) + goto err_node; + if (!debugfs_create_file("scale", 0600, root, host, &mmc_scale_fops)) goto err_node;