ssp_iio_sensor.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __SSP_IIO_SENSOR_H__
  3. #define __SSP_IIO_SENSOR_H__
  4. #define SSP_CHANNEL_AG(_type, _mod, _index) \
  5. { \
  6. .type = _type,\
  7. .modified = 1,\
  8. .channel2 = _mod,\
  9. .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
  10. .scan_index = _index,\
  11. .scan_type = {\
  12. .sign = 's',\
  13. .realbits = 16,\
  14. .storagebits = 16,\
  15. .shift = 0,\
  16. .endianness = IIO_LE,\
  17. },\
  18. }
  19. /* It is defined here as it is a mixed timestamp */
  20. #define SSP_CHAN_TIMESTAMP(_si) { \
  21. .type = IIO_TIMESTAMP, \
  22. .channel = -1, \
  23. .scan_index = _si, \
  24. .scan_type = { \
  25. .sign = 's', \
  26. .realbits = 64, \
  27. .storagebits = 64, \
  28. }, \
  29. }
  30. #define SSP_MS_PER_S 1000
  31. #define SSP_INVERTED_SCALING_FACTOR 1000000U
  32. #define SSP_FACTOR_WITH_MS \
  33. (SSP_INVERTED_SCALING_FACTOR * SSP_MS_PER_S)
  34. int ssp_common_buffer_postenable(struct iio_dev *indio_dev);
  35. int ssp_common_buffer_postdisable(struct iio_dev *indio_dev);
  36. int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
  37. unsigned int len, int64_t timestamp);
  38. /* Converts time in ms to frequency */
  39. static inline void ssp_convert_to_freq(u32 time, int *integer_part,
  40. int *fractional)
  41. {
  42. if (time == 0) {
  43. *fractional = 0;
  44. *integer_part = 0;
  45. return;
  46. }
  47. *integer_part = SSP_FACTOR_WITH_MS / time;
  48. *fractional = *integer_part % SSP_INVERTED_SCALING_FACTOR;
  49. *integer_part = *integer_part / SSP_INVERTED_SCALING_FACTOR;
  50. }
  51. /* Converts frequency to time in ms */
  52. static inline int ssp_convert_to_time(int integer_part, int fractional)
  53. {
  54. u64 value;
  55. value = (u64)integer_part * SSP_INVERTED_SCALING_FACTOR + fractional;
  56. if (value == 0)
  57. return 0;
  58. return div64_u64((u64)SSP_FACTOR_WITH_MS, value);
  59. }
  60. #endif /* __SSP_IIO_SENSOR_H__ */