sysfs.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. */
  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. };
  26. #define to_iio_dev_attr(_dev_attr) \
  27. container_of(_dev_attr, struct iio_dev_attr, dev_attr)
  28. ssize_t iio_read_const_attr(struct device *dev,
  29. struct device_attribute *attr,
  30. char *len);
  31. /**
  32. * struct iio_const_attr - constant device specific attribute
  33. * often used for things like available modes
  34. * @string: attribute string
  35. * @dev_attr: underlying device attribute
  36. */
  37. struct iio_const_attr {
  38. const char *string;
  39. struct device_attribute dev_attr;
  40. };
  41. #define to_iio_const_attr(_dev_attr) \
  42. container_of(_dev_attr, struct iio_const_attr, dev_attr)
  43. /* Some attributes will be hard coded (device dependent) and not require an
  44. address, in these cases pass a negative */
  45. #define IIO_ATTR(_name, _mode, _show, _store, _addr) \
  46. { .dev_attr = __ATTR(_name, _mode, _show, _store), \
  47. .address = _addr }
  48. #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
  49. struct iio_dev_attr iio_dev_attr_##_name \
  50. = IIO_ATTR(_name, _mode, _show, _store, _addr)
  51. #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
  52. struct iio_dev_attr iio_dev_attr_##_vname \
  53. = IIO_ATTR(_name, _mode, _show, _store, _addr)
  54. #define IIO_CONST_ATTR(_name, _string) \
  55. struct iio_const_attr iio_const_attr_##_name \
  56. = { .string = _string, \
  57. .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
  58. #define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
  59. struct iio_const_attr iio_const_attr_##_vname \
  60. = { .string = _string, \
  61. .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
  62. /* Generic attributes of onetype or another */
  63. /**
  64. * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
  65. * @_mode: sysfs file mode/permissions
  66. * @_show: output method for the attribute
  67. * @_store: input method for the attribute
  68. **/
  69. #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
  70. IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
  71. /**
  72. * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
  73. * @_show: output method for the attribute
  74. *
  75. * May be mode dependent on some devices
  76. **/
  77. #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
  78. IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
  79. /**
  80. * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
  81. * @_string: frequency string for the attribute
  82. *
  83. * Constant version
  84. **/
  85. #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
  86. IIO_CONST_ATTR(sampling_frequency_available, _string)
  87. #define IIO_DEV_ATTR_TEMP_RAW(_show) \
  88. IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
  89. #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
  90. IIO_CONST_ATTR(in_temp_offset, _string)
  91. #define IIO_CONST_ATTR_TEMP_SCALE(_string) \
  92. IIO_CONST_ATTR(in_temp_scale, _string)
  93. #endif /* _INDUSTRIAL_IO_SYSFS_H_ */