]> Pileus Git - ~andy/linux/commitdiff
wlcore: add support macros to easily add conf debugfs entries
authorEyal Shapira <eyal@wizery.com>
Thu, 7 Jun 2012 20:39:20 +0000 (23:39 +0300)
committerLuciano Coelho <coelho@ti.com>
Fri, 8 Jun 2012 06:14:07 +0000 (09:14 +0300)
The current debugfs code contains too much code duplication
of bolierplate code. Add some macro magic to avoid this and
enable adding new debugfs entries by using just a few lines.

Signed-off-by: Eyal Shapira <eyal@wizery.com>
Signed-off-by: Luciano Coelho <coelho@ti.com>
drivers/net/wireless/ti/wlcore/debugfs.c

index fcd60636e9d1989b397f3cf3f5c304b9f63aa608..50300ff0acb4b13171d135bc5f8a306971edc2b9 100644 (file)
@@ -102,6 +102,81 @@ static const struct file_operations tx_queue_len_ops = {
        .llseek = default_llseek,
 };
 
+static void chip_op_handler(struct wl1271 *wl, unsigned long value,
+                           void *arg)
+{
+       int ret;
+       int (*chip_op) (struct wl1271 *wl);
+
+       if (!arg) {
+               wl1271_warning("debugfs chip_op_handler with no callback");
+               return;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               return;
+
+       chip_op = arg;
+       chip_op(wl);
+
+       wl1271_ps_elp_sleep(wl);
+}
+
+
+static inline void no_write_handler(struct wl1271 *wl,
+                                   unsigned long value,
+                                   unsigned long param)
+{
+}
+
+#define WL12XX_CONF_DEBUGFS(param, conf_sub_struct,                    \
+                           min_val, max_val, write_handler_locked,     \
+                           write_handler_arg)                          \
+       static ssize_t param##_read(struct file *file,                  \
+                                     char __user *user_buf,            \
+                                     size_t count, loff_t *ppos)       \
+       {                                                               \
+       struct wl1271 *wl = file->private_data;                         \
+       return wl1271_format_buffer(user_buf, count,                    \
+                                   ppos, "%d\n",                       \
+                                   wl->conf.conf_sub_struct.param);    \
+       }                                                               \
+                                                                       \
+       static ssize_t param##_write(struct file *file,                 \
+                                    const char __user *user_buf,       \
+                                    size_t count, loff_t *ppos)        \
+       {                                                               \
+       struct wl1271 *wl = file->private_data;                         \
+       unsigned long value;                                            \
+       int ret;                                                        \
+                                                                       \
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);          \
+       if (ret < 0) {                                                  \
+               wl1271_warning("illegal value for " #param);            \
+               return -EINVAL;                                         \
+       }                                                               \
+                                                                       \
+       if (value < min_val || value > max_val) {                       \
+               wl1271_warning(#param " is not in valid range");        \
+               return -ERANGE;                                         \
+       }                                                               \
+                                                                       \
+       mutex_lock(&wl->mutex);                                         \
+       wl->conf.conf_sub_struct.param = value;                         \
+                                                                       \
+       write_handler_locked(wl, value, write_handler_arg);             \
+                                                                       \
+       mutex_unlock(&wl->mutex);                                       \
+       return count;                                                   \
+       }                                                               \
+                                                                       \
+       static const struct file_operations param##_ops = {             \
+               .read = param##_read,                                   \
+               .write = param##_write,                                 \
+               .open = simple_open,                                    \
+               .llseek = default_llseek,                               \
+       };
 static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
                          size_t count, loff_t *ppos)
 {