sysfs.c 3.5 KB

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