ssp_iio_sensor.h 1.7 KB

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