sysfs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* The industrial I/O core
  2. *
  3. *Copyright (c) 2008 Jonathan Cameron
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * General attributes
  10. */
  11. #ifndef _INDUSTRIAL_IO_SYSFS_H_
  12. #define _INDUSTRIAL_IO_SYSFS_H_
  13. struct iio_chan_spec;
  14. /**
  15. * struct iio_dev_attr - iio specific device attribute
  16. * @dev_attr: underlying device attribute
  17. * @address: associated register address
  18. * @l: list head for maintaining list of dynamically created attrs
  19. * @c: specification for the underlying channel
  20. */
  21. struct iio_dev_attr {
  22. struct device_attribute dev_attr;
  23. u64 address;
  24. struct list_head l;
  25. struct iio_chan_spec const *c;
  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_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
  50. struct iio_dev_attr iio_dev_attr_##_name \
  51. = IIO_ATTR(_name, _mode, _show, _store, _addr)
  52. #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
  53. struct iio_dev_attr iio_dev_attr_##_vname \
  54. = IIO_ATTR(_name, _mode, _show, _store, _addr)
  55. #define IIO_CONST_ATTR(_name, _string) \
  56. struct iio_const_attr iio_const_attr_##_name \
  57. = { .string = _string, \
  58. .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
  59. #define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
  60. struct iio_const_attr iio_const_attr_##_vname \
  61. = { .string = _string, \
  62. .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
  63. /* Generic attributes of onetype or another */
  64. /**
  65. * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
  66. * @_mode: sysfs file mode/permissions
  67. * @_show: output method for the attribute
  68. * @_store: input method for the attribute
  69. **/
  70. #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
  71. IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
  72. /**
  73. * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
  74. * @_show: output method for the attribute
  75. *
  76. * May be mode dependent on some devices
  77. **/
  78. #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
  79. IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
  80. /**
  81. * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
  82. * @_string: frequency string for the attribute
  83. *
  84. * Constant version
  85. **/
  86. #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
  87. IIO_CONST_ATTR(sampling_frequency_available, _string)
  88. /**
  89. * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times
  90. * @_show: output method for the attribute
  91. **/
  92. #define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \
  93. IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0)
  94. /**
  95. * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times
  96. * @_string: frequency string for the attribute
  97. *
  98. * Constant version
  99. **/
  100. #define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \
  101. IIO_CONST_ATTR(integration_time_available, _string)
  102. #define IIO_DEV_ATTR_TEMP_RAW(_show) \
  103. IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
  104. #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
  105. IIO_CONST_ATTR(in_temp_offset, _string)
  106. #define IIO_CONST_ATTR_TEMP_SCALE(_string) \
  107. IIO_CONST_ATTR(in_temp_scale, _string)
  108. #endif /* _INDUSTRIAL_IO_SYSFS_H_ */