1 // SPDX-License-Identifier: GPL-2.0
3 * Support for atomisp driver sysfs interface
5 * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
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.
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.
19 #include <linux/device.h>
20 #include <linux/err.h>
21 #include <linux/kernel.h>
23 #include "atomisp_compat.h"
24 #include "atomisp_internal.h"
25 #include "atomisp_ioctl.h"
26 #include "atomisp_drvfs.h"
28 #include "ia_css_debug.h"
32 * dbglvl: iunit css driver trace level
33 * dbgopt: iunit debug option:
35 * bit 1: running binary
36 * bit 2: memory statistic
39 struct device_driver *drv;
40 struct atomisp_device *isp;
46 #define OPTION_BIN_LIST BIT(0)
47 #define OPTION_BIN_RUN BIT(1)
48 #define OPTION_MEM_STAT BIT(2)
49 #define OPTION_VALID (OPTION_BIN_LIST \
53 static struct _iunit_debug iunit_debug = {
55 .dbgopt = OPTION_BIN_LIST,
58 static inline int iunit_dump_dbgopt(struct atomisp_device *isp,
63 if (opt & OPTION_VALID) {
64 if (opt & OPTION_BIN_LIST) {
65 ret = atomisp_css_dump_blob_infor(isp);
67 dev_err(isp->dev, "%s dump blob infor err[ret:%d]\n",
73 if (opt & OPTION_BIN_RUN) {
74 if (atomisp_streaming_count(isp)) {
75 atomisp_css_dump_sp_raw_copy_linecount(true);
76 atomisp_css_debug_dump_isp_binary();
79 dev_err(isp->dev, "%s dump running bin err[ret:%d]\n",
85 if (opt & OPTION_MEM_STAT)
86 hmm_show_mem_stat(__func__, __LINE__);
89 dev_err(isp->dev, "%s dump nothing[ret=%d]\n", __func__, ret);
96 static ssize_t iunit_dbglvl_show(struct device_driver *drv, char *buf)
98 iunit_debug.dbglvl = dbg_level;
99 return sysfs_emit(buf, "dtrace level:%u\n", iunit_debug.dbglvl);
102 static ssize_t iunit_dbglvl_store(struct device_driver *drv, const char *buf,
105 if (kstrtouint(buf, 10, &iunit_debug.dbglvl)
106 || iunit_debug.dbglvl < 1
107 || iunit_debug.dbglvl > 9) {
110 ia_css_debug_set_dtrace_level(iunit_debug.dbglvl);
115 static ssize_t iunit_dbgfun_show(struct device_driver *drv, char *buf)
117 iunit_debug.dbgfun = atomisp_get_css_dbgfunc();
118 return sysfs_emit(buf, "dbgfun opt:%u\n", iunit_debug.dbgfun);
121 static ssize_t iunit_dbgfun_store(struct device_driver *drv, const char *buf,
127 ret = kstrtouint(buf, 10, &opt);
131 ret = atomisp_set_css_dbgfunc(iunit_debug.isp, opt);
135 iunit_debug.dbgfun = opt;
140 static ssize_t iunit_dbgopt_show(struct device_driver *drv, char *buf)
142 return sysfs_emit(buf, "option:0x%x\n", iunit_debug.dbgopt);
145 static ssize_t iunit_dbgopt_store(struct device_driver *drv, const char *buf,
151 ret = kstrtouint(buf, 10, &opt);
155 iunit_debug.dbgopt = opt;
156 ret = iunit_dump_dbgopt(iunit_debug.isp, iunit_debug.dbgopt);
163 static const struct driver_attribute iunit_drvfs_attrs[] = {
164 __ATTR(dbglvl, 0644, iunit_dbglvl_show, iunit_dbglvl_store),
165 __ATTR(dbgfun, 0644, iunit_dbgfun_show, iunit_dbgfun_store),
166 __ATTR(dbgopt, 0644, iunit_dbgopt_show, iunit_dbgopt_store),
169 static int iunit_drvfs_create_files(struct device_driver *drv)
173 for (i = 0; i < ARRAY_SIZE(iunit_drvfs_attrs); i++)
174 ret |= driver_create_file(drv, &iunit_drvfs_attrs[i]);
179 static void iunit_drvfs_remove_files(struct device_driver *drv)
183 for (i = 0; i < ARRAY_SIZE(iunit_drvfs_attrs); i++)
184 driver_remove_file(drv, &iunit_drvfs_attrs[i]);
187 int atomisp_drvfs_init(struct atomisp_device *isp)
189 struct device_driver *drv = isp->dev->driver;
192 iunit_debug.isp = isp;
193 iunit_debug.drv = drv;
195 ret = iunit_drvfs_create_files(iunit_debug.drv);
197 dev_err(isp->dev, "drvfs_create_files error: %d\n", ret);
198 iunit_drvfs_remove_files(iunit_debug.drv);
204 void atomisp_drvfs_exit(void)
206 iunit_drvfs_remove_files(iunit_debug.drv);