msm: camera: common: create a common root folder for debugfs

Create common root folder under debugfs root named camera at probe. Add
utility functions to create subdirectories under the common camera root.

CRs-Fixed: 3093049
Change-Id: Ia4cefb5d2263ecabf1b9d70deefa1ee624b04f07
Signed-off-by: Anand Ravi <quic_ananravi@quicinc.com>
此提交包含在:
Anand Ravi
2021-12-13 14:49:13 -08:00
父節點 d123d73bc2
當前提交 cbe499e9eb
共有 20 個檔案被更改,包括 288 行新增205 行删除

查看文件

@@ -1,11 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2017-2021, The Linux Foundataion. All rights reserved.
* Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
*/
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/debugfs.h>
#include "cam_trace.h"
#include "cam_debug_util.h"
@@ -22,6 +23,85 @@ module_param(debug_priority, uint, 0644);
struct camera_debug_settings cam_debug;
struct dentry *cam_debugfs_root;
void cam_debugfs_init(void)
{
struct dentry *tmp;
if (!cam_debugfs_available()) {
cam_debugfs_root = NULL;
CAM_DBG(CAM_UTIL, "debugfs not available");
return;
}
if (cam_debugfs_root) {
CAM_WARN(CAM_UTIL, "already created debugfs root");
return;
}
tmp = debugfs_create_dir("camera", NULL);
if (IS_ERR_VALUE(tmp)) {
CAM_ERR(CAM_UTIL, "failed to create debugfs root folder (rc=%d)", PTR_ERR(tmp));
return;
}
cam_debugfs_root = tmp;
CAM_DBG(CAM_UTIL, "successfully created debugfs root");
}
void cam_debugfs_deinit(void)
{
if (!cam_debugfs_available())
return;
debugfs_remove_recursive(cam_debugfs_root);
cam_debugfs_root = NULL;
}
int cam_debugfs_create_subdir(const char *name, struct dentry **subdir)
{
struct dentry *tmp;
if (!cam_debugfs_root) {
CAM_WARN(CAM_UTIL, "debugfs root not created");
*subdir = NULL;
return -ENODEV;
}
if (!subdir) {
CAM_ERR(CAM_UTIL, "invalid subdir pointer %pK", subdir);
return -EINVAL;
}
tmp = debugfs_create_dir(name, cam_debugfs_root);
if (IS_ERR_VALUE(tmp)) {
CAM_ERR(CAM_UTIL, "failed to create debugfs subdir (name=%s, rc=%d)", name,
PTR_ERR(tmp));
return PTR_ERR(tmp);
}
*subdir = tmp;
return 0;
}
int cam_debugfs_lookup_subdir(const char *name, struct dentry **subdir)
{
if (!cam_debugfs_root) {
CAM_WARN(CAM_UTIL, "debugfs root not created");
*subdir = NULL;
return -ENODEV;
}
if (!subdir) {
CAM_ERR(CAM_UTIL, "invalid subdir pointer %pK", subdir);
return -EINVAL;
}
*subdir = debugfs_lookup(name, cam_debugfs_root);
return (*subdir) ? 0 : -ENOENT;
}
const struct camera_debug_settings *cam_debug_get_settings()
{
return &cam_debug;

查看文件

@@ -360,4 +360,59 @@ const struct camera_debug_settings *cam_debug_get_settings(void);
ssize_t cam_debug_sysfs_node_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count);
/**
* cam_debugfs_init()
*
* @brief: create camera debugfs root folder
*/
void cam_debugfs_init(void);
/**
* cam_debugfs_deinit()
*
* @brief: remove camera debugfs root folder
*/
void cam_debugfs_deinit(void);
/**
* cam_debugfs_create_subdir()
*
* @brief: create a directory within the camera debugfs root folder
*
* @name: name of the directory
* @subdir: pointer to the newly created directory entry
*
* @return: 0 on success, negative on failure
*/
int cam_debugfs_create_subdir(const char *name, struct dentry **subdir);
/**
* cam_debugfs_lookup_subdir()
*
* @brief: lookup a directory within the camera debugfs root folder
*
* @name: name of the directory
* @subdir: pointer to the successfully found directory entry
*
* @return: 0 on success, negative on failure
*/
int cam_debugfs_lookup_subdir(const char *name, struct dentry **subdir);
/**
* cam_debugfs_available()
*
* @brief: Check if debugfs is enabled for camera. Use this function before creating any
* debugfs entries.
*
* @return: true if enabled, false otherwise
*/
static inline bool cam_debugfs_available(void)
{
#if defined(CONFIG_DEBUG_FS)
return true;
#else
return false;
#endif
}
#endif /* _CAM_DEBUG_UTIL_H_ */

