1/*
2 * c8sectpfe-debugfs.c - C8SECTPFE STi DVB driver
3 *
4 * Copyright (c) STMicroelectronics 2015
5 *
6 * Author: Peter Griffin <peter.griffin@linaro.org>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2  of
10 * the License as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 */
17#include <linux/debugfs.h>
18#include <linux/device.h>
19#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/kernel.h>
22#include <linux/seq_file.h>
23#include <linux/slab.h>
24#include <linux/types.h>
25
26#include "c8sectpfe-debugfs.h"
27
28#define dump_register(nm ...)			\
29{						\
30	.name	= #nm,				\
31	.offset	= nm,				\
32}
33
34static const struct debugfs_reg32 fei_sys_regs[] = {
35	dump_register(SYS_INPUT_ERR_STATUS),
36	dump_register(SYS_OTHER_ERR_STATUS),
37	dump_register(SYS_INPUT_ERR_MASK),
38	dump_register(SYS_DMA_ROUTE),
39	dump_register(SYS_INPUT_CLKEN),
40	dump_register(IBENABLE_MASK),
41	dump_register(SYS_OTHER_CLKEN),
42	dump_register(SYS_CFG_NUM_IB),
43	dump_register(SYS_CFG_NUM_MIB),
44	dump_register(SYS_CFG_NUM_SWTS),
45	dump_register(SYS_CFG_NUM_TSOUT),
46	dump_register(SYS_CFG_NUM_CCSC),
47	dump_register(SYS_CFG_NUM_RAM),
48	dump_register(SYS_CFG_NUM_TP),
49
50	dump_register(C8SECTPFE_IB_IP_FMT_CFG(0)),
51	dump_register(C8SECTPFE_IB_TAGBYTES_CFG(0)),
52	dump_register(C8SECTPFE_IB_PID_SET(0)),
53	dump_register(C8SECTPFE_IB_PKT_LEN(0)),
54	dump_register(C8SECTPFE_IB_BUFF_STRT(0)),
55	dump_register(C8SECTPFE_IB_BUFF_END(0)),
56	dump_register(C8SECTPFE_IB_READ_PNT(0)),
57	dump_register(C8SECTPFE_IB_WRT_PNT(0)),
58	dump_register(C8SECTPFE_IB_PRI_THRLD(0)),
59	dump_register(C8SECTPFE_IB_STAT(0)),
60	dump_register(C8SECTPFE_IB_MASK(0)),
61	dump_register(C8SECTPFE_IB_SYS(0)),
62
63	dump_register(C8SECTPFE_IB_IP_FMT_CFG(1)),
64	dump_register(C8SECTPFE_IB_TAGBYTES_CFG(1)),
65	dump_register(C8SECTPFE_IB_PID_SET(1)),
66	dump_register(C8SECTPFE_IB_PKT_LEN(1)),
67	dump_register(C8SECTPFE_IB_BUFF_STRT(1)),
68	dump_register(C8SECTPFE_IB_BUFF_END(1)),
69	dump_register(C8SECTPFE_IB_READ_PNT(1)),
70	dump_register(C8SECTPFE_IB_WRT_PNT(1)),
71	dump_register(C8SECTPFE_IB_PRI_THRLD(1)),
72	dump_register(C8SECTPFE_IB_STAT(1)),
73	dump_register(C8SECTPFE_IB_MASK(1)),
74	dump_register(C8SECTPFE_IB_SYS(1)),
75
76	dump_register(C8SECTPFE_IB_IP_FMT_CFG(2)),
77	dump_register(C8SECTPFE_IB_TAGBYTES_CFG(2)),
78	dump_register(C8SECTPFE_IB_PID_SET(2)),
79	dump_register(C8SECTPFE_IB_PKT_LEN(2)),
80	dump_register(C8SECTPFE_IB_BUFF_STRT(2)),
81	dump_register(C8SECTPFE_IB_BUFF_END(2)),
82	dump_register(C8SECTPFE_IB_READ_PNT(2)),
83	dump_register(C8SECTPFE_IB_WRT_PNT(2)),
84	dump_register(C8SECTPFE_IB_PRI_THRLD(2)),
85	dump_register(C8SECTPFE_IB_STAT(2)),
86	dump_register(C8SECTPFE_IB_MASK(2)),
87	dump_register(C8SECTPFE_IB_SYS(2)),
88
89	dump_register(C8SECTPFE_IB_IP_FMT_CFG(3)),
90	dump_register(C8SECTPFE_IB_TAGBYTES_CFG(3)),
91	dump_register(C8SECTPFE_IB_PID_SET(3)),
92	dump_register(C8SECTPFE_IB_PKT_LEN(3)),
93	dump_register(C8SECTPFE_IB_BUFF_STRT(3)),
94	dump_register(C8SECTPFE_IB_BUFF_END(3)),
95	dump_register(C8SECTPFE_IB_READ_PNT(3)),
96	dump_register(C8SECTPFE_IB_WRT_PNT(3)),
97	dump_register(C8SECTPFE_IB_PRI_THRLD(3)),
98	dump_register(C8SECTPFE_IB_STAT(3)),
99	dump_register(C8SECTPFE_IB_MASK(3)),
100	dump_register(C8SECTPFE_IB_SYS(3)),
101
102	dump_register(C8SECTPFE_IB_IP_FMT_CFG(4)),
103	dump_register(C8SECTPFE_IB_TAGBYTES_CFG(4)),
104	dump_register(C8SECTPFE_IB_PID_SET(4)),
105	dump_register(C8SECTPFE_IB_PKT_LEN(4)),
106	dump_register(C8SECTPFE_IB_BUFF_STRT(4)),
107	dump_register(C8SECTPFE_IB_BUFF_END(4)),
108	dump_register(C8SECTPFE_IB_READ_PNT(4)),
109	dump_register(C8SECTPFE_IB_WRT_PNT(4)),
110	dump_register(C8SECTPFE_IB_PRI_THRLD(4)),
111	dump_register(C8SECTPFE_IB_STAT(4)),
112	dump_register(C8SECTPFE_IB_MASK(4)),
113	dump_register(C8SECTPFE_IB_SYS(4)),
114
115	dump_register(C8SECTPFE_IB_IP_FMT_CFG(5)),
116	dump_register(C8SECTPFE_IB_TAGBYTES_CFG(5)),
117	dump_register(C8SECTPFE_IB_PID_SET(5)),
118	dump_register(C8SECTPFE_IB_PKT_LEN(5)),
119	dump_register(C8SECTPFE_IB_BUFF_STRT(5)),
120	dump_register(C8SECTPFE_IB_BUFF_END(5)),
121	dump_register(C8SECTPFE_IB_READ_PNT(5)),
122	dump_register(C8SECTPFE_IB_WRT_PNT(5)),
123	dump_register(C8SECTPFE_IB_PRI_THRLD(5)),
124	dump_register(C8SECTPFE_IB_STAT(5)),
125	dump_register(C8SECTPFE_IB_MASK(5)),
126	dump_register(C8SECTPFE_IB_SYS(5)),
127
128	dump_register(C8SECTPFE_IB_IP_FMT_CFG(6)),
129	dump_register(C8SECTPFE_IB_TAGBYTES_CFG(6)),
130	dump_register(C8SECTPFE_IB_PID_SET(6)),
131	dump_register(C8SECTPFE_IB_PKT_LEN(6)),
132	dump_register(C8SECTPFE_IB_BUFF_STRT(6)),
133	dump_register(C8SECTPFE_IB_BUFF_END(6)),
134	dump_register(C8SECTPFE_IB_READ_PNT(6)),
135	dump_register(C8SECTPFE_IB_WRT_PNT(6)),
136	dump_register(C8SECTPFE_IB_PRI_THRLD(6)),
137	dump_register(C8SECTPFE_IB_STAT(6)),
138	dump_register(C8SECTPFE_IB_MASK(6)),
139	dump_register(C8SECTPFE_IB_SYS(6)),
140
141	dump_register(DMA_CPU_ID),
142	dump_register(DMA_CPU_VCR),
143	dump_register(DMA_CPU_RUN),
144	dump_register(DMA_CPU_PC),
145
146	dump_register(DMA_PER_TPn_DREQ_MASK),
147	dump_register(DMA_PER_TPn_DACK_SET),
148	dump_register(DMA_PER_TPn_DREQ),
149	dump_register(DMA_PER_TPn_DACK),
150	dump_register(DMA_PER_DREQ_MODE),
151	dump_register(DMA_PER_STBUS_SYNC),
152	dump_register(DMA_PER_STBUS_ACCESS),
153	dump_register(DMA_PER_STBUS_ADDRESS),
154	dump_register(DMA_PER_IDLE_INT),
155	dump_register(DMA_PER_PRIORITY),
156	dump_register(DMA_PER_MAX_OPCODE),
157	dump_register(DMA_PER_MAX_CHUNK),
158	dump_register(DMA_PER_PAGE_SIZE),
159	dump_register(DMA_PER_MBOX_STATUS),
160	dump_register(DMA_PER_MBOX_SET),
161	dump_register(DMA_PER_MBOX_CLEAR),
162	dump_register(DMA_PER_MBOX_MASK),
163	dump_register(DMA_PER_INJECT_PKT_SRC),
164	dump_register(DMA_PER_INJECT_PKT_DEST),
165	dump_register(DMA_PER_INJECT_PKT_ADDR),
166	dump_register(DMA_PER_INJECT_PKT),
167	dump_register(DMA_PER_PAT_PTR_INIT),
168	dump_register(DMA_PER_PAT_PTR),
169	dump_register(DMA_PER_SLEEP_MASK),
170	dump_register(DMA_PER_SLEEP_COUNTER),
171
172	dump_register(DMA_FIRMWARE_VERSION),
173	dump_register(DMA_PTRREC_BASE),
174	dump_register(DMA_PTRREC_INPUT_OFFSET),
175	dump_register(DMA_ERRREC_BASE),
176
177	dump_register(DMA_ERROR_RECORD(0)),
178	dump_register(DMA_ERROR_RECORD(1)),
179	dump_register(DMA_ERROR_RECORD(2)),
180	dump_register(DMA_ERROR_RECORD(3)),
181	dump_register(DMA_ERROR_RECORD(4)),
182	dump_register(DMA_ERROR_RECORD(5)),
183	dump_register(DMA_ERROR_RECORD(6)),
184	dump_register(DMA_ERROR_RECORD(7)),
185	dump_register(DMA_ERROR_RECORD(8)),
186	dump_register(DMA_ERROR_RECORD(9)),
187	dump_register(DMA_ERROR_RECORD(10)),
188	dump_register(DMA_ERROR_RECORD(11)),
189	dump_register(DMA_ERROR_RECORD(12)),
190	dump_register(DMA_ERROR_RECORD(13)),
191	dump_register(DMA_ERROR_RECORD(14)),
192	dump_register(DMA_ERROR_RECORD(15)),
193	dump_register(DMA_ERROR_RECORD(16)),
194	dump_register(DMA_ERROR_RECORD(17)),
195	dump_register(DMA_ERROR_RECORD(18)),
196	dump_register(DMA_ERROR_RECORD(19)),
197	dump_register(DMA_ERROR_RECORD(20)),
198	dump_register(DMA_ERROR_RECORD(21)),
199	dump_register(DMA_ERROR_RECORD(22)),
200
201	dump_register(DMA_IDLE_REQ),
202	dump_register(DMA_FIRMWARE_CONFIG),
203
204	dump_register(PIDF_BASE(0)),
205	dump_register(PIDF_BASE(1)),
206	dump_register(PIDF_BASE(2)),
207	dump_register(PIDF_BASE(3)),
208	dump_register(PIDF_BASE(4)),
209	dump_register(PIDF_BASE(5)),
210	dump_register(PIDF_BASE(6)),
211	dump_register(PIDF_BASE(7)),
212	dump_register(PIDF_BASE(8)),
213	dump_register(PIDF_BASE(9)),
214	dump_register(PIDF_BASE(10)),
215	dump_register(PIDF_BASE(11)),
216	dump_register(PIDF_BASE(12)),
217	dump_register(PIDF_BASE(13)),
218	dump_register(PIDF_BASE(14)),
219	dump_register(PIDF_BASE(15)),
220	dump_register(PIDF_BASE(16)),
221	dump_register(PIDF_BASE(17)),
222	dump_register(PIDF_BASE(18)),
223	dump_register(PIDF_BASE(19)),
224	dump_register(PIDF_BASE(20)),
225	dump_register(PIDF_BASE(21)),
226	dump_register(PIDF_BASE(22)),
227	dump_register(PIDF_LEAK_ENABLE),
228	dump_register(PIDF_LEAK_STATUS),
229	dump_register(PIDF_LEAK_COUNT_RESET),
230	dump_register(PIDF_LEAK_COUNTER),
231};
232
233void c8sectpfe_debugfs_init(struct c8sectpfei *fei)
234{
235	struct dentry		*root;
236	struct dentry		*file;
237
238	root = debugfs_create_dir("c8sectpfe", NULL);
239	if (!root)
240		goto err;
241
242	fei->root = root;
243
244	fei->regset =  devm_kzalloc(fei->dev, sizeof(*fei->regset), GFP_KERNEL);
245	if (!fei->regset)
246		goto err;
247
248	fei->regset->regs = fei_sys_regs;
249	fei->regset->nregs = ARRAY_SIZE(fei_sys_regs);
250	fei->regset->base = fei->io;
251
252	file = debugfs_create_regset32("registers", S_IRUGO, root,
253				fei->regset);
254	if (!file) {
255		dev_err(fei->dev,
256			"%s not able to create 'registers' debugfs\n"
257			, __func__);
258		goto err;
259	}
260
261	return;
262
263err:
264	debugfs_remove_recursive(root);
265}
266
267void c8sectpfe_debugfs_exit(struct c8sectpfei *fei)
268{
269	debugfs_remove_recursive(fei->root);
270	fei->root = NULL;
271}
272