Fabio Estevam | 0eb6048 | 2018-05-01 09:20:40 -0300 | [diff] [blame] | 1 | // 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 Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 8 | |
| 9 | #include <linux/debugfs.h> |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/kernel.h> |
| 12 | |
| 13 | #include "fsl_ssi.h" |
| 14 | |
| 15 | void fsl_ssi_dbg_isr(struct fsl_ssi_dbg *dbg, u32 sisr) |
| 16 | { |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 17 | if (sisr & SSI_SISR_RFRC) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 18 | dbg->stats.rfrc++; |
| 19 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 20 | if (sisr & SSI_SISR_TFRC) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 21 | dbg->stats.tfrc++; |
| 22 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 23 | if (sisr & SSI_SISR_CMDAU) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 24 | dbg->stats.cmdau++; |
| 25 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 26 | if (sisr & SSI_SISR_CMDDU) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 27 | dbg->stats.cmddu++; |
| 28 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 29 | if (sisr & SSI_SISR_RXT) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 30 | dbg->stats.rxt++; |
| 31 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 32 | if (sisr & SSI_SISR_RDR1) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 33 | dbg->stats.rdr1++; |
| 34 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 35 | if (sisr & SSI_SISR_RDR0) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 36 | dbg->stats.rdr0++; |
| 37 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 38 | if (sisr & SSI_SISR_TDE1) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 39 | dbg->stats.tde1++; |
| 40 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 41 | if (sisr & SSI_SISR_TDE0) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 42 | dbg->stats.tde0++; |
| 43 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 44 | if (sisr & SSI_SISR_ROE1) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 45 | dbg->stats.roe1++; |
| 46 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 47 | if (sisr & SSI_SISR_ROE0) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 48 | dbg->stats.roe0++; |
| 49 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 50 | if (sisr & SSI_SISR_TUE1) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 51 | dbg->stats.tue1++; |
| 52 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 53 | if (sisr & SSI_SISR_TUE0) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 54 | dbg->stats.tue0++; |
| 55 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 56 | if (sisr & SSI_SISR_TFS) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 57 | dbg->stats.tfs++; |
| 58 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 59 | if (sisr & SSI_SISR_RFS) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 60 | dbg->stats.rfs++; |
| 61 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 62 | if (sisr & SSI_SISR_TLS) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 63 | dbg->stats.tls++; |
| 64 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 65 | if (sisr & SSI_SISR_RLS) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 66 | dbg->stats.rls++; |
| 67 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 68 | if (sisr & SSI_SISR_RFF1) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 69 | dbg->stats.rff1++; |
| 70 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 71 | if (sisr & SSI_SISR_RFF0) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 72 | dbg->stats.rff0++; |
| 73 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 74 | if (sisr & SSI_SISR_TFE1) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 75 | dbg->stats.tfe1++; |
| 76 | |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 77 | if (sisr & SSI_SISR_TFE0) |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 78 | dbg->stats.tfe0++; |
| 79 | } |
| 80 | |
Nicolin Chen | 7a8fceb | 2017-12-17 18:52:02 -0800 | [diff] [blame] | 81 | /** |
| 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 Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 85 | */ |
| 86 | #define SIER_SHOW(flag, name) \ |
| 87 | do { \ |
Nicolin Chen | a818aa5 | 2017-12-17 18:52:03 -0800 | [diff] [blame] | 88 | if (SSI_SIER_##flag) \ |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 89 | seq_printf(s, #name "=%u\n", ssi_dbg->stats.name); \ |
| 90 | } while (0) |
| 91 | |
| 92 | |
| 93 | /** |
Nicolin Chen | 7a8fceb | 2017-12-17 18:52:02 -0800 | [diff] [blame] | 94 | * Display the statistics for the current SSI device |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 95 | * |
Nicolin Chen | 7a8fceb | 2017-12-17 18:52:02 -0800 | [diff] [blame] | 96 | * To avoid confusion, only show those counts that are enabled |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 97 | */ |
| 98 | static 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 | |
| 127 | static 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 | |
| 132 | static 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 | |
| 139 | int 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 Perches | 6a73cf4 | 2018-05-23 12:20:59 -0700 | [diff] [blame] | 145 | ssi_dbg->dbg_stats = debugfs_create_file("stats", 0444, |
Nicolin Chen | af4f7f3 | 2017-12-17 18:52:04 -0800 | [diff] [blame] | 146 | ssi_dbg->dbg_dir, ssi_dbg, |
| 147 | &fsl_ssi_stats_ops); |
Markus Pargmann | f138e62 | 2014-04-28 12:54:43 +0200 | [diff] [blame] | 148 | if (!ssi_dbg->dbg_stats) { |
| 149 | debugfs_remove(ssi_dbg->dbg_dir); |
| 150 | return -ENOMEM; |
| 151 | } |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | void 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 | } |