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