Skip to content
Permalink
Browse files
ASoC: rsnd: add debugfs support
Current rsnd supports #define DEBUG, but it is not helpful
if issue happen after 4-5 hours.
This patch adds debugfs support for it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  • Loading branch information
morimoto committed May 19, 2021
1 parent 7d84836 commit 414cf7fa2902ffed9742c0e71908061b5199fc1c
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 6 deletions.
@@ -1,3 +1,3 @@
# SPDX-License-Identifier: GPL-2.0
snd-soc-rcar-objs := core.o gen.o dma.o adg.o ssi.o ssiu.o src.o ctu.o mix.o dvc.o cmd.o
snd-soc-rcar-objs := core.o gen.o dma.o adg.o ssi.o ssiu.o src.o ctu.o mix.o dvc.o cmd.o debugfs.o
obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o
@@ -1736,6 +1736,7 @@ int rsnd_kctrl_new(struct rsnd_mod *mod,
*/
static const struct snd_soc_component_driver rsnd_soc_component = {
.name = "rsnd",
.probe = rsnd_debugfs_probe,
.hw_params = rsnd_hw_params,
.hw_free = rsnd_hw_free,
.pointer = rsnd_pointer,
@@ -275,6 +275,19 @@ static int rsnd_ctu_id_sub(struct rsnd_mod *mod)
return mod->id % 4;
}

#ifdef CONFIG_DEBUG_FS
static void rsnd_ctu_debug_info(struct seq_file *m,
struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU,
0x500 + rsnd_mod_id_raw(mod) * 0x100, 0x100);
}
#define DEBUG_INFO .debug_info = rsnd_ctu_debug_info
#else
#define DEBUG_INFO
#endif

static struct rsnd_mod_ops rsnd_ctu_ops = {
.name = CTU_NAME,
.probe = rsnd_ctu_probe_,
@@ -285,6 +298,7 @@ static struct rsnd_mod_ops rsnd_ctu_ops = {
.id = rsnd_ctu_id,
.id_sub = rsnd_ctu_id_sub,
.id_cmd = rsnd_mod_id_raw,
DEBUG_INFO
};

struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: GPL-2.0
//
// // Renesas R-Car debugfs support
//
// Copyright (c) 2021 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
//
// > mount -t debugfs none /sys/kernel/debug
// > cd /sys/kernel/debug/asoc/rcar-sound/ec500000.sound/rdai{N}/
// > cat playback/xxx
// > cat capture/xxx
//
#ifdef CONFIG_DEBUG_FS

#include <linux/debugfs.h>
#include "rsnd.h"

static int rsnd_debugfs_show(struct seq_file *m, void *v)
{
struct rsnd_dai_stream *io = m->private;
struct rsnd_mod *mod;
int i;

for_each_rsnd_mod(i, mod, io) {
u32 *status = mod->ops->get_status(mod, io, mod->type);

seq_printf(m, "[%s]\n", rsnd_mod_name(mod));
seq_printf(m, "status: %08x\n", *status);

if (mod->ops->debug_info)
mod->ops->debug_info(m, io, mod);
}

return 0;
}
DEFINE_SHOW_ATTRIBUTE(rsnd_debugfs);

void rsnd_debugfs_reg_show(struct seq_file *m, phys_addr_t _addr,
void __iomem *base, int offset, int size)
{
int i, j;

for (i = 0; i < size; i+=0x10) {
phys_addr_t addr = _addr + offset + i;
seq_printf(m, "%pa:", &addr);

for (j = 0; j < 0x10; j+=0x4)
seq_printf(m, " %08x", __raw_readl(base + offset + i + j));

seq_printf(m, "\n");
}
}

void rsnd_debugfs_mod_reg_show(struct seq_file *m, struct rsnd_mod *mod,
int reg_id, int offset, int size)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);

rsnd_debugfs_reg_show(m,
rsnd_gen_get_phy_addr(priv, reg_id),
rsnd_gen_get_base_addr(priv, reg_id),
offset, size);
}

