sysfs.c 3.3 KB

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