1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Support for atomisp driver sysfs interface
4 *
5 * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
6 */
7
8 #include <linux/device.h>
9 #include <linux/err.h>
10 #include <linux/kernel.h>
11
12 #include "atomisp_compat.h"
13 #include "atomisp_internal.h"
14 #include "atomisp_ioctl.h"
15 #include "atomisp_drvfs.h"
16 #include "hmm/hmm.h"
17 #include "ia_css_debug.h"
18
19 #define OPTION_BIN_LIST BIT(0)
20 #define OPTION_BIN_RUN BIT(1)
21 #define OPTION_VALID (OPTION_BIN_LIST | OPTION_BIN_RUN)
22
23 /*
24 * dbgopt: iunit debug option:
25 * bit 0: binary list
26 * bit 1: running binary
27 * bit 2: memory statistic
28 */
29 static unsigned int dbgopt = OPTION_BIN_LIST;
30
iunit_dump_dbgopt(struct atomisp_device * isp,unsigned int opt)31 static inline int iunit_dump_dbgopt(struct atomisp_device *isp,
32 unsigned int opt)
33 {
34 int ret = 0;
35
36 if (opt & OPTION_VALID) {
37 if (opt & OPTION_BIN_LIST) {
38 ret = atomisp_css_dump_blob_infor(isp);
39 if (ret) {
40 dev_err(isp->dev, "%s dump blob infor err[ret:%d]\n",
41 __func__, ret);
42 goto opt_err;
43 }
44 }
45
46 if (opt & OPTION_BIN_RUN) {
47 if (isp->asd.streaming) {
48 atomisp_css_dump_sp_raw_copy_linecount(true);
49 atomisp_css_debug_dump_isp_binary();
50 } else {
51 ret = -EPERM;
52 dev_err(isp->dev, "%s dump running bin err[ret:%d]\n",
53 __func__, ret);
54 goto opt_err;
55 }
56 }
57 } else {
58 ret = -EINVAL;
59 dev_err(isp->dev, "%s dump nothing[ret=%d]\n", __func__, ret);
60 }
61
62 opt_err:
63 return ret;
64 }
65
dbglvl_show(struct device * dev,struct device_attribute * attr,char * buf)66 static ssize_t dbglvl_show(struct device *dev, struct device_attribute *attr,
67 char *buf)
68 {
69 unsigned int dbglvl = ia_css_debug_get_dtrace_level();
70
71 return sysfs_emit(buf, "dtrace level:%u\n", dbglvl);
72 }
73
dbglvl_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t size)74 static ssize_t dbglvl_store(struct device *dev, struct device_attribute *attr,
75 const char *buf, size_t size)
76 {
77 unsigned int dbglvl;
78 int ret;
79
80 ret = kstrtouint(buf, 10, &dbglvl);
81 if (ret)
82 return ret;
83
84 if (dbglvl < 1 || dbglvl > 9)
85 return -ERANGE;
86
87 ia_css_debug_set_dtrace_level(dbglvl);
88 return size;
89 }
90 static DEVICE_ATTR_RW(dbglvl);
91
dbgfun_show(struct device * dev,struct device_attribute * attr,char * buf)92 static ssize_t dbgfun_show(struct device *dev, struct device_attribute *attr,
93 char *buf)
94 {
95 unsigned int dbgfun = atomisp_get_css_dbgfunc();
96
97 return sysfs_emit(buf, "dbgfun opt:%u\n", dbgfun);
98 }
99
dbgfun_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t size)100 static ssize_t dbgfun_store(struct device *dev, struct device_attribute *attr,
101 const char *buf, size_t size)
102 {
103 struct atomisp_device *isp = dev_get_drvdata(dev);
104 unsigned int opt;
105 int ret;
106
107 ret = kstrtouint(buf, 10, &opt);
108 if (ret)
109 return ret;
110
111 return atomisp_set_css_dbgfunc(isp, opt);
112 }
113 static DEVICE_ATTR_RW(dbgfun);
114
dbgopt_show(struct device * dev,struct device_attribute * attr,char * buf)115 static ssize_t dbgopt_show(struct device *dev, struct device_attribute *attr,
116 char *buf)
117 {
118 return sysfs_emit(buf, "option:0x%x\n", dbgopt);
119 }
120
dbgopt_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t size)121 static ssize_t dbgopt_store(struct device *dev, struct device_attribute *attr,
122 const char *buf, size_t size)
123 {
124 struct atomisp_device *isp = dev_get_drvdata(dev);
125 unsigned int opt;
126 int ret;
127
128 ret = kstrtouint(buf, 10, &opt);
129 if (ret)
130 return ret;
131
132 dbgopt = opt;
133 ret = iunit_dump_dbgopt(isp, dbgopt);
134 if (ret)
135 return ret;
136
137 return size;
138 }
139 static DEVICE_ATTR_RW(dbgopt);
140
141 static struct attribute *dbg_attrs[] = {
142 &dev_attr_dbglvl.attr,
143 &dev_attr_dbgfun.attr,
144 &dev_attr_dbgopt.attr,
145 NULL
146 };
147
148 static const struct attribute_group dbg_attr_group = {
149 .attrs = dbg_attrs,
150 };
151
152 const struct attribute_group *dbg_attr_groups[] = {
153 &dbg_attr_group,
154 NULL
155 };
156