int rsnd_debugfs_probe(struct snd_soc_component *component)
{
struct rsnd_priv *priv = dev_get_drvdata(component->dev);
struct rsnd_dai *rdai;
struct dentry *root, *dir;
char name[64];
int i;

/* Gen1 is not supported */
if (rsnd_is_gen1(priv))
return 0;

for_each_rsnd_dai(rdai, priv, i) {
/*
* created debugfs will be automatically
* removed, nothing to do for _remove.
* see
* soc_cleanup_component_debugfs()
*/
snprintf(name, sizeof(name), "rdai%d", i);
root = debugfs_create_dir(name, component->debugfs_root);

debugfs_create_file("playback", 0444, dir, &rdai->playback, &rsnd_debugfs_fops); \
debugfs_create_file("capture", 0444, dir, &rdai->capture , &rsnd_debugfs_fops); \
}

return 0;
}

#endif /* CONFIG_DEBUG_FS */
@@ -44,7 +44,8 @@ struct rsnd_dma {
};

struct rsnd_dma_ctrl {
void __iomem *base;
void __iomem *ppbase;
phys_addr_t ppres;
int dmaen_num;
int dmapp_num;
};
@@ -415,7 +416,7 @@ static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io,
}

#define rsnd_dmapp_addr(dmac, dma, reg) \
(dmac->base + 0x20 + reg + \
(dmac->ppbase + 0x20 + reg + \
(0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id))
static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg)
{
@@ -504,12 +505,31 @@ static int rsnd_dmapp_attach(struct rsnd_dai_stream *io,
return 0;
}

#ifdef CONFIG_DEBUG_FS
static void rsnd_dmapp_debug_info(struct seq_file *m,
struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma);

rsnd_debugfs_reg_show(m, dmac->ppres, dmac->ppbase,
0x20 + 0x10 * dmapp->dmapp_id, 0x10);
}
#define DEBUG_INFO .debug_info = rsnd_dmapp_debug_info
#else
#define DEBUG_INFO
#endif

static struct rsnd_mod_ops rsnd_dmapp_ops = {
.name = "audmac-pp",
.start = rsnd_dmapp_start,
.stop = rsnd_dmapp_stop,
.quit = rsnd_dmapp_stop,
.get_status = rsnd_mod_get_status,
DEBUG_INFO
};

