Commit 6edd8ee60ac9b974bd6ec3b1bcb2aab02762fa8c

Authored by Haavard Skinnemoen
Committed by Pierre Ossman
1 parent c5d5e9c40f

mmc: Export internal host state through debugfs

When CONFIG_DEBUG_FS is set, create a few files under /sys/kernel/debug
containing information about an mmc host's internal state. Currently,
just a single file is created, "ios", which contains information about
the current operating parameters for the bus (clock speed, bus width,
etc.)

Host drivers can add additional files and directories under the host's
root directory by passing the debugfs_root field in struct mmc_host as
the 'parent' parameter to debugfs_create_*.

Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>

Showing 5 changed files with 179 additions and 0 deletions Side-by-side Diff

drivers/mmc/core/Makefile
... ... @@ -11,4 +11,6 @@
11 11 mmc.o mmc_ops.o sd.o sd_ops.o \
12 12 sdio.o sdio_ops.o sdio_bus.o \
13 13 sdio_cis.o sdio_io.o sdio_irq.o
  14 +
  15 +mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
drivers/mmc/core/core.h
... ... @@ -52,5 +52,9 @@
52 52  
53 53 extern int use_spi_crc;
54 54  
  55 +/* Debugfs information for hosts and cards */
  56 +void mmc_add_host_debugfs(struct mmc_host *host);
  57 +void mmc_remove_host_debugfs(struct mmc_host *host);
  58 +
