mmc: Export internal host state through debugfs
[deliverable/linux.git] / 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 }
This page took 0.03892 seconds and 5 git commands to generate.