/*
@@ -864,9 +884,10 @@ int rsnd_dma_probe(struct rsnd_priv *priv)
}

dmac->dmapp_num = 0;
dmac->base = devm_ioremap_resource(dev, res);
if (IS_ERR(dmac->base))
return PTR_ERR(dmac->base);
dmac->ppres = res->start;
dmac->ppbase = devm_ioremap_resource(dev, res);
if (IS_ERR(dmac->ppbase))
return PTR_ERR(dmac->ppbase);

priv->dma = dmac;

@@ -285,6 +285,19 @@ static struct dma_chan *rsnd_dvc_dma_req(struct rsnd_dai_stream *io,
mod, "tx");
}

#ifdef CONFIG_DEBUG_FS
static void rsnd_dvc_debug_info(struct seq_file *m,
struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU,
0xe00 + rsnd_mod_id(mod) * 0x100, 0x60);
}
#define DEBUG_INFO .debug_info = rsnd_dvc_debug_info
#else
#define DEBUG_INFO
#endif

static struct rsnd_mod_ops rsnd_dvc_ops = {
.name = DVC_NAME,
.dma_req = rsnd_dvc_dma_req,
@@ -293,6 +306,7 @@ static struct rsnd_mod_ops rsnd_dvc_ops = {
.quit = rsnd_dvc_quit,
.pcm_new = rsnd_dvc_pcm_new,
.get_status = rsnd_mod_get_status,
DEBUG_INFO
};

struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id)
@@ -141,6 +141,15 @@ phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id)
return gen->res[reg_id];
}

#ifdef CONFIG_DEBUG_FS
void __iomem *rsnd_gen_get_base_addr(struct rsnd_priv *priv, int reg_id)
{
struct rsnd_gen *gen = rsnd_priv_to_gen(priv);

return gen->base[reg_id];
}
#endif

#define rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf) \
_rsnd_gen_regmap_init(priv, id_size, reg_id, name, conf, ARRAY_SIZE(conf))
static int _rsnd_gen_regmap_init(struct rsnd_priv *priv,
@@ -250,13 +250,27 @@ static int rsnd_mix_pcm_new(struct rsnd_mod *mod,
return ret;
}

#ifdef CONFIG_DEBUG_FS
static void rsnd_mix_debug_info(struct seq_file *m,
struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU,
0xd00 + rsnd_mod_id(mod) * 0x40, 0x30);
}
#define DEBUG_INFO .debug_info = rsnd_mix_debug_info
#else
#define DEBUG_INFO
#endif

static struct rsnd_mod_ops rsnd_mix_ops = {
.name = MIX_NAME,
.probe = rsnd_mix_probe_,
.init = rsnd_mix_init,
.quit = rsnd_mix_quit,
.pcm_new = rsnd_mix_pcm_new,
.get_status = rsnd_mod_get_status,
DEBUG_INFO
};

struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
@@ -345,6 +345,11 @@ struct rsnd_mod_ops {
int (*id)(struct rsnd_mod *mod);
int (*id_sub)(struct rsnd_mod *mod);
int (*id_cmd)(struct rsnd_mod *mod);

#ifdef CONFIG_DEBUG_FS
void (*debug_info)(struct seq_file *m,
struct rsnd_dai_stream *io, struct rsnd_mod *mod);
#endif
};

struct rsnd_dai_stream;
@@ -592,6 +597,9 @@ void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
struct rsnd_mod *mod,
enum rsnd_reg reg);
phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id);
#ifdef CONFIG_DEBUG_FS
void __iomem *rsnd_gen_get_base_addr(struct rsnd_priv *priv, int reg_id);
#endif

/*
* R-Car ADG
@@ -896,3 +904,14 @@ void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type);
dev_dbg(dev, param)

#endif

#ifdef CONFIG_DEBUG_FS
int rsnd_debugfs_probe(struct snd_soc_component *component);
void rsnd_debugfs_reg_show(struct seq_file *m, phys_addr_t _addr,
void __iomem *base, int offset, int size);
void rsnd_debugfs_mod_reg_show(struct seq_file *m, struct rsnd_mod *mod,
int reg_id, int offset, int size);

#else
#define rsnd_debugfs_probe NULL
#endif
@@ -597,6 +597,25 @@ static int rsnd_src_pcm_new(struct rsnd_mod *mod,
return ret;
}

#ifdef CONFIG_DEBUG_FS
static void rsnd_src_debug_info(struct seq_file *m,
struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU,
rsnd_mod_id(mod) * 0x20, 0x20);
seq_printf(m, "\n");
rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU,
0x1c0, 0x20);
seq_printf(m, "\n");
rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SCU,
0x200 + rsnd_mod_id(mod) * 0x40, 0x40);
}
#define DEBUG_INFO .debug_info = rsnd_src_debug_info
#else
#define DEBUG_INFO
#endif

static struct rsnd_mod_ops rsnd_src_ops = {
.name = SRC_NAME,
.dma_req = rsnd_src_dma_req,
@@ -608,6 +627,7 @@ static struct rsnd_mod_ops rsnd_src_ops = {
.irq = rsnd_src_irq,
.pcm_new = rsnd_src_pcm_new,
.get_status = rsnd_mod_get_status,
DEBUG_INFO
};

struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
@@ -1118,6 +1118,32 @@ static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
mod, name);
}

#ifdef CONFIG_DEBUG_FS
static void rsnd_ssi_debug_info(struct seq_file *m,
struct rsnd_dai_stream *io,
struct rsnd_mod *mod)
{
struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);

seq_printf(m, "clock: %s\n", rsnd_rdai_is_clk_master(rdai) ?
"provider" : "consumer");
seq_printf(m, "pin share: %d\n", __rsnd_ssi_is_pin_sharing(mod));
seq_printf(m, "can out clk: %d\n", rsnd_ssi_can_output_clk(mod));
seq_printf(m, "multi secondary: %d\n", rsnd_ssi_is_multi_secondary(mod, io));
seq_printf(m, "tdm: %d, %d\n", rsnd_runtime_is_tdm(io),
rsnd_runtime_is_tdm_split(io));
seq_printf(m, "chan: %d\n", ssi->chan);
seq_printf(m, "user: %d\n", ssi->usrcnt);

rsnd_debugfs_mod_reg_show(m, mod, RSND_GEN2_SSI,
rsnd_mod_id(mod) * 0x40, 0x40);
}
#define DEBUG_INFO .debug_info = rsnd_ssi_debug_info
#else
#define DEBUG_INFO
#endif

static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
.name = SSI_NAME,
.dma_req = rsnd_ssi_dma_req,
@@ -1132,6 +1158,7 @@ static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
.fallback = rsnd_ssi_fallback,
.hw_params = rsnd_ssi_hw_params,
.get_status = rsnd_ssi_get_status,
DEBUG_INFO
};

int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)

0 comments on commit 414cf7f

Please sign in to comment.