hwmon-sysfs.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * hwmon-sysfs.h - hardware monitoring chip driver sysfs defines
  4. *
  5. * Copyright (C) 2005 Yani Ioannou <yani.ioannou@gmail.com>
  6. */
  7. #ifndef _LINUX_HWMON_SYSFS_H
  8. #define _LINUX_HWMON_SYSFS_H
  9. #include <linux/device.h>
  10. struct sensor_device_attribute{
  11. struct device_attribute dev_attr;
  12. int index;
  13. };
  14. #define to_sensor_dev_attr(_dev_attr) \
  15. container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
  16. #define SENSOR_ATTR(_name, _mode, _show, _store, _index) \
  17. { .dev_attr = __ATTR(_name, _mode, _show, _store), \
  18. .index = _index }
  19. #define SENSOR_ATTR_RO(_name, _func, _index) \
  20. SENSOR_ATTR(_name, 0444, _func##_show, NULL, _index)
  21. #define SENSOR_ATTR_RW(_name, _func, _index) \
  22. SENSOR_ATTR(_name, 0644, _func##_show, _func##_store, _index)
  23. #define SENSOR_ATTR_WO(_name, _func, _index) \
  24. SENSOR_ATTR(_name, 0200, NULL, _func##_store, _index)
  25. #define SENSOR_DEVICE_ATTR(_name, _mode, _show, _store, _index) \
  26. struct sensor_device_attribute sensor_dev_attr_##_name \
  27. = SENSOR_ATTR(_name, _mode, _show, _store, _index)
  28. #define SENSOR_DEVICE_ATTR_RO(_name, _func, _index) \
  29. SENSOR_DEVICE_ATTR(_name, 0444, _func##_show, NULL, _index)
  30. #define SENSOR_DEVICE_ATTR_RW(_name, _func, _index) \
  31. SENSOR_DEVICE_ATTR(_name, 0644, _func##_show, _func##_store, _index)
  32. #define SENSOR_DEVICE_ATTR_WO(_name, _func, _index) \
  33. SENSOR_DEVICE_ATTR(_name, 0200, NULL, _func##_store, _index)
  34. struct sensor_device_attribute_2 {
  35. struct device_attribute dev_attr;
  36. u8 index;
  37. u8 nr;
  38. };
  39. #define to_sensor_dev_attr_2(_dev_attr) \
  40. container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
  41. #define SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index) \
  42. { .dev_attr = __ATTR(_name, _mode, _show, _store), \
  43. .index = _index, \
  44. .nr = _nr }
  45. #define SENSOR_ATTR_2_RO(_name, _func, _nr, _index) \
  46. SENSOR_ATTR_2(_name, 0444, _func##_show, NULL, _nr, _index)
  47. #define SENSOR_ATTR_2_RW(_name, _func, _nr, _index) \
  48. SENSOR_ATTR_2(_name, 0644, _func##_show, _func##_store, _nr, _index)
  49. #define SENSOR_ATTR_2_WO(_name, _func, _nr, _index) \
  50. SENSOR_ATTR_2(_name, 0200, NULL, _func##_store, _nr, _index)
  51. #define SENSOR_DEVICE_ATTR_2(_name,_mode,_show,_store,_nr,_index) \
  52. struct sensor_device_attribute_2 sensor_dev_attr_##_name \
  53. = SENSOR_ATTR_2(_name, _mode, _show, _store, _nr, _index)
  54. #define SENSOR_DEVICE_ATTR_2_RO(_name, _func, _nr, _index) \
  55. SENSOR_DEVICE_ATTR_2(_name, 0444, _func##_show, NULL, \
  56. _nr, _index)
  57. #define SENSOR_DEVICE_ATTR_2_RW(_name, _func, _nr, _index) \
  58. SENSOR_DEVICE_ATTR_2(_name, 0644, _func##_show, _func##_store, \
  59. _nr, _index)
  60. #define SENSOR_DEVICE_ATTR_2_WO(_name, _func, _nr, _index) \
  61. SENSOR_DEVICE_ATTR_2(_name, 0200, NULL, _func##_store, \
  62. _nr, _index)
  63. #endif /* _LINUX_HWMON_SYSFS_H */