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