wlcore: add a debugfs entry to allow changing the sleep mode by hand
[cascardo/linux.git] / drivers / net / wireless / ti / wlcore / debugfs.c
index 50300ff..91e43de 100644 (file)
@@ -177,6 +177,14 @@ static inline void no_write_handler(struct wl1271 *wl,
                .open = simple_open,                                    \
                .llseek = default_llseek,                               \
        };
+
+WL12XX_CONF_DEBUGFS(irq_pkt_threshold, rx, 0, 65535,
+                   chip_op_handler, wl1271_acx_init_rx_interrupt)
+WL12XX_CONF_DEBUGFS(irq_blk_threshold, rx, 0, 65535,
+                   chip_op_handler, wl1271_acx_init_rx_interrupt)
+WL12XX_CONF_DEBUGFS(irq_timeout, rx, 0, 100,
+                   chip_op_handler, wl1271_acx_init_rx_interrupt)
+
 static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
                          size_t count, loff_t *ppos)
 {
@@ -936,6 +944,82 @@ static const struct file_operations beacon_filtering_ops = {
        .llseek = default_llseek,
 };
 
+static ssize_t fw_stats_raw_read(struct file *file,
+                                char __user *userbuf,
+                                size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+
+       wl1271_debugfs_update_stats(wl);
+
+       return simple_read_from_buffer(userbuf, count, ppos,
+                                      wl->stats.fw_stats,
+                                      wl->stats.fw_stats_len);
+}
+
+static const struct file_operations fw_stats_raw_ops = {
+       .read = fw_stats_raw_read,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t sleep_auth_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->sleep_auth);
+}
+
+static ssize_t sleep_auth_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, 0, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value in sleep_auth");
+               return -EINVAL;
+       }
+
+       if (value < 0 || value > WL1271_PSM_MAX) {
+               wl1271_warning("sleep_auth must be between 0 and %d",
+                              WL1271_PSM_MAX);
+               return -ERANGE;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_acx_sleep_auth(wl, value);
+       if (ret < 0)
+               goto out_sleep;
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations sleep_auth_ops = {
+       .read = sleep_auth_read,
+       .write = sleep_auth_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
 static int wl1271_debugfs_add_files(struct wl1271 *wl,
                                    struct dentry *rootdir)
 {
@@ -957,6 +1041,11 @@ static int wl1271_debugfs_add_files(struct wl1271 *wl,
        DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
        DEBUGFS_ADD(forced_ps, rootdir);
        DEBUGFS_ADD(split_scan_timeout, rootdir);
+       DEBUGFS_ADD(irq_pkt_threshold, rootdir);
+       DEBUGFS_ADD(irq_blk_threshold, rootdir);
+       DEBUGFS_ADD(irq_timeout, rootdir);
+       DEBUGFS_ADD(fw_stats_raw, rootdir);
+       DEBUGFS_ADD(sleep_auth, rootdir);
 
        streaming = debugfs_create_dir("rx_streaming", rootdir);
        if (!streaming || IS_ERR(streaming))