fsl_ssi_dbg.c 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Freescale SSI ALSA SoC Digital Audio Interface (DAI) debugging functions
 *
 * Copyright 2014 Markus Pargmann <mpa@pengutronix.de>, Pengutronix
 *
 * Splitted from fsl_ssi.c
 *
 * This file is licensed under the terms of the GNU General Public License
 * version 2.  This program is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */

#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/kernel.h>

#include "fsl_ssi.h"

void fsl_ssi_dbg_isr(struct fsl_ssi_dbg *dbg, u32 sisr)
{
21
	if (sisr & SSI_SISR_RFRC)
22 23
		dbg->stats.rfrc++;

24
	if (sisr & SSI_SISR_TFRC)
25 26
		dbg->stats.tfrc++;

27
	if (sisr & SSI_SISR_CMDAU)
28 29
		dbg->stats.cmdau++;

30
	if (sisr & SSI_SISR_CMDDU)
31 32
		dbg->stats.cmddu++;

33
	if (sisr & SSI_SISR_RXT)
34 35
		dbg->stats.rxt++;

36
	if (sisr & SSI_SISR_RDR1)
37 38
		dbg->stats.rdr1++;

39
	if (sisr & SSI_SISR_RDR0)
40 41
		dbg->stats.rdr0++;

42
	if (sisr & SSI_SISR_TDE1)
43 44
		dbg->stats.tde1++;

45
	if (sisr & SSI_SISR_TDE0)
46 47
		dbg->stats.tde0++;

48
	if (sisr & SSI_SISR_ROE1)
49 50
		dbg->stats.roe1++;

51
	if (sisr & SSI_SISR_ROE0)
52 53
		dbg->stats.roe0++;

54
	if (sisr & SSI_SISR_TUE1)
55 56
		dbg->stats.tue1++;

57
	if (sisr & SSI_SISR_TUE0)
58 59
		dbg->stats.tue0++;

60
	if (sisr & SSI_SISR_TFS)
61 62
		dbg->stats.tfs++;

63
	if (sisr & SSI_SISR_RFS)
64 65
		dbg->stats.rfs++;

66
	if (sisr & SSI_SISR_TLS)
67 68
		dbg->stats.tls++;

69
	if (sisr & SSI_SISR_RLS)
70 71
		dbg->stats.rls++;

72
	if (sisr & SSI_SISR_RFF1)
73 74
		dbg->stats.rff1++;

75
	if (sisr & SSI_SISR_RFF0)
76 77
		dbg->stats.rff0++;

78
	if (sisr & SSI_SISR_TFE1)
79 80
		dbg->stats.tfe1++;

81
	if (sisr & SSI_SISR_TFE0)
82 83 84
		dbg->stats.tfe0++;
}

N
Nicolin Chen 已提交
85 86 87 88
/**
 * Show the statistics of a flag only if its interrupt is enabled
 *
 * Compilers will optimize it to a no-op if the interrupt is disabled
89 90 91
 */
#define SIER_SHOW(flag, name) \
	do { \
92
		if (SSI_SIER_##flag) \
93 94 95 96 97
			seq_printf(s, #name "=%u\n", ssi_dbg->stats.name); \
	} while (0)


/**
N
Nicolin Chen 已提交
98
 * Display the statistics for the current SSI device
99
 *
N
Nicolin Chen 已提交
100
 * To avoid confusion, only show those counts that are enabled
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
 */
static int fsl_ssi_stats_show(struct seq_file *s, void *unused)
{
	struct fsl_ssi_dbg *ssi_dbg = s->private;

	SIER_SHOW(RFRC_EN, rfrc);
	SIER_SHOW(TFRC_EN, tfrc);
	SIER_SHOW(CMDAU_EN, cmdau);
	SIER_SHOW(CMDDU_EN, cmddu);
	SIER_SHOW(RXT_EN, rxt);
	SIER_SHOW(RDR1_EN, rdr1);
	SIER_SHOW(RDR0_EN, rdr0);
	SIER_SHOW(TDE1_EN, tde1);
	SIER_SHOW(TDE0_EN, tde0);
	SIER_SHOW(ROE1_EN, roe1);
	SIER_SHOW(ROE0_EN, roe0);
	SIER_SHOW(TUE1_EN, tue1);
	SIER_SHOW(TUE0_EN, tue0);
	SIER_SHOW(TFS_EN, tfs);
	SIER_SHOW(RFS_EN, rfs);
	SIER_SHOW(TLS_EN, tls);
	SIER_SHOW(RLS_EN, rls);
	SIER_SHOW(RFF1_EN, rff1);
	SIER_SHOW(RFF0_EN, rff0);
	SIER_SHOW(TFE1_EN, tfe1);
	SIER_SHOW(TFE0_EN, tfe0);

	return 0;
}

static int fsl_ssi_stats_open(struct inode *inode, struct file *file)
{
	return single_open(file, fsl_ssi_stats_show, inode->i_private);
}

static const struct file_operations fsl_ssi_stats_ops = {
	.open = fsl_ssi_stats_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

int fsl_ssi_debugfs_create(struct fsl_ssi_dbg *ssi_dbg, struct device *dev)
{
	ssi_dbg->dbg_dir = debugfs_create_dir(dev_name(dev), NULL);
	if (!ssi_dbg->dbg_dir)
		return -ENOMEM;

149
	ssi_dbg->dbg_stats = debugfs_create_file("stats", 0444,
150 151
						 ssi_dbg->dbg_dir, ssi_dbg,
						 &fsl_ssi_stats_ops);
152 153 154 155 156 157 158 159 160 161 162 163 164
	if (!ssi_dbg->dbg_stats) {
		debugfs_remove(ssi_dbg->dbg_dir);
		return -ENOMEM;
	}

	return 0;
}

void fsl_ssi_debugfs_remove(struct fsl_ssi_dbg *ssi_dbg)
{
	debugfs_remove(ssi_dbg->dbg_stats);
	debugfs_remove(ssi_dbg->dbg_dir);
}