55 59 #endif
drivers/mmc/core/debugfs.c
  1 +/*
  2 + * Debugfs support for hosts and cards
  3 + *
  4 + * Copyright (C) 2008 Atmel Corporation
  5 + *
  6 + * This program is free software; you can redistribute it and/or modify
  7 + * it under the terms of the GNU General Public License version 2 as
  8 + * published by the Free Software Foundation.
  9 + */
  10 +#include <linux/debugfs.h>
  11 +#include <linux/fs.h>
  12 +#include <linux/seq_file.h>
  13 +#include <linux/stat.h>
  14 +
  15 +#include <linux/mmc/host.h>
  16 +
  17 +#include "core.h"
  18 +
  19 +/* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */
  20 +static int mmc_ios_show(struct seq_file *s, void *data)
  21 +{
  22 + static const char *vdd_str[] = {
  23 + [8] = "2.0",
  24 + [9] = "2.1",
  25 + [10] = "2.2",
  26 + [11] = "2.3",
  27 + [12] = "2.4",
  28 + [13] = "2.5",
  29 + [14] = "2.6",
  30 + [15] = "2.7",
  31 + [16] = "2.8",
  32 + [17] = "2.9",
  33 + [18] = "3.0",
  34 + [19] = "3.1",
  35 + [20] = "3.2",
  36 + [21] = "3.3",
  37 + [22] = "3.4",
  38 + [23] = "3.5",
  39 + [24] = "3.6",
  40 + };
  41 + struct mmc_host *host = s->private;
  42 + struct mmc_ios *ios = &host->ios;
  43 + const char *str;
  44 +
  45 + seq_printf(s, "clock:\t\t%u Hz\n", ios->clock);
  46 + seq_printf(s, "vdd:\t\t%u ", ios->vdd);
  47 + if ((1 << ios->vdd) & MMC_VDD_165_195)
  48 + seq_printf(s, "(1.65 - 1.95 V)\n");
  49 + else if (ios->vdd < (ARRAY_SIZE(vdd_str) - 1)
  50 + && vdd_str[ios->vdd] && vdd_str[ios->vdd + 1])
  51 + seq_printf(s, "(%s ~ %s V)\n", vdd_str[ios->vdd],
  52 + vdd_str[ios->vdd + 1]);
  53 + else
  54 + seq_printf(s, "(invalid)\n");
  55 +
  56 + switch (ios->bus_mode) {
  57 + case MMC_BUSMODE_OPENDRAIN:
  58 + str = "open drain";
  59 + break;
  60 + case MMC_BUSMODE_PUSHPULL:
  61 + str = "push-pull";
  62 + break;
  63 + default:
  64 + str = "invalid";
  65 + break;
  66 + }
  67 + seq_printf(s, "bus mode:\t%u (%s)\n", ios->bus_mode, str);
  68 +
  69 + switch (ios->chip_select) {
  70 + case MMC_CS_DONTCARE:
  71 + str = "don't care";
  72 + break;
  73 + case MMC_CS_HIGH:
  74 + str = "active high";
  75 + break;
  76 + case MMC_CS_LOW:
  77 + str = "active low";
  78 + break;
  79 + default:
  80 + str = "invalid";
  81 + break;
  82 + }
  83 + seq_printf(s, "chip select:\t%u (%s)\n", ios->chip_select, str);
  84 +
  85 + switch (ios->power_mode) {
  86 + case MMC_POWER_OFF:
  87 + str = "off";
  88 + break;
  89 + case MMC_POWER_UP:
  90 + str = "up";
  91 + break;
  92 + case MMC_POWER_ON:
  93 + str = "on";
  94 + break;
  95 + default:
  96 + str = "invalid";
  97 + break;
  98 + }
  99 + seq_printf(s, "power mode:\t%u (%s)\n", ios->power_mode, str);
  100 + seq_printf(s, "bus width:\t%u (%u bits)\n",
  101 + ios->bus_width, 1 << ios->bus_width);
  102 +
  103 + switch (ios->timing) {
  104 + case MMC_TIMING_LEGACY:
  105 + str = "legacy";
  106 + break;
  107 + case MMC_TIMING_MMC_HS:
  108 + str = "mmc high-speed";
  109 + break;
  110 + case MMC_TIMING_SD_HS:
  111 + str = "sd high-speed";
  112 + break;
  113 + default:
  114 + str = "invalid";
  115 + break;
  116 + }
  117 + seq_printf(s, "timing spec:\t%u (%s)\n", ios->timing, str);
  118 +
  119 + return 0;
  120 +}
  121 +
  122 +static int mmc_ios_open(struct inode *inode, struct file *file)
  123 +{
  124 + return single_open(file, mmc_ios_show, inode->i_private);
  125 +}
  126 +
  127 +static const struct file_operations mmc_ios_fops = {
  128 + .open = mmc_ios_open,
  129 + .read = seq_read,
  130 + .llseek = seq_lseek,
  131 + .release = single_release,
  132 +};
  133 +
  134 +void mmc_add_host_debugfs(struct mmc_host *host)
  135 +{
  136 + struct dentry *root;
  137 +
  138 + root = debugfs_create_dir(mmc_hostname(host), NULL);
  139 + if (IS_ERR(root))
  140 + /* Don't complain -- debugfs just isn't enabled */
  141 + return;
  142 + if (!root)
  143 + /* Complain -- debugfs is enabled, but it failed to
  144 + * create the directory. */
  145 + goto err_root;
  146 +
  147 + host->debugfs_root = root;
  148 +
  149 + if (!debugfs_create_file("ios", S_IRUSR, root, host, &mmc_ios_fops))
  150 + goto err_ios;
  151 +
  152 + return;
  153 +
  154 +err_ios:
  155 + debugfs_remove_recursive(root);
  156 + host->debugfs_root = NULL;
  157 +err_root:
  158 + dev_err(&host->class_dev, "failed to initialize debugfs\n");
  159 +}
  160 +
  161 +void mmc_remove_host_debugfs(struct mmc_host *host)
  162 +{
  163 + debugfs_remove_recursive(host->debugfs_root);
  164 +}
drivers/mmc/core/host.c
... ... @@ -127,6 +127,10 @@
127 127 if (err)
128 128 return err;
129 129  
  130 +#ifdef CONFIG_DEBUG_FS
  131 + mmc_add_host_debugfs(host);
  132 +#endif
  133 +
130 134 mmc_start_host(host);
131 135  
132 136 return 0;
... ... @@ -145,6 +149,10 @@
145 149 void mmc_remove_host(struct mmc_host *host)
146 150 {
147 151 mmc_stop_host(host);
  152 +
  153 +#ifdef CONFIG_DEBUG_FS
  154 + mmc_remove_host_debugfs(host);
  155 +#endif
148 156  
149 157 device_del(&host->class_dev);
150 158  
include/linux/mmc/host.h
... ... @@ -157,6 +157,8 @@
157 157 struct led_trigger *led; /* activity led */
158 158 #endif
159 159  
  160 + struct dentry *debugfs_root;
  161 +
160 162 unsigned long private[0] ____cacheline_aligned;
161 163 };
162 164