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