Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * iwmc3200top - Intel Wireless MultiCom 3200 Top Driver |
| 3 | * drivers/misc/iwmc3200top/debufs.c |
| 4 | * |
| 5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 6 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 | * 02110-1301, USA. |
| 20 | * |
| 21 | * |
| 22 | * Author Name: Maxim Grabarnik <maxim.grabarnink@intel.com> |
| 23 | * - |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 29 | #include <linux/string.h> |
| 30 | #include <linux/ctype.h> |
| 31 | #include <linux/mmc/sdio_func.h> |
| 32 | #include <linux/mmc/sdio.h> |
| 33 | #include <linux/debugfs.h> |
| 34 | |
| 35 | #include "iwmc3200top.h" |
| 36 | #include "fw-msg.h" |
| 37 | #include "log.h" |
| 38 | #include "debugfs.h" |
| 39 | |
| 40 | |
| 41 | |
| 42 | /* Constants definition */ |
| 43 | #define HEXADECIMAL_RADIX 16 |
| 44 | |
| 45 | /* Functions definition */ |
| 46 | |
| 47 | |
| 48 | #define DEBUGFS_ADD(name, parent) do { \ |
| 49 | dbgfs->dbgfs_##parent##_files.file_##name = \ |
| 50 | debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \ |
| 51 | &iwmct_dbgfs_##name##_ops); \ |
| 52 | } while (0) |
| 53 | |
| 54 | #define DEBUGFS_RM(name) do { \ |
| 55 | debugfs_remove(name); \ |
| 56 | name = NULL; \ |
| 57 | } while (0) |
| 58 | |
| 59 | #define DEBUGFS_READ_FUNC(name) \ |
| 60 | ssize_t iwmct_dbgfs_##name##_read(struct file *file, \ |
| 61 | char __user *user_buf, \ |
| 62 | size_t count, loff_t *ppos); |
| 63 | |
| 64 | #define DEBUGFS_WRITE_FUNC(name) \ |
| 65 | ssize_t iwmct_dbgfs_##name##_write(struct file *file, \ |
| 66 | const char __user *user_buf, \ |
| 67 | size_t count, loff_t *ppos); |
| 68 | |
| 69 | #define DEBUGFS_READ_FILE_OPS(name) \ |
| 70 | DEBUGFS_READ_FUNC(name) \ |
| 71 | static const struct file_operations iwmct_dbgfs_##name##_ops = { \ |
| 72 | .read = iwmct_dbgfs_##name##_read, \ |
| 73 | .open = iwmct_dbgfs_open_file_generic, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 74 | .llseek = generic_file_llseek, \ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | #define DEBUGFS_WRITE_FILE_OPS(name) \ |
| 78 | DEBUGFS_WRITE_FUNC(name) \ |
| 79 | static const struct file_operations iwmct_dbgfs_##name##_ops = { \ |
| 80 | .write = iwmct_dbgfs_##name##_write, \ |
| 81 | .open = iwmct_dbgfs_open_file_generic, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 82 | .llseek = generic_file_llseek, \ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #define DEBUGFS_READ_WRITE_FILE_OPS(name) \ |
| 86 | DEBUGFS_READ_FUNC(name) \ |
| 87 | DEBUGFS_WRITE_FUNC(name) \ |
| 88 | static const struct file_operations iwmct_dbgfs_##name##_ops = {\ |
| 89 | .write = iwmct_dbgfs_##name##_write, \ |
| 90 | .read = iwmct_dbgfs_##name##_read, \ |
| 91 | .open = iwmct_dbgfs_open_file_generic, \ |
Arnd Bergmann | 2b18ab36 | 2010-07-06 19:05:31 +0200 | [diff] [blame] | 92 | .llseek = generic_file_llseek, \ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | |
| 96 | /* Debugfs file ops definitions */ |
| 97 | |
| 98 | /* |
| 99 | * Create the debugfs files and directories |
| 100 | * |
| 101 | */ |
| 102 | void iwmct_dbgfs_register(struct iwmct_priv *priv, const char *name) |
| 103 | { |
| 104 | struct iwmct_debugfs *dbgfs; |
| 105 | |
| 106 | dbgfs = kzalloc(sizeof(struct iwmct_debugfs), GFP_KERNEL); |
| 107 | if (!dbgfs) { |
| 108 | LOG_ERROR(priv, DEBUGFS, "failed to allocate %zd bytes\n", |
| 109 | sizeof(struct iwmct_debugfs)); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | priv->dbgfs = dbgfs; |
| 114 | dbgfs->name = name; |
| 115 | dbgfs->dir_drv = debugfs_create_dir(name, NULL); |
| 116 | if (!dbgfs->dir_drv) { |
| 117 | LOG_ERROR(priv, DEBUGFS, "failed to create debugfs dir\n"); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Remove the debugfs files and directories |
| 126 | * |
| 127 | */ |
| 128 | void iwmct_dbgfs_unregister(struct iwmct_debugfs *dbgfs) |
| 129 | { |
| 130 | if (!dbgfs) |
| 131 | return; |
| 132 | |
| 133 | DEBUGFS_RM(dbgfs->dir_drv); |
| 134 | kfree(dbgfs); |
| 135 | dbgfs = NULL; |
| 136 | } |
| 137 | |