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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *
17 */
18
19 #include <linux/device.h>
20 #include <linux/err.h>
21 #include <linux/kernel.h>
22
23 #include "atomisp_compat.h"
24 #include "atomisp_internal.h"
25 #include "atomisp_ioctl.h"
26 #include "atomisp_drvfs.h"
27 #include "hmm/hmm.h"
28 #include "ia_css_debug.h"
29
30 #define OPTION_BIN_LIST BIT(0)
31 #define OPTION_BIN_RUN BIT(1)
32 #define OPTION_VALID (OPTION_BIN_LIST | OPTION_BIN_RUN)
33
34 /*
35 * dbgopt: iunit debug option:
36 * bit 0: binary list
37 * bit 1: running binary
38 * bit 2: memory statistic
39 */
40 static unsigned int dbgopt = OPTION_BIN_LIST;
41
iunit_dump_dbgopt(struct atomisp_device * isp,unsigned int opt)42 static inline int iunit_dump_dbgopt(struct atomisp_device *isp,
43 unsigned int opt)
44 {
45 int ret = 0;
46
47 if (opt & OPTION_VALID) {
48 if (opt & OPTION_BIN_LIST) {
49 ret = atomisp_css_dump_blob_infor(isp);
50 if (ret) {
51 dev_err(isp->dev, "%s dump blob infor err[ret:%d]\n",
52 __func__, ret);
53 goto opt_err;
54 }
55 }
56
57 if (opt & OPTION_BIN_RUN) {
58 if (isp->asd.streaming) {
59 atomisp_css_dump_sp_raw_copy_linecount(true);
60 atomisp_css_debug_dump_isp_binary();
61 } else {
62 ret = -EPERM;
63 dev_err(isp->dev, "%s dump running bin err[ret:%d]\n",
64 __func__, ret);
65 goto opt_err;
66 }
67 }
68 } else {
69 ret = -EINVAL;
70 dev_err(isp->dev, "%s dump nothing[ret=%d]\n", __func__, ret);
71 }
72
73 opt_err:
74 return ret;
75 }
76
dbglvl_show(struct device * dev,struct device_attribute * attr,char * buf)77 static ssize_t dbglvl_show(struct device *dev, struct device_attribute *attr,
78 char *buf)
79 {
80 unsigned int dbglvl = ia_css_debug_get_dtrace_level();
81
82 return sysfs_emit(buf, "dtrace level:%u\n", dbglvl);
83 }
84
dbglvl_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t size)85 static ssize_t dbglvl_store(struct device *dev, struct device_attribute *attr,
86 const char *buf, size_t size)
87 {
88 unsigned int dbglvl;
89 int ret;
90
91 ret = kstrtouint(buf, 10, &dbglvl);
92 if (ret)
93 return ret;
94
95 if (dbglvl < 1 || dbglvl > 9)
96 return -ERANGE;
97
98 ia_css_debug_set_dtrace_level(dbglvl);
99 return size;
100 }
101 static DEVICE_ATTR_RW(dbglvl);
102
dbgfun_show(struct device * dev,struct device_attribute * attr,char * buf)103 static ssize_t dbgfun_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
105 {
106 unsigned int dbgfun = atomisp_get_css_dbgfunc();
107
108 return sysfs_emit(buf, "dbgfun opt:%u\n", dbgfun);
109 }
110
dbgfun_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t size)111 static ssize_t dbgfun_store(struct device *dev, struct device_attribute *attr,
112 const char *buf, size_t size)
113 {
114 struct atomisp_device *isp = dev_get_drvdata(dev);
115 unsigned int opt;
116 int ret;
117
118 ret = kstrtouint(buf, 10, &opt);
119 if (ret)
120 return ret;
121
122 return atomisp_set_css_dbgfunc(isp, opt);
123 }
124 static DEVICE_ATTR_RW(dbgfun);
125
dbgopt_show(struct device * dev,struct device_attribute * attr,char * buf)126 static ssize_t dbgopt_show(struct device *dev, struct device_attribute *attr,
127 char *buf)
128 {
129 return sysfs_emit(buf, "option:0x%x\n", dbgopt);
130 }
131
dbgopt_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t size)132 static ssize_t dbgopt_store(struct device *dev, struct device_attribute *attr,
133 const char *buf, size_t size)
134 {
135 struct atomisp_device *isp = dev_get_drvdata(dev);
136 unsigned int opt;
137 int ret;
138
139 ret = kstrtouint(buf, 10, &opt);
140 if (ret)
141 return ret;
142
143 dbgopt = opt;
144 ret = iunit_dump_dbgopt(isp, dbgopt);
145 if (ret)
146 return ret;
147
148 return size;
149 }
150 static DEVICE_ATTR_RW(dbgopt);
151
152 static struct attribute *dbg_attrs[] = {
153 &dev_attr_dbglvl.attr,
154 &dev_attr_dbgfun.attr,
155 &dev_attr_dbgopt.attr,
156 NULL
157 };
158
159 static const struct attribute_group dbg_attr_group = {
160 .attrs = dbg_attrs,
161 };
162
163 const struct attribute_group *dbg_attr_groups[] = {
164 &dbg_attr_group,
165 NULL
166 };
167