查看文件

@@ -22,6 +22,8 @@
#define CAM_SS_START_PRESIL 0x08c00000
#define CAM_SS_START 0x0ac00000
#define CAM_CLK_DIRNAME "clk"
static uint skip_mmrm_set_rate;
module_param(skip_mmrm_set_rate, uint, 0644);
@@ -684,23 +686,32 @@ DEFINE_SIMPLE_ATTRIBUTE(cam_soc_util_clk_lvl_control,
*/
static int cam_soc_util_create_clk_lvl_debugfs(struct cam_hw_soc_info *soc_info)
{
char debugfs_dir_name[64];
int rc = 0;
struct dentry *dbgfileptr = NULL;
struct dentry *dbgfileptr = NULL, *clkdirptr = NULL;
if (!cam_debugfs_available())
return 0;
if (soc_info->dentry) {
CAM_DBG(CAM_UTIL, "Debugfs entry for %s already exist",
CAM_DBG(CAM_UTIL, "Debugfs entry for %s already exists",
soc_info->dev_name);
goto end;
}
memset(debugfs_dir_name, 0, sizeof(debugfs_dir_name));
strlcat(debugfs_dir_name, "clk_dir_", sizeof(debugfs_dir_name));
strlcat(debugfs_dir_name, soc_info->dev_name, sizeof(debugfs_dir_name));
rc = cam_debugfs_lookup_subdir(CAM_CLK_DIRNAME, &clkdirptr);
if (rc) {
rc = cam_debugfs_create_subdir(CAM_CLK_DIRNAME, &clkdirptr);
if (rc) {
CAM_ERR(CAM_UTIL, "DebugFS could not create clk directory!");
rc = -ENOENT;
goto end;
}
}
dbgfileptr = debugfs_create_dir(debugfs_dir_name, NULL);
if (!dbgfileptr) {
CAM_ERR(CAM_UTIL,"DebugFS could not create directory!");
dbgfileptr = debugfs_create_dir(soc_info->dev_name, clkdirptr);
if (IS_ERR_OR_NULL(dbgfileptr)) {
CAM_ERR(CAM_UTIL, "DebugFS could not create directory for dev:%s!",
soc_info->dev_name);
rc = -ENOENT;
goto end;
}
@@ -711,32 +722,11 @@ static int cam_soc_util_create_clk_lvl_debugfs(struct cam_hw_soc_info *soc_info)
soc_info->dentry, soc_info, &cam_soc_util_clk_lvl_options);
dbgfileptr = debugfs_create_file("clk_lvl_control", 0644,
soc_info->dentry, soc_info, &cam_soc_util_clk_lvl_control);
if (IS_ERR(dbgfileptr)) {
if (PTR_ERR(dbgfileptr) == -ENODEV)
CAM_WARN(CAM_UTIL, "DebugFS not enabled in kernel!");
else
rc = PTR_ERR(dbgfileptr);
}
rc = PTR_ERR_OR_ZERO(dbgfileptr);
end:
return rc;
}
/**
* cam_soc_util_remove_clk_lvl_debugfs()
*
* @brief: Removes the debugfs files used to view/control
* device clk rates
*
* @soc_info: Device soc information
*
*/
static void cam_soc_util_remove_clk_lvl_debugfs(
struct cam_hw_soc_info *soc_info)
{
debugfs_remove_recursive(soc_info->dentry);
soc_info->dentry = NULL;
}
int cam_soc_util_get_level_from_string(const char *string,
enum cam_vote_level *level)
{
@@ -2836,8 +2826,7 @@ int cam_soc_util_release_platform_resource(struct cam_hw_soc_info *soc_info)
/* release for gpio */
cam_soc_util_request_gpio_table(soc_info, false);
if (soc_info->clk_control_enable)
cam_soc_util_remove_clk_lvl_debugfs(soc_info);
soc_info->dentry = NULL;
return 0;
}