summaryrefslogtreecommitdiff
path: root/drivers/staging/fsl_ppfe/pfe_debugfs.c
blob: 4156610ddbb386e106b6adeabb25b09126730a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Copyright 2015-2016 Freescale Semiconductor, Inc.
 * Copyright 2017 NXP
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/module.h>
#include <linux/debugfs.h>
#include <linux/platform_device.h>

#include "pfe_mod.h"

static int dmem_show(struct seq_file *s, void *unused)
{
	u32 dmem_addr, val;
	int id = (long int)s->private;
	int i;

	for (dmem_addr = 0; dmem_addr < CLASS_DMEM_SIZE; dmem_addr += 8 * 4) {
		seq_printf(s, "%04x:", dmem_addr);

		for (i = 0; i < 8; i++) {
			val = pe_dmem_read(id, dmem_addr + i * 4, 4);
			seq_printf(s, " %02x %02x %02x %02x", val & 0xff,
				   (val >> 8) & 0xff, (val >> 16) & 0xff,
				   (val >> 24) & 0xff);
		}

		seq_puts(s, "\n");
	}

	return 0;
}

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

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

int pfe_debugfs_init(struct pfe *pfe)
{
	struct dentry *d;

	pr_info("%s\n", __func__);

	pfe->dentry = debugfs_create_dir("pfe", NULL);
	if (IS_ERR_OR_NULL(pfe->dentry))
		goto err_dir;

	d = debugfs_create_file("pe0_dmem", 0444, pfe->dentry, (void *)0,
				&dmem_fops);
	if (IS_ERR_OR_NULL(d))
		goto err_pe;

	d = debugfs_create_file("pe1_dmem", 0444, pfe->dentry, (void *)1,
				&dmem_fops);
	if (IS_ERR_OR_NULL(d))
		goto err_pe;

	d = debugfs_create_file("pe2_dmem", 0444, pfe->dentry, (void *)2,
				&dmem_fops);
	if (IS_ERR_OR_NULL(d))
		goto err_pe;

	d = debugfs_create_file("pe3_dmem", 0444, pfe->dentry, (void *)3,
				&dmem_fops);
	if (IS_ERR_OR_NULL(d))
		goto err_pe;

	d = debugfs_create_file("pe4_dmem", 0444, pfe->dentry, (void *)4,
				&dmem_fops);
	if (IS_ERR_OR_NULL(d))
		goto err_pe;

	d = debugfs_create_file("pe5_dmem", 0444, pfe->dentry, (void *)5,
				&dmem_fops);
	if (IS_ERR_OR_NULL(d))
		goto err_pe;

	return 0;

err_pe:
	debugfs_remove_recursive(pfe->dentry);

err_dir:
	return -1;
}

void pfe_debugfs_exit(struct pfe *pfe)
{
	debugfs_remove_recursive(pfe->dentry);
}