blob: 1255dfe19eef8b6e82070c394042c59fa70472ce [file] [log] [blame]
Fabio Estevam0eb60482018-05-01 09:20:40 -03001// SPDX-License-Identifier: GPL-2.0
2//
3// Freescale SSI ALSA SoC Digital Audio Interface (DAI) debugging functions
4//
5// Copyright 2014 Markus Pargmann <mpa@pengutronix.de>, Pengutronix
6//
7// Split from fsl_ssi.c
Markus Pargmannf138e622014-04-28 12:54:43 +02008
9#include <linux/debugfs.h>
10#include <linux/device.h>
11#include <linux/kernel.h>
12
13#include "fsl_ssi.h"
14
15void fsl_ssi_dbg_isr(struct fsl_ssi_dbg *dbg, u32 sisr)
16{
Nicolin Chena818aa52017-12-17 18:52:03 -080017 if (sisr & SSI_SISR_RFRC)
Markus Pargmannf138e622014-04-28 12:54:43 +020018 dbg->stats.rfrc++;
19
Nicolin Chena818aa52017-12-17 18:52:03 -080020 if (sisr & SSI_SISR_TFRC)
Markus Pargmannf138e622014-04-28 12:54:43 +020021 dbg->stats.tfrc++;
22
Nicolin Chena818aa52017-12-17 18:52:03 -080023 if (sisr & SSI_SISR_CMDAU)
Markus Pargmannf138e622014-04-28 12:54:43 +020024 dbg->stats.cmdau++;
25
Nicolin Chena818aa52017-12-17 18:52:03 -080026 if (sisr & SSI_SISR_CMDDU)
Markus Pargmannf138e622014-04-28 12:54:43 +020027 dbg->stats.cmddu++;
28
Nicolin Chena818aa52017-12-17 18:52:03 -080029 if (sisr & SSI_SISR_RXT)
Markus Pargmannf138e622014-04-28 12:54:43 +020030 dbg->stats.rxt++;
31
Nicolin Chena818aa52017-12-17 18:52:03 -080032 if (sisr & SSI_SISR_RDR1)
Markus Pargmannf138e622014-04-28 12:54:43 +020033 dbg->stats.rdr1++;
34
Nicolin Chena818aa52017-12-17 18:52:03 -080035 if (sisr & SSI_SISR_RDR0)
Markus Pargmannf138e622014-04-28 12:54:43 +020036 dbg->stats.rdr0++;
37
Nicolin Chena818aa52017-12-17 18:52:03 -080038 if (sisr & SSI_SISR_TDE1)
Markus Pargmannf138e622014-04-28 12:54:43 +020039 dbg->stats.tde1++;
40
Nicolin Chena818aa52017-12-17 18:52:03 -080041 if (sisr & SSI_SISR_TDE0)
Markus Pargmannf138e622014-04-28 12:54:43 +020042 dbg->stats.tde0++;
43
Nicolin Chena818aa52017-12-17 18:52:03 -080044 if (sisr & SSI_SISR_ROE1)
Markus Pargmannf138e622014-04-28 12:54:43 +020045 dbg->stats.roe1++;
46
Nicolin Chena818aa52017-12-17 18:52:03 -080047 if (sisr & SSI_SISR_ROE0)
Markus Pargmannf138e622014-04-28 12:54:43 +020048 dbg->stats.roe0++;
49
Nicolin Chena818aa52017-12-17 18:52:03 -080050 if (sisr & SSI_SISR_TUE1)
Markus Pargmannf138e622014-04-28 12:54:43 +020051 dbg->stats.tue1++;
52
Nicolin Chena818aa52017-12-17 18:52:03 -080053 if (sisr & SSI_SISR_TUE0)
Markus Pargmannf138e622014-04-28 12:54:43 +020054 dbg->stats.tue0++;
55
Nicolin Chena818aa52017-12-17 18:52:03 -080056 if (sisr & SSI_SISR_TFS)
Markus Pargmannf138e622014-04-28 12:54:43 +020057 dbg->stats.tfs++;
58
Nicolin Chena818aa52017-12-17 18:52:03 -080059 if (sisr & SSI_SISR_RFS)
Markus Pargmannf138e622014-04-28 12:54:43 +020060 dbg->stats.rfs++;
61
Nicolin Chena818aa52017-12-17 18:52:03 -080062 if (sisr & SSI_SISR_TLS)
Markus Pargmannf138e622014-04-28 12:54:43 +020063 dbg->stats.tls++;
64
Nicolin Chena818aa52017-12-17 18:52:03 -080065 if (sisr & SSI_SISR_RLS)
Markus Pargmannf138e622014-04-28 12:54:43 +020066 dbg->stats.rls++;
67
Nicolin Chena818aa52017-12-17 18:52:03 -080068 if (sisr & SSI_SISR_RFF1)
Markus Pargmannf138e622014-04-28 12:54:43 +020069 dbg->stats.rff1++;
70
Nicolin Chena818aa52017-12-17 18:52:03 -080071 if (sisr & SSI_SISR_RFF0)
Markus Pargmannf138e622014-04-28 12:54:43 +020072 dbg->stats.rff0++;
73
Nicolin Chena818aa52017-12-17 18:52:03 -080074 if (sisr & SSI_SISR_TFE1)
Markus Pargmannf138e622014-04-28 12:54:43 +020075 dbg->stats.tfe1++;
76
Nicolin Chena818aa52017-12-17 18:52:03 -080077 if (sisr & SSI_SISR_TFE0)
Markus Pargmannf138e622014-04-28 12:54:43 +020078 dbg->stats.tfe0++;
79}
80
Nicolin Chen7a8fceb2017-12-17 18:52:02 -080081/**
82 * Show the statistics of a flag only if its interrupt is enabled
83 *
84 * Compilers will optimize it to a no-op if the interrupt is disabled
Markus Pargmannf138e622014-04-28 12:54:43 +020085 */
86#define SIER_SHOW(flag, name) \
87 do { \
Nicolin Chena818aa52017-12-17 18:52:03 -080088 if (SSI_SIER_##flag) \
Markus Pargmannf138e622014-04-28 12:54:43 +020089 seq_printf(s, #name "=%u\n", ssi_dbg->stats.name); \
90 } while (0)
91
92
93/**
Nicolin Chen7a8fceb2017-12-17 18:52:02 -080094 * Display the statistics for the current SSI device
Markus Pargmannf138e622014-04-28 12:54:43 +020095 *
Nicolin Chen7a8fceb2017-12-17 18:52:02 -080096 * To avoid confusion, only show those counts that are enabled
Markus Pargmannf138e622014-04-28 12:54:43 +020097 */
98static int fsl_ssi_stats_show(struct seq_file *s, void *unused)
99{
100 struct fsl_ssi_dbg *ssi_dbg = s->private;
101
102 SIER_SHOW(RFRC_EN, rfrc);
103 SIER_SHOW(TFRC_EN, tfrc);
104 SIER_SHOW(CMDAU_EN, cmdau);
105 SIER_SHOW(CMDDU_EN, cmddu);
106 SIER_SHOW(RXT_EN, rxt);
107 SIER_SHOW(RDR1_EN, rdr1);
108 SIER_SHOW(RDR0_EN, rdr0);
109 SIER_SHOW(TDE1_EN, tde1);
110 SIER_SHOW(TDE0_EN, tde0);
111 SIER_SHOW(ROE1_EN, roe1);
112 SIER_SHOW(ROE0_EN, roe0);
113 SIER_SHOW(TUE1_EN, tue1);
114 SIER_SHOW(TUE0_EN, tue0);
115 SIER_SHOW(TFS_EN, tfs);
116 SIER_SHOW(RFS_EN, rfs);
117 SIER_SHOW(TLS_EN, tls);
118 SIER_SHOW(RLS_EN, rls);
119 SIER_SHOW(RFF1_EN, rff1);
120 SIER_SHOW(RFF0_EN, rff0);
121 SIER_SHOW(TFE1_EN, tfe1);
122 SIER_SHOW(TFE0_EN, tfe0);
123
124 return 0;
125}
126
127static int fsl_ssi_stats_open(struct inode *inode, struct file *file)
128{
129 return single_open(file, fsl_ssi_stats_show, inode->i_private);
130}
131
132static const struct file_operations fsl_ssi_stats_ops = {
133 .open = fsl_ssi_stats_open,
134 .read = seq_read,
135 .llseek = seq_lseek,
136 .release = single_release,
137};
138
139int fsl_ssi_debugfs_create(struct fsl_ssi_dbg *ssi_dbg, struct device *dev)
140{
141 ssi_dbg->dbg_dir = debugfs_create_dir(dev_name(dev), NULL);
142 if (!ssi_dbg->dbg_dir)
143 return -ENOMEM;
144
Joe Perches6a73cf42018-05-23 12:20:59 -0700145 ssi_dbg->dbg_stats = debugfs_create_file("stats", 0444,
Nicolin Chenaf4f7f32017-12-17 18:52:04 -0800146 ssi_dbg->dbg_dir, ssi_dbg,
147 &fsl_ssi_stats_ops);
Markus Pargmannf138e622014-04-28 12:54:43 +0200148 if (!ssi_dbg->dbg_stats) {
149 debugfs_remove(ssi_dbg->dbg_dir);
150 return -ENOMEM;
151 }
152
153 return 0;
154}
155
156void fsl_ssi_debugfs_remove(struct fsl_ssi_dbg *ssi_dbg)
157{
158 debugfs_remove(ssi_dbg->dbg_stats);
159 debugfs_remove(ssi_dbg->dbg_dir);
160}