1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2019-2020 NXP
4 */
5
6 #include <linux/debugfs.h>
7 #include <linux/device.h>
8 #include <linux/io.h>
9 #include <linux/kernel.h>
10 #include <linux/pm_runtime.h>
11 #include <linux/seq_file.h>
12 #include <linux/types.h>
13
14 #include "imx8-isi-core.h"
15 #include "imx8-isi-regs.h"
16
mxc_isi_read(struct mxc_isi_pipe * pipe,u32 reg)17 static inline u32 mxc_isi_read(struct mxc_isi_pipe *pipe, u32 reg)
18 {
19 return readl(pipe->regs + reg);
20 }
21
mxc_isi_debug_dump_regs_show(struct seq_file * m,void * p)22 static int mxc_isi_debug_dump_regs_show(struct seq_file *m, void *p)
23 {
24 #define MXC_ISI_DEBUG_REG(name) { name, #name }
25 static const struct {
26 u32 offset;
27 const char * const name;
28 } registers[] = {
29 MXC_ISI_DEBUG_REG(CHNL_CTRL),
30 MXC_ISI_DEBUG_REG(CHNL_IMG_CTRL),
31 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF_CTRL),
32 MXC_ISI_DEBUG_REG(CHNL_IMG_CFG),
33 MXC_ISI_DEBUG_REG(CHNL_IER),
34 MXC_ISI_DEBUG_REG(CHNL_STS),
35 MXC_ISI_DEBUG_REG(CHNL_SCALE_FACTOR),
36 MXC_ISI_DEBUG_REG(CHNL_SCALE_OFFSET),
37 MXC_ISI_DEBUG_REG(CHNL_CROP_ULC),
38 MXC_ISI_DEBUG_REG(CHNL_CROP_LRC),
39 MXC_ISI_DEBUG_REG(CHNL_CSC_COEFF0),
40 MXC_ISI_DEBUG_REG(CHNL_CSC_COEFF1),
41 MXC_ISI_DEBUG_REG(CHNL_CSC_COEFF2),
42 MXC_ISI_DEBUG_REG(CHNL_CSC_COEFF3),
43 MXC_ISI_DEBUG_REG(CHNL_CSC_COEFF4),
44 MXC_ISI_DEBUG_REG(CHNL_CSC_COEFF5),
45 MXC_ISI_DEBUG_REG(CHNL_ROI_0_ALPHA),
46 MXC_ISI_DEBUG_REG(CHNL_ROI_0_ULC),
47 MXC_ISI_DEBUG_REG(CHNL_ROI_0_LRC),
48 MXC_ISI_DEBUG_REG(CHNL_ROI_1_ALPHA),
49 MXC_ISI_DEBUG_REG(CHNL_ROI_1_ULC),
50 MXC_ISI_DEBUG_REG(CHNL_ROI_1_LRC),
51 MXC_ISI_DEBUG_REG(CHNL_ROI_2_ALPHA),
52 MXC_ISI_DEBUG_REG(CHNL_ROI_2_ULC),
53 MXC_ISI_DEBUG_REG(CHNL_ROI_2_LRC),
54 MXC_ISI_DEBUG_REG(CHNL_ROI_3_ALPHA),
55 MXC_ISI_DEBUG_REG(CHNL_ROI_3_ULC),
56 MXC_ISI_DEBUG_REG(CHNL_ROI_3_LRC),
57 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF1_ADDR_Y),
58 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF1_ADDR_U),
59 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF1_ADDR_V),
60 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF_PITCH),
61 MXC_ISI_DEBUG_REG(CHNL_IN_BUF_ADDR),
62 MXC_ISI_DEBUG_REG(CHNL_IN_BUF_PITCH),
63 MXC_ISI_DEBUG_REG(CHNL_MEM_RD_CTRL),
64 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF2_ADDR_Y),
65 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF2_ADDR_U),
66 MXC_ISI_DEBUG_REG(CHNL_OUT_BUF2_ADDR_V),
67 MXC_ISI_DEBUG_REG(CHNL_SCL_IMG_CFG),
68 MXC_ISI_DEBUG_REG(CHNL_FLOW_CTRL),
69 };
70
71 struct mxc_isi_pipe *pipe = m->private;
72 unsigned int i;
73
74 if (!pm_runtime_get_if_in_use(pipe->isi->dev))
75 return 0;
76
77 seq_printf(m, "--- ISI pipe %u registers ---\n", pipe->id);
78
79 for (i = 0; i < ARRAY_SIZE(registers); ++i)
80 seq_printf(m, "%20s[0x%02x]: 0x%08x\n",
81 registers[i].name, registers[i].offset,
82 mxc_isi_read(pipe, registers[i].offset));
83
84 pm_runtime_put(pipe->isi->dev);
85
86 return 0;
87 }
88 DEFINE_SHOW_ATTRIBUTE(mxc_isi_debug_dump_regs);
89
mxc_isi_debug_init(struct mxc_isi_dev * isi)90 void mxc_isi_debug_init(struct mxc_isi_dev *isi)
91 {
92 unsigned int i;
93
94 isi->debugfs_root = debugfs_create_dir(dev_name(isi->dev), NULL);
95
96 for (i = 0; i < isi->pdata->num_channels; ++i) {
97 struct mxc_isi_pipe *pipe = &isi->pipes[i];
98 char name[8];
99
100 sprintf(name, "pipe%u", pipe->id);
101 debugfs_create_file(name, 0444, isi->debugfs_root, pipe,
102 &mxc_isi_debug_dump_regs_fops);
103 }
104 }
105
mxc_isi_debug_cleanup(struct mxc_isi_dev * isi)106 void mxc_isi_debug_cleanup(struct mxc_isi_dev *isi)
107 {
108 debugfs_remove_recursive(isi->debugfs_root);
109 }
110