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