2 * Support for atomisp driver sysfs interface
4 * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <linux/err.h>
23 #include <linux/kernel.h>
24 #include <linux/pci.h>
26 #include "atomisp_compat.h"
27 #include "atomisp_internal.h"
28 #include "atomisp_ioctl.h"
33 * dbglvl: iunit css driver trace level
34 * dbgopt: iunit debug option:
36 * bit 1: running binary
37 * bit 2: memory statistic
40 struct pci_driver
*drv
;
41 struct atomisp_device
*isp
;
47 #define OPTION_BIN_LIST (1<<0)
48 #define OPTION_BIN_RUN (1<<1)
49 #define OPTION_MEM_STAT (1<<2)
50 #define OPTION_VALID (OPTION_BIN_LIST \
54 static struct _iunit_debug iunit_debug
= {
56 .dbgopt
= OPTION_BIN_LIST
,
59 static inline int iunit_dump_dbgopt(struct atomisp_device
*isp
,
64 if (opt
& OPTION_VALID
) {
65 if (opt
& OPTION_BIN_LIST
) {
66 ret
= atomisp_css_dump_blob_infor();
68 dev_err(atomisp_dev
, "%s dump blob infor err[ret:%d]\n",
74 if (opt
& OPTION_BIN_RUN
) {
75 if (atomisp_streaming_count(isp
)) {
76 atomisp_css_dump_sp_raw_copy_linecount(true);
77 atomisp_css_debug_dump_isp_binary();
80 dev_err(atomisp_dev
, "%s dump running bin err[ret:%d]\n",
86 if (opt
& OPTION_MEM_STAT
)
87 hmm_show_mem_stat(__func__
, __LINE__
);
90 dev_err(atomisp_dev
, "%s dump nothing[ret=%d]\n", __func__
,
98 static ssize_t
iunit_dbglvl_show(struct device_driver
*drv
, char *buf
)
100 iunit_debug
.dbglvl
= atomisp_css_debug_get_dtrace_level();
101 return sprintf(buf
, "dtrace level:%u\n", iunit_debug
.dbglvl
);
104 static ssize_t
iunit_dbglvl_store(struct device_driver
*drv
, const char *buf
,
107 if (kstrtouint(buf
, 10, &iunit_debug
.dbglvl
)
108 || iunit_debug
.dbglvl
< 1
109 || iunit_debug
.dbglvl
> 9) {
112 atomisp_css_debug_set_dtrace_level(iunit_debug
.dbglvl
);
117 static ssize_t
iunit_dbgfun_show(struct device_driver
*drv
, char *buf
)
119 iunit_debug
.dbgfun
= atomisp_get_css_dbgfunc();
120 return sprintf(buf
, "dbgfun opt:%u\n", iunit_debug
.dbgfun
);
123 static ssize_t
iunit_dbgfun_store(struct device_driver
*drv
, const char *buf
,
129 ret
= kstrtouint(buf
, 10, &opt
);
133 ret
= atomisp_set_css_dbgfunc(iunit_debug
.isp
, opt
);
137 iunit_debug
.dbgfun
= opt
;
142 static ssize_t
iunit_dbgopt_show(struct device_driver
*drv
, char *buf
)
144 return sprintf(buf
, "option:0x%x\n", iunit_debug
.dbgopt
);
147 static ssize_t
iunit_dbgopt_store(struct device_driver
*drv
, const char *buf
,
153 ret
= kstrtouint(buf
, 10, &opt
);
157 iunit_debug
.dbgopt
= opt
;
158 ret
= iunit_dump_dbgopt(iunit_debug
.isp
, iunit_debug
.dbgopt
);
165 static const struct driver_attribute iunit_drvfs_attrs
[] = {
166 __ATTR(dbglvl
, 0644, iunit_dbglvl_show
, iunit_dbglvl_store
),
167 __ATTR(dbgfun
, 0644, iunit_dbgfun_show
, iunit_dbgfun_store
),
168 __ATTR(dbgopt
, 0644, iunit_dbgopt_show
, iunit_dbgopt_store
),
171 static int iunit_drvfs_create_files(struct pci_driver
*drv
)
175 for (i
= 0; i
< ARRAY_SIZE(iunit_drvfs_attrs
); i
++)
176 ret
|= driver_create_file(&(drv
->driver
),
177 &iunit_drvfs_attrs
[i
]);
182 static void iunit_drvfs_remove_files(struct pci_driver
*drv
)
186 for (i
= 0; i
< ARRAY_SIZE(iunit_drvfs_attrs
); i
++)
187 driver_remove_file(&(drv
->driver
), &iunit_drvfs_attrs
[i
]);
190 int atomisp_drvfs_init(struct pci_driver
*drv
, struct atomisp_device
*isp
)
194 iunit_debug
.isp
= isp
;
195 iunit_debug
.drv
= drv
;
197 ret
= iunit_drvfs_create_files(iunit_debug
.drv
);
199 dev_err(atomisp_dev
, "drvfs_create_files error: %d\n", ret
);
200 iunit_drvfs_remove_files(drv
);
206 void atomisp_drvfs_exit(void)
208 iunit_drvfs_remove_files(iunit_debug
.drv
);