sysfs.c 3.5 KB

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