Path: blob/master/drivers/misc/iwmc3200top/debugfs.c
15111 views
/*1* iwmc3200top - Intel Wireless MultiCom 3200 Top Driver2* drivers/misc/iwmc3200top/debufs.c3*4* Copyright (C) 2009 Intel Corporation. All rights reserved.5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public License version8* 2 as published by the Free Software Foundation.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA18* 02110-1301, USA.19*20*21* Author Name: Maxim Grabarnik <[email protected]>22* -23*24*/2526#include <linux/kernel.h>27#include <linux/slab.h>28#include <linux/string.h>29#include <linux/ctype.h>30#include <linux/mmc/sdio_func.h>31#include <linux/mmc/sdio.h>32#include <linux/debugfs.h>3334#include "iwmc3200top.h"35#include "fw-msg.h"36#include "log.h"37#include "debugfs.h"38394041/* Constants definition */42#define HEXADECIMAL_RADIX 164344/* Functions definition */454647#define DEBUGFS_ADD(name, parent) do { \48dbgfs->dbgfs_##parent##_files.file_##name = \49debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \50&iwmct_dbgfs_##name##_ops); \51} while (0)5253#define DEBUGFS_RM(name) do { \54debugfs_remove(name); \55name = NULL; \56} while (0)5758#define DEBUGFS_READ_FUNC(name) \59ssize_t iwmct_dbgfs_##name##_read(struct file *file, \60char __user *user_buf, \61size_t count, loff_t *ppos);6263#define DEBUGFS_WRITE_FUNC(name) \64ssize_t iwmct_dbgfs_##name##_write(struct file *file, \65const char __user *user_buf, \66size_t count, loff_t *ppos);6768#define DEBUGFS_READ_FILE_OPS(name) \69DEBUGFS_READ_FUNC(name) \70static const struct file_operations iwmct_dbgfs_##name##_ops = { \71.read = iwmct_dbgfs_##name##_read, \72.open = iwmct_dbgfs_open_file_generic, \73.llseek = generic_file_llseek, \74};7576#define DEBUGFS_WRITE_FILE_OPS(name) \77DEBUGFS_WRITE_FUNC(name) \78static const struct file_operations iwmct_dbgfs_##name##_ops = { \79.write = iwmct_dbgfs_##name##_write, \80.open = iwmct_dbgfs_open_file_generic, \81.llseek = generic_file_llseek, \82};8384#define DEBUGFS_READ_WRITE_FILE_OPS(name) \85DEBUGFS_READ_FUNC(name) \86DEBUGFS_WRITE_FUNC(name) \87static const struct file_operations iwmct_dbgfs_##name##_ops = {\88.write = iwmct_dbgfs_##name##_write, \89.read = iwmct_dbgfs_##name##_read, \90.open = iwmct_dbgfs_open_file_generic, \91.llseek = generic_file_llseek, \92};939495/* Debugfs file ops definitions */9697/*98* Create the debugfs files and directories99*100*/101void iwmct_dbgfs_register(struct iwmct_priv *priv, const char *name)102{103struct iwmct_debugfs *dbgfs;104105dbgfs = kzalloc(sizeof(struct iwmct_debugfs), GFP_KERNEL);106if (!dbgfs) {107LOG_ERROR(priv, DEBUGFS, "failed to allocate %zd bytes\n",108sizeof(struct iwmct_debugfs));109return;110}111112priv->dbgfs = dbgfs;113dbgfs->name = name;114dbgfs->dir_drv = debugfs_create_dir(name, NULL);115if (!dbgfs->dir_drv) {116LOG_ERROR(priv, DEBUGFS, "failed to create debugfs dir\n");117return;118}119120return;121}122123/**124* Remove the debugfs files and directories125*126*/127void iwmct_dbgfs_unregister(struct iwmct_debugfs *dbgfs)128{129if (!dbgfs)130return;131132DEBUGFS_RM(dbgfs->dir_drv);133kfree(dbgfs);134dbgfs = NULL;135}136137138139