debugfs.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Debugfs support for hosts and cards
  4. *
  5. * Copyright (C) 2008 Atmel Corporation
  6. */
  7. #include <linux/moduleparam.h>
  8. #include <linux/export.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/fs.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/slab.h>
  13. #include <linux/stat.h>
  14. #include <linux/fault-inject.h>
  15. #include <linux/mmc/card.h>
  16. #include <linux/mmc/host.h>
  17. #include "core.h"
  18. #include "card.h"
  19. #include "host.h"
  20. #include "mmc_ops.h"
  21. #ifdef CONFIG_FAIL_MMC_REQUEST
  22. static DECLARE_FAULT_ATTR(fail_default_attr);
  23. static char *fail_request;
  24. module_param(fail_request, charp, 0);
  25. #endif /* CONFIG_FAIL_MMC_REQUEST */
  26. /* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */
  27. static int mmc_ios_show(struct seq_file *s, void *data)
  28. {
  29. static const char *vdd_str[] = {
  30. [8] = "2.0",
  31. [9] = "2.1",
  32. [10] = "2.2",
  33. [11] = "2.3",
  34. [12] = "2.4",
  35. [13] = "2.5",
  36. [14] = "2.6",
  37. [15] = "2.7",
  38. [16] = "2.8",
  39. [17] = "2.9",
  40. [18] = "3.0",
  41. [19] = "3.1",
  42. [20] = "3.2",
  43. [21] = "3.3",
  44. [22] = "3.4",
  45. [23] = "3.5",
  46. [24] = "3.6",
  47. };
  48. struct mmc_host *host = s->private;
  49. struct mmc_ios *ios = &host->ios;
  50. const char *str;
  51. seq_printf(s, "clock:\t\t%u Hz\n", ios->clock);
  52. if (host->actual_clock)
  53. seq_printf(s, "actual clock:\t%u Hz\n", host->actual_clock);
  54. seq_printf(s, "vdd:\t\t%u ", ios->vdd);
  55. if ((1 << ios->vdd) & MMC_VDD_165_195)
  56. seq_printf(s, "(1.65 - 1.95 V)\n");
  57. else if (ios->vdd < (ARRAY_SIZE(vdd_str) - 1)
  58. && vdd_str[ios->vdd] && vdd_str[ios->vdd + 1])
  59. seq_printf(s, "(%s ~ %s V)\n", vdd_str[ios->vdd],
  60. vdd_str[ios->vdd + 1]);
  61. else
  62. seq_printf(s, "(invalid)\n");
  63. switch (ios->bus_mode) {
  64. case MMC_BUSMODE_OPENDRAIN:
  65. str = "open drain";
  66. break;
  67. case MMC_BUSMODE_PUSHPULL:
  68. str = "push-pull";
  69. break;
  70. default:
  71. str = "invalid";
  72. break;
  73. }
  74. seq_printf(s, "bus mode:\t%u (%s)\n", ios->bus_mode, str);
  75. switch (ios->chip_select) {
  76. case MMC_CS_DONTCARE:
  77. str = "don't care";
  78. break;
  79. case MMC_CS_HIGH:
  80. str = "active high";
  81. break;
  82. case MMC_CS_LOW:
  83. str = "active low";
  84. break;
  85. default:
  86. str = "invalid";
  87. break;
  88. }
  89. seq_printf(s, "chip select:\t%u (%s)\n", ios->chip_select, str);
  90. switch (ios->power_mode) {
  91. case MMC_POWER_OFF:
  92. str = "off";
  93. break;
  94. case MMC_POWER_UP:
  95. str = "up";
  96. break;
  97. case MMC_POWER_ON:
  98. str = "on";
  99. break;
  100. default:
  101. str = "invalid";
  102. break;
  103. }
  104. seq_printf(s, "power mode:\t%u (%s)\n", ios->power_mode, str);
  105. seq_printf(s, "bus width:\t%u (%u bits)\n",
  106. ios->bus_width, 1 << ios->bus_width);
  107. switch (ios->timing) {
  108. case MMC_TIMING_LEGACY:
  109. str = "legacy";
  110. break;
  111. case MMC_TIMING_MMC_HS:
  112. str = "mmc high-speed";
  113. break;
  114. case MMC_TIMING_SD_HS:
  115. str = "sd high-speed";
  116. break;
  117. case MMC_TIMING_UHS_SDR12:
  118. str = "sd uhs SDR12";
  119. break;
  120. case MMC_TIMING_UHS_SDR25:
  121. str = "sd uhs SDR25";
  122. break;
  123. case MMC_TIMING_UHS_SDR50:
  124. str = "sd uhs SDR50";
  125. break;
  126. case MMC_TIMING_UHS_SDR104:
  127. str = "sd uhs SDR104";
  128. break;
  129. case MMC_TIMING_UHS_DDR50:
  130. str = "sd uhs DDR50";
  131. break;
  132. case MMC_TIMING_MMC_DDR52:
  133. str = "mmc DDR52";
  134. break;
  135. case MMC_TIMING_MMC_HS200:
  136. str = "mmc HS200";
  137. break;
  138. case MMC_TIMING_MMC_HS400:
  139. str = mmc_card_hs400es(host->card) ?
  140. "mmc HS400 enhanced strobe" : "mmc HS400";
  141. break;
  142. default:
  143. str = "invalid";
  144. break;
  145. }
  146. seq_printf(s, "timing spec:\t%u (%s)\n", ios->timing, str);
  147. switch (ios->signal_voltage) {
  148. case MMC_SIGNAL_VOLTAGE_330:
  149. str = "3.30 V";
  150. break;
  151. case MMC_SIGNAL_VOLTAGE_180:
  152. str = "1.80 V";
  153. break;
  154. case MMC_SIGNAL_VOLTAGE_120:
  155. str = "1.20 V";
  156. break;
  157. default:
  158. str = "invalid";
  159. break;
  160. }
  161. seq_printf(s, "signal voltage:\t%u (%s)\n", ios->signal_voltage, str);
  162. switch (ios->drv_type) {
  163. case MMC_SET_DRIVER_TYPE_A:
  164. str = "driver type A";
  165. break;
  166. case MMC_SET_DRIVER_TYPE_B:
  167. str = "driver type B";
  168. break;
  169. case MMC_SET_DRIVER_TYPE_C:
  170. str = "driver type C";
  171. break;
  172. case MMC_SET_DRIVER_TYPE_D:
  173. str = "driver type D";
  174. break;
  175. default:
  176. str = "invalid";
  177. break;
  178. }
  179. seq_printf(s, "driver type:\t%u (%s)\n", ios->drv_type, str);
  180. return 0;
  181. }
  182. DEFINE_SHOW_ATTRIBUTE(mmc_ios);
  183. static int mmc_clock_opt_get(void *data, u64 *val)
  184. {
  185. struct mmc_host *host = data;
  186. *val = host->ios.clock;
  187. return 0;
  188. }
  189. static int mmc_clock_opt_set(void *data, u64 val)
  190. {
  191. struct mmc_host *host = data;
  192. /* We need this check due to input value is u64 */
  193. if (val != 0 && (val > host->f_max || val < host->f_min))
  194. return -EINVAL;
  195. mmc_claim_host(host);
  196. mmc_set_clock(host, (unsigned int) val);
  197. mmc_release_host(host);
  198. return 0;
  199. }
  200. DEFINE_DEBUGFS_ATTRIBUTE(mmc_clock_fops, mmc_clock_opt_get, mmc_clock_opt_set,
  201. "%llu\n");
  202. void mmc_add_host_debugfs(struct mmc_host *host)
  203. {
  204. struct dentry *root;
  205. root = debugfs_create_dir(mmc_hostname(host), NULL);
  206. host->debugfs_root = root;
  207. debugfs_create_file("ios", S_IRUSR, root, host, &mmc_ios_fops);
  208. debugfs_create_x32("caps", S_IRUSR, root, &host->caps);
  209. debugfs_create_x32("caps2", S_IRUSR, root, &host->caps2);
  210. debugfs_create_file_unsafe("clock", S_IRUSR | S_IWUSR, root, host,
  211. &mmc_clock_fops);
  212. #ifdef CONFIG_FAIL_MMC_REQUEST
  213. if (fail_request)
  214. setup_fault_attr(&fail_default_attr, fail_request);
  215. host->fail_mmc_request = fail_default_attr;
  216. fault_create_debugfs_attr("fail_mmc_request", root,
  217. &host->fail_mmc_request);
  218. #endif
  219. }
  220. void mmc_remove_host_debugfs(struct mmc_host *host)
  221. {
  222. debugfs_remove_recursive(host->debugfs_root);
  223. }
  224. void mmc_add_card_debugfs(struct mmc_card *card)
  225. {
  226. struct mmc_host *host = card->host;
  227. struct dentry *root;
  228. if (!host->debugfs_root)
  229. return;
  230. root = debugfs_create_dir(mmc_card_id(card), host->debugfs_root);
  231. card->debugfs_root = root;
  232. debugfs_create_x32("state", S_IRUSR, root, &card->state);
  233. }
  234. void mmc_remove_card_debugfs(struct mmc_card *card)
  235. {
  236. debugfs_remove_recursive(card->debugfs_root);
  237. card->debugfs_root = NULL;
  238. }