debugfs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // // Renesas R-Car debugfs support
  4. //
  5. // Copyright (c) 2021 Kuninori Morimoto <[email protected]>
  6. //
  7. // > mount -t debugfs none /sys/kernel/debug
  8. // > cd /sys/kernel/debug/asoc/rcar-sound/ec500000.sound/rdai{N}/
  9. // > cat playback/xxx
  10. // > cat capture/xxx
  11. //
  12. #ifdef CONFIG_DEBUG_FS
  13. #include <linux/debugfs.h>
  14. #include "rsnd.h"
  15. static int rsnd_debugfs_show(struct seq_file *m, void *v)
  16. {
  17. struct rsnd_dai_stream *io = m->private;
  18. struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
  19. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  20. int i;
  21. /* adg is out of mods */
  22. rsnd_adg_clk_dbg_info(priv, m);
  23. for_each_rsnd_mod(i, mod, io) {
  24. u32 *status = mod->ops->get_status(mod, io, mod->type);
  25. seq_printf(m, "name: %s\n", rsnd_mod_name(mod));
  26. seq_printf(m, "status: %08x\n", *status);
  27. if (mod->ops->debug_info)
  28. mod->ops->debug_info(m, io, mod);
  29. }
  30. return 0;
  31. }
  32. DEFINE_SHOW_ATTRIBUTE(rsnd_debugfs);
  33. void rsnd_debugfs_reg_show(struct seq_file *m, phys_addr_t _addr,
  34. void __iomem *base, int offset, int size)
  35. {
  36. int i, j;
  37. for (i = 0; i < size; i += 0x10) {
  38. phys_addr_t addr = _addr + offset + i;
  39. seq_printf(m, "%pa:", &addr);
  40. for (j = 0; j < 0x10; j += 0x4)
  41. seq_printf(m, " %08x", __raw_readl(base + offset + i + j));
  42. seq_puts(m, "\n");
  43. }
  44. }
  45. void rsnd_debugfs_mod_reg_show(struct seq_file *m, struct rsnd_mod *mod,
  46. int reg_id, int offset, int size)
  47. {
  48. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  49. rsnd_debugfs_reg_show(m,
  50. rsnd_gen_get_phy_addr(priv, reg_id),
  51. rsnd_gen_get_base_addr(priv, reg_id),
  52. offset, size);
  53. }
  54. int rsnd_debugfs_probe(struct snd_soc_component *component)
  55. {
  56. struct rsnd_priv *priv = dev_get_drvdata(component->dev);
  57. struct rsnd_dai *rdai;
  58. struct dentry *dir;
  59. char name[64];
  60. int i;
  61. /* Gen1 is not supported */
  62. if (rsnd_is_gen1(priv))
  63. return 0;
  64. for_each_rsnd_dai(rdai, priv, i) {
  65. /*
  66. * created debugfs will be automatically
  67. * removed, nothing to do for _remove.
  68. * see
  69. * soc_cleanup_component_debugfs()
  70. */
  71. snprintf(name, sizeof(name), "rdai%d", i);
  72. dir = debugfs_create_dir(name, component->debugfs_root);
  73. debugfs_create_file("playback", 0444, dir, &rdai->playback, &rsnd_debugfs_fops);
  74. debugfs_create_file("capture", 0444, dir, &rdai->capture, &rsnd_debugfs_fops);
  75. }
  76. return 0;
  77. }
  78. #endif /* CONFIG_DEBUG_FS */