linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Chen <wenchao.chen666@gmail.com>
To: Vincent Whitchurch <vincent.whitchurch@axis.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@axis.com
Subject: Re: [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified
Date: Sat, 7 Oct 2023 10:27:15 +0800	[thread overview]
Message-ID: <CA+Da2qy=6CVEkuP5t2dPQVk_eHex-U4-BzJuQ2Y6ozZMfSEbuw@mail.gmail.com> (raw)
In-Reply-To: <20230929-mmc-caps-v2-2-11a4c2d94f15@axis.com>

On Fri, 29 Sept 2023 at 21:17, Vincent Whitchurch
<vincent.whitchurch@axis.com> wrote:
>
> During board verification, there is a need to test the various supported
> eMMC/SD speed modes.  However, since the framework chooses the best mode
> supported by the card and the host controller's caps, this currently
> necessitates changing the devicetree for every iteration.
>
> Allow the various speed mode host capabilities to be modified via
> debugfs in order to allow easier hardware verification.  The values to
> be written are the raw MMC_CAP* values from include/linux/mmc/host.h.
> This is rather low-level, and these defines are not guaranteed to be
> stable, but it is perhaps good enough for the intended use case.
>
> MMC_CAP_AGGRESSIVE_PM can also be set, in order to be able to
> re-initialize the card without having to physically remove and re-insert
> it.
>
>  /sys/kernel/debug/mmc0# grep timing ios
>  timing spec:   9 (mmc HS200)
>
>  // Turn on MMC_CAP_AGGRESSIVE_PM and re-trigger runtime suspend
>  /sys/kernel/debug/mmc0# echo $(($(cat caps) | (1 << 7))) > caps
>  /sys/kernel/debug/mmc0# echo on > /sys/bus/mmc/devices/mmc0\:0001/power/control
>  /sys/kernel/debug/mmc0# echo auto > /sys/bus/mmc/devices/mmc0\:0001/power/control
>
>  // MMC_CAP2_HS200_1_8V_SDR
>  /sys/kernel/debug/mmc0# echo $(($(cat caps2) & ~(1 << 5))) > caps2

$(($(cat caps2) & ~(1 << 5))) looks complicated, does it use echo DDR52 > caps2?

>  /sys/kernel/debug/mmc0# echo on > /sys/bus/mmc/devices/mmc0\:0001/power/control
>  /sys/kernel/debug/mmc0# grep timing ios
>  timing spec:   8 (mmc DDR52)
>
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> ---
>  drivers/mmc/core/debugfs.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
> index 2c97b94aab23..1642ea72d22c 100644
> --- a/drivers/mmc/core/debugfs.c
> +++ b/drivers/mmc/core/debugfs.c
> @@ -12,9 +12,12 @@
>  #include <linux/slab.h>
>  #include <linux/stat.h>
>  #include <linux/fault-inject.h>
> +#include <linux/time.h>
>
>  #include <linux/mmc/card.h>
>  #include <linux/mmc/host.h>
> +#include <linux/mmc/mmc.h>
> +#include <linux/mmc/sd.h>
>
>  #include "core.h"
>  #include "card.h"
> @@ -298,6 +301,49 @@ static const struct file_operations mmc_err_stats_fops = {
>         .release = single_release,
>  };
>
> +static int mmc_caps_get(void *data, u64 *val)
> +{
> +       *val = *(u32 *)data;
> +       return 0;
> +}
> +
> +static int mmc_caps_set(void *data, u64 val)
> +{
> +       u32 *caps = data;
> +       u32 diff = *caps ^ val;
> +       u32 allowed = MMC_CAP_AGGRESSIVE_PM |
> +                     MMC_CAP_SD_HIGHSPEED |
> +                     MMC_CAP_MMC_HIGHSPEED |
> +                     MMC_CAP_UHS |
> +                     MMC_CAP_DDR;
> +
> +       if (diff & ~allowed)
> +               return -EINVAL;
> +
> +       *caps = val;
> +
> +       return 0;
> +}
> +
> +static int mmc_caps2_set(void *data, u64 val)
> +{
> +       u32 allowed = MMC_CAP2_HSX00_1_8V | MMC_CAP2_HSX00_1_2V;
> +       u32 *caps = data;
> +       u32 diff = *caps ^ val;
> +
> +       if (diff & ~allowed)
> +               return -EINVAL;
> +
> +       *caps = val;
> +
> +       return 0;
> +}
> +
> +DEFINE_DEBUGFS_ATTRIBUTE(mmc_caps_fops, mmc_caps_get, mmc_caps_set,
> +                        "0x%08llx\n");
> +DEFINE_DEBUGFS_ATTRIBUTE(mmc_caps2_fops, mmc_caps_get, mmc_caps2_set,
> +                        "0x%08llx\n");
> +
>  void mmc_add_host_debugfs(struct mmc_host *host)
>  {
>         struct dentry *root;
> @@ -306,8 +352,9 @@ void mmc_add_host_debugfs(struct mmc_host *host)
>         host->debugfs_root = root;
>
>         debugfs_create_file("ios", S_IRUSR, root, host, &mmc_ios_fops);
> -       debugfs_create_x32("caps", S_IRUSR, root, &host->caps);
> -       debugfs_create_x32("caps2", S_IRUSR, root, &host->caps2);
> +       debugfs_create_file("caps", 0600, root, &host->caps, &mmc_caps_fops);
> +       debugfs_create_file("caps2", 0600, root, &host->caps2,
> +                           &mmc_caps2_fops);

Would it be better to use "S_IRUSR | S_IWUSR" instead of "0600"?

>         debugfs_create_file_unsafe("clock", S_IRUSR | S_IWUSR, root, host,
>                                    &mmc_clock_fops);
>
>
> --
> 2.34.1
>

  reply	other threads:[~2023-10-07  2:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29  7:45 [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Vincent Whitchurch
2023-09-29  7:45 ` [PATCH v2 1/2] mmc: core: Always reselect card type Vincent Whitchurch
2023-09-29  7:45 ` [PATCH v2 2/2] mmc: debugfs: Allow host caps to be modified Vincent Whitchurch
2023-10-07  2:27   ` Wenchao Chen [this message]
2023-10-09  7:28     ` Vincent Whitchurch
2023-10-10 14:27 ` [PATCH v2 0/2] mmc: Allow speed modes to be adjusted dynamically Ulf Hansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+Da2qy=6CVEkuP5t2dPQVk_eHex-U4-BzJuQ2Y6ozZMfSEbuw@mail.gmail.com' \
    --to=wenchao.chen666@gmail.com \
    --cc=kernel@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    --cc=vincent.whitchurch@axis.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).