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.
18 #include <linux/err.h>
19 #include <linux/kernel.h>
20 #include <linux/pci.h>
22 #include "atomisp_compat.h"
23 #include "atomisp_internal.h"
24 #include "atomisp_ioctl.h"
29 * dbglvl: iunit css driver trace level
30 * dbgopt: iunit debug option:
32 * bit 1: running binary
33 * bit 2: memory statistic
36 struct pci_driver *drv;
37 struct atomisp_device *isp;
43 #define OPTION_BIN_LIST (1<<0)
44 #define OPTION_BIN_RUN (1<<1)
45 #define OPTION_MEM_STAT (1<<2)
46 #define OPTION_VALID (OPTION_BIN_LIST \
50 static struct _iunit_debug iunit_debug = {
52 .dbgopt = OPTION_BIN_LIST,
55 static inline int iunit_dump_dbgopt(struct atomisp_device *isp,
60 if (opt & OPTION_VALID) {
61 if (opt & OPTION_BIN_LIST) {
62 ret = atomisp_css_dump_blob_infor();
64 dev_err(atomisp_dev, "%s dump blob infor err[ret:%d]\n",
70 if (opt & OPTION_BIN_RUN) {
71 if (atomisp_streaming_count(isp)) {
72 atomisp_css_dump_sp_raw_copy_linecount(true);
73 atomisp_css_debug_dump_isp_binary();
76 dev_err(atomisp_dev, "%s dump running bin err[ret:%d]\n",
82 if (opt & OPTION_MEM_STAT)
83 hmm_show_mem_stat(__func__, __LINE__);
86 dev_err(atomisp_dev, "%s dump nothing[ret=%d]\n", __func__,
94 static ssize_t iunit_dbglvl_show(struct device_driver *drv, char *buf)
96 iunit_debug.dbglvl = atomisp_css_debug_get_dtrace_level();
97 return sprintf(buf, "dtrace level:%u\n", iunit_debug.dbglvl);
100 static ssize_t iunit_dbglvl_store(struct device_driver *drv, const char *buf,
103 if (kstrtouint(buf, 10, &iunit_debug.dbglvl)
104 || iunit_debug.dbglvl < 1
105 || iunit_debug.dbglvl > 9) {
108 atomisp_css_debug_set_dtrace_level(iunit_debug.dbglvl);
113 static ssize_t iunit_dbgfun_show(struct device_driver *drv, char *buf)
115 iunit_debug.dbgfun = atomisp_get_css_dbgfunc();
116 return sprintf(buf, "dbgfun opt:%u\n", iunit_debug.dbgfun);
119 static ssize_t iunit_dbgfun_store(struct device_driver *drv, const char *buf,
125 ret = kstrtouint(buf, 10, &opt);
129 ret = atomisp_set_css_dbgfunc(iunit_debug.isp, opt);
133 iunit_debug.dbgfun = opt;
138 static ssize_t iunit_dbgopt_show(struct device_driver *drv, char *buf)
140 return sprintf(buf, "option:0x%x\n", iunit_debug.dbgopt);
143 static ssize_t iunit_dbgopt_store(struct device_driver *drv, const char *buf,
149 ret = kstrtouint(buf, 10, &opt);
153 iunit_debug.dbgopt = opt;
154 ret = iunit_dump_dbgopt(iunit_debug.isp, iunit_debug.dbgopt);
161 static const struct driver_attribute iunit_drvfs_attrs[] = {
162 __ATTR(dbglvl, 0644, iunit_dbglvl_show, iunit_dbglvl_store),
163 __ATTR(dbgfun, 0644, iunit_dbgfun_show, iunit_dbgfun_store),
164 __ATTR(dbgopt, 0644, iunit_dbgopt_show, iunit_dbgopt_store),
167 static int iunit_drvfs_create_files(struct pci_driver *drv)
171 for (i = 0; i < ARRAY_SIZE(iunit_drvfs_attrs); i++)
172 ret |= driver_create_file(&(drv->driver),
173 &iunit_drvfs_attrs[i]);
178 static void iunit_drvfs_remove_files(struct pci_driver *drv)
182 for (i = 0; i < ARRAY_SIZE(iunit_drvfs_attrs); i++)
183 driver_remove_file(&(drv->driver), &iunit_drvfs_attrs[i]);
186 int atomisp_drvfs_init(struct pci_driver *drv, struct atomisp_device *isp)
190 iunit_debug.isp = isp;
191 iunit_debug.drv = drv;
193 ret = iunit_drvfs_create_files(iunit_debug.drv);
195 dev_err(atomisp_dev, "drvfs_create_files error: %d\n", ret);
196 iunit_drvfs_remove_files(drv);
202 void atomisp_drvfs_exit(void)
204 iunit_drvfs_remove_files(iunit_debug.drv);