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