blob: a073cdce1f156fd3a1cfc1acc73992b38e87a257 [file] [log] [blame]
Bruno Randolf40ca22e2010-05-19 10:31:32 +09001#include <linux/device.h>
2#include <linux/pci.h>
3
4#include "base.h"
5#include "ath5k.h"
6#include "reg.h"
7
8#define SIMPLE_SHOW_STORE(name, get, set) \
9static ssize_t ath5k_attr_show_##name(struct device *dev, \
10 struct device_attribute *attr, \
11 char *buf) \
12{ \
Pavel Roskin95acbd42011-06-29 15:39:37 -040013 struct ieee80211_hw *hw = dev_get_drvdata(dev); \
14 struct ath5k_softc *sc = hw->priv; \
Bruno Randolf40ca22e2010-05-19 10:31:32 +090015 return snprintf(buf, PAGE_SIZE, "%d\n", get); \
16} \
17 \
18static ssize_t ath5k_attr_store_##name(struct device *dev, \
19 struct device_attribute *attr, \
20 const char *buf, size_t count) \
21{ \
Pavel Roskin95acbd42011-06-29 15:39:37 -040022 struct ieee80211_hw *hw = dev_get_drvdata(dev); \
23 struct ath5k_softc *sc = hw->priv; \
Bruno Randolf40ca22e2010-05-19 10:31:32 +090024 int val; \
25 \
26 val = (int)simple_strtoul(buf, NULL, 10); \
27 set(sc->ah, val); \
28 return count; \
29} \
30static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, \
31 ath5k_attr_show_##name, ath5k_attr_store_##name)
32
33#define SIMPLE_SHOW(name, get) \
34static ssize_t ath5k_attr_show_##name(struct device *dev, \
35 struct device_attribute *attr, \
36 char *buf) \
37{ \
Pavel Roskin95acbd42011-06-29 15:39:37 -040038 struct ieee80211_hw *hw = dev_get_drvdata(dev); \
39 struct ath5k_softc *sc = hw->priv; \
Bruno Randolf40ca22e2010-05-19 10:31:32 +090040 return snprintf(buf, PAGE_SIZE, "%d\n", get); \
41} \
42static DEVICE_ATTR(name, S_IRUGO, ath5k_attr_show_##name, NULL)
43
44/*** ANI ***/
45
46SIMPLE_SHOW_STORE(ani_mode, sc->ani_state.ani_mode, ath5k_ani_init);
47SIMPLE_SHOW_STORE(noise_immunity_level, sc->ani_state.noise_imm_level,
48 ath5k_ani_set_noise_immunity_level);
49SIMPLE_SHOW_STORE(spur_level, sc->ani_state.spur_level,
50 ath5k_ani_set_spur_immunity_level);
51SIMPLE_SHOW_STORE(firstep_level, sc->ani_state.firstep_level,
52 ath5k_ani_set_firstep_level);
53SIMPLE_SHOW_STORE(ofdm_weak_signal_detection, sc->ani_state.ofdm_weak_sig,
54 ath5k_ani_set_ofdm_weak_signal_detection);
55SIMPLE_SHOW_STORE(cck_weak_signal_detection, sc->ani_state.cck_weak_sig,
56 ath5k_ani_set_cck_weak_signal_detection);
57SIMPLE_SHOW(spur_level_max, sc->ani_state.max_spur_level);
58
59static ssize_t ath5k_attr_show_noise_immunity_level_max(struct device *dev,
60 struct device_attribute *attr,
61 char *buf)
62{
63 return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_NOISE_IMM_LVL);
64}
65static DEVICE_ATTR(noise_immunity_level_max, S_IRUGO,
66 ath5k_attr_show_noise_immunity_level_max, NULL);
67
68static ssize_t ath5k_attr_show_firstep_level_max(struct device *dev,
69 struct device_attribute *attr,
70 char *buf)
71{
72 return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_FIRSTEP_LVL);
73}
74static DEVICE_ATTR(firstep_level_max, S_IRUGO,
75 ath5k_attr_show_firstep_level_max, NULL);
76
77static struct attribute *ath5k_sysfs_entries_ani[] = {
78 &dev_attr_ani_mode.attr,
79 &dev_attr_noise_immunity_level.attr,
80 &dev_attr_spur_level.attr,
81 &dev_attr_firstep_level.attr,
82 &dev_attr_ofdm_weak_signal_detection.attr,
83 &dev_attr_cck_weak_signal_detection.attr,
84 &dev_attr_noise_immunity_level_max.attr,
85 &dev_attr_spur_level_max.attr,
86 &dev_attr_firstep_level_max.attr,
87 NULL
88};
89
90static struct attribute_group ath5k_attribute_group_ani = {
91 .name = "ani",
92 .attrs = ath5k_sysfs_entries_ani,
93};
94
95
96/*** register / unregister ***/
97
98int
99ath5k_sysfs_register(struct ath5k_softc *sc)
100{
Felix Fietkau8efa5d72010-12-02 10:27:06 +0100101 struct device *dev = sc->dev;
Bruno Randolf40ca22e2010-05-19 10:31:32 +0900102 int err;
103
104 err = sysfs_create_group(&dev->kobj, &ath5k_attribute_group_ani);
105 if (err) {
106 ATH5K_ERR(sc, "failed to create sysfs group\n");
107 return err;
108 }
109
110 return 0;
111}
112
113void
114ath5k_sysfs_unregister(struct ath5k_softc *sc)
115{
Felix Fietkau8efa5d72010-12-02 10:27:06 +0100116 struct device *dev = sc->dev;
Bruno Randolf40ca22e2010-05-19 10:31:32 +0900117
118 sysfs_remove_group(&dev->kobj, &ath5k_attribute_group_ani);
119}