sysfs.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* The industrial I/O core
  3. *
  4. *Copyright (c) 2008 Jonathan Cameron
  5. *
  6. * General attributes
  7. */
  8. #ifndef _INDUSTRIAL_IO_SYSFS_H_
  9. #define _INDUSTRIAL_IO_SYSFS_H_
  10. struct iio_buffer;
  11. struct iio_chan_spec;
  12. /**
  13. * struct iio_dev_attr - iio specific device attribute
  14. * @dev_attr: underlying device attribute
  15. * @address: associated register address
  16. * @l: list head for maintaining list of dynamically created attrs
  17. * @c: specification for the underlying channel
  18. * @buffer: the IIO buffer to which this attribute belongs to (if any)
  19. */
  20. struct iio_dev_attr {
  21. struct device_attribute dev_attr;
  22. u64 address;
  23. struct list_head l;
  24. struct iio_chan_spec const *c;
  25. struct iio_buffer *buffer;
  26. };
  27. #define to_iio_dev_attr(_dev_attr) \
  28. container_of(_dev_attr, struct iio_dev_attr, dev_attr)
  29. ssize_t iio_read_const_attr(struct device *dev,
  30. struct device_attribute *attr,
  31. char *len);
  32. /**
  33. * struct iio_const_attr - constant device specific attribute
  34. * often used for things like available modes
  35. * @string: attribute string
  36. * @dev_attr: underlying device attribute
  37. */
  38. struct iio_const_attr {
  39. const char *string;
  40. struct device_attribute dev_attr;
  41. };
  42. #define to_iio_const_attr(_dev_attr) \
  43. container_of(_dev_attr, struct iio_const_attr, dev_attr)
  44. /* Some attributes will be hard coded (device dependent) and not require an
  45. address, in these cases pass a negative */
  46. #define IIO_ATTR(_name, _mode, _show, _store, _addr) \
  47. { .dev_attr = __ATTR(_name, _mode, _show, _store), \
  48. .address = _addr }
  49. #define IIO_ATTR_RO(_name, _addr) \
  50. { .dev_attr = __ATTR_RO(_name), \
  51. .address = _addr }
  52. #define IIO_ATTR_WO(_name, _addr) \
  53. { .dev_attr = __ATTR_WO(_name), \
  54. .address = _addr }
  55. #define IIO_ATTR_RW(_name, _addr) \
  56. { .dev_attr = __ATTR_RW(_name), \
  57. .address = _addr }
  58. #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
  59. struct iio_dev_attr iio_dev_attr_##_name \
  60. = IIO_ATTR(_name, _mode, _show, _store, _addr)
  61. #define IIO_DEVICE_ATTR_RO(_name, _addr) \
  62. struct iio_dev_attr iio_dev_attr_##_name \
  63. = IIO_ATTR_RO(_name, _addr)
  64. #define IIO_DEVICE_ATTR_WO(_name, _addr) \
  65. struct iio_dev_attr iio_dev_attr_##_name \
  66. = IIO_ATTR_WO(_name, _addr)
  67. #define IIO_DEVICE_ATTR_RW(_name, _addr) \
  68. struct iio_dev_attr iio_dev_attr_##_name \
  69. = IIO_ATTR_RW(_name, _addr)
  70. #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
  71. struct iio_dev_attr iio_dev_attr_##_vname \
  72. = IIO_ATTR(_name, _mode, _show, _store, _addr)
  73. #define IIO_CONST_ATTR(_name, _string) \
  74. struct iio_const_attr iio_const_attr_##_name \
  75. = { .string = _string, \
  76. .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
  77. #define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
  78. struct iio_const_attr iio_const_attr_##_vname \
  79. = { .string = _string, \
  80. .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
  81. /* Generic attributes of onetype or another */
  82. /**
  83. * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
  84. * @_mode: sysfs file mode/permissions
  85. * @_show: output method for the attribute
  86. * @_store: input method for the attribute
  87. **/
  88. #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
  89. IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
  90. /**
  91. * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
  92. * @_show: output method for the attribute
  93. *
  94. * May be mode dependent on some devices
  95. **/
  96. #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
  97. IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
  98. /**
  99. * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
  100. * @_string: frequency string for the attribute
  101. *
  102. * Constant version
  103. **/
  104. #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
  105. IIO_CONST_ATTR(sampling_frequency_available, _string)
  106. /**
  107. * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times
  108. * @_show: output method for the attribute
  109. **/
  110. #define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \
  111. IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0)
  112. /**
  113. * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times
  114. * @_string: frequency string for the attribute
  115. *
  116. * Constant version
  117. **/
  118. #define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \
  119. IIO_CONST_ATTR(integration_time_available, _string)
  120. #define IIO_DEV_ATTR_TEMP_RAW(_show) \
  121. IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
  122. #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
  123. IIO_CONST_ATTR(in_temp_offset, _string)
  124. #define IIO_CONST_ATTR_TEMP_SCALE(_string) \
  125. IIO_CONST_ATTR(in_temp_scale, _string)
  126. #endif /* _INDUSTRIAL_IO_SYSFS_H_ */