blob: 90757de7bf599e70291af0e226ae29d377b7c67e [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{ \
13 struct ath5k_softc *sc = dev_get_drvdata(dev); \
14 return snprintf(buf, PAGE_SIZE, "%d\n", get); \
15} \
16 \
17static ssize_t ath5k_attr_store_##name(struct device *dev, \
18 struct device_attribute *attr, \
19 const char *buf, size_t count) \
20{ \
21 struct ath5k_softc *sc = dev_get_drvdata(dev); \
22 int val; \
23 \
24 val = (int)simple_strtoul(buf, NULL, 10); \
25 set(sc->ah, val); \
26 return count; \
27} \
28static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, \
29 ath5k_attr_show_##name, ath5k_attr_store_##name)
30
31#define SIMPLE_SHOW(name, get) \
32static ssize_t ath5k_attr_show_##name(struct device *dev, \
33 struct device_attribute *attr, \
34 char *buf) \
35{ \
36 struct ath5k_softc *sc = dev_get_drvdata(dev); \
37 return snprintf(buf, PAGE_SIZE, "%d\n", get); \
38} \
39static DEVICE_ATTR(name, S_IRUGO, ath5k_attr_show_##name, NULL)
40
41/*** ANI ***/
42
43SIMPLE_SHOW_STORE(ani_mode, sc->ani_state.ani_mode, ath5k_ani_init);
44SIMPLE_SHOW_STORE(noise_immunity_level, sc->ani_state.noise_imm_level,
45 ath5k_ani_set_noise_immunity_level);
46SIMPLE_SHOW_STORE(spur_level, sc->ani_state.spur_level,
47 ath5k_ani_set_spur_immunity_level);
48SIMPLE_SHOW_STORE(firstep_level, sc->ani_state.firstep_level,
49 ath5k_ani_set_firstep_level);
50SIMPLE_SHOW_STORE(ofdm_weak_signal_detection, sc->ani_state.ofdm_weak_sig,
51 ath5k_ani_set_ofdm_weak_signal_detection);
52SIMPLE_SHOW_STORE(cck_weak_signal_detection, sc->ani_state.cck_weak_sig,
53 ath5k_ani_set_cck_weak_signal_detection);
54SIMPLE_SHOW(spur_level_max, sc->ani_state.max_spur_level);
55
56static ssize_t ath5k_attr_show_noise_immunity_level_max(struct device *dev,
57 struct device_attribute *attr,
58 char *buf)
59{
60 return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_NOISE_IMM_LVL);
61}
62static DEVICE_ATTR(noise_immunity_level_max, S_IRUGO,
63 ath5k_attr_show_noise_immunity_level_max, NULL);
64
65static ssize_t ath5k_attr_show_firstep_level_max(struct device *dev,
66 struct device_attribute *attr,
67 char *buf)
68{
69 return snprintf(buf, PAGE_SIZE, "%d\n", ATH5K_ANI_MAX_FIRSTEP_LVL);
70}
71static DEVICE_ATTR(firstep_level_max, S_IRUGO,
72 ath5k_attr_show_firstep_level_max, NULL);
73
74static struct attribute *ath5k_sysfs_entries_ani[] = {
75 &dev_attr_ani_mode.attr,
76 &dev_attr_noise_immunity_level.attr,
77 &dev_attr_spur_level.attr,
78 &dev_attr_firstep_level.attr,
79 &dev_attr_ofdm_weak_signal_detection.attr,
80 &dev_attr_cck_weak_signal_detection.attr,
81 &dev_attr_noise_immunity_level_max.attr,
82 &dev_attr_spur_level_max.attr,
83 &dev_attr_firstep_level_max.attr,
84 NULL
85};
86
87static struct attribute_group ath5k_attribute_group_ani = {
88 .name = "ani",
89 .attrs = ath5k_sysfs_entries_ani,
90};
91
92
93/*** register / unregister ***/
94
95int
96ath5k_sysfs_register(struct ath5k_softc *sc)
97{
98 struct device *dev = &sc->pdev->dev;
99 int err;
100
101 err = sysfs_create_group(&dev->kobj, &ath5k_attribute_group_ani);
102 if (err) {
103 ATH5K_ERR(sc, "failed to create sysfs group\n");
104 return err;
105 }
106
107 return 0;
108}
109
110void
111ath5k_sysfs_unregister(struct ath5k_softc *sc)
112{
113 struct device *dev = &sc->pdev->dev;
114
115 sysfs_remove_group(&dev->kobj, &ath5k_attribute_group_ani);
116}